Startup crash when Claude Desktop launches several instances at once: comtypes.gen race on UIAutomationCore wrapper (0.7.2)
Environment Windows 11 Pro 10.0.26200, Windows-MCP 0.7.2 installed as a Claude Desktop Extension (.mcpb), uv 0.11.33, CPython 3.13 (uv-managed), Claude Desktop 1.52386.3.
What happens
Claude Desktop starts two or three copies of the server within the same second at app launch (a shared pool for Cowork and Code sessions plus a per-session instance). On a cold start, where comtypes/gen/ doesn't yet hold the UIAutomationCore wrapper, the copies race to generate it. One of them imports the module while another is still writing it and dies with an ImportError. Claude then reports "MCP Windows-MCP: Server disconnected".
Two crashes an hour apart, same trace, different missing symbol and different file length, which is the tell that the file was mid-write:
File ".../src/windows_mcp/watchdog/event_handlers.py", line 7, in <module>
uia_client = _AutomationClient.instance()
File ".../src/windows_mcp/uia/core.py", line 68, in __init__
self.UIAutomationCore = comtypes.client.GetModule("UIAutomationCore.dll")
...
File ".../.venv/Lib/site-packages/comtypes/gen/UIAutomationClient.py", line 4, in <module>
from comtypes.gen._944DE083_8FB8_45CF_BCB7_C477ACB2F897_0_1_0 import (
...<341 lines>...
ImportError: cannot import name 'IUIAutomationCacheRequest' from 'comtypes.gen._944DE083_...' ...<356 lines>...
ImportError: cannot import name 'UIA_IsOffscreenPropertyId' from 'comtypes.gen._944DE083_...'A single uv run windows-mcp from a terminal starts cleanly, so the bug only shows under concurrent launch.
Workaround that fixed it Generate the wrapper once from a single process, then every later start only reads it:
cd "$env:APPDATA\Claude\Claude Extensions\ant.dir.cursortouch.windows-mcp"
Remove-Item .venv\Lib\site-packages\comtypes\gen\* -Exclude __init__.py -Force
uv run python -c "import comtypes.client as c; c.GetModule('UIAutomationCore.dll')"It recurs whenever the gen folder is wiped (extension update, or a uv sync that reinstalls comtypes).
Suggested fix
uia/core.py calls comtypes.client.GetModule at import time via watchdog/event_handlers.py line 7, with nothing guarding against a sibling process generating the same module. Options, cheapest first: pre-generate the wrapper as a build step and ship it in the .mcpb; or wrap GetModule in a cross-process file lock (for example msvcrt.locking on a sentinel in comtypes/gen/); or on ImportError, delete the partial gen module and retry once. Lazy-loading the UIA client on first tool call instead of at module import would also narrow the window.
Happy to test a patch on this machine.
Source: CursorTouch/Windows-MCP