You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stdio_client not starting in windows: getting NotImplementedError #359
anyio.open_process in stdio_client not working in windows. It raises NotImplementedError.
asyncwithstdio_client(server_params) as (read, write):
asyncwithClientSession(
read, write, sampling_callback=handle_sampling_message
) assession:
# Initialize the connectionawaitsession.initialize()
It gives out error:
async with stdio_client(server_param) as (read, write):
File "C:\Python311\Lib\contextlib.py", line 204, in __aenter__
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio.py", line 104, in stdio_client
process = await anyio.open_process(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\anyio\_core\_subprocesses.py", line 190, in open_process
return await get_async_backend().open_process(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\anyio\_backends\_asyncio.py", line 2561, in open_process
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\subprocess.py", line 218, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 1680, in subprocess_exec
transport = await self._make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 502, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError
@dsp-ant I had several users report issues with mcp-agent on Windows at least in part due to this. I got around to spending several hours to fix this, and figured I'd contribute the fix back upstream (or downstream? 🙃 ). #372 should cover most cases.
@saqadri#372 PR still giving me the same error in windows: NotImplementedError
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio\__init__.py", line 113, in stdio_client
process = await _create_platform_compatible_process(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio\__init__.py", line 210, in _create_platform_compatible_process
process = await create_windows_process(command, args, env, errlog, cwd)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio\win32.py", line 85, in create_windows_process
process = await anyio.open_process(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\anyio\_core\_subprocesses.py", line 190, in open_process
return await get_async_backend().open_process(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\anyio\_backends\_asyncio.py", line 2561, in open_process
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\subprocess.py", line 218, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 1680, in subprocess_exec
transport = await self._make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 502, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError
@saqadri#372 PR still giving me the same error in windows: NotImplementedError
return await anext(self.gen)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio\__init__.py", line 113, in stdio_client
process = await _create_platform_compatible_process(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio\__init__.py", line 210, in _create_platform_compatible_process
process = await create_windows_process(command, args, env, errlog, cwd)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\mcp\client\stdio\win32.py", line 85, in create_windows_process
process = await anyio.open_process(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\anyio\_core\_subprocesses.py", line 190, in open_process
return await get_async_backend().open_process(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\site-packages\anyio\_backends\_asyncio.py", line 2561, in open_process
process = await asyncio.create_subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\subprocess.py", line 218, in create_subprocess_exec
transport, protocol = await loop.subprocess_exec(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 1680, in subprocess_exec
transport = await self._make_subprocess_transport(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Python311\Lib\asyncio\base_events.py", line 502, in _make_subprocess_transport
raise NotImplementedError
NotImplementedError
@JexinSam I'll investigate - is there anything special about your setup. For example are you running in a Jupyter notebook or regular Python script? A snippet and repro steps would be super helpful.
frommcpimportClientSession, StdioServerParameters, typesfromtypingimportListfrommcp.client.stdioimportstdio_clientimportos, jsonfromfastapiimportFastAPI, HTTPExceptionapp=FastAPI()
CONFIG_FILE='mcp-server-config.json'defload_server_config() ->dict:
# Load server configuration from the config fileifos.path.exists(CONFIG_FILE):
withopen(CONFIG_FILE, "r", encoding="utf-8") asf:
returnjson.load(f) # Load server configurationraiseFileNotFoundError(f"Could not find config file {CONFIG_FILE}")
defcreate_server_parameters(server_config: dict) ->List[StdioServerParameters]:
"""Create server parameters from the server configuration."""server_parameters= []
# Create server parameters for each server configurationforconfiginserver_config["mcpServers"].values():
server_parameter=StdioServerParameters(
command=config["command"],
args=config.get("args", []),
env={**config.get("env", {}), "PATH": os.getenv("PATH")}
)
# Add environment variables from the system if not providedforkey, valueinserver_parameter.env.items():
iflen(value) ==0andkeyinos.environ:
server_parameter.env[key] =os.getenv(key)
server_parameters.append(server_parameter)
returnserver_parametersasyncdefget_mcp_tools(server_param: StdioServerParameters) ->List:
"""Asynchronously retrieves and converts tools from a server using specified parameters"""mcp_tools= []
asyncwithstdio_client(server_param) as (read, write):
asyncwithClientSession(read, write) assession:
awaitsession.initialize() # Initialize the sessiontools: types.ListToolsResult=awaitsession.list_tools() # Retrieve tools from the serverfortool_dataintools.tools:
mcp_tools.append(tool_data.__dict__)
returnmcp_tools@app.get("/api/mcp-tools")asyncdefget_mcp_tools_api():
"""API endpoint to retrieve MCP tools."""server_config=load_server_config() # Load server configurationserver_params=create_server_parameters(server_config)
tools=awaitget_mcp_tools(server_params[0]) # Get tools from the first serverreturn {"tools": tools}
fastapi dev app.py
# accessing /api/mcp-tools is resulting in NotImplementedError
It is a hunch, but I noticed this issue in windows when using streamlit and jupyter as well, and at least for the streamlit case having the above resolved the issue.
Hi all, thanks for reporting this issue - we shipped several windows fixes in the last ~1-2 months especially around process management and termination.
Curious if anyone here is still experiencing this? Otherwise would be closing this one soon.
Closing as stale — we asked for additional information and haven't heard back. If you're still experiencing this on the latest release, please reopen with a minimal reproducible example and we'll take another look.
Activity
Kludex commentedon Mar 24, 2025
Hmmm... I think we need to choose the spawn mode somewhere...
saqadri commentedon Mar 26, 2025
@dsp-ant I had several users report issues with mcp-agent on Windows at least in part due to this. I got around to spending several hours to fix this, and figured I'd contribute the fix back upstream (or downstream? 🙃 ). #372 should cover most cases.
isakulaksiz commentedon Mar 27, 2025
NotImplementedError in asyncio subprocess_exec when using MCP client on Windows with Python 3.12 #369
JexinSam commentedon Mar 27, 2025
@saqadri #372 PR still giving me the same error in windows: NotImplementedError
saqadri commentedon Mar 27, 2025
@JexinSam I'll investigate - is there anything special about your setup. For example are you running in a Jupyter notebook or regular Python script? A snippet and repro steps would be super helpful.
JexinSam commentedon Mar 28, 2025
I am trying to run mcp client in fastapi server.
Here is a sample code:
mcp-server-config.json
{ "mcpServers": { "mysql": { "command": "python", "args": ["path/to/mcp-host/mysql-server"], "env": {}, "transport": "stdio" } } }app.py
saqadri commentedon Mar 28, 2025
@JexinSam thanks for the repro steps. I can try looking into this later today. In the meantime, can you please try setting this to see if it helps?
It is a hunch, but I noticed this issue in windows when using streamlit and jupyter as well, and at least for the streamlit case having the above resolved the issue.
JexinSam commentedon Mar 28, 2025
Yes the issue is related to asyncio in windows. But the above code doesn't solve it for me.
fastapi/fastapi#7770
Turns out it happens only when --reload is enabled in fastapi.
felixweinberger commentedon Sep 26, 2025
Hi all, thanks for reporting this issue - we shipped several windows fixes in the last ~1-2 months especially around process management and termination.
Curious if anyone here is still experiencing this? Otherwise would be closing this one soon.
maxisbey commentedon Mar 24, 2026
Closing as stale — we asked for additional information and haven't heard back. If you're still experiencing this on the latest release, please reopen with a minimal reproducible example and we'll take another look.
AI Disclaimer