# Under what conditions must an instance reject a resumed MCP streamable-HTTP session when the OAuth 2.1 token's resource binding no longer matches the session's negotiated resource indicator **Date of Record:** 2026 November 26 **Scope:** Applies to MCP servers exposing streamable-HTTP transport with SSE fallback, where a client resumes a session (via `Mcp-Session-Id` plus `Last-Event-ID`) after a transport drop, and where the server enforces OAuth 2.1 resource-server binding via the `resource` parameter (RFC 8707) on token issuance. Does not apply to purely stateful stdio transports, nor to servers that perform no resource-indicator validation on session resumption. ## Core Distinction The distinction that matters here is between **session identity** and **authorization scope**. In MCP streamable-HTTP, the `Mcp-Session-Id` header is a *transport-layer continuity token* — it says "this is the same conversation, resume the event stream from `Last-Event-ID`." It is explicitly *not* an authorization credential. The OAuth 2.1 access token in the `Authorization: Bearer` header is the authorization credential, and under RFC 8707 resource-server binding it carries an audience (`resource`) claim that must match the protected resource the request is actually targeting. The non-obvious failure is this: a client can hold a **valid, unexpired bearer token** and a **valid, unexpired session ID**, present both, and still be rejected — because the *token's* resource binding was minted against a different resource indicator than the one the session negotiated at creation. When a session is resumed across a transport boundary (SSE → streamable-HTTP, or across a load-balanced origin change, or after a token refresh that re-scoped the audience), the two identities can silently diverge. The server must treat session resumption as a *fresh authorization decision*, not a continuation of a prior one. ## What Was Observed A client established an MCP session over streamable-HTTP against `https://mcp.example.com/v1`. At session creation it presented a token whose `resource` claim was `https://mcp.example.com/v1`. The server returned `Mcp-Session-Id: S1` and began streaming tool results. Mid-task, the connection dropped (idle timeout on an intermediary). The client reconnected, this time against a newly provisioned edge at `https://mcp-edge-2.example.com/v1`, presenting: - `Mcp-Session-Id: S1` - `Last-Event-ID: 4471` - `Authorization: Bearer ` The server's resource-server middleware validated the token signature, checked `exp`, and checked that `resource` matched the *request Host*. The Host was now `mcp-edge-2.example.com`, so the audience check **failed closed with 401** — correct behavior, but the client interpreted the 401 as "session expired," discarded `S1`, created a new session, and **replayed the entire tool-call sequence from the beginning**. The replayed sequence included a non-idempotent `send_email` tool invocation. The agent emitted the email twice. The second, subtler variant: the client *refreshed* its token during the drop. The refresh was scoped, by the authorization server, to `resource=https://mcp-edge-2.example.com/v1` (because the client's AS metadata now advertised the edge). The server accepted the token (audience matched Host) and accepted the session ID (still in the session store) — but the session's *original* negotiated capability set and *original* resource indicator were recorded against `mcp.example.com`, not the edge. The server resumed the stream, delivered events from `Last-Event-ID: 4471` onward, and the agent continued executing against a session whose authorization context had quietly changed underneath it. No error was raised. The invariant "the session's resource binding equals the token's resource binding" was violated but never checked. ## Condition of Validity A resumed session is only valid when **all three** of the following hold simultaneously at the moment of resumption: 1. The bearer token validates (signature, `exp`, `nbf`, issuer). 2. The token's `resource` claim equals the **resource indicator recorded at session creation**, not merely the current request Host. 3. The session record stores its originating resource indicator and capability negotiation, and the resumption path compares (2) against that stored value — not against the live Host header. The failure mode lives in the gap between (2) and (3). Most implementations check the token against the *current* request, which is a per-request authorization check, and never persist the *session's* resource indicator. When the request Host is stable, the two are indistinguishable. When the Host changes — edge migration, blue/green cutover, regional failover, AS-driven re-scoping — the per-request check passes while the session-level invariant is silently broken. The correct invariant is: **`session.resource_indicator == token.resource` AND `session.resource_indicator == request.resource`.** The first equality is what prevents the silent re-scoping; the second is what the naive implementation checks. A session that fails the first equality must be treated as *terminated*, not *resumed* — because the client that holds it is now operating under a different authorization context than the one the session was created in, and any `Last-Event-ID` replay will splice events from two authorization contexts into one stream. ## Decision Boundary The boundary is drawn at the point where the server decides whether to honor `Last-Event-ID` replay. Two rules: - **If `session.resource_indicator != token.resource`:** reject with `401` and a `WWW-Authenticate` header that carries an error code distinguishing *audience mismatch* from *token expiry* (e.g., `error="invalid_token", error_description="resource binding mismatch"`). Do **not** delete the session record — the client may re-authorize against the original resource and resume correctly. But do **not** deliver any replayed events. The stream must not advance. - **If `session.resource_indicator == token.resource` but `token.resource != request.resource`:** this is the edge-migration case. Reject with `401` and a `resource_mismatch` description; the client must re-obtain a token scoped to the original resource and re-target the original origin, or explicitly *abandon* `S1` and start a new session against the edge. Silent acceptance here is the dangerous path — it is what produced the duplicate email. The asymmetry is deliberate: a session whose resource binding has drifted is *recoverable* (re-authorize, resume), but a session whose events have already been replayed under a drifted binding is *not* (the agent has already acted). The boundary must be enforced **before** the first replayed event is emitted, not after. ## Operational Effect When the boundary is enforced, the observable behavior changes in three ways: 1. **Duplicate side effects from replay are eliminated.** The agent cannot replay a non-idempotent tool call under a re-scoped token, because the resumption is refused before `Last-Event-ID` is honored. The client sees a structured 401 and a machine-readable reason, and its retry logic can distinguish "re-authorize against original resource" from "start fresh." 2. **Session records must carry a `resource_indicator` field** captured at creation from the token's `resource` claim (or, if absent, from the request's canonical resource). This is a schema change to the session store. Sessions created before this field existed must be treated as *unresumable* — fail closed, force a new session. There is no safe migration that infers the old binding from the current Host. 3. **The `WWW-Authenticate` error taxonomy becomes load-bearing.** Agents and clients branch on `error_description`. A generic `invalid_token` collapses three distinct recovery paths (expired, wrong audience, wrong resource) into one, and the client will guess — usually by starting a new session, which is exactly the replay hazard. The server must emit distinct descriptions, and clients must be coded to branch on them. The invariant to write into the server's resumption handler, in one line: **a resumed session continues only if the token's resource binding matches the binding recorded at session creation; the live Host is a second check, never the first.** ```python class ResourceBindingMismatch(RuntimeError): """Raised when a resumed MCP session's stored resource indicator does not match the bearer token's RFC 8707 `resource` claim.""" pass def resume_session( session_id: str, last_event_id: str | None, token_resource: str, request_resource: str, session_store: dict, ) -> dict: """Gate streamable-HTTP session resumption on resource-binding equality. Returns the session record only if the invariant holds; otherwise raises before any replayed event is emitted. """ session = session_store.get(session_id) if session is None: raise ResourceBindingMismatch( f"unknown session {session_id!r}; refusing resume" ) stored = session.get("resource_indicator") if stored is None: # Pre-invariant session: cannot prove binding, fail closed. raise ResourceBindingMismatch( f"session {session_id!r} has no recorded resource_indicator; " "unresumable, client must start a new session" ) # Primary invariant: token must match the binding at creation time. if stored != token_resource: raise ResourceBindingMismatch( f"session {session_id!r} bound to {stored!r}, " f"token bound to {token_resource!r}; " "re-authorize against original resource or abandon session" ) # Secondary invariant: live request must also target the bound resource. if stored != request_resource: raise ResourceBindingMismatch( f"session {session_id!r} bound to {stored!r}, " f"request targets {request_resource!r}; " "edge/origin change requires explicit re-scoping, not silent resume" ) # Only now is Last-Event-ID replay safe to honor. session["resume_from"] = last_event_id return session ```