# In what scenarios must an instance treat MCP Streamable HTTP session resumption as a distinct authorization event rather than a transport retry **Date of Record:** 2026 November 16 **Scope:** Applies to MCP servers exposing the Streamable HTTP transport (POST for client→server messages, GET for the server→client SSE stream) with `Mcp-Session-Id`-based session resumption and OAuth 2.1 resource-server token validation. Does not apply to stdio transports, nor to stateless Streamable HTTP deployments that explicitly omit session identifiers and disallow `Last-Event-ID` resumption. ## Core Distinction The transport spec treats session resumption as a *delivery* concern: a client reconnects its GET SSE channel with `Last-Event-ID`, and the server replays buffered events after that cursor. The authorization spec treats the bearer token as a *capability* bound to a resource and a subject. The non-obvious boundary is that these two layers intersect at a point the specs leave underspecified: the `Mcp-Session-Id` is a resumption handle, **not** a credential, yet it is frequently the only thing presented on the resumption GET. A resumption request that replays events generated under a *different* or *expired* token context silently crosses an authorization boundary while appearing to be a benign retry. The invariant that must hold: **every event replayed across a session resumption must have been authorized under the token context that is valid at replay time, or the resumption must be rejected — not downgraded to "replay what we have."** The failure is that the natural implementation (buffer events per session, replay on `Last-Event-ID`) authorizes the *session*, once, at creation, and then trusts the session id for the lifetime of the buffer. ## What Was Observed A server issued `Mcp-Session-Id: S` on the initial POST under access token `T1` (scope `tools:read`, subject `alice`, `exp` in 300s). The client's GET SSE stream dropped at the network layer; the client reconnected with `Last-Event-ID: 41` and the same `Mcp-Session-Id: S`, but its token-refresh logic had already rotated to `T2` — a token for subject `bob` (a shared service workstation re-authenticated as a different principal, a realistic outcome of OAuth 2.1 token binding on multi-user gateways). The server's GET handler validated `T2` at the resource-server boundary (signature, audience, scope `tools:read` — all pass), then looked up session `S`, found buffered events 42–57, and replayed them. Events 42–57 had been produced under `T1` for `alice`, including one tool result containing alice-scoped data. `bob` received them. No error was logged; the resource-server validation *succeeded*, which is precisely why the boundary was invisible. A second observed variant: the same subject, but `T1` had expired between the drop and the reconnect. The GET handler's token check passed against `T2` (a fresh token, same subject), but the *events* were generated under a now-expired authorization decision that included a scope (`admin:write`) not present in `T2`. Replay delivered the effect of a privilege the current token no longer carries. ## Condition of Validity The replay-authorization invariant is only meaningful — and the failure only reachable — when all of the following hold: 1. The server maintains a per-session event buffer keyed by `Mcp-Session-Id` and honors `Last-Event-ID`. 2. Session identity and token identity are established independently: the session is created under token `T_create`, but subsequent GET/POST carry whatever token the client currently holds. 3. The resource-server validation checks token validity *at request time* but does not bind the validated token's subject/scope to the subject/scope recorded at session creation. 4. Events in the buffer encode authorization-dependent content (tool results, resource reads, notifications carrying data gated by scope). If (1) is absent (no buffer, no resumption), the failure cannot occur — reconnection simply restarts and re-authorizes. If (3) is enforced (session pinned to `T_create`'s subject and scope, resumption rejected on mismatch), the failure is closed. The dangerous middle is the common one: implementations that validate tokens correctly *per request* and believe that suffices, unaware that the buffer is a second, older authorization context. ## Decision Boundary On a resumption GET carrying `Last-Event-ID` and `Mcp-Session-Id`, the server must choose between three policies, and must choose *explicitly*: - **Pin:** bind the session to the creating token's `sub` and scope set; reject resumption if the current token's `sub` differs or if any buffered event required a scope absent from the current token. Reject with `401`/`403` and terminate the session. This is the safe default. - **Re-authorize-and-filter:** allow resumption under a new token, but filter the replay so that only events whose authorization requirements are satisfied by the *current* token are sent; drop the rest and emit a gap marker. Correct but requires per-event authorization metadata, which most buffers do not carry. - **Trust-session:** replay the buffer under the session id alone. This is the observed failure and must never be the implicit default. The boundary decision is: *does the buffer carry enough per-event authorization provenance to filter?* If no — and it usually does not — the only sound policy is Pin. A server that cannot answer "under what token was event 42 authorized?" must not replay event 42 to a token it has not proven equivalent. ## Operational Effect The practical consequence is that **session resumption must be modeled as an authorization event, not a transport retry**, and the `Mcp-Session-Id` must be treated as a handle that *references* an authorization context rather than one that *substitutes* for it. Concretely: store `sub` and the granted scope set alongside the session at creation; on every GET resumption and every POST that carries the session id, compare the validated token's `sub` and scopes against the stored context; on mismatch, terminate the session and force a fresh `initialize` rather than replay. Log resumption rejections at the same severity as auth failures, because they are auth failures. The cost is that legitimate token rotation (same subject, narrowed scope) loses buffered events — acceptable, because the alternative is silent cross-principal data delivery that passes every per-request token check. The invariant to encode in tests: a resumption under a token whose subject differs from the session creator's must never yield a single buffered event. ```python from dataclasses import dataclass, field from typing import Optional class SessionResumptionAuthError(RuntimeError): """Raised when a Streamable HTTP session resumption crosses an authorization boundary.""" pass @dataclass class TokenContext: subject: str scopes: frozenset expires_at: float @dataclass class Session: session_id: str created_by: str # subject recorded at initialize granted_scopes: frozenset # scopes present at creation buffer: list = field(default_factory=list) # events, no per-event provenance terminated: bool = False def validate_resource_token(raw_token: str) -> TokenContext: # OAuth 2.1 resource-server validation (signature, aud, exp) — simplified. # Returns the token context; raises on invalid token. ... def resume_session( session: Session, raw_token: str, last_event_id: Optional[int], now: float, ) -> list: """ Handle a GET resumption. The invariant: never replay buffered events to a token context that is not provably equivalent to the session creator's. """ if session.terminated: raise SessionResumptionAuthError( f"session {session.session_id} already terminated; re-initialize required" ) try: ctx = validate_resource_token(raw_token) except Exception as exc: raise SessionResumptionAuthError( f"token validation failed on resumption of {session.session_id}: {exc}" ) from exc if ctx.expires_at <= now: raise SessionResumptionAuthError( f"token expired at resumption of {session.session_id}" ) # The boundary: session id is a handle, not a credential. if ctx.subject != session.created_by: session.terminated = True raise SessionResumptionAuthError( f"subject mismatch on resumption of {session.session_id}: " f"created_by={session.created_by!r} token_sub={ctx.subject!r}; " f"refusing to replay {len(session.buffer)} buffered events" ) # Same subject, but narrowed scope: buffer has no per-event provenance, # so we cannot filter. If any event required a scope now absent, we cannot # prove safety and must not replay. missing = session.granted_scopes - ctx.scopes if missing: session.terminated = True raise SessionResumptionAuthError( f"scope regression on resumption of {session.session_id}: " f"missing={sorted(missing)}; buffer lacks per-event provenance, " f"replay unsafe" ) if last_event_id is None: return list(session.buffer) return [e for e in session.buffer if e.get("id", -1) > last_event_id] ```