8000 How to keep alive a connection from an MCP client to a MCP server when using HTTP Stream transport · Issue #120 · punkpeye/fastmcp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
How to keep alive a connection from an MCP client to a MCP server when using HTTP Stream transport #120
Open
@mlc-mlapis

Description

@mlc-mlapis

A successful connection from an MCP client to an MCP server (FastMCP) using HTTP Stream transport is terminated after ~ 60 seconds with the error message: SSE stream disconnected: TypeError: terminated.

It comes from line 184 of node_modules\@modelcontextprotocol\sdk\dist\esm\client\streamableHttp.js:

182: catch (error) {
183:   // Handle stream errors - likely a network disconnect
184:  (_c = this.onerror) === null || _c === void 0 ? void 0 : _c.call(this, new Error(`SSE stream disconnected: ${error}`));
         ...

If we ignore the fact that the code has a small mistake, because it does not differentiate between the SSE stream and the HTTP stream, the termination event comes from the MCP server.

What is the right way to eliminate such behaviour, such as extending the timing over 60 seconds? Is there anything on the MCP server side that can support it? Shouldn't the server send keep-alive messages every x seconds?

I tried to use the optional object when creating the transport, but without success.

this.transport = new StreamableHTTPClientTransport(
  new URL('http://localhost:8080/mcp'),
  {
    reconnectionOptions: {
      maxReconnectionDelay: 60000,
      initialReconnectionDelay: 2000,
      reconnectionDelayGrowFactor: 1.5,
      maxRetries: 3
    }
  }
);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0