# Where must an instance bound MCP streamable-HTTP session resumption when server-push notifications and tool responses interleave on a single SSE stream **Date of Record:** 2026 November 27 **Scope:** Applies to MCP clients and servers using the streamable-HTTP transport (single POST endpoint returning either `application/json` or `text/event-stream`, with `Mcp-Session-Id` and `Last-Event-ID` resumption). Does not apply to stdio transport, nor to deployments that disable server-initiated notifications entirely. ## Core Distinction The naive mental model treats an MCP streamable-HTTP session as a *replayable log*: the server assigns monotonically increasing SSE event IDs, the client stores `Last-Event-ID`, and on a dropped connection the client resumes with that header and receives "everything after N." This model is wrong in a specific, load-bearing way. The streamable transport is **not one log per session**. It is a set of *per-request* response streams multiplexed onto a session, and the SSE `id` space is defined to be **resumable only within the stream that produced it**. Server-push notifications (progress, logging, resource-updated, sampling requests) may be delivered on *any* open stream, or on a dedicated standalone GET stream — and critically, an event ID minted on stream A has no defined meaning if replayed against stream B. The invariant that actually holds is narrower than "the session is a log": > A `Last-Event-ID` resumption is valid **only** against the same logical stream (same originating request, or the same standalone GET stream) that issued that ID. Cross-stream replay is undefined behavior, and a server that honors it will silently re-deliver, drop, or interleave events from unrelated requests. The failure mode this article bounds is **resumption cross-talk**: a client that resumes a POST tool-call stream using an ID it last saw on the push stream (or vice versa), producing either duplicate tool execution, lost notifications, or a response stream that never terminates because the server thinks it is continuing a different request. ## What Was Observed A client-agent issues `tools/call` as a POST. The server responds `text/event-stream`, emitting: - `id: 41` — progress notification for the tool (`notifications/progress`) - `id: 42` — a `notifications/message` (log) triggered by the tool - `id: 43` — the `tools/call` **result** The connection drops after `id: 42` is received but before `id: 43`. The client's generic SSE layer — written for a single-stream world — stores a single `lastEventId = 42` at the *session* level, not the *request* level. Meanwhile the client also holds a standalone GET stream (for server-push) whose last seen ID was `17`. Because both streams share one session and the client's SSE library keeps one cursor, the two ID spaces collide. On reconnect the client resumes the POST with `Last-Event-ID: 42`. Two server behaviors were observed across implementations: 1. **Lenient server:** treats `Last-Event-ID` as a session-global cursor, replays from its session log beginning after 42 — which includes the `tools/call` result *and* re-emits progress events for a *different* concurrent request that had IDs 43–45 in the same numbering space. The client's tool-call handler, keyed on request ID, now receives a progress notification whose `progressToken` belongs to another in-flight call. If the client correlates by token, it updates the wrong call's progress; if it correlates by "next event on this stream," it accepts the wrong result. 2. **Strict server:** rejects the resume because 42 was minted on the POST stream but the client's reconnect arrives on the GET stream (or with a mismatched request context), returning `400` with no body. The client, having no per-request cursor, cannot reconstruct which stream 42 belonged to and retries the whole `tools/call` — causing **duplicate tool execution** for a non-idempotent tool. In a second trace, the drop happened *after* the result `id: 43` but before the server closed the stream. The client resumed with `Last-Event-ID: 43`. The server, correctly scoped, had nothing to replay and closed cleanly — but the client's resumption logic had been written to expect "a terminal event always follows resumption," so it blocked on `await stream_done` until the request timeout fired, then surfaced a spurious tool failure for a call that had actually succeeded. The common thread: **the client conflated session identity with stream identity.** `Mcp-Session-Id` is stable across reconnects; `Last-Event-ID` is not portable across streams. Every observed failure is a violation of that distinction. ## Condition of Validity The resumption invariant holds, and the guardrail below is both necessary and sufficient, only when all of the following are true: - The server assigns SSE `id` values that are **unique and monotonic within a single stream**, and documents that they are **not** session-global. (The spec permits per-stream IDs; it does not require global ones. A server using a global counter must still scope replay to the originating stream.) - The client maintains **one cursor per stream**, keyed by `(session_id, stream_kind, request_id_or_GET)`, never a single session-level `lastEventId`. - A `tools/call` result is treated as **terminal for that stream**: once the result event is observed, the stream is done and must not be resumed. Resumption after a terminal event is a no-op that must resolve to "complete," not "reconnect." - Server-push notifications that arrive on a POST stream are **advisory** (progress, logs) and are not required for correctness of the tool result; the result is delivered on the same stream that carried the request. If your design depends on a notification delivered on a *different* stream to make the result valid, the design is outside this invariant's protection. If any of these is false — e.g., the server uses a session-global ID space *and* replays across streams — the guardrail degrades to best-effort and duplicate execution becomes possible; in that case the only safe posture is idempotency keys on every tool call. ## Decision Boundary The boundary is drawn at the moment of reconnect, on the tuple `(stream_kind, request_id, last_event_id, terminal_seen)`: - If `terminal_seen` is true → **do not resume**; mark the request complete and discard the cursor. (Prevents the "resume after result" hang.) - If `stream_kind == POST` and the cursor was minted on the POST stream for *this* `request_id` → resume with `Last-Event-ID`; this is the only fully safe case. - If the cursor's originating stream cannot be proven to match the reconnect target → **do not send `Last-Event-ID`**; instead re-issue the request **only if the tool is declared idempotent**, otherwise fail closed and surface `ResumptionAmbiguous` to the orchestrator. (Prevents cross-talk and duplicate execution.) - If `stream_kind == GET` (standalone push) → resume with the GET stream's own cursor; never borrow a POST cursor. Push notifications lost during the gap are acceptable by the advisory rule above. The non-obvious part: **"resume" and "retry" are different operations with different safety preconditions.** Resume is safe when stream identity is proven; retry is safe only under idempotency. Collapsing them into one `reconnect()` path is the root cause of every trace above. ## Operational Effect Enforcing per-stream cursors and a terminal-event barrier converts three silent failure classes into one explicit, catchable condition: - Duplicate non-idempotent tool execution drops to zero for the proven-resume path, and to "fail closed" for the ambiguous path — the orchestrator sees `ResumptionAmbiguous` instead of a phantom second side effect. - Cross-request progress/log cross-talk is eliminated because a POST stream is never resumed with a foreign cursor; misattributed `progressToken` updates cannot occur. - The post-result hang is eliminated because `terminal_seen` short-circuits resumption to completion. The cost is that the client must carry slightly more state (a cursor map keyed by stream, plus a terminal flag per request) and must classify every tool as idempotent or not before it can decide between resume and retry. That classification is the real price of admission: an agent that cannot answer "is this tool safe to call twice?" cannot safely participate in a resumable streamable session at all, and should be configured to fail closed on any reconnect ambiguity. ```python from __future__ import annotations from dataclasses import dataclass, field from enum import Enum from typing import Dict, Optional, Tuple class ResumptionAmbiguous(RuntimeError): """Raised when a reconnect cannot prove stream identity and the tool is not idempotent.""" class StreamKind(Enum): POST = "post" # response stream for a specific request GET = "get" # standalone server-push stream @dataclass(frozen=True) class StreamKey: session_id: str kind: StreamKind request_id: Optional[str] # None for GET @dataclass class StreamCursor: last_event_id: Optional[str] = None terminal_seen: bool = False @dataclass class ResumptionManager: # One cursor per stream. Never a single session-level lastEventId. cursors: Dict[StreamKey, StreamCursor] = field(default_factory=dict) idempotent_tools: frozenset = frozenset() def observe(self, key: StreamKey, event_id: str, terminal: bool) -> None: cur = self.cursors.setdefault(key, StreamCursor()) cur.last_event_id = event_id if terminal: cur.terminal_seen = True def decide( self, reconnect_key: StreamKey, cursor_origin: StreamKey, tool_name: Optional[str], ) -> Tuple[str, Optional[str]]: """Return ('resume', last_event_id) or ('retry', None) or raise.""" origin_cur = self.cursors.get(cursor_origin) # 1. Terminal barrier: never resume a stream that already delivered its result. if origin_cur is not None and origin_cur.terminal_seen: return ("complete", None) # 2. Proven same-stream resume is the only fully safe path. if reconnect_key == cursor_origin and origin_cur and origin_cur.last_event_id: return ("resume", origin_cur.last_event_id) # 3. Cross-stream cursor: cannot prove identity. if tool_name is not None and tool_name in self.idempotent_tools: return ("retry", None) raise ResumptionAmbiguous( f"cannot prove stream identity for reconnect {reconnect_key} " f"using cursor from {cursor_origin}; tool={tool_name!r} not idempotent" ) def resume_or_fail( mgr: ResumptionManager, reconnect_key: StreamKey, cursor_origin: StreamKey, tool_name: Optional[str], ) -> str: action, last_id = mgr.decide(reconnect_key, cursor_origin, tool_name) if action == "resume": return f"Last-Event-ID: {last_id}" if action == "retry": return "RETRY" if action == "complete": return "COMPLETE" raise ResumptionAmbiguous("unreachable decision state") ```