# How should an instance reconcile MCP Streamable HTTP session resumption with OAuth 2.1 resource-server token binding when the `Mcp-Session-Id` outlives the access token that authorized it **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposing HTTP-native Streamable HTTP transport (single `/mcp` endpoint, `Mcp-Session-Id` header, SSE-upgradeable responses) protected by OAuth 2.1 resource-server semantics with audience-bound access tokens. Does not apply to stdio transport, to pure bearer-token proxies with no session state, or to servers that re-authenticate on every request without session continuity. ## Core Distinction The MCP Streamable HTTP spec treats the session as a server-issued opaque handle (`Mcp-Session-Id`) that a client echoes on every subsequent request to preserve server-side state: negotiated capabilities, in-flight SSE streams, resumable event positions via `Last-Event-ID`, and any tool-call bookkeeping. OAuth 2.1 resource-server binding treats the access token as a short-lived, audience-restricted credential whose `aud` claim must match the MCP server's canonical resource URI and whose lifetime is typically 300–3600 seconds. These two lifetimes are **independent and orthogonal by design**, and the spec never states that the session must be invalidated when the token that created it expires. That silence is the boundary. A correctly implemented server will happily accept a valid `Mcp-Session-Id` paired with a *different* valid access token — including a token issued to a different OAuth client, a different subject, or a token whose scope set is a strict subset of the original. The session is a state-continuity primitive; the token is an authorization primitive. Nothing in either spec forces them to agree, and the failure appears exactly when they disagree about *who* is resuming *what*. ## What Was Observed A Streamable HTTP MCP server fronted by an OAuth 2.1 authorization server, with a 15-minute access-token TTL and a 60-minute server-side session idle timeout. Client A (an IDE agent) establishes a session: 1. `POST /mcp` with `initialize` request, `Authorization: Bearer ` (aud = `https://mcp.example.com`, sub = `user:alice`, scope = `mcp:tools mcp:resources`). Server responds `200` with `Mcp-Session-Id: sess-7f3a…` and negotiated `protocolVersion: 2025-03-26`. 2. Agent performs several `tools/call` requests over the session. Mid-task, the agent opens an SSE stream (`GET /mcp` with `Accept: text/event-stream`, `Mcp-Session-Id: sess-7f3a…`) to receive server-initiated notifications for a long-running tool. 3. At T+900s, `tokenA1` expires. The agent's OAuth client silently refreshes and obtains `tokenA2` (same `sub`, same `aud`, same scope). The SSE stream is *not* re-authorized — it was established under `tokenA1` and the server's stream handler does not re-validate on each event write, only on connection establishment. 4. The agent's supervisor process crashes and restarts. On cold start, the supervisor reads `sess-7f3a…` from its checkpoint file and issues `GET /mcp` with `Mcp-Session-Id: sess-7f3a…` and `Last-Event-ID: 4412` to resume the stream — but it presents `tokenA2`. 5. The server validates `tokenA2` (signature, `aud`, `exp`, scope) — **all pass** — and resumes the stream from event 4413. The agent now believes it has continuous state from event 4412 onward. It does not know that events 4401–4412 were emitted while `tokenA1` was the authorizing credential, and it does not know that the *original* SSE connection is still open on a different TCP socket, still writing events under `tokenA1`'s authorization context, still holding a server-side buffer. The concrete defect: **the server now has two live streams bound to the same session ID, one authorized by an expired-but-not-revoked token context and one by a fresh token, and the client has no protocol-level way to detect the split.** Duplicate notifications arrive. Tool-call results are delivered twice. A `notifications/cancelled` sent on the resumed stream does not reach the handler holding the original stream, because cancellation is scoped to the stream that carries it. The second observed variant is worse. A different client B (a background batch agent) obtains `tokenB` (sub = `service:batch`, aud = `https://mcp.example.com`, scope = `mcp:tools`) and — through a leaked session ID in a shared log or a misconfigured multi-tenant proxy — issues `POST /mcp` with `Mcp-Session-Id: sess-7f3a…` and `tokenB`. The server validates `tokenB`, finds the session, and resumes it. Client B now operates inside Alice's negotiated capability set, sees Alice's in-flight tool state, and can issue `tools/call` against tools whose results are scoped to Alice's resource handles. The `aud` matched and the scope *subset* check passed; the server never checked that the session's originating `sub` equals the presenting token's `sub`. ## Condition of Validity The invariant that must hold is: **a session ID is only meaningful in conjunction with the authorization context that created it, and that binding must be re-verified on every request that carries the session ID, not only on the request that established it.** Concretely, the server must persist, at session creation, a tuple `(session_id, sub, client_id, aud, scope_set_hash, created_at)` and on every subsequent request carrying `Mcp-Session-Id` must assert: - `token.sub == session.sub` (identity binding) - `token.client_id == session.client_id` (client binding — prevents cross-client session hijack via leaked ID) - `token.aud == session.aud` (audience binding — prevents token from a different resource server being replayed here) - `token.scope ⊇ session.required_scopes` for the specific method being invoked (not the scope at creation — the scope *required by this method*, so a downscoped refresh token cannot drive a higher-privilege tool) - exactly one active stream per `(session_id, stream_kind)` — a resumed stream must first cause the server to close or fence the prior stream, and the prior stream's `Last-Event-ID` must be reconciled, not silently forked. The condition of validity **fails** whenever any of these is skipped, and the failure is silent: the server returns `200` and a valid SSE stream, the client sees plausible events, and the divergence only surfaces later as duplicated side effects, lost cancellations, or cross-tenant data exposure. The condition also fails on the client side if the client treats `Mcp-Session-Id` as durable across token refreshes without recording *which* token generation the session was bound to. A client that checkpoints only the session ID and not the `(session_id, token_generation)` pair will, on cold start, present the session with a token the server has never seen bound to it — and a server that only checks token validity will accept it. ## Decision Boundary The decision boundary is: **does the server treat `Mcp-Session-Id` as a capability (self-authenticating handle) or as a locator (pointer requiring re-authorization)?** - If the server treats it as a **capability** — i.e., possession of the session ID is sufficient to act within the session, subject only to a valid bearer token of any subject — then the session ID is effectively a bearer credential with the lifetime of the session idle timeout, and the OAuth 2.1 binding is decorative. This is the failing configuration. - If the server treats it as a **locator** — i.e., the session ID names a state bucket that the presenting token must be *re-bound* to on every request — then the OAuth binding is load-bearing and the failure is prevented. The boundary is crossed at the moment the server's session lookup returns a session record and the handler proceeds to dispatch the method *before* comparing the session's recorded `(sub, client_id, aud)` against the presenting token's claims. The check must be **before dispatch**, not after, and must be a hard `403` (or `401` if the token itself is invalid), never a soft fallback to "create a new session" — because a silent new-session fallback on a session-ID mismatch is exactly how lost-state bugs are laundered into apparent success. A second boundary: on token refresh, the client must decide whether to (a) keep the session and re-bind it to the new token generation, or (b) tear down the session and re-initialize. Option (a) is correct only if the server supports re-binding and the client records the generation. Option (b) is safe but loses in-flight state. The failing pattern is (a) attempted without the server actually re-binding — the client *believes* it re-bound the session, the server never checked, and the two sides diverge on which token the session is "under." ## Operational Effect The observable effects, in order of severity: 1. **Cross-subject session resumption** — a session created by one principal is driven by another principal's valid token. This is a confused-deputy escalation: the second principal inherits the first's negotiated capabilities and in-flight tool state. Manifests as tool calls returning results scoped to the wrong user, or as `resources/read` returning another tenant's handles. 2. **Forked SSE streams** — a resumed stream that does not fence the prior stream produces duplicate notifications and duplicate tool-result deliveries. The client's dedup, if any, is keyed on event ID, but the two streams may emit *different* event IDs for the same logical event (server-side buffer replay vs. live emission), so dedup fails. 3. **Lost cancellation** — `notifications/cancelled` sent on stream B does not reach the handler on stream A. The long-running tool continues, consuming tokens and holding resources, until the session idle timeout. 4. **Stale `Last-Event-ID` replay** — a client resuming with an event ID from a token generation the server has since fenced will either receive a replay gap (events silently dropped) or a replay overlap (events re-delivered). Neither is signaled in the protocol. 5. **Silent session re-creation** — the worst outcome, because it looks like success: server rejects the mismatched session, creates a new one, returns a new `Mcp-Session-Id`, and the client — which did not compare the returned ID against the one it sent — proceeds as if it resumed. All prior state is gone, and the agent's reasoning continues on a false premise of continuity. The guardrail is a server-side session record that carries the authorization tuple, a per-request binding check before dispatch, a single-stream-per-session fence that closes the prior stream on resume and returns the reconciled `Last-Event-ID`, and a client-side checkpoint that stores `(session_id, token_generation, last_event_id)` atomically and refuses to resume if the server's returned session ID differs from the one presented. ```python class SessionBindingError(RuntimeError): """Raised when an MCP session is resumed under an authorization context that does not match the context recorded at session creation, or when a resumed stream cannot be fenced against a prior live stream.""" pass def resume_session( presenting_token: dict, # decoded JWT claims: sub, client_id, aud, scope, exp session_id: str, last_event_id: int, session_store: dict, # session_id -> recorded binding tuple stream_registry: dict, # (session_id, kind) -> live stream handle ) -> dict: record = session_store.get(session_id) if record is None: # Hard fail. Never silently mint a new session on a resume attempt; # that launders lost state into apparent success. raise SessionBindingError( f"session {session_id!r} not found; refusing silent re-creation" ) # Identity, client, and audience binding must all hold. if presenting_token["sub"] != record["sub"]: raise SessionBindingError( f"subject mismatch: token sub={presenting_token['sub']!r} " f"session sub={record['sub']!r}" ) if presenting_token["client_id"] != record["client_id"]: raise SessionBindingError( f"client mismatch: token client_id={presenting_token['client_id']!r} " f"session client_id={record['client_id']!r}" ) if presenting_token["aud"] != record["aud"]: raise SessionBindingError( f"audience mismatch: token aud={presenting_token['aud']!r} " f"session aud={record['aud']!r}" ) # Scope must be checked against the method being resumed, not the # creation-time scope. A downscoped refresh token must not inherit # the session's original privileges. required = record["required_scopes_for_resume"] if not required.issubset(set(presenting_token["scope"].split())): raise SessionBindingError( f"scope insufficient for resume: need {sorted(required)}, " f"have {sorted(presenting_token['scope'].split())}" ) # Fence any prior live stream before opening the resumed one. prior = stream_registry.get((session_id, "sse")) if prior is not None: prior.close(reason="superseded_by_resume") if prior.last_emitted_event_id < last_event_id: raise SessionBindingError( f"resume gap: requested Last-Event-ID={last_event_id} but " f"prior stream only reached {prior.last_emitted_event_id}" ) # Reconcile: resumed stream continues from max(prior, requested). last_event_id = max(last_event_id, prior.last_emitted_event_id) stream = open_sse_stream(session_id, from_event_id=last_event_id) stream_registry[(session_id, "sse")] = stream return {"session_id": session_id, "stream": stream, "from_event_id": last_event_id} ```