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
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
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)
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 mcp/init.py 開始,追蹤其對 mcp/client/stdio 和 mcp/os/win32/utilities.py 的 eager import。檢查現有的 null-check 如何處理缺少 pywin32 的情況,然後確認在 Windows 上匯入 mcp.server.stdio 對僅使用 server 的使用者不再要求 pywin32,同時仍支援 client stdio 清理。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 活躍
- 描述清晰度
- 描述清楚
- 新手友好度
- 76/100