Skip to content

Commit bfd10ca

Browse files
committed
fix: make pywin32 imports soft to support server-only Windows installs
Wrap pywin32 imports in try/except ImportError so that server-only Windows users are not forced to install pywin32. The package is only needed for Job Object support in mcp.client.stdio, but the eager import in mcp/__init__.py pulls it in for all users. All downstream functions (_create_job_object, _maybe_assign_process_to_job, terminate_windows_process_tree) already null-check these modules before use, so graceful degradation is fully covered. Fixes server-only deployments that fail with pywin32 installation errors when antivirus software locks extracted DLLs during uv cache cleanup. Github-Issue: #2233 Reported-by: Nikhil Suresh
1 parent 7ba41dc commit bfd10ca

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/mcp/os/win32/utilities.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,18 @@
1717

1818
# Windows-specific imports for Job Objects
1919
if sys.platform == "win32":
20-
import pywintypes
21-
import win32api
22-
import win32con
23-
import win32job
20+
try:
21+
import pywintypes
22+
import win32api
23+
import win32con
24+
import win32job
25+
except ImportError:
26+
# pywin32 is not installed — degrade gracefully.
27+
# All downstream code null-checks these modules before use.
28+
pywintypes = None
29+
win32api = None
30+
win32con = None
31+
win32job = None
2432
else:
2533
# Type stubs for non-Windows platforms
2634
win32api = None

0 commit comments

Comments
 (0)