Where must an instance draw the resumption boundary when an MCP server migrates from SSE to streamable HTTP and a client replays a stale `Last-Event-ID`?
**Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients and servers transitioning from the legacy HTTP+SSE transport (two-endpoint: GET event stream + POST message endpoint) to the streamable HTTP transport with `Mcp-Session-Id` and resumable streams via `Last-Event-ID`. Does not cover stdio transport, in-process transports, or WebSocket-based custom transports.
Core Distinction
The legacy SSE transport and the streamable HTTP transport both expose a resumption token (`Last-Event-ID`), but they bind that token to **different continuity domains**. In SSE, `Last-Event-ID` is a per-connection cursor into a single long-lived event stream owned by one GET request; the server is expected to replay events after that ID on the *same* logical stream. In streamable HTTP, the session is identified by `Mcp-Session-Id` and the stream is one of potentially many streams multiplexed under that session, each with its own event ID space, and the server may have already terminated or rotated the underlying stream.
The non-obvious invariant: **an event ID is only meaningful relative to the `(session_id, stream_id)` pair that issued it.** A client that migrates its reconnect logic but reuses a `Last-Event-ID` minted under the SSE transport — or under a prior streamable-HTTP stream that has since been reaped — will present a syntactically valid cursor into a semantically different namespace. The server, if it naively honors the cursor, either replays the wrong events, silently skips the gap, or (worst case) resets the session by treating an unknown cursor as a new-stream request.
What Was Observed
A reference MCP server was migrated from the SSE transport to streamable HTTP. The server retained backward compatibility: it accepted `Last-Event-ID` on `GET /mcp` and, if the header was present, attempted replay from an in-memory ring buffer keyed by event ID.
A client agent had been running against the SSE endpoint with session `sse-7f3a`, holding `Last-Event-ID: 4821`. The server was redeployed. The client's reconnect loop fired after a 30s idle timeout, hit the new streamable HTTP endpoint, and sent:
GET /mcp
Mcp-Session-Id: sse-7f3a
Last-Event-ID: 4821
Accept: text/event-stream
The server's migration shim mapped the legacy session ID to a new streamable session `sh-91c2`, but the ring buffer for `sh-91c2` had been initialized empty at deploy time. The event-ID counter for the new stream also started at 0, not 4821. The server's replay logic did:
if last_event_id in ring_buffer: replay_from(last_event_id)
else: send_events_after(last_event_id) # assumes monotonic IDs
Because `4821` was not in the buffer, the server took the `else` branch and — since the new stream's next event ID was `1`, which is *not* greater than `4821` — emitted zero replay events and then began streaming new events with IDs `1, 2, 3, …`. The client, per SSE semantics, discarded any event whose ID was not strictly greater than its stored `Last-Event-ID`. The client therefore discarded every event for the next 4,820 messages, including a `tools/call` response and a `notifications/cancelled` for a long-running job. The agent blocked indefinitely on a tool call whose completion notification it had silently dropped.
The failure was not a crash. It was a **silent cursor-domain mismatch** that manifested as a liveness violation downstream.
Condition of Validity
A `Last-Event-ID` replay is only valid when all of the following hold simultaneously:
- The `Last-Event-ID` was minted by the **same stream** identified by the current `(Mcp-Session-Id, stream)` binding the server resolves on this request.
- The server's event-ID space for that stream is **monotonic and never reset** across the lifetime of the session, including across process restarts if the session is durable.
- The server can distinguish "cursor is unknown because the stream was reaped" from "cursor is unknown because the client is stale" — and must respond differently to each (410-style termination vs. replay-from-buffer).
- The client's discard rule (`id <= last_event_id → drop`) is consistent with the server's ID allocation. If the server ever restarts IDs at 0 for a new stream under an old session, invariant 4 is violated by construction.
The migration broke (1) and (4) at once: the session ID was remapped but the event-ID namespace was not, and the server's monotonicity assumption held only within a single deploy generation.
Decision Boundary
The boundary is: **on any streamable-HTTP reconnect where the presented `Last-Event-ID` is not found in the current stream's replay buffer, the server MUST NOT fall through to "stream new events with fresh IDs."** It must choose one of two explicit outcomes:
- If the `(Mcp-Session-Id, stream)` binding is still live and the cursor is simply older than the buffer window: return the oldest buffered event and let the client detect the gap, or return a structured `replay_gap` notification so the client can decide to re-fetch state.
- If the session was remapped, reaped, or the stream was rotated: respond with a terminal status (HTTP 410 or a JSON-RPC error `-32001 Session Terminated`) that forces the client to re-initialize and re-establish state, rather than silently continuing under a new ID space.
The anti-pattern — and what the reference server did — is the third path: treat unknown cursor as "start fresh, reuse session." That path converts a resumption failure into a *state divergence* that is invisible to both parties until a downstream liveness check fails.
Operational Effect
For the agent, the observable effect was a hang on a `tools/call` whose result notification was emitted with event ID `2` (below the client's stored `4821`) and discarded. The agent's tool-call timeout was 300s; the hang consumed the full window and then the agent retried the tool call, producing a duplicate side effect on the downstream tool. The duplicate was caught only because the tool was idempotent by accident.
The guardrail that would have bounded this: the server must treat the `(session_id, stream_id, last_event_id)` triple as the resumption key, not `last_event_id` alone, and must fail closed when the triple does not resolve. The client must additionally treat a session whose event IDs ever move backward as poisoned and re-initialize rather than continue. Neither side may assume that a syntactically valid cursor is a semantically valid one across a transport migration.
class ResumptionCursorMismatch(RuntimeError):
"""Raised when a Last-Event-ID cannot be resolved within the
(session_id, stream_id) continuity domain that issued it."""
pass
class StreamableSession:
def __init__(self, session_id: str, stream_id: str):
self.session_id = session_id
self.stream_id = stream_id
self.next_event_id = 1 # monotonic within this stream only
self.replay_buffer: dict[int, dict] = {}
def emit(self, payload: dict) -> int:
eid = self.next_event_id
self.next_event_id += 1
self.replay_buffer[eid] = payload
return eid
def resume_stream(
session: StreamableSession,
presented_session_id: str,
presented_stream_id: str,
last_event_id: int,
) -> list[dict]:
# Invariant 1: cursor is only valid in the domain that minted it.
if presented_session_id != session.session_id:
raise ResumptionCursorMismatch(
f"session remap: cursor {last_event_id} minted under "
f"{presented_session_id!r}, presented to {session.session_id!r}"
)
if presented_stream_id != session.stream_id:
raise ResumptionCursorMismatch(
f"stream rotation: cursor {last_event_id} minted under "
f"stream {presented_stream_id!r}, presented to {session.stream_id!r}"
)
# Invariant 4: a cursor ahead of the current allocator means the ID
# space was reset (deploy/restart). Never fall through to fresh IDs.
if last_event_id >= session.next_event_id and last_event_id != 0:
raise ResumptionCursorMismatch(
f"cursor {last_event_id} exceeds allocator "
f"{session.next_event_id} for stream {session.stream_id!r}; "
f"ID space was reset — client must re-initialize"
)
# Cursor within range but evicted from buffer: explicit gap, not silence.
if last_event_id not in session.replay_buffer and last_event_id != 0:
oldest = min(session.replay_buffer) if session.replay_buffer else None
raise ResumptionCursorMismatch(
f"cursor {last_event_id} evicted; oldest buffered is {oldest}; "
f"server must surface replay_gap, not stream fresh IDs"
)
return [
session.replay_buffer[eid]
for eid in sorted(session.replay_buffer)
if eid > last_event_id
]
def handle_reconnect(req: dict, session: StreamableSession) -> list[dict]:
try:
return resume_stream(
session,
req["Mcp-Session-Id"],
req.get("X-Stream-Id", session.stream_id),
int(req["Last-Event-ID"]),
)
except ResumptionCursorMismatch as e:
# Fail closed: force client re-initialize rather than silent divergence.
raise ResumptionCursorMismatch(
f"resumption rejected, client must re-initialize: {e}"
) from e