Skip to content

MCP server in the HTTP Streamable mode broken #1190

Closed

Description

@akolotov

Starting from v1.12.0 (checked with v1.12.0 and v1.12.1) any request to the MCP server in the HTTP Streamable mode produces an error:

INFO:     127.0.0.1:32926 - "POST /mcp/ HTTP/1.1" 307 Temporary Redirect
[07/23/25 16:34:18] INFO     Processing request of type ListToolsRequest                                        server.py:625
INFO:     127.0.0.1:32926 - "POST /mcp HTTP/1.1" 200 OK
                    INFO     Terminating session: None                                                 streamable_http.py:630
                    ERROR    Error in message router                                                   streamable_http.py:880
                             ╭────────────────── Traceback (most recent call last) ──────────────────╮                       
                             │ /usr/local/lib/python3.12/site-packages/mcp/server/streamable_http.py │                       
                             │ :831 in message_router                                                │                       
                             │                                                                       │                       
                             │   828 │   │   │   # Create a message router that distributes messages │                       
                             │   829 │   │   │   async def message_router():                         │                       
                             │   830 │   │   │   │   try:                                            │                       
                             │ ❱ 831 │   │   │   │   │   async for session_message in write_stream_r │                       
                             │   832 │   │   │   │   │   │   # Determine which request stream(s) sho │                       
                             │   833 │   │   │   │   │   │   message = session_message.message       │                       
                             │   834 │   │   │   │   │   │   target_request_id = None                │                       
                             │                                                                       │                       
                             │ /usr/local/lib/python3.12/site-packages/anyio/abc/_streams.py:35 in   │                       
                             │ __anext__                                                             │                       
                             │                                                                       │                       
                             │    32 │                                                               │                       
                             │    33 │   async def __anext__(self) -> T_co:                          │                       
                             │    34 │   │   try:                                                    │                       
                             │ ❱  35 │   │   │   return await self.receive()                         │                       
                             │    36 │   │   except EndOfStream:                                     │                       
                             │    37 │   │   │   raise StopAsyncIteration                            │                       
                             │    38                                                                 │                       
                             │                                                                       │                       
                             │ /usr/local/lib/python3.12/site-packages/anyio/streams/memory.py:111   │                       
                             │ in receive                                                            │                       
                             │                                                                       │                       
                             │   108 │   async def receive(self) -> T_co:                            │                       
                             │   109 │   │   await checkpoint()                                      │                       
                             │   110 │   │   try:                                                    │                       
                             │ ❱ 111 │   │   │   return self.receive_nowait()                        │                       
                             │   112 │   │   except WouldBlock:                                      │                       
                             │   113 │   │   │   # Add ourselves in the queue                        │                       
                             │   114 │   │   │   receive_event = Event()                             │                       
                             │                                                                       │                       
                             │ /usr/local/lib/python3.12/site-packages/anyio/streams/memory.py:93 in │                       
                             │ receive_nowait                                                        │                       
                             │                                                                       │                       
                             │    90 │   │                                                           │                       
                             │    91 │   │   """                                                     │                       
                             │    92 │   │   if self._closed:                                        │                       
                             │ ❱  93 │   │   │   raise ClosedResourceError                           │                       
                             │    94 │   │                                                           │                       
                             │    95 │   │   if self._state.waiting_senders:                         │                       
                             │    96 │   │   │   # Get the item from the next sender                 │                       
                             ╰───────────────────────────────────────────────────────────────────────╯                       
                             ClosedResourceError

Rollback to 1.11.0 fix the issue.

Activity

  1. felixweinberger commented on Oct 3, 2025

    @felixweinberger
    Contributor

    Hi thank you for reporting this - could you please provide a full code snippet that demonstrates the issue so we can debug on our machines?

  2. elioengcomp commented on Oct 3, 2025

    @elioengcomp

    Hi thank you for reporting this - could you please provide a full code snippet that demonstrates the issue so we can debug on our machines?

    This is what I used:

    mcp = FastMCP("My Test Server", 
        stateless_http=True,
        json_response=True,
        port=settings.SERVER_PORT, 
        token_verifier=SimpleTokenVerifier(),
        auth=AuthSettings(
            issuer_url=AnyHttpUrl(settings.API_BASE_URL),
            resource_server_url=AnyHttpUrl(settings.SERVER_URL),
            required_scopes=["email"],
        )
    )
    

    If I drop the json_response the error is gone.

  3. added
    ready for workEnough information for someone to start working on
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    P1Significant bug affecting many users, highly requested feature
    and removed
    needs reproneeds additional information to be able to reproduce bug
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    on Oct 3, 2025
  4. christoph88 commented on Oct 17, 2025

    @christoph88

    I still have issues with this streaming http server. how can I send you debug info? https://docs.ahrefs.com/docs/mcp/reference/introduction

  5. felixweinberger commented on Oct 17, 2025

    @felixweinberger
    Contributor

    I still have issues with this streaming http server. how can I send you debug info? https://docs.ahrefs.com/docs/mcp/reference/introduction

    Is your issue with the ahrefs server specifically or something you built? Are you running a server yourself or you mean you have trouble connecting to the ahrefs mcp server?

  6. christoph88 commented on Oct 17, 2025

    @christoph88

    I have trouble connecting through chatmcp. The MCP server itself works when using it through my ide with the same setup. It's a streaming http server.

    Is there a way I can provide you with logs

  7. felixweinberger commented on Oct 17, 2025

    @felixweinberger
    Contributor

    I have trouble connecting through chatmcp. The MCP server itself works when using it through my ide with the same setup. It's a streaming http server.

    Is there a way I can provide you with logs

    Just paste them here in this issue or share a gist if it's a lot

  8. ofek commented on Oct 21, 2025

    @ofek

    @felixweinberger This is bloating our logs and can be easily reproduced as follows:

    1. Install PyCLI MCP
      pip install pycli-mcp
      
    2. Install MCP Inspector
      npm i @modelcontextprotocol/inspector
      
    3. In one shell session run the server using its own CLI:
      pycli-mcp pycli_mcp.cli:pycli_mcp
      
    4. In another shell session query the server using the inspector:
      mcp-inspector --cli --transport http http://localhost:8000/mcp/ --method tools/list
      
    5. Notice output from the server that is similar to the following:
      ❯ pycli-mcp pycli_mcp.cli:pycli_mcp
      Serving: pycli-mcp
      INFO:     Started server process [62884]
      INFO:     Waiting for application startup.
      INFO:     Application startup complete.
      INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
      INFO:     127.0.0.1:57660 - "POST /mcp/ HTTP/1.1" 200 OK
      Error in message router
      Traceback (most recent call last):
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\mcp\server\streamable_http.py", line 831, in message_router
          async for session_message in write_stream_reader:
          ...<45 lines>...
                  )
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\anyio\abc\_streams.py", line 41, in __anext__
          return await self.receive()
                ^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\anyio\streams\memory.py", line 111, in receive
          return self.receive_nowait()
                ~~~~~~~~~~~~~~~~~~~^^
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\anyio\streams\memory.py", line 93, in receive_nowait
          raise ClosedResourceError
      anyio.ClosedResourceError
      INFO:     127.0.0.1:57662 - "POST /mcp/ HTTP/1.1" 202 Accepted
      INFO:     127.0.0.1:57660 - "GET /mcp/ HTTP/1.1" 200 OK
      INFO:     127.0.0.1:57664 - "POST /mcp/ HTTP/1.1" 200 OK
      ERROR:mcp.server.streamable_http:Error in message router
      Traceback (most recent call last):
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\mcp\server\streamable_http.py", line 831, in message_router
          async for session_message in write_stream_reader:
          ...<45 lines>...
                  )
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\anyio\abc\_streams.py", line 41, in __anext__
          return await self.receive()
                ^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\anyio\streams\memory.py", line 111, in receive
          return self.receive_nowait()
                ~~~~~~~~~~~~~~~~~~~^^
        File "C:\Users\ofek\AppData\Roaming\uv\tools\pycli-mcp\Lib\site-packages\anyio\streams\memory.py", line 93, in receive_nowait
          raise ClosedResourceError
      anyio.ClosedResourceError
      
  9. added
    P0Broken core functionality, security issues, critical missing feature
    and removed
    P1Significant bug affecting many users, highly requested feature
    on Dec 2, 2025
  10. maxisbey commented on Dec 2, 2025

    @maxisbey
    Contributor

    Consolidating duplicate issues:

    The following issues have been closed as duplicates of this one:

    Root Cause Summary (from #1363):

    This is a race condition in message_router() at streamable_http.py:959:

    1. message_router enters async for write_stream_reader loop
    2. The iterator calls checkpoint(), yielding control
    3. Request completes/fails early and calls terminate(), closing the stream
    4. message_router resumes and encounters closed stream → ClosedResourceError

    Proposed Fix: PR #1384 adds explicit ClosedResourceError handling before the generic except Exception block.

    Workaround (from #1363): Suppress logs via uvicorn config:

    mcp.server.streamable_http:
      level: CRITICAL

    AI Disclaimer

  11. ofek commented on Dec 2, 2025

    @ofek

    @maxisbey What's blocking the proposed fix that you mentioned from being merged?

  12. added
    P1Significant bug affecting many users, highly requested feature
    and removed
    P0Broken core functionality, security issues, critical missing feature
    on Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions