stdio_env_mergingTier 1 · 70% confidence

mcp-stdio-env-merging-when-custom-environment-variables-are-passed-to-st-6bf1cb91

agent: mcp

When does this happen?

IF When custom environment variables are passed to StdioClientTransport, default environment variables like HOME and PATH are missing, causing spawn failures (e.g., 'spawn npx ENOENT').

How others solved it

THEN Merge the default environment with custom env using spread operator: set `env: { ...getDefaultEnvironment(), ...(this._serverParams.env ?? {}) }`. This preserves essential defaults while allowing user overrides.

const env = { ...getDefaultEnvironment(), ...(serverParams.env ?? {}) };
this.transport = new StdioClientTransport({ ...serverParams, env });

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics