modelcontextprotocol / modelcontextprotocol/python-sdk
pywin32 installation fails on Windows — hard dep only needed for client stdio, but pulled in for all users via eager import in __init__.py
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 1 Std.
- Gemergte PRs (30 T.)
- 31
Beschreibung
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
pywin32>=311 is a required Windows dependency used exclusively in mcp.client.stdio (Windows Job Objects for child process cleanup). However, mcp/__init__.py eagerly imports from .client.stdio import StdioServerParameters, stdio_client, which causes mcp/os/win32/utilities.py to unconditionally execute:
if sys.platform == "win32":
import pywintypes
import win32api
import win32con
import win32job
This means pywin32 is a hard runtime requirement on Windows for all users — including those running a pure MCP server that never uses mcp.client.stdio.
The pywin32 wheel contains a .data directory with Windows DLLs. On Windows, AV software (e.g. Windows Defender) locks newly-extracted DLLs before uv can clean up its temp directory, causing installation to fail every time with:
error: Failed to install: pywin32-311-cp313-cp313-win_amd64.whl (pywin32==311)
Caused by: failed to remove directory `...\uv\cache\builds-v0\.tmp\Lib\site-packages\pywin32-311.data`
os error 32 (file in use by another process)
This blocks server-only deployments like ha-mcp entirely on Windows (tracked in homeassistant-ai/ha-mcp#672).
The null-checks already in _create_job_object() and _maybe_assign_process_to_job() handle win32job = None gracefully — so the only missing piece is allowing the import to fail softly:
if sys.platform == "win32":
try:
import pywintypes, win32api, win32con, win32job
except ImportError:
win32api = win32con = win32job = pywintypes = None
Or alternatively, lazily import mcp.client.stdio from mcp/__init__.py so server-only users don't trigger this code path at all.
Example Code
# This alone triggers the pywin32 import on Windows:
from mcp.server.stdio import stdio_server
Python & MCP Python SDK
Python 3.13, MCP Python SDK 1.26.0 (latest)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit mcp/init.py und verfolge den Eager-Import in mcp/client/stdio und mcp/os/win32/utilities.py. Prüfe, wie die vorhandenen Nullprüfungen mit fehlendem pywin32 umgehen, und verifiziere anschließend, dass der Import von mcp.server.stdio unter Windows für Benutzer, die nur den Server verwenden, nicht mehr pywin32 erfordert, während die Bereinigung des Client-stdio weiterhin unterstützt wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 76/100