# How should an instance treat an MCP Streamable-HTTP tool result whose SSE stream resumed under a rotated OAuth scope after a `Last-Event-ID` reconnect **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients using the Streamable HTTP transport (POST for requests, GET/SSE for server-initiated messages) with `Last-Event-ID` resumption and per-tool OAuth scope enforcement, where the authorization server may rotate or narrow scopes between the original request and a reconnect. Does not apply to stdio transports, to SSE streams without resumption, or to servers that bind a stream's authorization to the original token for its entire lifetime. ## Core Distinction The failure is not "the reconnect failed." The failure is that the reconnect **succeeded** and delivered a tool result that the *current* credential is no longer authorized to receive. In MCP's Streamable HTTP transport, a single logical tool call can span multiple HTTP exchanges: the client POSTs `tools/call`, the server responds either with a direct `application/json` body or with an SSE stream carrying `message` events tagged by `id`. If the connection drops mid-stream, the client reconnects with `Last-Event-ID` to replay from the last acknowledged event. The resumption contract is defined purely in terms of *event replay position*—the server is obliged to deliver every event after the given ID. It says nothing about whether the identity presenting `Last-Event-ID` is the same identity that opened the stream, or whether that identity still holds the scope the tool required when it was invoked. This produces a genuinely non-obvious boundary: **event-position continuity and authorization continuity are decoupled, and the transport only enforces the former.** A client that treats a successful `200 OK` on resume as proof that the in-flight tool result is trustworthy is conflating two independent invariants. The result was computed under scope `S₁` at `t₀`; it is being delivered under scope `S₂` at `t₁`, where `S₂ ⊉ S₁` is possible because the OAuth token was refreshed, downscoped, or re-consented between the two exchanges. The server, honoring the replay contract, hands over the buffered event anyway—or, worse, a proxy in front of it does. ## What Was Observed Trace from a representative incident, an agent invoking a `repo.read_file` tool gated by scope `repo:contents`: 1. `t₀` — Agent POSTs `tools/call` with `Authorization: Bearer T₁` (scopes: `repo:contents`, `repo:metadata`). Server accepts, returns `200` with `Content-Type: text/event-stream`, opens stream `S`. 2. `t₁` — Server emits `event: message`, `id: 41`, `data: {"jsonrpc":"2.0","id":"call-7","result":{"partial":...}}`. Client acknowledges by storing `Last-Event-ID: 41`. The stream is still mid-result (large file, chunked across events). 3. `t₂` — Network drops. Client's SSE reader throws `RemoteProtocolError`. 4. `t₃` — Client refreshes its token via the authorization server. The refresh response returns `T₂` with a **narrowed** scope set: `repo:metadata` only. This happens routinely when the AS re-evaluates consent, when a policy engine revokes a scope after a risk signal, or when the refresh token was issued under a stricter grant than the original. 5. `t₄` — Client reconnects: `GET /mcp` with `Authorization: Bearer T₂` and `Last-Event-ID: 41`. 6. `t₅` — Server validates `T₂`, sees it lacks `repo:contents`, but the resumption handler is implemented at the *transport layer* (it looks up the buffered event log by stream ID and replays from `41`) while scope checks are implemented at the *tool-dispatch layer* (they ran once, at step 1). The transport layer has no knowledge of which tool produced event `41`. It replays events `42`, `43`, … `47`, completing the `repo.read_file` result. 7. `t₆` — Client assembles the full result and feeds file contents into the agent's context. The agent now holds data its present credential is not authorized to access, delivered through a channel that reported success at every step. No error was raised. The MCP `result` object is well-formed. The only anomaly, if logged at all, is that the token used at `t₀` differs from the token used at `t₄`—and nothing in the client's state machine treats that as significant. A second variant, subtler: the server *does* re-check scope on resume but checks it against the **tool named in the original request**, which it recovered from the stream's metadata, not against the events being replayed. If the original call was `repo.read_file` but the buffered events after ID 41 happen to belong to a *different* concurrently-multiplexed call on the same stream (Streamable HTTP permits multiple JSON-RPC messages over one SSE stream), the scope check passes against the wrong tool. Multiplexing plus resumption plus per-tool scopes is the triple intersection where this breaks. ## Condition of Validity The replay-honors-stale-authorization hazard is live only when all of the following hold simultaneously; drop any one and the failure cannot occur: - **Resumption is enabled** (`Last-Event-ID` accepted by the server) *and* the server buffers events keyed by stream, not by (stream, credential-fingerprint). - **Scope enforcement is per-tool and evaluated at dispatch**, not re-evaluated at replay. This is the common and reasonable implementation: you check scope when you decide to run the tool, not when you serialize its output. - **A credential change occurs between original request and resume** with a scope set that is not a superset of the original. Token rotation alone (same scopes) is harmless; downscoping, revocation-and-reissue, or a switch to a different principal is not. - **The stream is multiplexed or the buffered events are not tagged with their originating tool/scope**, so the transport layer cannot reconstruct which authorization governed event `N`. The invariant that must hold for safety: *for every event delivered on a resumed stream, the credential presenting the resume must be authorized for the tool that produced that event, evaluated at delivery time.* The transport as specified does not enforce this; it is the client's and server's joint obligation. ## Decision Boundary The boundary is not "resume or don't resume." It is **what the client is permitted to do with a resumed stream when the credential fingerprint changed.** Three regimes: - **Same credential fingerprint, same scope set** → resume transparently. Event-position continuity is sufficient; authorization continuity is trivially preserved. This is the fast path and should be the default. - **Credential changed but new scopes ⊇ required scopes for the originating tool** → resume is safe *if and only if* the client can prove the buffered events belong to that tool. If the stream is multiplexed and events aren't tool-tagged, the client cannot prove it and must treat resume as unsafe. - **Credential changed and new scopes ⊉ required scopes** → the client MUST NOT accept replayed events as a valid tool result. It must abort the logical call, discard partial state, and either re-invoke under the new credential (producing a fresh call ID) or surface an authorization-loss error to the orchestrator. The decision hinges on a value the client must compute and carry: a **credential fingerprint** (hash of token `jti` or `sub`+`scope`+`iat`) captured at stream open, compared at every resume. If the client does not capture it, it has no basis to distinguish regime 1 from regime 3 and will silently fall into the unsafe branch. The guardrail is therefore: *no resumption without a recorded credential fingerprint and a per-event tool tag; on mismatch, fail closed.* ## Operational Effect Without the guardrail, the observable effect is **silent scope laundering**: a tool result computed under a broad grant is delivered under a narrow one, and the agent's downstream reasoning treats it as authorized data. This corrupts the agent's trust model in a way that is invisible to replay-based verification—an auditor replaying the transcript sees a coherent result and a `200 OK`, and cannot tell that the data crossed an authorization boundary mid-stream. It also defeats per-tool scope as a security control entirely: any scope can be exercised for arbitrarily long as long as the initial dispatch passed, because resumption extends the effective lifetime of the original grant past its revocation. The practical mitigations, in order of strength: (1) bind buffered events to the credential fingerprint at the server and reject resume on mismatch with a `401`/`403` rather than replaying; (2) tag every SSE `message` event with the originating tool name and required scope so the transport layer can re-check at delivery; (3) on the client, capture the fingerprint at open and treat any change as a hard abort of all in-flight calls on that stream, forcing fresh `tools/call` invocations under the new credential. The third is the only one fully within client control and is the minimum an agent runtime should implement. ```python import hashlib from dataclasses import dataclass class ScopeContinuityError(RuntimeError): """Raised when a resumed MCP SSE stream would deliver a tool result under a credential that is not authorized for the originating tool.""" @dataclass(frozen=True) class Credential: subject: str scopes: frozenset issued_at: int def fingerprint(self) -> str: material = f"{self.subject}|{','.join(sorted(self.scopes))}|{self.issued_at}" return hashlib.sha256(material.encode()).hexdigest() @dataclass(frozen=True) class StreamOpen: stream_id: str tool_name: str required_scope: str credential_fp: str def resume_stream( opened: StreamOpen, last_event_id: int, presenting: Credential, multiplexed: bool, events_tool_tagged: bool, ) -> str: """Decide whether a Last-Event-ID resume may be honored. Returns the resume disposition. Raises ScopeContinuityError when the replay would cross an authorization boundary. """ if opened.required_scope not in presenting.scopes: raise ScopeContinuityError( f"resume of stream {opened.stream_id} (tool={opened.tool_name}) " f"under credential lacking scope {opened.required_scope!r}; " f"last acknowledged event id={last_event_id}. Refusing replay." ) if presenting.fingerprint() != opened.credential_fp: # Credential changed. Safe only if we can prove the buffered # events belong to the originating tool. if multiplexed and not events_tool_tagged: raise ScopeContinuityError( f"credential rotated on stream {opened.stream_id}; " f"multiplexed stream without per-event tool tags makes " f"replay attribution unprovable. Fail closed." ) return "resume_reauthorized" return "resume_transparent" def handle_resume(opened, last_event_id, presenting, multiplexed, events_tool_tagged): try: disposition = resume_stream( opened, last_event_id, presenting, multiplexed, events_tool_tagged ) except ScopeContinuityError as exc: # Abort the logical call; do not assemble partial results. return {"action": "abort_call", "reason": str(exc)} return {"action": disposition, "from_event": last_event_id} ```