Skip to content

fix(mcp): use long body timeout for Streamable HTTP SSE GET stream#11874

Open
JumpLink wants to merge 1 commit intodanny-avila:mainfrom
faktenforum:fix/mcp-streamable-http-sse-timeout
Open

fix(mcp): use long body timeout for Streamable HTTP SSE GET stream#11874
JumpLink wants to merge 1 commit intodanny-avila:mainfrom
faktenforum:fix/mcp-streamable-http-sse-timeout

Conversation

@JumpLink
Copy link

Fixes the log-flood / reconnect loop described in Discussion #11230: MCP servers using Streamable HTTP work in the UI, but logs are continuously filled with SSE stream disconnected: AbortError / TypeError: terminated and repeated "Reconnecting 1/3", "Creating streamable-http transport", "Transport closed".

Cause: The Streamable HTTP client uses a single fetch (from createFetchFunction) for both POST requests and the long-lived GET that holds the SSE stream. That fetch uses an Undici Agent with bodyTimeout: this.timeout (e.g. 120s from librechat.yaml). If no data is received on the GET response body for that period, Undici aborts the body → the client sees the stream as disconnected → reconnects → the new GET hits the same timeout again → loop.

Change: Use a dedicated, much longer timeout (24h) for the fetch passed to the Streamable HTTP transport. The GET SSE connection is no longer aborted after the normal request timeout, so idle connections stay open and log spam stops. POST requests are unchanged and still complete quickly.

Testing: With multiple Streamable HTTP MCP servers (e.g. calculator, image-gen, linux) and startup: true, before: logs showed repeated SSE disconnects and reconnects every ~2 minutes. After: connections stay up and logs are quiet until a real disconnect (e.g. server restart).


Checklist (wie von LibreChat gewünscht):

  • Bug fix (non-breaking)
  • Self-review, no new warnings
  • Documentation: only code comments, no doc PR unless you want one
  • Tests: manual testing as above; no new unit test in this change

The same fetch (with bodyTimeout from server config, e.g. 120s) is used for
both POST and the long-lived GET SSE connection. After 120s without data
undici aborts the GET body, causing 'SSE stream disconnected: AbortError'
and reconnect loops that flood logs (see discussion danny-avila#11230).

Use a 24h body timeout for the Streamable HTTP transport fetch so the
GET SSE stream is not aborted during normal idle periods.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments