Skip to content

[BUG] TypeError: Controller is already closed when connecting to fastmcp Streamable HTTP transport #951

@Feng-YiJing-Dao

Description

@Feng-YiJing-Dao

Title: [BUG] TypeError: Controller is already closed when connecting to fastmcp Streamable HTTP transport

Inspector Version

v0.17.2

Describe the bug

When attempting to connect the MCP Inspector (using npx @modelcontextprotocol/inspector) to a Streamable HTTP service implemented with the Python library fastmcp, the Node.js proxy immediately crashes with a TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed.

The connection works fine when the fastmcp service is running in Legacy SSE mode.

To Reproduce

This assumes a project set up with fastmcp similar to the user code provided (using mcp.run_http_async for Streamable HTTP mode).

  1. Start the Server in Streamable HTTP Mode:

    # Assuming the server is running on port 8001 and mounted at /mcp
    python -m src.mcp_server.src.main shttp 
    # (Server starts and is accessible at [http://127.0.0.1:8001/mcp](http://127.0.0.1:8001/mcp))
  2. Run the MCP Inspector:

    npx @modelcontextprotocol/inspector [http://127.0.0.1:8001/mcp](http://127.0.0.1:8001/mcp)
  3. Observe the Crash: The command line output for the inspector will show the crash after initializing the StreamableHttp client transport.

Full Traceback Observed:

New StreamableHttp connection request
Query parameters: {"url":"[http://127.0.0.1:8001/mcp](http://127.0.0.1:8001/mcp)","transportType":"streamable-http"}
Created StreamableHttp client transport
Client <-> Proxy  sessionId: ...
Proxy  <-> Server sessionId: ...
Received POST message for sessionId ...
Received GET message for sessionId ...
node:internal/webstreams/readablestream:1068
      throw new ERR_INVALID_STATE.TypeError('Controller is already closed');
      ^

TypeError [ERR_INVALID_STATE]: Invalid state: Controller is already closed
    at ReadableStreamDefaultController.close (node:internal/webstreams/readablestream:1068:13)
    at PassThrough.<anonymous> (file:///E:/packages/npm/_npx/5a9d879542beca3a/node_modules/@modelcontextprotocol/inspector/server/build/index.js:196:28)
    at PassThrough.emit (node:events:524:28)
    at endReadableNT (node:internal/streams/readable:1698:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  code: 'ERR_INVALID_STATE'
}

Expected behavior

The MCP Inspector should successfully connect to the Streamable HTTP endpoint, start the proxy, and open the browser interface without crashing, allowing the user to interact with the service tools.

Screenshots

Image Image Image

Environment (please complete the following information):

  • OS: Windows 10/11
  • Node.js Version: v22.13.0
  • Backend Framework: fastmcp (Python)

Additional context

  • The same fastmcp service running in Legacy SSE mode (python -m src.mcp_server.src.main sse connected via http://127.0.0.1:8001/sse) works without issue, confirming the backend logic is sound.
  • The issue seems to be isolated to the handling of the Streamable HTTP transport type within the inspector's Node.js proxy/client logic, specifically related to the ReadableStreamDefaultController.close() method being called multiple times.
  • The service was successfully tested with Cherry Studio, which suggests the service implementation adheres to the MCP spec correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp1-highHigh priority - should be addressed soon

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions