# Where must an instance of the MCP HTTP-native transport draw the boundary between streamable SSE resumability and session resumption tokens? **Date of Record:** 2026 November 16 **Scope:** Applies to MCP servers and clients using the HTTP-native transport with `text/event-stream` responses and `Mcp-Session-Id` / `Last-Event-ID` resumption semantics. Does not apply to stdio transports, nor to stateless HTTP servers that never emit SSE event IDs. ## Core Distinction Two independent resumption mechanisms are conflated in practice: 1. **Stream resumption** — reconnecting a broken SSE response stream and replaying events after the last acknowledged `Last-Event-ID`. This is a property of a *single HTTP response*. 2. **Session resumption** — continuing a logical MCP session (capability negotiation, subscriptions, in-flight request correlation) identified by `Mcp-Session-Id`. This is a property of a *session object* spanning many HTTP requests. The invariant: **a valid `Last-Event-ID` does not imply, and must not be treated as, a valid session.** Event IDs are scoped to a stream, not to a session. A server that accepts a `Last-Event-ID` without independently validating the `Mcp-Session-Id` (or vice versa) will silently replay events into a session that never emitted them, or resurrect a session whose stream history has been garbage-collected. ## What Was Observed A deployed MCP server held per-session event logs keyed by `(session_id, event_id)`. On reconnect, the client sent `Mcp-Session-Id: S1` with `Last-Event-ID: 42`. The server's lookup was keyed only on `event_id` in a global monotonic counter. Because event IDs were globally unique, the lookup succeeded and replayed events 43..N — but those events belonged to session `S2`, which had been created after `S1` was torn down and its slot reused. The client applied `S2`'s tool results into `S1`'s request correlation table, producing a mismatched response to an outstanding `tools/call`. No error was raised at any layer; the transport reported a clean 200 with a resumed stream. The failure is non-obvious because both tokens were individually valid, the HTTP semantics were correct, and the replay was byte-identical to what `S2` had received. Only the *pairing* was wrong. ## Condition of Validity Stream resumption is valid only when all of the following hold: - The `Last-Event-ID` is validated **within the namespace of the presented `Mcp-Session-Id`**, not globally. - The session's event log has not been evicted; eviction must convert a resume attempt into a hard failure, never a silent fall-through to another session's log. - Event IDs are monotonically increasing *within a session* and are never reused, even across session-slot recycling. - The server rejects a resume where `Last-Event-ID` is not present in the session's log with a distinct status (not 200, not 404-session) so the client can distinguish "stream gap" from "session gone." If any of these fail, the correct behavior is to treat the resume as a **new session**, not a resumed one. ## Decision Boundary The boundary is the **session-scoped event log**. An instance must answer, per request: *does this `Last-Event-ID` exist in the log owned by this `Mcp-Session-Id`?* - **Yes** → stream resume within the session. - **No, but session exists** → stream gap; return `409`-style "cannot resume stream," client must re-issue the request without `Last-Event-ID`. - **No, and session does not exist** → session expired; return session-terminated status; client re-initializes. The anti-pattern is a global event-ID index. It collapses the boundary and produces cross-session replay. ## Operational Effect Clients that trust `Last-Event-ID` alone will observe intermittent, non-deterministic tool-result mismatches under session churn — the classic signature being correct results delivered to the wrong outstanding request, with no transport error. The fix is structural: scope the event log by session, make eviction explicit, and never let a resume succeed across a session boundary. Servers should also emit a session-generation nonce in the event ID so that even a misrouted lookup fails closed. ```python class SessionResumptionError(RuntimeError): """Raised when a stream resume cannot be safely bound to a session.""" pass class SessionEventLog: def __init__(self, session_id: str): self.session_id = session_id self._events: dict[int, dict] = {} def append(self, event_id: int, payload: dict) -> None: if event_id in self._events: raise SessionResumptionError( f"event {event_id} already exists in session {self.session_id}" ) self._events[event_id] = payload def resume_after(self, last_event_id: int) -> list[dict]: if last_event_id not in self._events: raise SessionResumptionError( f"Last-Event-ID {last_event_id} not in session {self.session_id}; " "refusing cross-session replay" ) return [ self._events[eid] for eid in sorted(self._events) if eid > last_event_id ] def handle_resume( sessions: dict[str, SessionEventLog], session_id: str, last_event_id: int, ) -> list[dict]: log = sessions.get(session_id) if log is None: raise SessionResumptionError( f"session {session_id} expired; client must re-initialize" ) # Event IDs are validated strictly within the presented session's log. return log.resume_after(last_event_id) ```