An MCP server works correctly when launched locally from the terminal (where API_KEY is set in the shell environment). When Claude Code launches the same server via MCP config, the server fails with 'API_KEY not set.' What is the cause?
Answer: The MCP config's stdio transport launches the server as a child process that does not inherit the terminal shell's environment — env vars must be explicitly specified in the config
When the MCP runtime launches a server via stdio transport, it forks a child process that starts with a clean environment — it does not inherit the parent shell's exports. Environment variables set in your terminal (via export or .zshrc) are not automatically available to the server process. The fix is to explicitly list required env vars in the config's env block, which the runtime injects into the child process. Claude Code does support env vars (A) — the fix is explicit injection, not a platform limitation. .env.local (C) is not read by the MCP runtime. HTTP+SSE (D) doesn't solve the env var problem — it changes the transport, not the environment injection mechanism.