modelcontextprotocol / modelcontextprotocol/python-sdk

Windows MCP SSH stdio transport closes after initialize when PROGRAMDATA is missing from inherited environment

Aperta
#3,335 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

v1 v2
Lingua principale
Python
Stelle
24.3k
Fork
4k
Merge medio
1g 1h
PR unite (30g)
31

Descrizione

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 PROGRAMDATA is inherited by the spawned process.
  • Tested the restricted environment with Popen.
  • Ran the stdio client tests successfully: 25 passed, 8 skipped.
  • git diff --check passes.

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in src/mcp/client/stdio.py e ispeziona l'elenco Windows DEFAULT_INHERITED_ENV_VARS. Esegui i test del client stdio e verifica che il processo avviato erediti PROGRAMDATA; il completamento è indicato dai 25 test superati e dagli 8 test ignorati riportati, nonché da un git diff --check pulito.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
cli
Tipo di issue
Bug
Difficoltà
1/5
Tempo stimato
Meno di un'ora
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.