Skip to content

Let MCP registry env override inherited parent keys - #344

Merged
tylerreckart merged 4 commits into
mainfrom
fix/mcp-env-extra-overrides
Sep 21, 2026
Merged

tylerreckart merged 4 commits into
mainfrom
fix/mcp-env-extra-overrides

Conversation

@cursor

@cursor cursor Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem

MCP subprocess spawn stripped secret-shaped parent keys, then appended registry env_extra. glibc and macOS getenv (and execvp PATH search) use the first KEY= in environ.

Non-secret parent keys that operators also set in mcp_servers.json — PATH, NODE_ENV, HTTP_PROXY, PLAYWRIGHT_BROWSERS_PATH if already in the host env — stayed on the parent value. printenv KEY and Node/C children that call getenv ignored the registry. Secret keys still worked because they were dropped from the parent copy first.

Fix

When building the child environment, skip inherited keys that env_extra sets, then append env_extra. The registry value is the only copy, so first-match and last-match consumers agree. Secret-shaped parent keys are still stripped; registry secrets remain operator opt-in.

Tests

unit_mcp — printenv MCP_ENV_OVERRIDE_PROBE returns from-registry when the parent has from-parent. Existing secret-strip + env_extra pass-through case unchanged. 2 env cases locally; ASan/UBSan driver clean on those cases. Pre-existing Subprocess: terminate is idempotent SIGTERM flake is unrelated.

Independently mergeable against main (0456350). Code hunks (mcp/subprocess.{h,cpp}, docs, env test after the existing strip case) auto-merge with #337/#343 (mcp/types + parse_response tests). CHANGELOG [Unreleased] will need a rebase after whichever sibling merges first.

Open in Web View Automation 

Note

Low Risk
Localized change to MCP child environment assembly with a targeted unit test; secret scrubbing and opt-in registry secrets are unchanged.

Overview
MCP subprocess spawn now honors mcp_servers.json env for keys that already exist in the arbiter process environment.

Previously the child inherited a scrubbed copy of the parent environ and appended registry env_extra, producing duplicate KEY= entries. On glibc/macOS, getenv, execvp PATH lookup, and Node’s process.env use the first match, so operator overrides like PATH, NODE_ENV, HTTP_PROXY, or PLAYWRIGHT_BROWSERS_PATH were silently ignored when the host already set them. Secret-shaped parent keys are still stripped first; registry secrets remain explicit opt-in.

The fix drops inherited entries whose names appear in env_extra, then appends env_extra so the registry value is the only copy. Docs in docs/concepts/mcp.md and Subprocess comments describe merge/override semantics; unit_mcp adds a printenv regression test.

Reviewed by Cursor Bugbot for commit 44f9c3f. Bugbot is set up for automated code reviews on this repo. Configure here.

glibc/macOS getenv uses the first KEY= in environ. Appending
env_extra after a scrubbed parent copy left PATH/NODE_ENV/etc.
stuck on the parent value. Skip inherited keys that env_extra
sets so the registry value is the only copy.

Co-authored-by: Tyler Reckart <tylerreckart@users.noreply.github.com>
@tylerreckart
tylerreckart marked this pull request as ready for review September 21, 2026 12:59
@tylerreckart
tylerreckart enabled auto-merge (squash) September 21, 2026 12:59
@tylerreckart
tylerreckart merged commit 5f291b2 into main Sep 21, 2026
6 checks passed
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.

3 participants