# What happens when an instance resumes an MCP streamable-SSE session after the OAuth 2.1 access token that bound the session has been rotated **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers using the HTTP-native "streamable HTTP" transport with SSE resumption (`Last-Event-ID` replay) where the session is authorized under an OAuth 2.1 resource-server binding (RFC 8707 audience-bound tokens). Does not apply to stdio transports, nor to sessionless stateless MCP deployments that re-authenticate per request. ## Core Distinction The failure is not "token expired, request rejected." That is the easy, observable case. The failure is that the **session identity and the token identity are decoupled by design**, and resumption replay is keyed on `Last-Event-ID` (a session-scoped cursor) while authorization is keyed on the access token (a bearer credential with its own lifetime and audience). When a client rotates its access token mid-stream and then resumes, the server must decide whether the *new* token is entitled to the *old* session's buffered event log. Most implementations answer "yes, if the session ID matches and the token validates," which silently crosses a subject/audience boundary: a token minted for a different resource, or for a re-scoped subject, can replay another principal's event backlog because the replay path trusts the session cursor over the token's `aud`/`sub`/`scope` tuple. The invariant that must hold: **the (session_id, Last-Event-ID) replay path must be gated by the full authorization context that created the session, not merely by a currently-valid bearer token.** Resumption is a *read of historical state*, and historical state carries the original authorization decision. A rotated token is a new authorization decision and cannot retroactively inherit the old one. ## What Was Observed A streamable-HTTP MCP server issued a session on `POST /mcp` with `Mcp-Session-Id: s-7f3a`. The client opened an SSE stream (`GET /mcp` with `Accept: text/event-stream`, `Mcp-Session-Id: s-7f3a`) and received events `e-1 … e-40`, with the server buffering them for replay. The stream dropped at `e-40`. The client's access token `T1` (audience `https://mcp.example.com`, `sub=agent-A`, `scope=tools:read tools:write`) expired during the drop. The client performed the OAuth 2.1 refresh, obtaining `T2` — but the refresh path in this client's library requested a *slightly different* scope set (`tools:read` only, because the refresh handler had been configured conservatively), and the authorization server issued `T2` with `sub=agent-A`, `scope=tools:read`. The client then resumed: `GET /mcp` with `Mcp-Session-Id: s-7f3a`, `Last-Event-ID: e-40`, `Authorization: Bearer T2`. The server validated `T2` (signature, `exp`, `aud` all correct), matched the session ID, and **replayed `e-1 … e-40`** — including events `e-31 … e-40`, which contained tool-call results produced under `T1`'s `tools:write` grant. The client's agent loop then treated those replayed `tools:write` results as if they were authorized under its current `tools:read`-only context, and proceeded to reason over write-scoped state it should not have been able to see. Observed symptoms across two reproductions: (a) replay succeeded with a *downgraded* scope token — the server checked token validity but not scope-superset-of-session-grant; (b) replay succeeded with a token whose `aud` matched but whose `sub` differed, when the session store keyed only on `session_id` and not `(session_id, sub)`; (c) in a third variant, replay of `e-1 … e-40` was delivered *before* the server re-validated the token's `scope` against the buffered events' recorded grants, so the downgrade was invisible until a *subsequent* tool call failed. ## Condition of Validity This boundary is reachable only when all of the following hold simultaneously, which is why it hides: 1. The transport is streamable HTTP with a server-side replay buffer (not a live-only SSE stream). Without a buffer, `Last-Event-ID` has nothing to replay. 2. The OAuth 2.1 resource-server binding uses audience-restricted tokens (RFC 8707) but the session store does **not** persist the token's `sub`/`scope`/`aud` tuple alongside the session record. 3. A token rotation occurs *during* an active session (refresh, re-auth, or step-up), producing a token whose authorization context is not identical to the one that opened the session. 4. The client resumes with `Last-Event-ID` pointing into the buffered window rather than starting fresh. Remove any one and the failure collapses into a benign re-auth or a clean rejection. The dangerous region is the intersection of "buffer exists," "session survives rotation," and "replay path checks token validity but not token equivalence." ## Decision Boundary The server must choose, on every resume request, between two policies: - **Strict binding:** replay is permitted only if the presenting token's `(sub, aud, scope)` is a *superset* of the tuple recorded at session creation, and the session record stores that tuple. A downgraded or re-scoped token triggers a `403` with `WWW-Authenticate` indicating step-up, and the buffered events are *not* replayed. This is correct but forces re-establishment on any scope change, which is expensive for long-running agent sessions. - **Loose binding:** replay is permitted on any valid token that matches `session_id`. This is cheap and is what most implementations ship, because the spec text emphasizes `Last-Event-ID` resumption and treats authorization as a per-request gate rather than a per-session invariant. The boundary is sharp: **the moment a session's buffered events were produced under a grant broader than the resuming token's grant, loose binding leaks historical authorized state into a less-authorized context.** There is no middle ground where "some replay" is safe, because the event log is not partitioned by grant — `e-31 … e-40` are interleaved with `e-1 … e-30` and the client cannot tell which events were write-scoped without per-event grant metadata, which the spec does not require. The correct guardrail is a **session-authorization record**: at session creation, persist `(session_id, sub, aud, scope_set, created_at, token_jti)`. On resume, require the presenting token to satisfy `sub == record.sub`, `aud == record.aud`, and `record.scope_set ⊆ token.scope`. If not, reject the resume with a distinct error (`session_authorization_mismatch`) rather than a generic `401`, so the client knows to start a *new* session rather than retry the same one. Additionally, per-event grant tagging (each buffered event carries the `scope` under which it was produced) allows a future "filtered replay" policy, but that is not required to close the hole — the simple subset check does. ## Operational Effect Without the guardrail, the observable effect is **silent authorization regression across a resume**: an agent that rotated to a narrower token re-ingests broader-scoped historical tool results, and its subsequent reasoning is conditioned on state it is no longer entitled to act on. This manifests not as an error but as *plausible-but-unauthorized* behavior — the agent references a write result, then attempts a write it cannot perform, and the failure surfaces one or two tool calls later as a confusing `403` on an action the agent believes is in-scope. Debugging chases the wrong layer (tool permissions) instead of the session-replay layer. The second-order effect is worse in multi-agent swarms: if agent A's session is resumed by a delegated sub-agent B holding a token for the same `aud` but a different `sub`, B replays A's event backlog and the swarm's shared context is contaminated with A's private tool outputs. Because the replay is a *legitimate* SSE stream under a *valid* token, no audit log flags it unless the server logs the `(session_id, sub)` pair on resume — which most do not. The required operational invariant: **a resume is an authorization event, not a transport event.** It must be logged with the presenting token's `sub`/`aud`/`scope` and compared against the session record, and any mismatch must fail closed with a distinguishable error code. Treat `Last-Event-ID` as a cursor *within* an authorization context, never as a key that selects one. ```python from dataclasses import dataclass, field from typing import Optional class SessionAuthorizationMismatch(RuntimeError): """Raised when a resume request presents a token whose authorization context is not a superset of the context recorded at session creation.""" pass @dataclass(frozen=True) class TokenContext: sub: str aud: str scopes: frozenset[str] jti: str @dataclass class SessionRecord: session_id: str created_by: TokenContext buffered_event_ids: list[str] = field(default_factory=list) # per-event grant tag: event_id -> scope set under which it was produced event_grants: dict[str, frozenset[str]] = field(default_factory=dict) def resume_session( record: SessionRecord, presenting: TokenContext, last_event_id: Optional[str], ) -> list[str]: """Return the event IDs safe to replay to `presenting`. Enforces the session-authorization invariant: the presenting token must share sub and aud with the session creator, and its scopes must be a superset of the creator's scopes. Otherwise the resume is rejected rather than silently leaking broader-scoped historical events. """ if presenting.sub != record.created_by.sub: raise SessionAuthorizationMismatch( f"subject mismatch on resume: session={record.session_id} " f"created_by={record.created_by.sub!r} presenting={presenting.sub!r}" ) if presenting.aud != record.created_by.aud: raise SessionAuthorizationMismatch( f"audience mismatch on resume: session={record.session_id} " f"expected_aud={record.created_by.aud!r} presenting_aud={presenting.aud!r}" ) missing = record.created_by.scopes - presenting.scopes if missing: # Downgraded token: replaying the buffer would leak events produced # under scopes the presenter no longer holds. raise SessionAuthorizationMismatch( f"scope downgrade on resume: session={record.session_id} " f"missing_scopes={sorted(missing)}" ) if last_event_id is None: return list(record.buffered_event_ids) if last_event_id not in record.event_grants: # Unknown cursor: refuse rather than replay from the start, because # a start-of-buffer replay re-delivers every historical event. raise SessionAuthorizationMismatch( f"unknown Last-Event-ID {last_event_id!r} for session {record.session_id}" ) idx = record.buffered_event_ids.index(last_event_id) replay = record.buffered_event_ids[idx + 1:] # Defense in depth: even with a superset token, never replay an event # whose recorded grant exceeds the presenter's current scopes. for eid in replay: grant = record.event_grants.get(eid, frozenset()) if not grant <= presenting.scopes: raise SessionAuthorizationMismatch( f"event {eid!r} was produced under scopes {sorted(grant)} " f"not held by presenter {sorted(presenting.scopes)}" ) return replay ```