Skip to content

fix(proxy): omit bracketed [::1] from child process NO_PROXY#2186

Open
panandicoding wants to merge 3 commits into
MoonshotAI:mainfrom
panandicoding:fix/no-proxy-bracketed-ipv6-child
Open

fix(proxy): omit bracketed [::1] from child process NO_PROXY#2186
panandicoding wants to merge 3 commits into
MoonshotAI:mainfrom
panandicoding:fix/no-proxy-bracketed-ipv6-child

Conversation

@panandicoding

@panandicoding panandicoding commented Jul 25, 2026

Copy link
Copy Markdown

Related Issue

Closes #1931

Description

The bracketed IPv6 loopback [::1] in NO_PROXY is only needed in-process for undici's EnvHttpProxyAgent (which mis-parses a bare ::1 as host : port 1). However, proxyEnvForChild() and reconcileChildNoProxy() were propagating the same value verbatim into child processes (stdio MCP servers).

Python's httpx parses all://[::1] and treats :1] as the port, raising httpx.InvalidURL — crashing any Python-based MCP server when a proxy is configured.

Fix

  • Introduce LOOPBACK_NO_PROXY_CHILD (without [::1]) alongside the existing LOOPBACK_NO_PROXY.
  • Add resolveNoProxyForChild() which uses the child-safe loopback list.
  • proxyEnvForChild() and reconcileChildNoProxy() now call resolveNoProxyForChild() instead of resolveNoProxy().
  • The in-process resolveNoProxy() (used by createProxyDispatcher for undici) is unchanged — it still includes [::1].

Applied to both packages/agent-core and packages/agent-core-v2 (identical proxy utilities).

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run pnpm changeset to add a changeset.
  • I have updated user-facing docs in docs/.

The bracketed IPv6 loopback [::1] in NO_PROXY is only needed in-process for undici's EnvHttpProxyAgent. When propagated to child processes (stdio MCP servers), Python's httpx parses �ll://[::1] and treats :1] as the port, raising httpx.InvalidURL and crashing any Python-based MCP server when a proxy is configured.

Introduce LOOPBACK_NO_PROXY_CHILD (without [::1]) and resolveNoProxyForChild() used by proxyEnvForChild() and reconcileChildNoProxy(). The in-process resolveNoProxy() is unchanged.

Closes MoonshotAI#1931
@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cc7deaa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c51d246eae

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

// proxy is configured. The bracketed form is only needed in-process for undici's
// EnvHttpProxyAgent; children rely on `NODE_USE_ENV_PROXY` (Node ≥ 22) which
// handles bare `::1` correctly.
const LOOPBACK_NO_PROXY_CHILD = ['localhost', '127.0.0.1', '::1'] as const;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the bracketed loopback for Node children

When a spawned stdio MCP server is Node and connects to an IPv6-loopback URL while HTTP_PROXY is set, this removes the only loopback entry Node recognizes. Using the repository-required Node 24.15.0 with NODE_USE_ENV_PROXY=1, NO_PROXY=::1 sent fetch('http://[::1]:...') through the proxy, while NO_PROXY=[::1] connected directly. JavaScript MCP children can therefore lose access to local IPv6 services or expose those requests to the proxy; select the value based on the child runtime rather than applying the Python workaround to every child.

AGENTS.md reference: AGENTS.md:L32-L36

Useful? React with 👍 / 👎.


const LOOPBACK_NO_PROXY = ['localhost', '127.0.0.1', '::1', '[::1]'] as const;

// Child processes (e.g. stdio MCP servers) must NOT receive the bracketed `[::1]`:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Move the new v2 comments into the module header

The scoped guide requires comments in this package to live solely in the top-of-file header, but this change adds an implementation narrative beside the constant and another function-level JSDoc above resolveNoProxyForChild. Remove these mid-file comments or consolidate only the module's externally visible responsibility into the existing header.

AGENTS.md reference: packages/agent-core-v2/AGENTS.md:L11-L14

Useful? React with 👍 / 👎.

Node children (undici via NODE_USE_ENV_PROXY) require the bracketed [::1]
to bypass the proxy for IPv6 loopback; non-Node children (Python httpx)
crash on it. Detect the command basename (node/npx/tsx/ts-node) and pass
the appropriate loopback list.

Also consolidates mid-file comments into the module header per
agent-core-v2 comment conventions.
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.

stdio MCP child env injects bracketed [::1] into NO_PROXY, crashing Python httpx-based MCP servers

1 participant