nanocoder
nanocoder copied to clipboard
[Bug] MCP stdio servers receive the entire parent environment as soon as an `env` is configured
Description
With no env set, the MCP SDK starts a stdio server with a small safe set of variables. As soon as a server config has any env entry, Nanocoder passes {...process.env, ...server.env}, so the server also gets every API key and token in the parent environment. Servers supplied by an ACP client always get the full environment, because the client's empty env list becomes {}.
Environment
- OS: Windows 11 Home 10.0.26300
- Node version: v22.22.3
- Nanocoder version: 1.32.0 (built from main at eb7dee57)
- Provider: Not provider-specific
- Model: Not model-specific
Steps to Reproduce
- Set a variable such as
NC_VERIFY_SECRET_KEY=parent-secret-valuein the shell that starts Nanocoder. - Call
TransportFactory.createTransport({name: 'srv', transport: 'stdio', command: 'node', env: {FOO: 'bar'}}). - Read the env the transport will pass to the child (
transport._serverParams.env).
Expected Behavior
The server gets the SDK's safe default environment plus the configured env. NC_VERIFY_SECRET_KEY is not included.
Actual Behavior
The server env holds the 117 variables of the parent process, including the secret one.
Logs/Screenshots
env.FOO = "bar"
'NC_VERIFY_SECRET_KEY' in env -> true (server env carries 117 parent variables)
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] I can reproduce this issue consistently
- [x] This issue occurs with the latest version of nanocoder (main)
Suggested fix:
source/mcp/transport-factory.ts:129:env: server.env ? {...process.env, ...server.env} : undefined. Spread the SDK'sgetDefaultEnvironment()instead ofprocess.env(or only the variables the user listed).source/acp/acp-capabilities.ts:122:toRecord(server.env)is{}when empty, which is truthy. Passundefinedwhen there are no entries.- Add a test that a secret in
process.envdoes not reach the server env. - This is a design decision for you: some users may rely on the full environment, so consider an opt-in flag.