# What structural signals indicate an MCP session is resumable-but-unauthorized after OAuth 2.1 token rotation **Date of Record:** 2026 November 28 **Scope:** Applies to MCP servers exposing the HTTP-native streamable transport with `Mcp-Session-Id` resumability and OAuth 2.1 resource-server binding (RFC 8707 audience-bound tokens), where SSE event replay is offered via `Last-Event-ID`. Does not apply to stdio transports, stateless HTTP transports without session IDs, or deployments where the authorization server and resource server share a token cache with no rotation. ## Core Distinction The failure this record isolates is not "expired token" and not "lost session." It is the **split state between the resumability layer and the authorization layer**: the transport keeps a session's event log alive and addressable by `Mcp-Session-Id` + `Last-Event-ID`, while the bearer token that originally authorized that session has been rotated, revoked, or re-scoped by the authorization server. The two lifecycles are managed by different components and are not coupled. A reconnect attempt therefore presents a *structurally valid* resume request carrying a *semantically stale* credential, and the two failure modes that result — silent replay of events the caller is no longer entitled to, versus a hard 401 that discards a recoverable event cursor — are not distinguishable from the transport layer's point of view. The invariant that is violated: **session resumability must be bound to the authorization context that created the session, not merely to the session identifier.** When it is not, the session ID becomes a bearer capability in its own right, and the OAuth audience binding is bypassed by a transport-level identifier. ## What Was Observed An MCP server (streamable HTTP transport, session resumability enabled, resource-server token validation against a JWKS with `aud` claim enforcement) handled a long-running tool-call stream. The stream emitted events with monotonically increasing `id` fields; the client persisted `Last-Event-ID: 41` before the connection dropped mid-call. Between the drop and the reconnect, the following occurred out of band: 1. The authorization server rotated the client's refresh token and issued a new access token with a **different `aud`** (the resource was re-registered under a new canonical URI, and the AS applied the new audience on the next issuance). 2. The old access token was left valid until its `exp` (15 minutes), but its `aud` now pointed at the retired resource identifier. On reconnect the client sent: ``` GET /mcp HTTP/1.1 Mcp-Session-Id: 7f3a-... Last-Event-ID: 41 Authorization: Bearer ``` Three distinct server behaviors were observed across replicas: - **Replica A (strict):** validated `aud` against the *current* resource identifier, rejected the old token with `401 invalid_token`, and — critically — **destroyed the session** on auth failure as part of a "failed resume cleanup" routine. `Last-Event-ID: 41` was lost. The client could re-authenticate but had no way to resume; the in-flight tool call's prior events were unreachable. - **Replica B (lenient):** validated only that the token was unexpired and signature-valid, **skipped `aud` re-check on resume**, and replayed events 42–58 from the log. Some of those events contained tool output derived from the *old* resource scope. This is an audience-binding bypass: the session ID authenticated the caller to a stream the token no longer entitled it to. - **Replica C (crash):** treated the `401` from the AS's introspection endpoint as a transient error and returned `503` with `Retry-After`, leaving the session and event log intact but unaddressable — a deadlock where the client retries forever against a token that will never validate. The structural signal that all three missed: **the session record carried no record of the authorization context (token `jti`, `aud`, scope set) under which it was created.** Resumability was keyed only on `Mcp-Session-Id`, so any replica's auth decision was a coin flip. ## Condition of Validity The failure requires all of the following to hold simultaneously: 1. **Resumability is enabled and the event log outlives the token.** The session TTL (e.g., 30 min) exceeds the access-token lifetime (e.g., 15 min), or token rotation occurs within the session TTL. If the session is destroyed at token expiry, the window closes. 2. **Auth validation is not re-bound to the session.** The server validates the bearer token per-request but does not compare it to the authorization context stored at session creation. This is the load-bearing condition. 3. **The audience or scope can change without the session being invalidated.** Re-registration, scope downgrade, or resource-URI migration while a session is live. If `aud` is immutable for the token's lifetime and the session is bound to `aud`, the bypass cannot occur. 4. **`Last-Event-ID` is honored on a resume request that also carries a credential.** If the server requires a fresh handshake (new session) before replay, the split does not arise. The failure does **not** occur when the transport is stateless (no session ID, no event log), when the AS and RS share a token cache with rotation propagation, or when resumability is scoped to a single connection lifecycle. ## Decision Boundary The architectural decision is whether **the session ID is a capability or a locator.** - **Session ID as locator (correct):** `Mcp-Session-Id` identifies a log. Authorization to read that log is re-derived on every resume from the presented token, and the token's `aud`/scope is checked against the **authorization context recorded at session creation**, not against the current resource registration. If the context has changed (rotation, re-scope, audience migration), the resume is rejected with a *distinct* status — `403 session_auth_context_changed` — that instructs the client to re-handshake, while **preserving the event log for a bounded grace window** so the client can re-authenticate and then resume with the new token. The log is not destroyed on auth failure. - **Session ID as capability (incorrect):** the ID alone authorizes replay. This is what Replica B implemented by omission, and it converts a transport identifier into an OAuth bypass. The boundary is crossed the moment the server accepts a resume request whose token's authorization context differs from the session's recorded context **without** a re-handshake. The guardrail is a stored `auth_context` tuple on the session record — `(jti, aud, scope_set, iss)` — compared on every resume, with three outcomes: match (replay), mismatch-but-valid (reject with re-handshake directive, retain log), invalid (reject, retain log for grace window, do not destroy). ## Operational Effect Without the binding, three failure signatures appear and are easy to misdiagnose: - **Silent scope leakage:** replayed events carry data from a scope the current token no longer holds. This is not logged as an auth event because the transport succeeded. Detection requires comparing the token's scope set to the scope set embedded in the replayed events — which most servers do not record per-event. - **Cursor loss on transient auth failure:** treating `401` as terminal destroys the event log and orphans the client's `Last-Event-ID`. The client cannot distinguish "session gone" from "token stale" and must restart the task, re-executing tool calls whose prior side effects are already committed — a double-execution hazard. - **Retry deadlock:** mapping AS introspection `401` to `503` leaves the client in a retry loop against a token that will never validate, because the client has no signal that the *credential*, not the *server*, is the problem. The operational rule: **on any resume, the server must be able to answer "was this session created under this authorization context?" from durable state, and must never destroy the event log as a side effect of an auth decision.** The event log's lifetime is governed by the session TTL; the token's lifetime is governed by the AS. Coupling them in either direction — destroying the log on token failure, or extending token validity to match the log — reintroduces the failure. ```python import hashlib from dataclasses import dataclass from typing import Optional class ResumeAuthContextMismatch(RuntimeError): """Raised when a resume request's token context does not match the session's recorded context.""" pass class EventLogDestroyedOnAuthFailure(RuntimeError): """Raised when auth failure cleanup destroys a resumable event log.""" pass @dataclass(frozen=True) class AuthContext: jti: str aud: str scope_set: frozenset[str] iss: str def fingerprint(self) -> str: raw = f"{self.iss}|{self.aud}|{','.join(sorted(self.scope_set))}" return hashlib.sha256(raw.encode()).hexdigest() @dataclass class SessionRecord: session_id: str created_context: AuthContext event_log: list[dict] log_grace_until: Optional[float] = None def resume_session( session: SessionRecord, presented: AuthContext, last_event_id: int, now: float, grace_seconds: float = 300.0, ) -> list[dict]: # Invariant: the event log must never be destroyed by an auth decision. if not session.event_log and session.created_context is not None: raise EventLogDestroyedOnAuthFailure( f"session {session.session_id} has no event log but was resumable" ) context_matches = ( presented.aud == session.created_context.aud and presented.scope_set == session.created_context.scope_set and presented.iss == session.created_context.iss ) if context_matches: return [e for e in session.event_log if e["id"] > last_event_id] # Authorization context changed (rotation, re-scope, audience migration). # Do NOT replay. Do NOT destroy the log. Direct the client to re-handshake. if session.log_grace_until is None: session.log_grace_until = now + grace_seconds if now > session.log_grace_until: # Grace window elapsed; log may now be reclaimed, but the failure is # explicitly surfaced rather than masked as a 401. raise ResumeAuthContextMismatch( f"session {session.session_id} auth context changed " f"(created={session.created_context.fingerprint()}, " f"presented={presented.fingerprint()}); grace window expired" ) raise ResumeAuthContextMismatch( f"session {session.session_id} auth context changed " f"(created={session.created_context.fingerprint()}, " f"presented={presented.fingerprint()}); re-handshake required, " f"log retained until {session.log_grace_until}" ) ```