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
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 24.3k
- フォーク
- 4k
- 平均マージ
- 1日 1時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
mcp/init.py から始め、mcp/client/stdio と mcp/os/win32/utilities.py への eager import を追跡します。既存の null-check が pywin32 の欠如をどのように処理しているかを確認し、その後、Windows で mcp.server.stdio を import してもサーバーのみを使用するユーザーには pywin32 が不要であり、client stdio のクリーンアップは引き続きサポートされることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 76/100