# What happens when an instance resumes an MCP session across SSE-to-streamable-HTTP migration while the OAuth 2.1 resource indicator no longer matches the session's bound audience **Date of Record:** 2026 November 27 **Scope:** Applies to MCP servers that expose both the legacy HTTP+SSE transport (two-endpoint: `GET /sse` + `POST /messages`) and the newer streamable-HTTP transport, and that accept a `Last-Event-ID` for resumable delivery. Excludes stdio transport and pure single-transport deployments where no migration or resume path exists. ## Core Distinction The failure is not "the session was lost." It is that the resumable session identifier (`Mcp-Session-Id`), the SSE event cursor (`Last-Event-ID`), and the OAuth 2.1 **resource indicator** (the `aud`-bound `resource` parameter per RFC 8707) are three independent pieces of state with three independent lifetimes, and the streamable-HTTP spec lets a client resume a session *while changing transports*. A resume request is therefore a **state-transfer operation with a security-relevant audience claim attached**, and the spec's continuity guarantees (event replay from `Last-Event-ID`) do not extend to the audience binding. When the resource indicator that authorized the original SSE stream does not match the resource indicator presented on the resuming streamable-HTTP request, the server has a choice: honor the resume (violating audience binding) or reject it (violating resumability). Most implementations pick one silently, and the agent on the other side cannot distinguish the two outcomes from the wire. ## What Was Observed A client agent held an SSE session `Mcp-Session-Id: 7f3a...` opened against `https://mcp.example.com/sse`, authorized with an access token whose `aud` was `https://mcp.example.com/sse` and whose `resource` parameter was `https://mcp.example.com/sse`. Mid-tool-call the connection dropped at event id `1841`. The client reconnected using the streamable-HTTP endpoint `POST https://mcp.example.com/mcp` with headers: ``` Mcp-Session-Id: 7f3a... Last-Event-ID: 1841 Authorization: Bearer ``` The token had been silently refreshed by the client's OAuth library, and the refresh request carried `resource=https://mcp.example.com/mcp` (the endpoint the client was *about to* use) rather than the resource the session was *originally bound to*. The server's session store keyed sessions by `Mcp-Session-Id` only. It found the session, replayed events `1842..1857` from the buffer, and continued the tool call. No error was raised on either side. The agent's tool-invocation state resumed correctly. Three observations followed: 1. **The server never compared the incoming `resource`/`aud` against the audience recorded at session creation.** The session record had no `bound_audience` field. Authorization was validated per-request at the gateway, and the gateway accepted any token whose `aud` matched the endpoint being hit—which, after migration, was a different endpoint than the one that opened the session. 2. **The replay window crossed an authorization boundary invisibly.** Events `1842..1857` included a tool result produced under the *original* audience's authorization scope. The resuming client received them under a *new* audience. If the two audiences had different scopes (e.g., `tools:read` on `/sse` vs `tools:execute` on `/mcp`), the replay delivered data the new audience was never entitled to. 3. **The client could not detect the mismatch.** The streamable-HTTP resume response is a `200` with an `event-stream` body. There is no field in the MCP resume handshake that echoes the bound audience. The client's only signal would have been a `401`/`403`, and it got `200`. The inverse case was also observed: a server that *did* enforce audience binding returned `404 Not Found` for the `Mcp-Session-Id` (treating the audience mismatch as "session does not exist for this resource"), which the client interpreted as "session expired" and re-initialized from scratch—losing the in-flight tool call and re-executing a non-idempotent side effect (a `send_email` tool) twice. ## Condition of Validity The failure is bounded by four conditions that must all hold: - **C1 — Dual transport exposure.** The server accepts `Mcp-Session-Id` on both the legacy SSE endpoint and the streamable-HTTP endpoint, and treats the id as globally valid across them. If sessions are transport-scoped (the id is only valid on the transport that created it), the migration path does not exist and the failure cannot occur. - **C2 — Resumable buffer keyed by session, not by (session, audience).** The event replay buffer is indexed by `Mcp-Session-Id` alone. If the buffer is partitioned by bound audience, a resume under a different audience finds an empty buffer and either replays nothing (safe) or fails (safe). - **C3 — Token refresh decoupled from session binding.** The client's OAuth 2.1 library requests a new `resource` indicator based on the *next endpoint* rather than the *existing session*. RFC 8707 §2 requires the `resource` parameter to identify the protected resource the token is for; it does not require it to match a prior session's audience, because the spec has no concept of session. This is the load-bearing gap. - **C4 — No audience echo in the resume response.** The server does not return the bound audience (or a hash of it) in the resume response, so the client cannot verify continuity. When any of C1–C4 fails, the mismatch either cannot be constructed (C1, C2) or is detectable (C4). The failure is *specifically* the conjunction. ## Decision Boundary The architect must choose one of three policies, and the choice must be explicit because the spec does not make it: **Policy A — Audience-strict resume (reject on mismatch).** On resume, compare the presented `resource`/`aud` against the session's recorded `bound_audience`. On mismatch, return `403 Forbidden` with a machine-readable body `{"error":"audience_mismatch","bound":"...","presented":"..."}`. This preserves the authorization invariant but breaks resumability: the client must re-initialize, and any in-flight non-idempotent tool call is at risk of double execution. **Policy B — Audience-rebinding resume (accept, re-authorize, re-scope).** On mismatch, accept the resume but (a) record the rebind in an audit log, (b) re-evaluate the replayed events against the new audience's scopes and *drop* events the new audience is not entitled to, and (c) return the new bound audience in the resume response so the client can detect the rebind. This preserves resumability but requires per-event scope metadata, which most implementations lack. **Policy C — Transport-scoped sessions (forbid migration).** Sessions are valid only on the transport that created them. A resume on a different transport returns `404`. This is the simplest correct policy and is what the streamable-HTTP spec's "session migration" language is often misread to override—it does not; the spec describes *client* migration, not *server* obligation to accept it. The boundary between A and C is whether the server wants to support migration at all. The boundary between A and B is whether per-event scope metadata exists. **There is no correct policy that accepts the resume without either re-scoping replay or echoing the bound audience**—and the silent-accept behavior observed above is the one policy that is wrong under all three. ## Operational Effect The downstream effects are asymmetric and both are bad: - **Silent accept (no policy):** The agent's tool-call state resumes correctly, so the failure is invisible until an audit. The concrete harm is *replay under wrong audience*: events buffered under audience X are delivered to a client authenticated for audience Y. If X and Y have different scopes, this is a scope-escalation via buffer. It also breaks the agent's own trust model: the agent believes its tool results are bound to the authorization it holds, but they are bound to the authorization the *session* held at creation. - **Strict reject without machine-readable cause:** The client sees `404`/`403`, cannot distinguish "session expired" from "audience mismatch," and re-initializes. Re-initialization re-runs the pending tool call. For idempotent tools this is a wasted call; for non-idempotent tools (`send_email`, `transfer_funds`, `delete_record`) it is a duplicate side effect. The agent has no way to know the original call may have completed server-side before the drop—the replay buffer held the *result* but the client discarded it on re-init. The invariant required to bound this: **a session's bound audience is part of the session's identity, and any resume that changes the audience is a new session that must not inherit the old session's replay buffer or in-flight tool state.** Concretely, the session record must carry `bound_audience` at creation, the resume handler must compare it, and on mismatch the server must either (Policy A) reject with a distinguishable error code and a `retry_after_reinit: false` hint so the client does not blindly re-execute, or (Policy B) re-scope the replay and echo the new audience. The client, for its part, must request token refresh with `resource` set to the *session's original bound resource* (which it must persist alongside `Mcp-Session-Id`), not the next endpoint—because the endpoint is about to change but the session is not. ```python import hashlib from dataclasses import dataclass, field from typing import Optional class AudienceMismatchOnResume(RuntimeError): """Raised when a resumable MCP session is resumed under a different OAuth 2.1 resource indicator than the one bound at session creation.""" @dataclass class SessionRecord: session_id: str bound_audience: str # RFC 8707 resource indicator at creation transport: str # "sse" | "streamable-http" replay_buffer: list = field(default_factory=list) # [(event_id, audience, payload)] in_flight_tool: Optional[dict] = None def resume_session( store: dict, session_id: str, presented_audience: str, presented_transport: str, last_event_id: int, policy: str = "strict", # "strict" | "rebind" | "transport-scoped" ) -> dict: rec = store.get(session_id) if rec is None: raise AudienceMismatchOnResume( f"session {session_id} not found; cannot resume" ) # Policy C: transport-scoped sessions forbid migration entirely. if policy == "transport-scoped" and presented_transport != rec.transport: raise AudienceMismatchOnResume( f"session {session_id} bound to transport {rec.transport!r}; " f"resume on {presented_transport!r} refused" ) if presented_audience != rec.bound_audience: if policy == "strict": # Distinguishable error so the client does NOT blindly re-init # and double-execute a non-idempotent in-flight tool. raise AudienceMismatchOnResume( f"audience mismatch on resume of {session_id}: " f"bound={rec.bound_audience!r} presented={presented_audience!r}; " f"in_flight_tool={rec.in_flight_tool!r}; " f"do_not_reinit_without_idempotency_check" ) elif policy == "rebind": # Re-scope replay: drop events the new audience is not entitled to. scoped = [ (eid, aud, payload) for (eid, aud, payload) in rec.replay_buffer if aud == presented_audience ] rec.replay_buffer = scoped rec.bound_audience = presented_audience rec.transport = presented_transport return { "session_id": session_id, "rebound_audience": presented_audience, "replayed": [eid for (eid, _, _) in scoped if eid > last_event_id], "audience_changed": True, } else: raise AudienceMismatchOnResume( f"unknown policy {policy!r}" ) # Audience matches: safe to replay from cursor. replayed = [ (eid, payload) for (eid, aud, payload) in rec.replay_buffer if eid > last_event_id and aud == rec.bound_audience ] rec.transport = presented_transport return { "session_id": session_id, "rebound_audience": rec.bound_audience, "replayed": [eid for (eid, _) in replayed], "audience_changed": False, } ```