Skip to content
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

PATH lost and npx not found when proxying MCP servers because get_default_environment() is not used when user provides env in StdioServerParameters #185

Open
zhjch05 opened this issue Feb 1, 2025 · 1 comment

Comments

@zhjch05
Copy link

zhjch05 commented Feb 1, 2025

Describe the bug
In https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/stdio.py#L102

process = await anyio.open_process(
      [server.command, *server.args],
      env=server.env if server.env is not None else get_default_environment(),
      stderr=sys.stderr,
)

I wonder in the case where user specifies the env input, why get_default_environment()'s env vars are not retained? Not sure if this is a bug or left as it is intentionally.
get_default_environment() returns crucial env vars like PATH and without it I current run into a issue where I have a proxy MCP server under uv and it tries to connect to a npx based MCP server but when env vars are specified in server params then the PATH is no longer injected, resulting in npx not found error in my use case.
Can we change it to following? Not sure if this has side effects or not, if it works happy to create a PR for that. So default envs are always provided but will be overwritten by user if they want.

process = await anyio.open_process(
      [server.command, *server.args],
      env={
          **get_default_environment(),
          **(server.env or {})
      },
      stderr=sys.stderr,
)

To Reproduce
In a uvx isolated python environment, create a python client to connect to npx based pkg like @modelcontextprotocol/server-slack with env like SLACK_TEAM_ID configured, then it will raise an npx not found error.

Expected behavior
It should execute the npx based MCP server correctly.

Screenshots

Image

Desktop (please complete the following information):

  • OS: [MacOS]
  • Browser [N/A]
  • Version [14.0 (23A344)]
@zhjch05
Copy link
Author

zhjch05 commented Feb 3, 2025

discussed in #99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant