Skip to content

Bug: missing MCP server causes a crash #469

@tomjuggler

Description

@tomjuggler

Issue

There are a lot of errors reported here - basically this happens when I try to run Cecli without my "browser" mcp running. Cecli runs fine when the server is running but this is the error when it is not.

If I comment out the MCP below, Cecli runs fine.

MCP in question:

"browser": {
    "transport": "http",
    "url": "http://localhost:8222/mcp" 
  }

Error:

unhandled exception during asyncio.run() shutdown
task: <Task finished name='mcp.shared.session.BaseSession._receive_loop' coro=<BaseSession._receive_loop() done, defined at /home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py:351> exception=RuntimeError('dictionary changed size during iteration')>
Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 117, in receive
    return self.receive_nowait()
           ~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 112, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py", line 357, in _receive_loop
    async for message in self._read_stream:
    ...<76 lines>...
            await self._handle_response(message)
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/abc/_streams.py", line 41, in __anext__
    return await self.receive()
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 125, in receive
    await receive_event.wait()
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 1789, in wait
    await self._event.wait()
  File "/usr/lib/python3.14/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py", line 448, in _receive_loop
    for id, stream in self._response_streams.items():
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
RuntimeError: dictionary changed size during iteration
unhandled exception during asyncio.run() shutdown
task: <Task finished name='mcp.shared.session.BaseSession._receive_loop' coro=<BaseSession._receive_loop() done, defined at /home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py:351> exception=RuntimeError('dictionary changed size during iteration')>
Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 117, in receive
    return self.receive_nowait()
           ~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 112, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py", line 357, in _receive_loop
    async for message in self._read_stream:
    ...<76 lines>...
            await self._handle_response(message)
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/abc/_streams.py", line 41, in __anext__
    return await self.receive()
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 125, in receive
    await receive_event.wait()
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 1789, in wait
    await self._event.wait()
  File "/usr/lib/python3.14/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py", line 448, in _receive_loop
    for id, stream in self._response_streams.items():
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
RuntimeError: dictionary changed size during iteration
unhandled exception during asyncio.run() shutdown
task: <Task finished name='mcp.shared.session.BaseSession._receive_loop' coro=<BaseSession._receive_loop() done, defined at /home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py:351> exception=RuntimeError('dictionary changed size during iteration')>
Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 117, in receive
    return self.receive_nowait()
           ~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 112, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py", line 357, in _receive_loop
    async for message in self._read_stream:
    ...<76 lines>...
            await self._handle_response(message)
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/abc/_streams.py", line 41, in __anext__
    return await self.receive()
           ^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/streams/memory.py", line 125, in receive
    await receive_event.wait()
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 1789, in wait
    await self._event.wait()
  File "/usr/lib/python3.14/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/shared/session.py", line 448, in _receive_loop
    for id, stream in self._response_streams.items():
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
RuntimeError: dictionary changed size during iteration
an error occurred during closing of asynchronous generator <async_generator object stdio_client at 0x7f7f39edbe10>
asyncgen: <async_generator object stdio_client at 0x7f7f39edbe10>
  + Exception Group Traceback (most recent call last):
  |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 783, in __aexit__
  |     raise BaseExceptionGroup(
  |         "unhandled errors in a TaskGroup", self._exceptions
  |     ) from None
  | BaseExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/stdio/__init__.py", line 189, in stdio_client
    |     yield read_stream, write_stream
    | GeneratorExit
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/stdio/__init__.py", line 183, in stdio_client
    anyio.create_task_group() as tg,
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 789, in __aexit__
    if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 461, in __exit__
    raise RuntimeError(
    ...<2 lines>...
    )
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
an error occurred during closing of asynchronous generator <async_generator object stdio_client at 0x7f7f392b0320>
asyncgen: <async_generator object stdio_client at 0x7f7f392b0320>
  + Exception Group Traceback (most recent call last):
  |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 783, in __aexit__
  |     raise BaseExceptionGroup(
  |         "unhandled errors in a TaskGroup", self._exceptions
  |     ) from None
  | BaseExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/stdio/__init__.py", line 189, in stdio_client
    |     yield read_stream, write_stream
    | GeneratorExit
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/stdio/__init__.py", line 183, in stdio_client
    anyio.create_task_group() as tg,
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 789, in __aexit__
    if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 461, in __exit__
    raise RuntimeError(
    ...<2 lines>...
    )
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
an error occurred during closing of asynchronous generator <async_generator object streamable_http_client at 0x7f7f392d8340>
asyncgen: <async_generator object streamable_http_client at 0x7f7f392d8340>
  + Exception Group Traceback (most recent call last):
  |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 783, in __aexit__
  |     raise BaseExceptionGroup(
  |         "unhandled errors in a TaskGroup", self._exceptions
  |     ) from None
  | BaseExceptionGroup: unhandled errors in a TaskGroup (2 sub-exceptions)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_transports/default.py", line 101, in map_httpcore_exceptions
    |     yield
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_transports/default.py", line 394, in handle_async_request
    |     resp = await self._pool.handle_async_request(req)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_async/connection_pool.py", line 256, in handle_async_request
    |     raise exc from None
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_async/connection_pool.py", line 236, in handle_async_request
    |     response = await connection.handle_async_request(
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |         pool_request.request
    |         ^^^^^^^^^^^^^^^^^^^^
    |     )
    |     ^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_async/connection.py", line 101, in handle_async_request
    |     raise exc
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_async/connection.py", line 78, in handle_async_request
    |     stream = await self._connect(request)
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_async/connection.py", line 124, in _connect
    |     stream = await self._network_backend.connect_tcp(**kwargs)
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_backends/auto.py", line 31, in connect_tcp
    |     return await self._backend.connect_tcp(
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |     ...<5 lines>...
    |     )
    |     ^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_backends/anyio.py", line 113, in connect_tcp
    |     with map_exceptions(exc_map):
    |          ~~~~~~~~~~~~~~^^^^^^^^^
    |   File "/usr/lib/python3.14/contextlib.py", line 162, in __exit__
    |     self.gen.throw(value)
    |     ~~~~~~~~~~~~~~^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpcore/_exceptions.py", line 14, in map_exceptions
    |     raise to_exc(exc) from exc
    | httpcore.ConnectError: All connection attempts failed
    | 
    | The above exception was the direct cause of the following exception:
    | 
    | Traceback (most recent call last):
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/streamable_http.py", line 565, in handle_request_async
    |     await self._handle_post_request(ctx)
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/streamable_http.py", line 340, in _handle_post_request
    |     async with ctx.client.stream(
    |                ~~~~~~~~~~~~~~~~~^
    |         "POST",
    |         ^^^^^^^
    |     ...<2 lines>...
    |         headers=headers,
    |         ^^^^^^^^^^^^^^^^
    |     ) as response:
    |     ^
    |   File "/usr/lib/python3.14/contextlib.py", line 214, in __aenter__
    |     return await anext(self.gen)
    |            ^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_client.py", line 1583, in stream
    |     response = await self.send(
    |                ^^^^^^^^^^^^^^^^
    |     ...<4 lines>...
    |     )
    |     ^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_client.py", line 1629, in send
    |     response = await self._send_handling_auth(
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |     ...<4 lines>...
    |     )
    |     ^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_client.py", line 1657, in _send_handling_auth
    |     response = await self._send_handling_redirects(
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |     ...<3 lines>...
    |     )
    |     ^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_client.py", line 1694, in _send_handling_redirects
    |     response = await self._send_single_request(request)
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_client.py", line 1730, in _send_single_request
    |     response = await transport.handle_async_request(request)
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_transports/default.py", line 393, in handle_async_request
    |     with map_httpcore_exceptions():
    |          ~~~~~~~~~~~~~~~~~~~~~~~^^
    |   File "/usr/lib/python3.14/contextlib.py", line 162, in __exit__
    |     self.gen.throw(value)
    |     ~~~~~~~~~~~~~~^^^^^^^
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/httpx/_transports/default.py", line 118, in map_httpcore_exceptions
    |     raise mapped_exc(message) from exc
    | httpx.ConnectError: All connection attempts failed
    +---------------- 2 ----------------
    | Traceback (most recent call last):
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/streamable_http.py", line 670, in streamable_http_client
    |     yield (
    |     ...<3 lines>...
    |     )
    | GeneratorExit
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/streamable_http.py", line 647, in streamable_http_client
    async with anyio.create_task_group() as tg:
               ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 789, in __aexit__
    if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 461, in __exit__
    raise RuntimeError(
    ...<2 lines>...
    )
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in
an error occurred during closing of asynchronous generator <async_generator object stdio_client at 0x7f7f39edb570>
asyncgen: <async_generator object stdio_client at 0x7f7f39edb570>
  + Exception Group Traceback (most recent call last):
  |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 783, in __aexit__
  |     raise BaseExceptionGroup(
  |         "unhandled errors in a TaskGroup", self._exceptions
  |     ) from None
  | BaseExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/stdio/__init__.py", line 189, in stdio_client
    |     yield read_stream, write_stream
    | GeneratorExit
    +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/mcp/client/stdio/__init__.py", line 183, in stdio_client
    anyio.create_task_group() as tg,
    ~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 789, in __aexit__
    if self.cancel_scope.__exit__(type(exc), exc, exc.__traceback__):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tom/.platformio/penv/lib/python3.14/site-packages/anyio/_backends/_asyncio.py", line 461, in __exit__
    raise RuntimeError(
    ...<2 lines>...
    )
RuntimeError: Attempted to exit cancel scope in a different task than it was entered in

Version and model info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions