Skip to content

Default Environment should be appended with custom env's passed to client (instead of replacing) #216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Pdash-exceeds opened this issue Mar 23, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@Pdash-exceeds
Copy link

Describe the bug
In this line

env: this._serverParams.env ?? getDefaultEnvironment(),

To Reproduce
Steps to reproduce the behavior:

  1. Connect a stdio client without custom env (works)
  2. Connect the same client with custom env (fails because HOME, PATH and other default envs are missing when spawning the process)

Expected behavior
Both cases should pass.
env: { ...getDefaultEnvironment(), ...(this._serverParams.env ?? {}) },

Logs
file:///Users/pradeeptadash/langchain_mcp/node_modules/@langchain/mcp-adapters/dist/src/client.js:407
throw new MCPClientError(Failed to connect to stdio server "${serverName}": ${error}, serverName);
^

MCPClientError: Failed to connect to stdio server "linear-server": Error: spawn npx ENOENT
at MultiServerMCPClient.initializeStdioConnection (file:///Users/pradeeptadash/langchain_mcp/node_modules/@langchain/mcp-adapters/dist/src/client.js:407:19)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async MultiServerMCPClient.initializeConnections (file:///Users/pradeeptadash/langchain_mcp/node_modules/@langchain/mcp-adapters/dist/src/client.js:371:17)

Additional context
Add any other context about the problem here.

@jiashengguo
Copy link

@Pdash-exceeds, thanks for filing this!

Does no one use 'env'? 😂

@Pdash-exceeds
Copy link
Author

I think most people use a remote MCP so they don't use env

@xianminx
Copy link

xianminx commented Apr 2, 2025

I think most people use a remote MCP so they don't use env

this is for stdio, and I am struggling with env config for testing various local mcp servers.
#242 this is wanted.

@zerogu
Copy link

zerogu commented Apr 8, 2025

To use the Notion MCP, which requires certain environment variables, I worked around the original design by merging getDefaultEnvironment() with my own env like this:

{
  "command": "npx",
  "args": ["-y", "@suekou/mcp-notion-server"],
  "env": {
    "NOTION_API_TOKEN": "your-integration-token",
    "NOTION_MARKDOWN_CONVERSION": "true"
  }
}
import { StdioClientTransport, StdioServerParameters, getDefaultEnvironment } from '@modelcontextprotocol/sdk/client/stdio.js'

...

serverParams.env = {
    ...getDefaultEnvironment(),
    ...serverParams.env
}

this.transport = new StdioClientTransport(serverParams as StdioServerParameters)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants