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
When running the mcp client using uv run client.py on Windows, the client connects and runs correctly, but after the response is returned, a RuntimeError: no running event loop is thrown during shutdown. The error occurs inside the terminate_windows_process function in win32.py, which uses anyio.fail_after() after the event loop has already closed.
To Reproduce
Steps to reproduce the behavior:
Use the following Python code to create a minimal MCP client that connects to a server and runs a tool-enabled Groq chat query:
Start the server with a valid tool (like knowledge_base).
Run the client using:
uv run client.py
Observe the traceback at shutdown related to RuntimeError: no running event loop.
Expected behavior
The client should shut down gracefully without throwing exceptions after processing a response.
Screenshots / Traceback
Exception ignored in: <async_generator object stdio_client at 0x000002025AE0EFC0>
Traceback (most recent call last):
File "C:\Program Files\Python312\Lib\asyncio\tasks.py", line 314, in __step_run_and_handle_result
result = coro.send(None)
^^^^^^^^^^^^^^^
RuntimeError: async generator ignored GeneratorExit
Exception ignored in: <coroutine object terminate_windows_process at 0x000002025AF5F3E0>
Traceback (most recent call last):
File "...\Lib\site-packages\mcp\client\stdio\win32.py", line 105, in terminate_windows_process
with anyio.fail_after(2.0):
File "C:\Program Files\Python312\Lib\contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "...\Lib\site-packages\anyio\_core\_tasks.py", line 112, in fail_after
with get_async_backend().create_cancel_scope(
File "...\Lib\site-packages\anyio\_backends\_asyncio.py", line 456, in __exit__
ifcurrent_task() is not self._host_task:
^^^^^^^^^^^^^^
RuntimeError: no running event loop
Desktop (please complete the following information):
OS: Windows 11
Python Version: 3.12
MCP Version: [insert version]
AnyIO Version: [insert version]
Terminal: Windows PowerShell
Command Used:uv run client.py
Additional context
This issue seems to be a Windows-specific async shutdown bug.
Happens when anyio.fail_after() is used after the event loop is already closed.
Suggest adding a check before using async context tools during shutdown, such as:
Describe the bug
When running the
mcp
client usinguv run client.py
on Windows, the client connects and runs correctly, but after the response is returned, aRuntimeError: no running event loop
is thrown during shutdown. The error occurs inside theterminate_windows_process
function inwin32.py
, which usesanyio.fail_after()
after the event loop has already closed.To Reproduce
Steps to reproduce the behavior:
GROQ_API_KEY
.knowledge_base
).RuntimeError: no running event loop
.Expected behavior
The client should shut down gracefully without throwing exceptions after processing a response.
Screenshots / Traceback
Desktop (please complete the following information):
uv run client.py
Additional context
anyio.fail_after()
is used after the event loop is already closed.try/except RuntimeError
to suppress it gracefully.The text was updated successfully, but these errors were encountered: