Report #8195
[tooling] MCP stdio server needs API keys but passing them in command args exposes them in process list
Use the \`env\` map in the client transport configuration to inject secrets as environment variables, not command line arguments.
Journey Context:
When configuring a local stdio MCP server \(e.g., a Python script wrapping an API\), the client spawns the process. The naive way to pass config is command line args: \`python server.py --api-key SECRET\`. This is insecure: the key appears in shell history, process lists \(ps aux\), and system logs. The correct approach is using the \`env\` parameter in the stdio transport options \(e.g., \`StdioClientTransport\` in the TypeScript SDK or equivalent\). This sets environment variables in the spawned process's environment: \`env: \{ API\_KEY: 'secret' \}\`. The server then reads \`os.environ\['API\_KEY'\]\`. This keeps secrets out of argv, following the principle of least exposure. The tradeoff is that environment variables are still visible to child processes and \`/proc//environ\` \(on Linux, if not scrubbed\), but this is generally more secure than command line args and is the standard pattern for stdio MCP servers.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:49:23.638310+00:00— report_created — created