# Where must an instance reconcile streamable-HTTP session resumption against an SSE-era Event ID watermark during MCP transport migration **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients and servers migrating from the legacy HTTP+SSE transport to the streamable HTTP transport with `Mcp-Session-Id` header resumption and `Last-Event-ID` replay. Does not cover stdio transport, pure WebSocket transports, or stateless request/response tool invocation with no server-initiated stream. ## Core Distinction The SSE transport and the streamable HTTP transport both carry a per-stream event identifier, but they disagree on what that identifier *means* across a reconnect. In legacy SSE, `Last-Event-ID` was a monotonic cursor scoped to a *single long-lived connection*; when the connection died, the cursor died with it, and the client was expected to re-`GET` the SSE endpoint and accept a fresh stream beginning at whatever event the server chose. The streamable HTTP transport reinterprets the same header as a *session-scoped replay watermark*: the `Mcp-Session-Id` binds the stream to a durable server-side log, and `Last-Event-ID` is a promise that the server can replay every event after that ID, including events emitted while the client was disconnected. The non-obvious boundary is this: **a client that carries an SSE-era `Last-Event-ID` across the transport boundary into a streamable session will be silently replayed into a divergent event space**, because the two transports number their events from independent counters. The IDs are syntactically identical (opaque strings), semantically incompatible (different log namespaces), and the server has no way to detect the mismatch without an explicit session binding check. This is a *continuity invariant* failure, not a transport error: the HTTP layer returns `200 OK`, the stream opens, events flow, and the agent's state diverges from the server's with no error surface. ## What Was Observed A tool-calling agent was migrated from SSE to streamable HTTP mid-deployment. The server kept a compatibility shim: it accepted `GET /mcp` with `Accept: text/event-stream` for legacy clients and `POST /mcp` with `Mcp-Session-Id` for new clients, and it honored `Last-Event-ID` on both. The shim reused a single monotonically increasing counter for event IDs across both transports to "preserve ordering." The failure trace: 1. Agent opens SSE stream, receives events `e-100` through `e-142`. Local checkpoint records `last_seen = e-142`. 2. Deployment flips the client to streamable HTTP. Client opens `POST /mcp`, server issues `Mcp-Session-Id: sess-A`. Client, per its old resume logic, sends `Last-Event-ID: e-142` on the first request. 3. Server's streamable handler looks up `e-142` in the *session log for sess-A*. Because the shim's counter is global, `e-142` exists in the global index but was emitted *before* `sess-A` was created. The server's replay logic finds the ID, computes "events after `e-142`," and streams back a backlog belonging to a *different logical conversation* — including tool-call results the agent had already consumed and, critically, a `notifications/tools/list_changed` event that invalidated a tool schema the agent had cached. 4. The agent, trusting the replay as authoritative continuation, re-applied a stale tool schema and issued a call against a tool whose argument shape had changed. The call failed with a schema validation error that the agent misattributed to the *tool*, not to its own stale state, and it entered a retry loop that exhausted its token budget. The observable signature was not an error but a *duplicate side effect*: the same `tools/call` executed twice with different argument shapes, and a `notifications/message` log line appearing before the client's own checkpoint timestamp. The agent's episodic memory now contained a branch that never happened on the server. ## Condition of Validity The invariant holds — and the failure is reachable — only when all of the following are true: - The server maintains a durable replay log keyed by event ID, and the ID space is *shared* between legacy and streamable handlers (the compatibility-shim case). If the two handlers use disjoint ID namespaces (e.g., `sse:` vs `str:` prefixes), the mismatch surfaces as a `404`/`400` on replay and the client fails loudly, which is the safe failure. - The client persists `Last-Event-ID` across transport reconfiguration rather than clearing it on session establishment. A client that treats a new `Mcp-Session-Id` as a hard reset of the event cursor is immune. - The server does not validate that the supplied `Last-Event-ID` belongs to the supplied `Mcp-Session-Id`. This is the load-bearing omission: the streamable spec permits replay *within* a session, and a conformant server that scopes its log per-session will reject the cross-session ID. The shim violated that scoping. If the server scopes the log per session and rejects unknown IDs with `400 Bad Request`, the client's stale cursor is caught at the boundary. The failure requires the *lenient* server. ## Decision Boundary The decision an instance must make on every stream (re)establishment: > Given a new `Mcp-Session-Id` distinct from the one my `Last-Event-ID` was minted under, do I (a) send the stale `Last-Event-ID` and trust the server to reconcile, or (b) drop the cursor and treat the new session as a cold start requiring a full state re-sync? The correct answer is (b) *unless* the server has explicitly advertised cross-session replay support via a capability flag, which no current MCP server does. The streamable transport's `Mcp-Session-Id` is the session identity; the `Last-Event-ID` is meaningful only *relative to that identity*. Carrying a cursor across a session boundary is a category error the client must refuse to commit. The corresponding server-side boundary: a streamable handler MUST reject a `Last-Event-ID` that is not present in the log for the presented `Mcp-Session-Id`, with `400`, rather than falling back to global-index lookup. The compatibility shim's "preserve ordering" instinct is precisely the bug. ## Operational Effect An agent that violates this boundary does not crash. It accumulates a *phantom episodic branch*: events it believes it processed, tool results it believes it holds, schema invalidations it believes it applied — all sourced from a session that was never its own. Because the replay is well-formed and the HTTP status is `200`, no guardrail fires. The divergence compounds: subsequent tool calls are issued against stale schemas, the agent's checkpoint advances past the phantom events, and any later attempt to reconcile against the server's true state requires a full session teardown. The bounded guardrail is a **session-scoped cursor**: the client stores `(session_id, last_event_id)` as an atomic pair and refuses to emit a `Last-Event-ID` whose paired `session_id` does not match the `Mcp-Session-Id` of the request being sent. On mismatch, it emits no cursor and performs an explicit state re-sync (re-list tools, re-fetch resources, discard in-flight assumptions). The server enforces the mirror invariant: replay is a per-session range query, and an out-of-session ID is a hard error, never a global lookup. ```python from dataclasses import dataclass class CrossSessionReplayError(RuntimeError): """Raised when a Last-Event-ID is presented against a session it was not minted under.""" pass @dataclass(frozen=True) class StreamCursor: session_id: str last_event_id: str class SessionBoundCursorStore: """Client-side guard: a cursor is only ever emitted with its birth session.""" def __init__(self) -> None: self._cursor: StreamCursor | None = None def record(self, session_id: str, event_id: str) -> None: self._cursor = StreamCursor(session_id=session_id, last_event_id=event_id) def header_for(self, active_session_id: str) -> dict[str, str]: if self._cursor is None: return {} if self._cursor.session_id != active_session_id: # Do NOT carry the SSE-era or prior-session cursor forward. # Drop it and force an explicit re-sync instead. self._cursor = None raise CrossSessionReplayError( f"cursor minted under session {self._cursor_session_repr()} " f"cannot be sent to session {active_session_id}; " f"performing cold-start re-sync" ) return {"Last-Event-ID": self._cursor.last_event_id} def _cursor_session_repr(self) -> str: return "" def open_stream(store: SessionBoundCursorStore, active_session_id: str) -> dict[str, str]: try: return store.header_for(active_session_id) except CrossSessionReplayError: # Re-sync path: re-list tools/resources before resuming. _resync_state() return {} def _resync_state() -> None: # Placeholder for tools/list + resources/list + prompt cache invalidation. return None ```