Skip to content

fix(mcp): use SelectorEventLoop for the MCP loop thread on Windows#61445

Open
ahmadmdabit wants to merge 1 commit into
NousResearch:mainfrom
ahmadmdabit:fix/mcp-windows-selector-event-loop
Open

fix(mcp): use SelectorEventLoop for the MCP loop thread on Windows#61445
ahmadmdabit wants to merge 1 commit into
NousResearch:mainfrom
ahmadmdabit:fix/mcp-windows-selector-event-loop

Conversation

@ahmadmdabit

Copy link
Copy Markdown

What

Build an explicit asyncio.SelectorEventLoop() for the dedicated MCP event-loop thread on Windows, instead of asyncio.new_event_loop() (which returns a ProactorEventLoop on win32). Non-Windows behavior is unchanged.

Why

The ProactorEventLoop's subprocess-pipe reads hang the MCP SDK stdio_client initialize handshake, so on Windows MCP discovery times out and no MCP tools register. This mirrors the existing win32 SelectorEventLoop handling in cli.py and hermes_cli/web_server.py.

Evidence: a raw stdio pipe to the server responds in ~0.6s; the same MCP SDK ClientSession call raises TimeoutError on initialize under the default (Proactor) loop but returns INITIALIZED OK, TOOLS: 14 under WindowsSelectorEventLoopPolicy.

Fixes #61444.

How to test

  • Windows: configure any stdio MCP server; discovery now completes and tools register (verified: 14 tools discovered in ~2.6s; previously hung until timeout).
  • pytest tests/tools/test_mcp_loop_windows_selector.py -v

Platforms tested

  • Windows 10/11 (Python 3.11.9). The non-Windows path is unchanged (else branch keeps asyncio.new_event_loop()); the new regression test is win32-gated.

The dedicated MCP event-loop thread was built with asyncio.new_event_loop(),
which on Windows returns a ProactorEventLoop. Its subprocess-pipe reads hang
the stdio_client initialize handshake, so MCP discovery times out and no MCP
tools register. Build an explicit SelectorEventLoop on win32, matching the
existing win32 SelectorEventLoop handling in cli.py and web_server.py.

Adds a regression test asserting the loop is not a ProactorEventLoop on
Windows.
@alt-glitch alt-glitch added type/bug Something isn't working tool/mcp MCP client and OAuth platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows P2 Medium — degraded but workaround exists labels Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Medium — degraded but workaround exists platform/windows Native Windows-specific behavior or breakage sweeper:risk-platform-windows Sweeper risk: may break or behave differently on native Windows tool/mcp MCP client and OAuth type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP stdio servers never connect on Windows — MCP loop uses ProactorEventLoop, hangs stdio_client initialize

2 participants