Repository navigation
TD-5304: a stdio MCP server's environment is an allow-list - #130
Merged
Merged
Conversation
TD-5267 scrubbed secret-shaped names from the daemon's environment before a server got it, a deny-list that let any name nobody thought of through. A server now starts with the MCP SDKs' own default list for its operating system (read from the TypeScript SDK package), plus the locale, time zone, temp folder and a password-free proxy, then the names it asks for in its own inherit_env, then its own env values. An exported shell function is never passed. Settings keeps inherit_env while the command, transport and host stay the same. Checked with real servers on Linux: a Python server launched with uv run, and a Node server on the official TypeScript SDK, which saw only the allow-listed names. macOS and Windows rely on the SDKs' lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Owner decision #8, stage 2. Stage 1 was the TD-5267 scrub.
Before: a stdio MCP server got the daemon's environment minus secret-shaped names. That is a deny-list, so any variable whose name nobody thought of went to every server.
Now a server starts with:
DEFAULT_INHERITED_ENV_VARS(read from the installed package). On POSIX that isHOME LOGNAME PATH SHELL TERM USER; on Windows it is 18 names.LANG,LANGUAGE, everyLC_*,TMPDIRandTZ(on Windows,TMPandTZ).HTTP(S)_PROXY,NO_PROXYandALL_PROXYin either case, when the value carries no password.mcp.servers.<id>.inherit_env, passed unfiltered,envvalues, last.A value that is an exported shell function (starting with
()) is never passed, as the SDKs do. On Windows, names match in any case.Also changed
inherit_envwhile the command, transport and host stay the same, and drops it otherwise (the parity tests cover this).inherit_env.Runtime check (Linux): real servers start under the allowlist. One is a Python server launched with
uv run. The other is a Node server on the official TypeScript SDK, which reported seeing only the allowlisted names; an API key and an unlisted variable set in the daemon did not reach it.Not tried: macOS and Windows with real servers. CI is Linux-only. Those systems use the SDKs' own lists, the environment SDK-based clients already start servers with there.
Tests:
test_mcp_child_env.py(new), plustest_mcp_secrets.py::TestSpawnandtest_mcp_config_parity.pyupdated. Full core suite: 9051 passed. ruff and mypy are clean. Release scan: 0 hits.🤖 Generated with Claude Code