Skip to content

Context7 Platform -- Up-to-date docs for AI agents

Disable SSE keepalives so hung exchanges are reapable (#3019)

Fahreddin Özcanc68104e52c2d
diff --git a/.changeset/mcp-drop-self-cancellations.md b/.changeset/mcp-drop-self-cancellations.md
new file mode 100644
index 00000000..ecb7c0a1
--- /dev/null
+++ b/.changeset/mcp-drop-self-cancellations.md
@@ -0,0 +1,5 @@
+---
+"@upstash/context7-mcp": patch
+---
+
+Disable SSE keepalive heartbeats on the HTTP handler (`keepAliveMs: 0`). Every tool is a millisecond vector query, so no legitimate exchange needs a heartbeat — but a hung exchange kept alive by heartbeats can never be reaped by a proxy's stream idle timeout. One such hang is deterministic: a 2025-era JSON-RPC batch carrying a request plus its own `notifications/cancelled` gets no response for the cancelled request (per spec), the SDK transport then never closes the stream, and heartbeats kept it alive until the gateway's 1200s hard cap — the dominant source of leaked upstream connections in the 2026-08-11 mcp.context7.com outage. With heartbeats off, silent hangs go idle and the proxy reaps them at its idle timeout.
diff --git a/packages/mcp/src/index.ts b/packages/mcp/src/index.ts
index e7e3c3a6..fc2301da 100644
--- a/packages/mcp/src/index.ts
+++ b/packages/mcp/src/index.ts
@@ -365,7 +365,17 @@ async function main() {
// no session store. The handler serves modern (2026-07-28) traffic natively
// and 2025-era traffic through its stateless legacy fallback, which answers
// GET/DELETE (session operations) with 405.
+ // keepAliveMs: 0 disables SSE keepalive heartbeats. Every tool here is a
+ // millisecond vector query (p100 ~28s), so no legitimate exchange needs a
+ // heartbeat to stay alive — but a hung exchange kept "alive" by heartbeats
+ // can never be reaped by the gateway's stream idle timeout. A batch
+ // carrying a request plus its own notifications/cancelled produces exactly
+ // that: per spec the cancelled request gets no response, the SDK transport
+ // then never closes the stream, and with heartbeats it survived until the
+ // gateway's 1200s hard cap (the 2026-08-11 outage). Silent hangs instead
+ // go idle and the gateway reaps them at streamIdleTimeout (300s).
const mcpHandler = createMcpHandler(() => createMcpServer(), {
+ keepAliveMs: 0,
onerror: (error) => console.error("MCP handler error:", error),
});
// Without onerror, request-conversion / handler.fetch throws are answered