-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix Windows subprocess NotImplementedError (STDIO clients) #596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix Windows subprocess NotImplementedError (STDIO clients) #596
Conversation
…ack to subprocess.Popen
Hi team! This is my first pull request. PR fixes Windows compatibility for MCP STDIO clients by introducing a fallback to subprocess.Popen wrapped with async I/O streams. It ensures that Windows users can now use streamlit and similar STDIO clients without errors. Please let me know if you'd like any further changes. Thank you for your time and for maintaining such an awesome project! Regards |
@dsp-ant @jerome3o-anthropic would appreciate any kind of feedback on this if possible from your end. Thanks a ton! Regards |
#555 solves this in a much cleaner way |
Thanks for sharing 🙏 I just tested it on my setup (Windows 11 + Python 3.13), and I’m still hitting the same error: I think I have tested #555 well by updating the init and win32 python files in my .venv mcp path with the edits suggested here. Baically #555 still uses await anyio.open_process(...) in both primary and fallback paths, which internally relies on asyncio.create_subprocess_exec(). Unfortunately, that call raises NotImplementedError on my machine, so the fallback logic never helps. In my fork, I catch the failure and bypass the entire async subprocess path by: So for Windows users with newer Python versions or CI environments, my fallback is the only one that works when the async event loop doesn’t support subprocesses. Let me know what you think. Have you tested this in event loop scenarios like the one pointed out in this PR? Thanks |
I am on windows 11; also using it in an event loop. are you using windows proactor for the async loop? edit:
import asyncio
import os
if os.name == 'nt':
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) |
Aah that explains it :) For me it is This I think is the default. I actually tried to add your session.py code but cannot get the event loop to change for some reason (I guess due to Streamlit's own eventloop). I understand #555 might work perfectly under the ProactorEventLoop, but this patch "might" help to support environments where that’s not the default
(note - personally I have faced this with my Streamlit UI only) That said, I really appreciate the clean structure of the other solution. Thanks |
One more thing, in case you'd want to look at the implementation of the streamlit code - you can have a look at Repo - https://github.com/theailanguage/mcp_client This is a tutorial video for the same that I built for a course |
Fix subprocess creation errors on Windows for STDIO client connections.
This updates
create_windows_process
to properly handle the case where asyncio cannot create subprocess transports on Windows by falling back to using thesubprocess
module manually.Additionally, minor import sorting and style issues have been fixed according to
ruff
linter checks.Motivation and Context
On Windows systems, MCP clients that connect via STDIO were failing with a
NotImplementedError
duringanyio.open_process()
. This is becauseasyncio
on Windows does not implement full support for subprocess transports.This change provides a clean workaround:
subprocess.Popen
withasyncio
wrapping.This allows MCP STDIO clients (e.g., streamlit_client_ui.py) to work successfully on Windows without changing user workflows.
edit:
the default event loop comes out as (Windows 11, Python 3.13) -
<class 'asyncio.windows_events._WindowsSelectorEventLoop'>
My understanding is that #555 might work under the ProactorEventLoop, but my patch "might" help to support environments where that’s not the default
(note - personally I have faced this with my Streamlit UI only)
How Has This Been Tested?
streamlit_client_ui.py
to launch the MCP client.ruff
orpyright
issues for the updated file.Breaking Changes
No breaking changes.
Types of changes
Checklist
Additional context
This fix is especially important for making MCP tools and agents accessible on all platforms, including Windows, thereby helping broader adoption.