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
StreamableHTTP session manager shutting down #1104
When the MCP tool is being executed, it occasionally displays the message "StreamableHTTP session manager shutting down". Subsequently, when another request is made, an error occurs, specifically "Task group is not initialized. Make sure to use run()".
INFO: 127.0.0.1:57464 - "POST /mcp/ HTTP/1.1" 200 OK
2025-07-09 09:56:48 | INFO | logging:callHandlers:1762 - Processing request of type CallToolRequest
2025-07-09 09:56:48 | INFO | logging:callHandlers:1762 - Processing request of type CallToolRequest
2025-07-09 09:56:48 | INFO | logging:callHandlers:1762 - Processing request of type CallToolRequest
2025-07-09 09:56:48 | INFO | logging:callHandlers:1762 - Processing request of type CallToolRequest
2025-07-09 10:00:32 | INFO | logging:callHandlers:1762 - StreamableHTTP session manager shutting down
ERROR: + Exception Group Traceback (most recent call last):
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\starlette\routing.py", line 692, in lifespan
| async with self.lifespan_context(app) as maybe_state:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\fastapi\routing.py", line 133, in merged_lifespan
| async with original_context(app) as maybe_original_state:
| ^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\fastapi\routing.py", line 133, in merged_lifespan
| async with original_context(app) as maybe_original_state:
| ^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\fastapi\routing.py", line 133, in merged_lifespan
| async with original_context(app) as maybe_original_state:
| ^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\fastapi\routing.py", line 133, in merged_lifespan
| async with original_context(app) as maybe_original_state:
| ^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\core\lifespan.py", line 22, in lifespan
| async with mcp.mcp.session_manager.run():
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\streamable_http_manager.py", line 106, in run
| async with anyio.create_task_group() as tg:
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\anyio\_backends\_asyncio.py", line 772, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Exception Group Traceback (most recent call last):
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\streamable_http_manager.py", line 235, in run_server
| async with http_transport.connect() as streams:
| ^^^^^^^^^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 231, in __aexit__
| await self.gen.athrow(value)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\streamable_http.py", line 846, in connect
| async with anyio.create_task_group() as tg:
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\anyio\_backends\_asyncio.py", line 772, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Exception Group Traceback (most recent call last):
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\streamable_http.py", line 919, in connect
| yield read_stream, write_stream
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\streamable_http_manager.py", line 238, in run_server
| await self.app.run(
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\lowlevel\server.py", line 500, in run
| async with AsyncExitStack() as stack:
| ^^^^^^^^^^^^^^^^
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 754, in __aexit__
| raise exc_details[1]
| File "C:\Users\STGF\AppData\Roaming\uv\python\cpython-3.12.9-windows-x86_64-none\Lib\contextlib.py", line 737, in __aexit__
| cb_suppress = await cb(*exc_details)
| ^^^^^^^^^^^^^^^^^^^^^^
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\shared\session.py", line 223, in __aexit__
| return await self._task_group.__aexit__(exc_type, exc_val, exc_tb)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\anyio\_backends\_asyncio.py", line 772, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Exception Group Traceback (most recent call last):
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\lowlevel\server.py", line 511, in run
| async with anyio.create_task_group() as tg:
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\anyio\_backends\_asyncio.py", line 772, in __aexit__
| raise BaseExceptionGroup(
| ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\lowlevel\server.py", line 539, in _handle_message
| await self._handle_request(
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\server\lowlevel\server.py", line 593, in _handle_request
| await message.respond(response)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\shared\session.py", line 134, in respond
| await self._session._send_response( # type: ignore[reportPrivateUsage]
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\mcp\shared\session.py", line 346, in _send_response
| await self._write_stream.send(session_message)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\anyio\streams\memory.py", line 242, in send
| self.send_nowait(item)
| File "D:\project\py\mr-tools-service\.venv\Lib\site-packages\anyio\streams\memory.py", line 211, in send_nowait
| raise ClosedResourceError
| anyio.ClosedResourceError
+------------------------------------
Activity
LTaooo commentedon Jul 8, 2025
Only the MCP has shut down; FastAPI has not.
mehmetaltuntas commentedon Jul 8, 2025
Are you able to provide
StreamableHTTPServerTransportsetup where you get the initialise it all?LTaooo commentedon Jul 9, 2025
LTaooo commentedon Jul 9, 2025
Test Script
It's not 100% error-prone.
LTaooo commentedon Jul 9, 2025
Logs
LTaooo commentedon Jul 11, 2025
#841
It has been fixed, and I tested it with no issues.