Skip to content

TD-5304: a stdio MCP server's environment is an allow-list - #130

Merged
captcrock merged 1 commit into
mainfrom
td/5304-mcp-env-allowlist
Nov 24, 2026
Merged

captcrock merged 1 commit into
mainfrom
td/5304-mcp-env-allowlist

Conversation

@captcrock

Copy link
Copy Markdown
Contributor

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:

  • the MCP SDKs' own default list for its operating system, copied from the TypeScript SDK's DEFAULT_INHERITED_ENV_VARS (read from the installed package). On POSIX that is HOME LOGNAME PATH SHELL TERM USER; on Windows it is 18 names.
  • LANG, LANGUAGE, every LC_*, TMPDIR and TZ (on Windows, TMP and TZ).
  • HTTP(S)_PROXY, NO_PROXY and ALL_PROXY in either case, when the value carries no password.
  • then the names this server lists in the new mcp.servers.<id>.inherit_env, passed unfiltered,
  • and its own env values, 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

  • Settings keeps inherit_env while the command, transport and host stay the same, and drops it otherwise (the parity tests cover this).
  • A server that fails to start now says to look at inherit_env.
  • The docs table and config help are updated.

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), plus test_mcp_secrets.py::TestSpawn and test_mcp_config_parity.py updated. Full core suite: 9051 passed. ruff and mypy are clean. Release scan: 0 hits.

🤖 Generated with Claude Code

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>
@captcrock
captcrock merged commit e756bf7 into main Nov 24, 2026
4 checks passed
@captcrock
captcrock deleted the td/5304-mcp-env-allowlist branch November 24, 2026 17:12
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.

1 participant