Description
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
}
}
);