Skip to content

feat(mcp): add per-entrypoint proxy support for MCP servers#279

Merged
nanbingxyz merged 4 commits intonanbingxyz:mainfrom
HmbleCreator:main
Jun 30, 2025
Merged

feat(mcp): add per-entrypoint proxy support for MCP servers#279
nanbingxyz merged 4 commits intonanbingxyz:mainfrom
HmbleCreator:main

Conversation

@HmbleCreator
Copy link
Copy Markdown
Contributor

@HmbleCreator HmbleCreator commented Jun 29, 2025

Summary

This PR implements per-entrypoint proxy support for MCP servers, addressing #259. Users can now specify a proxy for each entrypoint/server individually, enabling mixed proxy and direct connections within the same app instance.


What’s Changed

  • Type Update:

    • Added an optional proxy field to the IMCPServer interface (src/types/mcp.d.ts).
  • Config Update:

    • Example usage of the new proxy field in src/mcp.config.ts.
  • Activation Logic:

    • For process-based entrypoints, if proxy is set, the environment will include HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY.
    • For HTTP/SSE entrypoints, a clear TODO is left for future support (pending SDK/transport capability).

How it Works

  • Process-based entrypoints:
    If a server config includes a proxy field, the proxy is injected as environment variables when the process is started.
    No breaking changes for users who do not specify a proxy.

  • HTTP/SSE entrypoints:
    The code is ready to pass a proxy option to the transport if/when the SDK supports it.
    Currently, this is a no-op, but the code is structured for easy future extension.


Why

  • Some APIs/models require a proxy, while others do not.
  • This change allows users to configure proxies on a per-entrypoint basis, as requested in [Feature Request] Proxy for entrypoint #259.
  • The solution is non-breaking and future-proof.

Next Steps / Notes

  • Full HTTP/SSE proxy support will require SDK/transport changes or extension.
  • UI support for proxy configuration can be added in a future PR if desired.

Closes #259


Summary by CodeRabbit

  • New Features

    • Added support for proxy configuration when connecting to local MCP servers.
    • Proxy settings can now be specified for the AppleNotes server.
    • Enabled HTTPS proxy support for multiple chat service providers to route requests through specified proxies.
  • Chores

    • Updated configuration and server definitions to include an optional proxy property.
    • Updated API base URLs and added example proxy configurations for various service providers.

- Add optional `proxy` field to IMCPServer interface
- Allow specifying a proxy for each server in mcp.config.ts
- Inject proxy as HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY for process-based entrypoints
- Prepare activation logic for future HTTP/SSE proxy support (pending SDK capability)
- Non-breaking: servers without a proxy field are unaffected

Closes nanbingxyz#259
@recurseml
Copy link
Copy Markdown

recurseml Bot commented Jun 29, 2025

✨ No issues found! Your code is sparkling clean! ✨

Need help? Join our Discord for support!
https://discord.gg/NCpkJ4kF

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 29, 2025

"""

Walkthrough

Proxy configuration support has been introduced for MCP server entrypoints and chat service providers. The configuration schema, type definitions, and sample server config now include an optional proxy property. When launching a local MCP server, the process environment is extended with proxy variables if specified. Chat services use the proxy setting to route HTTP requests via an HTTPS proxy agent. HTTP transport code contains a placeholder for future proxy support.

Changes

File(s) Change Summary
src/types/mcp.d.ts, src/providers/types.ts Added optional proxy?: string property to IMCPServer interface and IChatProviderConfig interface.
src/mcp.config.ts, src/providers/*.ts Added example proxy property with value 'http://localhost:8080' to multiple server and provider configs; updated some API base URLs and fixed minor string formatting.
src/main/mcp.ts Reads proxy from config; sets HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY environment variables for local server process if specified; added commented placeholder for HTTP transport proxy.
src/intellichat/services/*.ts Added HTTPS proxy agent support in makeRequest methods for Anthropic, Google, OpenAI chat services; validates proxy URL and passes agent to fetch calls.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MCPClient
    participant MCPServer (Local)
    participant Proxy

    User->>MCPClient: Activate server (with proxy in config)
    MCPClient->>MCPServer (Local): Spawn process with proxy env vars (HTTP_PROXY, etc.)
    MCPServer (Local)->>Proxy: Outbound requests use proxy settings
    Proxy->>MCPServer (Local): Forwards traffic
Loading
sequenceDiagram
    participant ChatClient
    participant ChatService
    participant Proxy
    participant RemoteAPI

    ChatClient->>ChatService: makeRequest with proxy config
    ChatService->>Proxy: Create HTTPS proxy agent (if proxy set)
    ChatService->>RemoteAPI: fetch request via proxy agent
    RemoteAPI-->>ChatService: Response
    ChatService-->>ChatClient: Return response
Loading

Assessment against linked issues

Objective Addressed Explanation
Add proxy configuration support to entrypoints (server config, #259)
Pass proxy settings via environment when launching local MCP server (#259)
Update type definitions to include proxy property (#259)
Add proxy placeholder for HTTP transport (future support, #259)

Poem

🐇 Through tunnels deep, a proxy shines,
Guiding calls through secret lines.
AppleNotes and chat unite,
With proxy paths to set things right.
Configs updated, agents spun,
The rabbit hops—new journeys begun! 🌐✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-30T13_17_57_590Z-debug-0.log


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4683262 and 1e899b8.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • package.json (1 hunks)
  • src/intellichat/services/AnthropicChatService.ts (3 hunks)
  • src/intellichat/services/GoogleChatService.ts (2 hunks)
  • src/intellichat/services/OpenAIChatService.ts (3 hunks)
  • src/providers/Azure.ts (2 hunks)
  • src/providers/LMStudio.ts (3 hunks)
  • src/providers/Ollama.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/providers/Ollama.ts
  • src/intellichat/services/OpenAIChatService.ts
  • src/intellichat/services/GoogleChatService.ts
  • src/intellichat/services/AnthropicChatService.ts
  • src/providers/Azure.ts
  • src/providers/LMStudio.ts
🔇 Additional comments (1)
package.json (1)

112-113: Re-evaluate loosening @types/node to a caret range

Changing from an exact "20.2.5" to "^20.2.5" allows any newer 20.x release to be installed. While breaking changes are rare, upstream type regressions do occasionally slip through and could subtly break the Electron build or MCP typings.

If reproducible builds are critical, consider pinning and relying on your dependency-update bot to bump deliberately. Otherwise, ensure CI is run with a clean cache to compile against the latest @types/node@20 before merging.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@HmbleCreator HmbleCreator marked this pull request as ready for review June 29, 2025 15:44
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/mcp.config.ts (1)

12-12: Consider adding a comment to clarify this is an example configuration.

The hardcoded proxy URL http://localhost:8080 serves as a good example, but could cause confusion or connection issues if users copy this configuration without understanding it's demonstrative.

Consider adding a comment to make this clearer:

      isActive: false,
+     // Example proxy configuration - replace with your actual proxy URL
      proxy: 'http://localhost:8080',
src/main/mcp.ts (1)

274-280: Correct implementation of proxy environment variables.

The conditional spread operator properly sets standard proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY) when a proxy is configured. This follows Node.js conventions for proxy configuration.

Consider adding basic URL validation for the proxy field to catch obvious configuration errors early:

        const mergedEnv = {
          ...getDefaultEnvironment(),
          ...env,
          PATH: process.env.PATH,
          ...(proxy
            ? {
+               // Basic validation: ensure proxy URL looks valid
+               ...((() => {
+                 try {
+                   new URL(proxy);
+                 } catch (error) {
+                   logging.error(`Invalid proxy URL: ${proxy}`, error);
+                   throw new Error(`Invalid proxy URL: ${proxy}`);
+                 }
+                 return {};
+               })()),
                HTTP_PROXY: proxy,
                HTTPS_PROXY: proxy,
                ALL_PROXY: proxy,
              }
            : {}),
        };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 68fa62c and 58c01bf.

📒 Files selected for processing (3)
  • src/main/mcp.ts (3 hunks)
  • src/mcp.config.ts (1 hunks)
  • src/types/mcp.d.ts (1 hunks)
🔇 Additional comments (3)
src/types/mcp.d.ts (1)

14-14: LGTM! Clean type definition with helpful documentation.

The optional proxy field is properly typed and includes a clear comment with an example URL format.

src/main/mcp.ts (2)

233-234: Good documentation of future HTTP transport proxy support.

The comments clearly indicate that HTTP/SSE proxy support is planned but not yet implemented. This helps set proper expectations.

Also applies to: 239-242


265-265: Clean destructuring to extract proxy configuration.

The destructuring correctly extracts the proxy field alongside other server configuration properties.

- Add optional `proxy` field to IMCPServer interface
- Allow specifying a proxy for each server in mcp.config.ts
- Inject proxy as HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY for process-based entrypoints
- Add URL validation to catch invalid proxy configurations early
- Prepare activation logic for future HTTP/SSE proxy support (pending SDK capability)
- Non-breaking: servers without a proxy field are unaffected

Closes nanbingxyz#259
@nanbingxyz
Copy link
Copy Markdown
Owner

Thanks for your contribution! 🙌 Great to see improvements around proxy support.

Quick note regarding the proxied models scope: As mentioned in #259, we should also consider proxies for model providers (like OpenAI), not just the MCP server. This helps users in regions where services like api.openai.com might be inaccessible directly. Could we expand this to cover those cases too?

Really appreciate you driving this forward! 🚀

@HmbleCreator
Copy link
Copy Markdown
Contributor Author

Thanks for your contribution! 🙌 Great to see improvements around proxy support.

Quick note regarding the proxied models scope: As mentioned in #259, we should also consider proxies for model providers (like OpenAI), not just the MCP server. This helps users in regions where services like api.openai.com might be inaccessible directly. Could we expand this to cover those cases too?

Really appreciate you driving this forward! 🚀

I have added support for OpenAI models. Do you want to extend this to other providers (Anthropic, Google, etc.)?
And do you also want to update the documentation or UI?

@nanbingxyz
Copy link
Copy Markdown
Owner

Thanks for your contribution! 🙌 Great to see improvements around proxy support.
Quick note regarding the proxied models scope: As mentioned in #259, we should also consider proxies for model providers (like OpenAI), not just the MCP server. This helps users in regions where services like api.openai.com might be inaccessible directly. Could we expand this to cover those cases too?
Really appreciate you driving this forward! 🚀

I have added support for OpenAI models. Do you want to extend this to other providers (Anthropic, Google, etc.)? And do you also want to update the documentation or UI?

I noticed it adds support for the mcp server proxy, but I don't see specific OpenAI model support yet.

Let's focus first on finalizing the core proxy mechanism. My thought is to allow setting a proxy per provider (OpenAI, Anthropic, etc.).

We can handle storing the proxy configs and updating the UI separately in a follow-up. Does that approach work for you?

…ders

- Added `proxy` field with example and documentation comment to all provider config files (OpenAI, Anthropic, Google, Azure, Baidu, Moonshot, Mistral, DeepSeek, Ollama, LMStudio, Grok, Doubao, 5ire)
- Ensured all provider configs are type-safe and match ProviderType union
- Fixed linter/type error for 5ire provider by using correct name

This enables users to easily set up per-provider proxying for any supported model provider.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (5)
src/intellichat/services/AnthropicChatService.ts (1)

247-256: Consider improving error logging and validation.

The proxy implementation is solid, but consider these improvements:

  1. Logging: console.error may not be suitable for production environments where structured logging is preferred.
  2. Validation: Consider validating the proxy URL format before creating the HttpsProxyAgent.
// Proxy support: if provider.proxy is set, use https-proxy-agent
let agent;
if (provider.proxy) {
+  // Basic URL validation
+  if (!provider.proxy.startsWith('http://') && !provider.proxy.startsWith('https://')) {
+    throw new Error(`Invalid proxy URL format: ${provider.proxy}`);
+  }
  try {
    agent = new HttpsProxyAgent(provider.proxy);
  } catch (error) {
-    console.error(`Invalid proxy URL for provider: ${provider.proxy}`, error);
+    debug(`Invalid proxy URL for provider: ${provider.proxy}`, error);
    throw error;
  }
}
src/intellichat/services/GoogleChatService.ts (1)

269-278: Consistent implementation with room for improvement.

The proxy implementation follows the same pattern as AnthropicChatService, which is good for consistency. However, the same improvement opportunities apply here:

  1. Logging: Consider using the existing debug logger instead of console.error.
  2. Validation: Add URL format validation before HttpsProxyAgent creation.
// Proxy support: if provider.proxy is set, use https-proxy-agent
let agent;
if (provider.proxy) {
+  // Basic URL validation
+  if (!provider.proxy.startsWith('http://') && !provider.proxy.startsWith('https://')) {
+    throw new Error(`Invalid proxy URL format: ${provider.proxy}`);
+  }
  try {
    agent = new HttpsProxyAgent(provider.proxy);
  } catch (error) {
-    console.error(`Invalid proxy URL for provider: ${provider.proxy}`, error);
+    debug(`Invalid proxy URL for provider: ${provider.proxy}`, error);
    throw error;
  }
}
src/providers/Doubao.ts (1)

265-266: Consider using HTTPS for the proxy example.

The proxy configuration example uses HTTP instead of HTTPS. For security best practices, consider using HTTPS in the example.

// Example proxy configuration - replace with your actual proxy URL
-proxy: 'http://localhost:8080',
+proxy: 'https://localhost:8080',
src/providers/Azure.ts (1)

267-268: Consider HTTPS for security in proxy example.

The proxy example uses HTTP which may not align with security best practices.

// Example proxy configuration - replace with your actual proxy URL
-proxy: 'http://localhost:8080',
+proxy: 'https://localhost:8080',
src/providers/Fire.ts (1)

200-201: Use HTTPS for proxy example security.

The proxy example uses HTTP instead of HTTPS, which may not reflect security best practices.

// Example proxy configuration - replace with your actual proxy URL
-proxy: 'http://localhost:8080',
+proxy: 'https://localhost:8080',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d51645b and 4683262.

📒 Files selected for processing (17)
  • src/intellichat/services/AnthropicChatService.ts (3 hunks)
  • src/intellichat/services/GoogleChatService.ts (2 hunks)
  • src/intellichat/services/OpenAIChatService.ts (3 hunks)
  • src/providers/Anthropic.ts (1 hunks)
  • src/providers/Azure.ts (2 hunks)
  • src/providers/Baidu.ts (1 hunks)
  • src/providers/DeepSeek.ts (1 hunks)
  • src/providers/Doubao.ts (1 hunks)
  • src/providers/Fire.ts (2 hunks)
  • src/providers/Google.ts (1 hunks)
  • src/providers/Grok.ts (1 hunks)
  • src/providers/LMStudio.ts (1 hunks)
  • src/providers/Mistral.ts (1 hunks)
  • src/providers/Moonshot.ts (1 hunks)
  • src/providers/Ollama.ts (1 hunks)
  • src/providers/OpenAI.ts (2 hunks)
  • src/providers/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • src/providers/types.ts
  • src/providers/Anthropic.ts
  • src/providers/Baidu.ts
  • src/providers/Google.ts
  • src/providers/Moonshot.ts
  • src/providers/DeepSeek.ts
  • src/providers/Grok.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/intellichat/services/OpenAIChatService.ts (1)
src/main/logging.ts (1)
  • error (38-40)
🔇 Additional comments (16)
src/providers/Ollama.ts (1)

6-7: LGTM: Proxy configuration follows established pattern.

The proxy configuration is consistent with other provider files and includes helpful documentation.

src/providers/OpenAI.ts (2)

194-194: LGTM: Quote consistency improvement.

Good fix replacing curly quotes with standard ASCII quotes for better consistency.


261-262: LGTM: Proxy configuration follows established pattern.

The proxy configuration is consistent with other provider files and includes helpful documentation.

src/providers/Mistral.ts (2)

105-105: LGTM: Apostrophe consistency improvement.

Good fix replacing the typographic apostrophe with a standard ASCII apostrophe for better consistency.


112-113: LGTM: Proxy configuration follows established pattern.

The proxy configuration is consistent with other provider files and includes helpful documentation.

src/providers/LMStudio.ts (1)

6-7: LGTM: Proxy configuration follows established pattern.

The proxy configuration is consistent with other provider files and includes helpful documentation.

src/intellichat/services/OpenAIChatService.ts (2)

21-21: LGTM: Proper import for proxy support.

Correct import of HttpsProxyAgent for proxy functionality.


286-286: LGTM: Correct conditional agent inclusion.

The conditional spread operator correctly includes the agent only when it's defined.

src/intellichat/services/AnthropicChatService.ts (2)

27-27: LGTM: Proxy agent import added.

The import of HttpsProxyAgent is correctly placed and aligns with the proxy support implementation.


266-266: LGTM: Conditional agent application.

The conditional spread operator correctly applies the agent only when it exists, maintaining backward compatibility.

src/intellichat/services/GoogleChatService.ts (2)

28-28: LGTM: Consistent proxy agent import.

The import matches the pattern established in AnthropicChatService, maintaining consistency across chat services.


286-286: LGTM: Consistent conditional agent application.

The conditional spread operator usage matches other services, ensuring consistency across the codebase.

src/providers/Doubao.ts (1)

264-264: Confirm Doubao API endpoint

The HEAD request to https://api.doubao.com/v1 did not return a response. Please verify that this new base URL is correct and accessible—e.g., try a GET against the root or consult the API docs.

• File: src/providers/Doubao.ts
• Line: 264

Also consider whether the proxy example should use https:// instead of http:// for consistency and security.

src/providers/Azure.ts (1)

194-194: LGTM: Typography correction.

Good fix replacing curly quotes with straight quotes for better text consistency.

src/providers/Fire.ts (2)

158-158: LGTM: Typography correction.

Good consistency improvement replacing curly quotes with straight quotes.


199-199: Manual verification required: New API domain unreachable

The sandbox environment failed to resolve api.5ire.com, so we can’t confirm availability of the new endpoint. Please verify:

  • That https://api.5ire.com/v1 is the correct, live API base URL.
  • DNS records for api.5ire.com are published and propagating.
  • The service is up and responding (e.g., via dig, nslookup, or direct curl -I from a network with internet access).

Comment thread src/providers/Ollama.ts
Comment thread src/providers/LMStudio.ts
Comment thread src/intellichat/services/OpenAIChatService.ts
Comment thread src/providers/Azure.ts Outdated
…esolve process type error

- Dynamically set apiBase in Azure provider using AZURE_RESOURCE_NAME and AZURE_DEPLOYMENT_ID environment variables
- Added instructions to install @types/node to resolve process type error
- Updated proxy fallback logic and placeholder consistency in Ollama and LMStudio providers
- Improved proxy error handling in OpenAI, Anthropic, and Google chat services
@nanbingxyz nanbingxyz merged commit 4f6e05e into nanbingxyz:main Jun 30, 2025
1 check passed
@nanbingxyz
Copy link
Copy Markdown
Owner

Cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Proxy for entrypoint

2 participants