Skip to content

fix(core): respect NO_PROXY for network-based MCP servers#27012

Merged
cocosheng-g merged 4 commits into
google-gemini:mainfrom
cocosheng-g:issue-3340
May 14, 2026
Merged

fix(core): respect NO_PROXY for network-based MCP servers#27012
cocosheng-g merged 4 commits into
google-gemini:mainfrom
cocosheng-g:issue-3340

Conversation

@cocosheng-g
Copy link
Copy Markdown
Contributor

Summary

Fixes issue where local MCP servers (localhost/127.0.0.1) are unreachable when a global proxy is configured, even if NO_PROXY is set. Introduced a surgical, proxy-aware fetcher specifically for MCP network transports that respects NO_PROXY.

Details

  • Replaced globalThis.fetch with a localized undici.fetch using EnvHttpProxyAgent in mcp-client.ts.
  • EnvHttpProxyAgent correctly handles NO_PROXY and no_proxy environment variables.
  • The change is scoped strictly to StreamableHTTPClientTransport and SSEClientTransport initialization, ensuring zero risk to core Gemini API traffic.
  • Added type-safe response conversion to maintain compatibility with the MCP SDK.

Related Issues

Fixes #3340

How to Validate

  1. Start a local HTTP MCP server.
  2. Set HTTP_PROXY to an invalid address (e.g., http://127.0.0.1:8888).
  3. Set NO_PROXY=127.0.0.1.
  4. Run gemini chat and attempt to use a tool from the local MCP server.
  5. Verify the connection succeeds bypassing the proxy.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS

@cocosheng-g cocosheng-g requested a review from a team as a code owner May 13, 2026 18:57
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses connectivity issues for local MCP servers in environments with global proxy configurations. By integrating a specialized fetcher that respects the NO_PROXY environment variable, the changes ensure that traffic to local endpoints bypasses unnecessary proxy routing while maintaining existing error handling logic for SSE streams.

Highlights

  • Proxy Handling: Introduced a proxy-aware fetcher using undici's EnvHttpProxyAgent to ensure network-based MCP servers correctly respect NO_PROXY environment variables.
  • Connection Reliability: Resolved issues where local MCP servers (localhost/127.0.0.1) were unreachable when a global proxy was configured.
  • Compatibility: Implemented response conversion to maintain compatibility between undici fetch results and the existing MCP SDK requirements.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces proxy-aware fetching in the MCP client by utilizing undici's EnvHttpProxyAgent to respect the NO_PROXY environment variable. This change ensures that requests to local MCP servers bypass global proxies when configured. The implementation includes logic to wrap the fetch operation, conditionally using the proxy agent and converting undici responses to standard Response objects for compatibility. I have no feedback to provide.

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality labels May 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

80 tests passed successfully on gemini-3-flash-preview.

🧠 Model Steering Guidance

This PR modifies files that affect the model's behavior (prompts, tools, or instructions).

  • ⚠️ Consider adding Evals: No behavioral evaluations (evals/*.eval.ts) were added or updated in this PR. Consider adding a test case to verify the new behavior and prevent regressions.
  • 🚀 Maintainer Reminder: Please ensure that these changes do not regress results on benchmark evals before merging.

This is an automated guidance message triggered by steering logic signatures.

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/extensions Issues related to Gemini CLI extensions capability labels May 13, 2026
@cocosheng-g cocosheng-g enabled auto-merge May 14, 2026 14:56
Copy link
Copy Markdown
Contributor

@adamfweidman adamfweidman left a comment

Choose a reason for hiding this comment

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

Approved with a comment

Comment thread packages/core/src/tools/mcp-client.ts
Comment thread packages/core/src/tools/mcp-client.ts Outdated
@cocosheng-g cocosheng-g added this pull request to the merge queue May 14, 2026
@adamfweidman adamfweidman removed this pull request from the merge queue due to a manual request May 14, 2026
@cocosheng-g cocosheng-g added this pull request to the merge queue May 14, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 14, 2026
@cocosheng-g cocosheng-g added this pull request to the merge queue May 14, 2026
Merged via the queue into google-gemini:main with commit e3f2d3e May 14, 2026
29 of 32 checks passed
@cocosheng-g cocosheng-g deleted the issue-3340 branch May 14, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality area/extensions Issues related to Gemini CLI extensions capability priority/p2 Important but can be addressed in a future release. priority/p3 Backlog - a good idea but not currently a priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add the NO_PROXY env variable feature to avoid proxy calling MCP servers listening on localhost

3 participants