fix(mcp): use SelectorEventLoop for the MCP loop thread on Windows#61445
Open
ahmadmdabit wants to merge 1 commit into
Open
fix(mcp): use SelectorEventLoop for the MCP loop thread on Windows#61445ahmadmdabit wants to merge 1 commit into
ahmadmdabit wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Build an explicit
asyncio.SelectorEventLoop()for the dedicated MCP event-loop thread on Windows, instead ofasyncio.new_event_loop()(which returns aProactorEventLoopon win32). Non-Windows behavior is unchanged.Why
The
ProactorEventLoop's subprocess-pipe reads hang the MCP SDKstdio_clientinitializehandshake, so on Windows MCP discovery times out and no MCP tools register. This mirrors the existing win32SelectorEventLoophandling incli.pyandhermes_cli/web_server.py.Evidence: a raw stdio pipe to the server responds in ~0.6s; the same MCP SDK
ClientSessioncall raisesTimeoutErroroninitializeunder the default (Proactor) loop but returnsINITIALIZED OK, TOOLS: 14underWindowsSelectorEventLoopPolicy.Fixes #61444.
How to test
pytest tests/tools/test_mcp_loop_windows_selector.py -vPlatforms tested
elsebranch keepsasyncio.new_event_loop()); the new regression test is win32-gated.