# In what scenarios must an instance treat MCP SSE stream resumption across a session migration as invalidated by OAuth 2.1 resource-server audience rebinding **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers exposing both the legacy HTTP+SSE transport (GET event stream + POST message endpoint) and the streamable-HTTP transport, where a client resumes an interrupted SSE stream (`Last-Event-ID`) after the server has migrated the session identifier and the bearer token's `aud`/resource indicator has been rebound to a new canonical resource URI. Does not apply to pure stdio transports, nor to in-process session migration where no OAuth resource binding is present. ## Core Distinction The failure is not "the client reconnected and lost events." It is subtler: the MCP session is *logically continuous* (same `Mcp-Session-Id` lineage, same `Last-Event-ID` replay cursor) while the *authorization envelope* is *discontinuous* (the resource-server binding now validates against a different `aud`). Resumable SSE semantics assume the replay cursor is authoritative for state reconstruction. OAuth 2.1 resource-server binding assumes the token's audience is authoritative for authorization. During a migration these two authorities point at different resource identities, and the transport layer will happily replay events that were emitted under the *old* audience into a session that is now authorized under the *new* one. The invariant that must hold—**replayed events must be authorized under the same resource binding as the token that resumes the stream**—is silently violated because neither the SSE replay path nor the token validator knows about the other. ## What Was Observed An MCP server fronted by an SSE endpoint at `GET /sse` and a message endpoint at `POST /message?sessionId=…`. The server was being migrated to streamable HTTP at `POST /mcp` with `Accept: text/event-stream`, and the OAuth 2.1 resource server was repointed from resource indicator `https://mcp.old.example/v1` to `https://mcp.new.example/v1`. The migration kept the session store and the event log shared. Sequence that broke: 1. Client holds `Mcp-Session-Id: s-7f3a`, token `T_old` with `aud=https://mcp.old.example/v1`, and has consumed events up to `Last-Event-ID: 1042`. 2. Network blip. Client reconnects to the *new* streamable-HTTP endpoint with `Mcp-Session-Id: s-7f3a` and `Last-Event-ID: 1042`, presenting a freshly minted `T_new` with `aud=https://mcp.new.example/v1` (correct per RFC 8707 resource indicators). 3. Server's resource-server middleware validates `T_new` against the new audience: **pass**. Session store lookup for `s-7f3a`: **hit** (migration preserved it). Event log replay from `1042`: **emits events 1043–1051**. 4. Events 1043–1048 were originally produced by a `tools/call` that had been authorized under `T_old` and scoped to the old resource. The client now applies them as if they belonged to the new-audience session. A `notifications/tools/list_changed` event at 1049 causes the client to re-fetch tool definitions, but the *tool invocation results* in 1043–1048 reference artifacts (a resource URI `mcp.old.example/artifacts/...`) that the new audience's downstream policy does not grant. The agent proceeds to act on stale, cross-audience state. The observable symptom is not an auth error. It is a *silent state splice*: the agent's memory now contains results produced under a resource identity it can no longer legitimately reference, and subsequent tool calls fail with confusing `403 resource_not_visible` errors that look like a client bug. ## Condition of Validity Resumption across migration is valid **only if** all three hold: - The event log is partitioned by resource indicator, and replay from `Last-Event-ID` is filtered to events whose originating audience equals the resuming token's `aud`. This requires the event record to carry `aud` as a first-class field, not merely the session id. - The session store treats `(sessionId, aud)` as the key, not `sessionId` alone. A session migrated across audiences is a *new* session that inherits no replay cursor. - The server issues a distinct `Mcp-Session-Id` (or a versioned suffix, e.g. `s-7f3a@new`) at the migration boundary and returns it in the streamable-HTTP response headers, forcing the client to drop its old cursor. If any one is absent, the replay cursor and the audience binding are decoupled and the splice occurs. In the observed incident, condition 1 failed (events carried only `sessionId`) and condition 2 failed (store keyed on `sessionId`), while condition 3 was attempted but the client ignored the rotated id because it had already sent `Last-Event-ID` on the first resumed request. ## Decision Boundary The operational rule: **on any request that carries both `Last-Event-ID` and a bearer token whose `aud` differs from the audience recorded at the cursor's origin, the server MUST refuse replay and force a cold re-subscribe.** The refusal is not a `401`—the token is valid—it is a `409` with a machine-readable body instructing the client to discard its cursor and re-issue `initialize`-equivalent state sync against the new resource. Treating this as an auth failure sends the client into a token-refresh loop that never resolves, because the token is already correct. Conversely, if `aud` matches the cursor's origin audience, replay proceeds normally even if the session id was rotated for unrelated reasons (e.g., load-balancer affinity). The discriminator is audience equality, not session-id equality. Session-id rotation alone is safe to ignore; audience change is not. ## Operational Effect Bounding this requires three concrete guards, all cheap: - Stamp every event log record with the `aud` under which it was produced, and reject `Last-Event-ID` replay when `aud` mismatches. - Key the session store on `(sessionId, aud)` and, at migration, emit a `notifications/session_migrated` event that the client must acknowledge before any further replay is served. - In the resource-server middleware, validate that a request bearing `Last-Event-ID` is authorized for the *origin* audience of that cursor, not merely for the current endpoint's audience. Without these, the agent's episodic memory silently absorbs cross-audience tool results, and the resulting failures surface far downstream as inexplicable policy denials—the exact class of stale-memory drift that is hardest to attribute because the transport layer reported success at every step. ```python from dataclasses import dataclass from typing import Optional class CrossAudienceReplayError(RuntimeError): """Raised when an SSE replay cursor's origin audience does not match the resuming token's resource binding during MCP session migration.""" def __init__(self, session_id: str, cursor_aud: str, token_aud: str): self.session_id = session_id self.cursor_aud = cursor_aud self.token_aud = token_aud super().__init__( f"session {session_id}: cursor origin aud={cursor_aud!r} " f"!= resuming token aud={token_aud!r}; replay refused" ) @dataclass class EventRecord: event_id: int session_id: str aud: str payload: dict @dataclass class ResumeRequest: session_id: str last_event_id: Optional[int] token_aud: str def resume_stream( req: ResumeRequest, event_log: list[EventRecord], session_aud_index: dict[str, str], ) -> list[EventRecord]: if req.last_event_id is None: # Cold subscribe: no cursor, no splice risk. return [e for e in event_log if e.session_id == req.session_id and e.aud == req.token_aud] cursor_events = [ e for e in event_log if e.session_id == req.session_id and e.event_id == req.last_event_id ] if not cursor_events: # Unknown cursor: force cold re-subscribe rather than guess. return [] cursor_aud = cursor_events[0].aud if cursor_aud != req.token_aud: # The invariant: replay must be authorized under the same resource # binding as the token that resumes the stream. raise CrossAudienceReplayError(req.session_id, cursor_aud, req.token_aud) recorded_aud = session_aud_index.get(req.session_id) if recorded_aud is not None and recorded_aud != req.token_aud: raise CrossAudienceReplayError(req.session_id, recorded_aud, req.token_aud) return [ e for e in event_log if e.session_id == req.session_id and e.event_id > req.last_event_id and e.aud == req.token_aud ] ```