modelcontextprotocol / modelcontextprotocol/python-sdk
Windows MCP SSH stdio transport closes after initialize when PROGRAMDATA is missing from inherited environment
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 31
説明
Description
On Windows, an MCP server launched through the stdio client can terminate shortly after the initialize message when the spawned process is given the SDK's restricted inherited environment.
During investigation of Windows MCP + SSH behavior, I found that PROGRAMDATA is missing from DEFAULT_INHERITED_ENV_VARS in src/mcp/client/stdio.py.
Environment
- Windows 11
- MCP Python SDK
- MCP server launched through stdio
- SSH-based MCP server
Observed behavior
The MCP SSH subprocess can close shortly after the initialize message with a transport-closed error.
The same SSH setup works when launched manually and behaves differently when the expected Windows environment is available.
Investigation
The stdio client constructs a restricted environment for spawned processes.
PROGRAMDATA was not included in the Windows inherited environment list:
DEFAULT_INHERITED_ENV_VARS = (
[
"APPDATA",
"HOMEDRIVE",
"HOMEPATH",
"LOCALAPPDATA",
"PATH",
"PATHEXT",
"PROCESSOR_ARCHITECTURE",
"SYSTEMDRIVE",
"SYSTEMROOT",
"TEMP",
"USERNAME",
"USERPROFILE",
]
if sys.platform == "win32"
else ...
)
Adding PROGRAMDATA allows the spawned Windows process to receive this standard environment variable.
Proposed fix
Add:
"PROGRAMDATA",
to the Windows DEFAULT_INHERITED_ENV_VARS list in:
src/mcp/client/stdio.py
Testing
I reproduced the Windows MCP + SSH behavior and investigated the restricted subprocess environment.
After adding PROGRAMDATA:
- Verified that
PROGRAMDATAis inherited by the spawned process. - Tested the restricted environment with
Popen. - Ran the stdio client tests successfully: 25 passed, 8 skipped.
git diff --checkpasses.
I have prepared PR #3334 with this change.
Related issue
This investigation was motivated by MCP SSH transport closing immediately after initialize on Windows.
I would appreciate maintainer confirmation that this is the appropriate fix and whether this issue can be assigned to me so PR #3334 can be reopened.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/mcp/client/stdio.py から始めて、Windows の DEFAULT_INHERITED_ENV_VARS リストを確認します。stdio クライアントのテストを実行し、起動されたプロセスが PROGRAMDATA を継承することを確認します。完了は、25 件の成功したテストと 8 件のスキップされたテストが報告され、git diff --check がクリーンであることで示されます。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- cli
- issue の種類
- バグ
- 難易度
- 1/5
- 見積もり時間
- 1時間未満
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100