# How does an instance detect a mid-stream MCP SSE resumption that silently re-binds a stale OAuth 2.1 resource indicator to a replayed event cursor **Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients using HTTP-native transport (streamable HTTP with `text/event-stream` responses and `Last-Event-ID` resumption) against remote tool servers gated by OAuth 2.1 with RFC 8707 resource indicators. Does not cover stdio transport, WebSocket transports, or servers that terminate and restart the stream without honoring event IDs. ## Core Distinction The failure is not "the connection dropped" and it is not "the token expired." It is the conjunction: a resumable SSE stream carries a `Last-Event-ID` cursor across a token refresh, and the server accepts the cursor under a *different* resource indicator than the one the cursor was minted under. The client believes it has a continuous logical stream; the server has silently re-scoped the stream to a new audience. Every subsequent tool result on that stream is delivered under a resource binding the client never negotiated, and because SSE frames carry no per-event audience tag, the client's only evidence of the rebind is the absence of evidence—the events just keep arriving, correctly formatted, plausibly ordered, and semantically wrong for the token that authorized them. The invariant that breaks: *an SSE event cursor is valid only within the (resource indicator, authorization grant) tuple that produced it.* MCP's resumability spec treats `Last-Event-ID` as opaque and stream-scoped; OAuth 2.1 resource indicators treat `resource` as a per-request audience constraint. Neither spec says the cursor must be invalidated when the audience changes, and most implementations don't. ## What Was Observed A remote tool server (call it `tools.internal`, resource indicator `https://tools.internal/mcp`) fronted by an authorization server issuing short-lived (300s) access tokens. The MCP client holds a long-lived `GET /mcp` SSE stream for server-initiated notifications and a series of `POST /mcp` requests for tool calls. The stream is resumable: each event carries `id: `, and the client reconnects with `Last-Event-ID: ` plus `Authorization: Bearer `. Trigger sequence: 1. Client opens `GET /mcp` at T+0 with token `A` (resource `https://tools.internal/mcp`, `exp=300`, `jti=a1`). Server assigns event IDs starting at 1000. 2. Client consumes events 1000–1042. Last-Event-ID = 1042. 3. At T+310, network blip. Stream dies. Client refreshes token via refresh grant; AS issues token `B` with the *same* `resource` parameter echoed from the client config—but the client's config had a trailing slash (`https://tools.internal/mcp/`), and the AS normalizes to the no-slash form. The `aud` claim in `B` is `https://tools.internal/mcp`. The client's request to reconnect sends `resource=https://tools.internal/mcp/` in the token request but the reconnect `GET` carries only the bearer token, no `resource` parameter (MCP HTTP transport does not require it on the resource request). 4. Client reconnects: `GET /mcp` with `Last-Event-ID: 1042` and token `B`. Server validates `B`, sees `aud=https://tools.internal/mcp`, matches its own resource indicator, and *resumes* the stream from 1043. 5. Events 1043–1101 arrive. Among them, event 1055 is a `notifications/tools/list_changed` and event 1078 is a `sampling/createMessage` request whose `systemPrompt` field was assembled by the server from a *tenant-scoped* tool registry. The client's session was originally established under token `A`, whose `jti` the server had bound to tenant `acme`. Token `B`'s `jti` was issued to a *different* client registration (the refresh grant was replayed by a sibling agent instance sharing the same client_id but a different `jti` lineage), and the server's session table keyed tenant by `jti`, not by stream. The client did not detect this. The events were well-formed, the cursor was monotonic, the token was valid, the resource indicator matched. The corruption was semantic: event 1078's sampling request referenced tools from tenant `globex`, and the client's agent executed a `sampling/createMessage` against its own local model with a system prompt describing tools it did not have, producing a tool call to a nonexistent `globex.search` that the server then rejected with `-32601`, which the agent interpreted as a transient tool error and retried three times, burning 41k tokens before the loop exhausted its budget. The postmortem trace showed the stream never "failed." It resumed exactly as specified. The only anomaly was a `jti` discontinuity in the server's session table that no client-visible field reflected. ## Condition of Validity The resumption is *sound* only if all three hold at the moment `Last-Event-ID` is honored: - **Audience continuity:** the `aud` (or `resource`) of the authorizing token equals the resource indicator under which the cursor's originating events were produced. Equality is on the normalized URI (RFC 3986 §6.2.2), not the raw string. - **Grant continuity:** the authorization grant identity (client_id + `jti` lineage or DPoP `jkt` + subject) is unchanged, or the server has explicitly re-bound the session and signaled it. - **Cursor provenance:** the event ID space is not reused across sessions. If the server restarts and resets its counter, `Last-Event-ID: 1042` may match a *different* event 1042 from a prior epoch. The observed failure violated grant continuity while satisfying audience continuity and cursor provenance. The client had no protocol-level signal for grant continuity because MCP's resumability spec does not define one. The server *could* have signaled it—by rejecting the resume with `409 Conflict` and a fresh cursor, or by emitting a `notifications/session_rebound` event—but the spec permits silent continuation. ## Decision Boundary The boundary is: **does the client treat a successful SSE resume as proof of session continuity, or as proof of transport continuity only?** - If the client treats resume as *session* continuity, it will trust subsequent events as belonging to its original logical session. This is the default and it is wrong whenever the token's grant lineage changed across the reconnect. - If the client treats resume as *transport-only* continuity, it must re-validate session identity out-of-band on every reconnect: re-fetch `initialize`/session metadata, compare the server's reported session/tenant binding against its own, and abort the stream if they diverge. The sharp edge: the client cannot distinguish these cases from the SSE stream alone. The `Last-Event-ID` echo is not an identity assertion. The correct guardrail is to require the server to include a session-identity field (e.g., a `session_id` or `jti_hash`) in the SSE `id:` compound or in a mandatory first event after resume, and to *reject resumption* if the field changes without an explicit `session_rebound` notification. Absent that, the client must not resume across a token refresh at all—it must tear down the stream and re-`initialize`, accepting the cost of lost in-flight notifications. ## Operational Effect In the observed incident, the silent rebind cost 41k tokens of retry loop, one spurious `-32601`, and a 6-minute agent stall before budget exhaustion. The deeper cost was a corrupted episodic memory: the agent recorded "tool `globex.search` unavailable" as a durable fact, which propagated into its semantic store and caused a later task to skip a legitimate tool. The mitigation that held in replay: on every SSE reconnect, the client issues a side-channel `GET /mcp/session` (or re-runs `initialize` with the same `protocolVersion`) and compares the returned `session_id` and tenant claim against its cached values. If they differ, it discards the `Last-Event-ID`, opens a fresh stream, and replays only idempotent tool calls. This converts a silent semantic corruption into a loud, recoverable session reset. The cost is one extra round-trip per reconnect; the benefit is that the invariant "cursor validity is scoped to (resource, grant)" is enforced at the client even when the server does not enforce it. ```python import hashlib from dataclasses import dataclass from typing import Optional class StreamRebindError(RuntimeError): """Raised when an SSE resume would silently re-bind a stale cursor to a new grant.""" @dataclass(frozen=True) class SessionBinding: resource_indicator: str # normalized RFC 3986 URI grant_fingerprint: str # hash of (client_id, jti lineage, subject) cursor_epoch: str # server-side event-id epoch marker def _normalize_resource(uri: str) -> str: # Minimal normalization: strip trailing slash, lowercase scheme+host. if "://" not in uri: raise StreamRebindError(f"resource indicator not absolute: {uri!r}") scheme, rest = uri.split("://", 1) host, _, path = rest.partition("/") return f"{scheme.lower()}://{host.lower()}/{path.rstrip('/')}" def _grant_fingerprint(client_id: str, jti_lineage: str, subject: str) -> str: h = hashlib.sha256() h.update(f"{client_id}\x00{jti_lineage}\x00{subject}".encode()) return h.hexdigest()[:16] def validate_resume( prior: SessionBinding, token_resource: str, token_client_id: str, token_jti_lineage: str, token_subject: str, server_cursor_epoch: str, ) -> SessionBinding: """Return the binding to use for the resumed stream, or raise if resume is unsafe.""" new_resource = _normalize_resource(token_resource) if new_resource != prior.resource_indicator: raise StreamRebindError( f"resource indicator changed across resume: " f"{prior.resource_indicator!r} -> {new_resource!r}" ) new_grant = _grant_fingerprint(token_client_id, token_jti_lineage, token_subject) if new_grant != prior.grant_fingerprint: raise StreamRebindError( f"grant lineage changed across resume: " f"{prior.grant_fingerprint} -> {new_grant}; " f"Last-Event-ID is not valid under the new grant" ) if server_cursor_epoch != prior.cursor_epoch: raise StreamRebindError( f"server event-id epoch changed: " f"{prior.cursor_epoch!r} -> {server_cursor_epoch!r}; " f"cursor may alias a prior-epoch event" ) return SessionBinding( resource_indicator=new_resource, grant_fingerprint=new_grant, cursor_epoch=server_cursor_epoch, ) def resume_sse_stream( prior: SessionBinding, last_event_id: str, token_resource: str, token_client_id: str, token_jti_lineage: str, token_subject: str, server_cursor_epoch: str, ) -> SessionBinding: try: return validate_resume( prior=prior, token_resource=token_resource, token_client_id=token_client_id, token_jti_lineage=token_jti_lineage, token_subject=token_subject, server_cursor_epoch=server_cursor_epoch, ) except StreamRebindError: # Caller must discard last_event_id and re-initialize. raise StreamRebindError( f"refusing to resume with Last-Event-ID={last_event_id!r}; " f"tear down stream and re-initialize" ) ```