66
77from __future__ import annotations
88
9- import os
109from contextlib import asynccontextmanager
1110from datetime import timedelta
1211from typing import TYPE_CHECKING , Any , Literal , Protocol
@@ -69,7 +68,17 @@ class StdioConnection(TypedDict):
6968 """Command line arguments to pass to the executable."""
7069
7170 env : NotRequired [dict [str , str ] | None ]
72- """The environment to use when spawning the process."""
71+ """The environment to use when spawning the process.
72+
73+ If not specified or set to None, a subset of the default environment
74+ variables from the current process will be used.
75+
76+ Please refer to the MCP SDK documentation for details on which
77+ environment variables are included by default. The behavior
78+ varies by operating system.
79+
80+ https://github.com/modelcontextprotocol/python-sdk/blob/c47c767ff437ee88a19e6b9001e2472cb6f7d5ed/src/mcp/client/stdio/__init__.py#L51
81+ """
7382
7483 cwd : NotRequired [str | Path | None ]
7584 """The working directory to use when spawning the process."""
@@ -196,6 +205,8 @@ async def _create_stdio_session( # noqa: PLR0913
196205 command: Command to execute.
197206 args: Arguments for the command.
198207 env: Environment variables for the command.
208+ If not specified, inherits a subset of the current environment.
209+ The details are implemented in the MCP sdk.
199210 cwd: Working directory for the command.
200211 encoding: Character encoding.
201212 encoding_error_handler: How to handle encoding errors.
@@ -204,13 +215,6 @@ async def _create_stdio_session( # noqa: PLR0913
204215 Yields:
205216 An initialized ClientSession.
206217 """
207- # NOTE: execution commands (e.g., `uvx` / `npx`) require PATH envvar to be set.
208- # To address this, we automatically inject existing PATH envvar into the `env`,
209- # if it's not already set.
210- env = env or {}
211- if "PATH" not in env :
212- env ["PATH" ] = os .environ .get ("PATH" , "" )
213-
214218 server_params = StdioServerParameters (
215219 command = command ,
216220 args = args ,
0 commit comments