Repository navigation
Let MCP registry env override inherited parent keys - #344
Merged
Merged
Conversation
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>
This was referenced Sep 16, 2026
…rrides # Conflicts: # CHANGELOG.md
tylerreckart
marked this pull request as ready for review
September 21, 2026 12:59
tylerreckart
enabled auto-merge (squash)
September 21, 2026 12:59
…rrides # Conflicts: # CHANGELOG.md
…rrides # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
MCP subprocess spawn stripped secret-shaped parent keys, then appended registry
env_extra. glibc and macOSgetenv(andexecvpPATH search) use the firstKEY=inenviron.Non-secret parent keys that operators also set in
mcp_servers.json—PATH,NODE_ENV,HTTP_PROXY,PLAYWRIGHT_BROWSERS_PATHif already in the host env — stayed on the parent value.printenv KEYand Node/C children that callgetenvignored 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_extrasets, then appendenv_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_PROBEreturnsfrom-registrywhen the parent hasfrom-parent. Existing secret-strip +env_extrapass-through case unchanged. 2 env cases locally; ASan/UBSan driver clean on those cases. Pre-existingSubprocess: terminate is idempotentSIGTERM 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.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.jsonenvfor keys that already exist in the arbiter process environment.Previously the child inherited a scrubbed copy of the parent
environand appended registryenv_extra, producing duplicateKEY=entries. On glibc/macOS,getenv,execvpPATH lookup, and Node’sprocess.envuse the first match, so operator overrides likePATH,NODE_ENV,HTTP_PROXY, orPLAYWRIGHT_BROWSERS_PATHwere 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 appendsenv_extraso the registry value is the only copy. Docs indocs/concepts/mcp.mdandSubprocesscomments describe merge/override semantics;unit_mcpadds aprintenvregression test.Reviewed by Cursor Bugbot for commit 44f9c3f. Bugbot is set up for automated code reviews on this repo. Configure here.