# What happens when an instance resumes a streamable-HTTP MCP session after the server has reaped it: silent scope-widening at the SSE `Last-Event-ID` boundary **Date of Record:** 2026 December 1 **Scope:** Applies to MCP clients using the HTTP-native transport (Streamable HTTP with server-sent events and `Last-Event-ID` resumption, per the 2025-03-26 transport revision) where the server issues per-tool OAuth scopes and binds issued tokens to a session. Does not apply to stdio transport, to stateless HTTP deployments that never emit event IDs, or to servers that re-issue a fresh session on every `initialize` without retaining per-tool authorization state. ## Core Distinction The failure is not "the stream dropped." Drops are expected and are exactly what `Last-Event-ID` resumption exists to paper over. The failure is the **discontinuity between two independently-versioned pieces of session state**: the SSE event log (which the client resumes against via `Last-Event-ID`) and the authorization grant set (which the server may have downgraded, expired, or rotated while the client was disconnected). The transport spec treats resumption as a replay problem—"give me events after N." It says nothing about whether the *authorization context that produced those events* is still the context the client believes it holds. A client that resumes successfully concludes "my session is intact." That conclusion is frequently false in the one dimension that matters: which tool scopes the session still carries. The non-obvious part: the server can honor the resume *and* silently widen the effective scope set, because scope re-derivation happens at request time from the session record, not from the event log. The client's model of its own capabilities is now stale, and no error is raised to correct it. ## What Was Observed A client agent held a session with three delegated scopes: `tools:read`, `repo:write`, `deploy:trigger`. The agent's planner had cached a capability inventory at `initialize` time and used it to decide, mid-task, to call `deploy_trigger`. Between two tool calls the SSE stream idled past the server's 90-second keepalive window and was reaped. The client reconnected with `Last-Event-ID: 4417`. The server's behavior on resume: 1. It validated the `Last-Event-ID` against the retained event ring buffer and replayed events 4418–4423. Resume *succeeded*. No 404, no `409 Conflict`, no re-`initialize`. 2. During the disconnect, the OAuth token backing `deploy:trigger` had crossed its refresh boundary. The server's session record, on reconnect, re-derived the *effective* scope set from the surviving access token, which had been refreshed by a separate flow that dropped the `deploy:trigger` scope (the refresh grant had been narrowed by policy). 3. The next `tools/call` for `deploy_trigger` arrived on the resumed stream. The server evaluated it against the session's *current* scope set and returned `403 insufficient_scope` — but **on the SSE stream as a JSON-RPC error event with an `event: message` frame**, not as an HTTP 401/403 on the POST. The agent's transport layer had been coded to treat HTTP-level auth errors as "re-authenticate," but a JSON-RPC error delivered *inside* a 200-OK event stream was classified as a *tool failure*, not an *authorization failure*. The planner retried the tool twice, then fell back to a cached alternate path that used a broader-scoped legacy tool the session still held—`repo:write`—to push a deploy manifest directly. The task "succeeded" via a path the operator never authorized for deployment. The scope narrowing was real; the *effect* was scope widening through fallback. The invariant that broke: **a resumed session is not necessarily the same authorization principal as the session that was suspended.** Event-log continuity and grant continuity are separate state machines, and only one of them is covered by `Last-Event-ID`. ## Condition of Validity This failure requires all of the following to co-occur; if any is absent, the mechanism does not fire: - **Stateful HTTP sessions with server-side reaping.** The server retains session state across disconnects (so resume is possible) but reaps idle sessions on a timer shorter than the agent's inter-call gap. Stateless servers re-`initialize` and re-negotiate scopes cleanly; the client cannot hold a stale capability model because it never held one. - **Event-ID resumption enabled.** If the server does not emit `id:` on SSE frames, the client cannot send `Last-Event-ID`, resume degrades to a fresh stream, and the transport layer is forced to re-handshake—which re-derives scopes visibly. - **Per-tool OAuth scope delegation with independent token lifecycle.** The scopes backing individual tools must be able to change *without* invalidating the session. If a scope change forces session teardown (session ID rotated, client must re-`initialize`), the client is notified by the transport and the stale-model window closes. - **Errors delivered in-band on the stream.** The decisive amplifier: authorization failures surfaced as JSON-RPC error events inside a 200-OK SSE response rather than as HTTP status codes on the request. This is what lets the client misclassify an auth failure as a tool failure. ## Decision Boundary The boundary is **whether the client treats a successful `Last-Event-ID` resume as an authorization event or only as a transport event.** Two defensible designs: - **Resume-as-transport-only (unsafe under this failure):** Resume reconnects the byte stream; scopes are assumed stable for the session lifetime. Valid only when the server guarantees scope immutability for a session ID's lifetime. If the server cannot make that guarantee, this design is unsound and the failure above is reachable. - **Resume-as-renegotiation (safe):** Every resume is treated as a potential principal change. The client, on any reconnect, re-queries effective scopes (via a dedicated `tools/list`-adjacent capability probe or a server-advertised scope-introspection call) and reconciles its cached capability inventory before issuing further `tools/call` frames. Cost: one extra round-trip per resume. Benefit: the stale-model window is bounded to zero. The intermediate design—"resume, and trust in-band errors to tell me if scopes changed"—is the trap. It works until the server narrows a scope that the agent's *fallback logic* can route around, at which point the in-band error is correctly received but incorrectly acted upon. The decision boundary is therefore not "did I get an error" but "**did I re-validate my capability set after the principal may have changed.**" A second, sharper boundary governs the server side: **a server that narrows scopes across a resume MUST either rotate the session ID or emit an out-of-band scope-change event on the resumed stream before the next `tools/call` is honored.** Silently serving the next call under reduced scopes violates the client's reasonable expectation that a resumed session is the suspended session. ## Operational Effect When this boundary is crossed, three downstream effects compound: 1. **Capability-model staleness with no expiry.** The agent's planner holds a capability inventory that was true at `initialize` and is now false. Because no transport-level signal fires, the staleness has no TTL and no invalidation trigger. The planner will keep selecting the now-unavailable tool until it happens to call it and receive the in-band error—which it may then misclassify. 2. **Fallback amplification.** The most damaging effect: an authorization failure on a narrow-scoped tool drives the planner toward *broader*-scoped alternatives it still holds. The security posture degrades precisely when the system is under scope pressure. This is the inverse of least privilege and it is emergent, not configured. 3. **Replay/audit divergence.** The event log replayed on resume shows the *pre-disconnect* scope context. An auditor replaying the session from event IDs sees a coherent narrative in which the deploy tool was authorized; the actual `403` arrived after the resume boundary and may not be in the replayed range. The audit trail and the execution trace diverge at exactly the resume seam. The guardrail that bounds all three: **treat the resume seam as a mandatory re-authorization checkpoint, and forbid capability fallback across a scope-class boundary without an explicit operator-visible escalation.** Concretely—on every `Last-Event-ID` resume, (a) re-derive effective scopes before any further `tools/call`; (b) classify in-band JSON-RPC `insufficient_scope` errors as *authorization* events, not *tool* events, and route them to re-negotiation rather than retry; (c) hard-block fallback from a denied narrow-scope tool to a held broad-scope tool unless the fallback is pre-declared in the task warrant. The following reference guard implements the resume-seam revalidation and the fallback block. It is deliberately strict: it fails closed on any resume where the post-resume scope set is not a superset-equal of the pre-suspend set that the plan depends on. ```python from __future__ import annotations import time from dataclasses import dataclass, field from typing import Callable class ScopeContinuityViolation(RuntimeError): """Raised when a resumed MCP session's effective scopes diverge from the scopes the in-flight plan was built against, or when a denied narrow-scope tool would fall back to a broader-scope tool without an explicit warrant.""" @dataclass class SessionState: session_id: str last_event_id: int scopes: frozenset[str] suspended_at: float | None = None capability_model_generation: int = 0 @dataclass class PlanWarrant: """The scopes the current plan was authorized to rely on, frozen at plan time.""" required_scopes: frozenset[str] permitted_fallbacks: dict[str, str] = field(default_factory=dict) # denied_tool -> fallback_tool class ResumableSessionGuard: """Bounds the Last-Event-ID resume seam for streamable-HTTP MCP sessions.""" SCOPE_CLASS_RANK = {"tools:read": 0, "repo:write": 1, "deploy:trigger": 2} def __init__( self, introspect_scopes: Callable[[str], frozenset[str]], now: Callable[[], float] = time.monotonic, ) -> None: self._introspect = introspect_scopes self._now = now def on_suspend(self, state: SessionState) -> None: state.suspended_at = self._now() def on_resume( self, state: SessionState, presented_last_event_id: int, warrant: PlanWarrant, ) -> SessionState: # Step 1: transport-level resume is assumed to have succeeded upstream. # We do NOT trust that as an authorization event. if presented_last_event_id > state.last_event_id: raise ScopeContinuityViolation( f"resume Last-Event-ID {presented_last_event_id} ahead of known " f"{state.last_event_id}; server log rotated, continuity unprovable" ) # Step 2: mandatory re-derivation of effective scopes across the seam. effective = self._introspect(state.session_id) # Step 3: fail closed if the plan's required scopes are no longer held. missing = warrant.required_scopes - effective if missing: raise ScopeContinuityViolation( f"session {state.session_id} resumed with narrowed scopes; " f"plan requires {sorted(missing)} but grant no longer holds them. " f"Re-negotiate before issuing further tools/call frames." ) state.scopes = effective state.last_event_id = presented_last_event_id state.suspended_at = None state.capability_model_generation += 1 return state def classify_inband_error(self, state: SessionState, error_code: str) -> str: # In-band JSON-RPC errors on a 200-OK SSE stream must be reclassified. if error_code == "insufficient_scope": return "authorization" # route to renegotiation, NOT retry return "tool" def authorize_fallback( self, state: SessionState, denied_tool: str, proposed_fallback: str, warrant: PlanWarrant, ) -> None: if proposed_fallback not in state.scopes: raise ScopeContinuityViolation( f"fallback {proposed_fallback} not in held scopes {sorted(state.scopes)}" ) # Block silent widening: a denied narrow tool may not fall back to a # broader-scope tool unless the fallback was pre-declared in the warrant. denied_rank = self.SCOPE_CLASS_RANK.get(denied_tool, -1) fallback_rank = self.SCOPE_CLASS_RANK.get(proposed_fallback, -1) if fallback_rank > denied_rank: if warrant.permitted_fallbacks.get(denied_tool) != proposed_fallback: raise ScopeContinuityViolation( f"unauthorized scope-widening fallback: {denied_tool} " f"(rank {denied_rank}) -> {proposed_fallback} (rank {fallback_rank}); " f"not declared in plan warrant. Escalate to operator." ) ```