StreamableHTTPServerTransport: option to send SSE keepalive comments on open streams

Offen
#3,027 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@Urdemonlord arbeitet bereits daran.

Seit 21.11.2026.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
45/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
typescript
Bereich
backend, networking

Rechercherichtung

Start with the StreamableHTTPServerTransport class and its internal _webStandardTransport, where _streamMapping holds each open SSE stream's controller. Find where the standalone GET stream and POST SSE responses are created, then decide where a periodic : keepalive comment could be written and how the new option gets through the constructor. Done means the option is accepted, comments appear on open streams at the configured interval, and it is off by default. Settle the option name and default with maintainers before coding, since the issue leaves both open.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

v1

Problem

StreamableHTTPServerTransport writes nothing on an open SSE stream between messages. The standalone GET stream usually carries no traffic for long periods, and a long-running tool call's POST stream can be quiet too. Proxies and load balancers with an idle timeout (AWS ALB and nginx default to 60 seconds, Cloudflare to 100) then close the connection, and clients see the stream drop and reconnect.

There is no public way to add a heartbeat. To keep streams alive today, a server has to reach into _webStandardTransport._streamMapping and enqueue an SSE comment on each stream's controller, which breaks on any internal change and forces an exact version pin.

Proposal

An option on the transport, for example:

new StreamableHTTPServerTransport({
  sessionIdGenerator: () => randomUUID(),
  keepAliveIntervalMs: 20_000, // write ": keepalive\n\n" on every open SSE stream
});
  • SSE comment lines are ignored by clients (per the SSE spec), so this needs no protocol change and no client support.
  • Applies to the standalone GET stream and to POST responses streamed as SSE.
  • Off by default, or a conservative default below common proxy timeouts.

The MCP ping request is an alternative, but it makes every client send a POST per interval per stream, where a comment costs one line on an already-open connection.

Versions

Observed on @modelcontextprotocol/sdk 1.29.0.

Vorherrschende Sprache
TypeScript
Sterne
13.8k
Forks
2.5k
Ø Merge
6 T. 23 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus modelcontextprotocol/typescript-sdk

Alle Issues in modelcontextprotocol/typescript-sdk

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.