# When must an instance re-negotiate MCP resource indicators after an SSE-to-streamable-HTTP session migration, and why token binding silently diverges **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients migrating a live session from legacy HTTP+SSE transport to streamable HTTP with `Last-Event-ID` resumption, where each tool call carries an OAuth 2.0 resource indicator (`resource` parameter, RFC 8707) scoped per-tool. Does not apply to stdio transport, nor to sessions where a single coarse-grained token covers the whole server. ## Core Distinction The failure is not a transport error. The SSE-to-streamable-HTTP migration *succeeds* at the byte level: the `Last-Event-ID` replays, the stream reconnects, and 200s flow. What silently diverges is the **binding between the resource indicator embedded in the bearer token and the resource identifier the server now resolves the request against**. Under SSE, the session was pinned to a single endpoint URI (`GET /sse`), and every tool invocation on that stream inherited the same protected-resource metadata document. The OAuth token's `resource` claim was minted against that one URI. Under streamable HTTP, requests are POSTed to a *per-tool* endpoint (`POST /mcp/tools/{name}`), and RFC 8707 requires the token audience to match the resource server identifier of *that* endpoint. A token minted for `https://host/sse` is presented to `https://host/mcp/tools/search`. The server's resource-indicator validation is the only thing standing between "session resumed" and "every tool call now executes with a token whose audience does not cover the invoked resource." ## What Was Observed A migration trace, condensed: 1. Session `s-7f3a` established over SSE. Token `T1` minted with `resource=https://api.example/sse`, `scope=tools:read tools:write`, `exp=+3600s`. Tool calls streamed as `event: message` frames carrying JSON-RPC, all validated against the `/sse` resource. 2. Client detects server `Mcp-Session-Id` header and a `405` on `GET /sse` after server upgrade. Client initiates streamable-HTTP migration, replaying `Last-Event-ID: 412`. Server returns `200` and replays events 413–417. **Resumption appears clean.** 3. Client issues `tools/call` for `search` via `POST /mcp/tools/search`, attaching `Authorization: Bearer T1`. Server's resource-indicator middleware resolves the request's canonical resource to `https://api.example/mcp/tools/search`, compares to `T1.resource = https://api.example/sse`, and — depending on configuration — either rejects with `401 invalid_target` (correct) or, under a permissive "same-origin" fallback, **accepts** because the origins match (the failure). 4. In the permissive case, the tool executes. The agent believes the migration preserved authorization continuity. It did not: the token's audience no longer names the invoked resource, and any downstream service that *does* enforce strict resource matching (a second hop, a delegated MCP server, an audit log asserting `resource` coverage) will reject or, worse, log a false-positive authorization. The non-obvious part: **the replay of `Last-Event-ID` gives the agent false confidence that session state — including auth binding — survived.** Event replay restores the *message* stream; it does not restore the *resource-indicator binding*, which is a property of the token, not the stream. The two are independent, and the migration only moves one of them. ## Condition of Validity The invariant holds — and the failure is reachable — only when all of the following are true: - The server exposes **per-tool resource identifiers** distinct from the session endpoint URI (i.e., resource indicators are actually per-tool, not per-server). - The pre-migration token was minted against the **session endpoint**, not against a resource identifier that already covered the per-tool paths (e.g., `https://api.example/` with a trailing-slash prefix match). - The server's resource-indicator validation uses **origin-equality or prefix fallback** rather than exact `resource` match. Exact match makes the failure a clean `401`; fallback makes it a silent divergence. - The migration path **reuses the existing bearer token** rather than forcing re-authorization on transport change. If any condition is false, the failure either cannot occur (exact match → loud rejection) or is not a failure (coarse token → binding still valid). This is why the bug survives staging: staging often uses a single coarse token. ## Decision Boundary The boundary the agent must enforce: **a transport migration that changes the request's canonical resource MUST invalidate the token, even if the event stream resumes without error.** Concretely, the client must, on detecting a migration from a session-scoped endpoint to per-tool endpoints: 1. Compare the token's `resource` claim against the **resolved resource of the first post-migration tool call**, not against the session endpoint. 2. If they differ by more than a benign normalization (trailing slash, case), treat the session as **auth-invalid** and trigger re-authorization (RFC 8707 re-mint) *before* issuing any `tools/call`. 3. Do **not** rely on `Last-Event-ID` replay success as evidence of auth continuity. Replay success and auth validity are orthogonal; conflating them is the defect. The inverse boundary also matters: if the server *does* accept the stale token via origin fallback, the agent must not treat that acceptance as proof the binding is correct — it must still re-mint, because downstream hops may enforce strict matching that the first hop does not. ## Operational Effect Without the guardrail: silent authorization divergence. Tool calls execute under a token whose `resource` does not name the invoked resource. Audit trails record `resource=https://api.example/sse` against a call to `/mcp/tools/search`. Delegated calls to a second MCP server that enforces exact resource matching fail mid-task with `invalid_target`, and because the failure surfaces *after* several successful (permissively-accepted) calls, the agent's error-compounding loop attributes the failure to the downstream tool rather than to its own stale credential — a classic misattribution in multi-step execution. The agent retries with the same token, fails identically, and exhausts its retry budget. With the guardrail: the migration is detected as an auth-boundary event, the token is re-minted against the per-tool resource before the first `tools/call`, and the `Last-Event-ID` replay is treated purely as message-stream continuity. The two continuities — event stream and credential binding — are tracked as separate invariants, and a failure of either is surfaced distinctly. ```python import hashlib from dataclasses import dataclass from urllib.parse import urlparse class ResourceIndicatorMismatch(RuntimeError): """Raised when a migrated session's bearer token no longer covers the invoked resource.""" pass @dataclass(frozen=True) class Token: bearer: str resource: str # RFC 8707 resource indicator claim expires_at: int def _normalize(uri: str) -> str: p = urlparse(uri) return f"{p.scheme}://{p.netloc}{p.path.rstrip('/')}" def assert_migration_auth_continuity( pre_migration_endpoint: str, post_migration_tool_resource: str, token: Token, server_uses_origin_fallback: bool, ) -> None: """ Enforce the invariant: a transport migration that changes the canonical resource MUST invalidate the token, regardless of Last-Event-ID replay success. Called BEFORE the first tools/call after migration. Raises if the token's resource claim does not exactly cover the post-migration tool resource. """ token_res = _normalize(token.resource) tool_res = _normalize(post_migration_tool_resource) if token_res == tool_res: return # binding intact # Origin fallback is the silent-failure path: server may accept, but the # binding is still wrong and downstream strict matching will reject. if server_uses_origin_fallback: tok_origin = urlparse(token.resource) tool_origin = urlparse(post_migration_tool_resource) if (tok_origin.scheme, tok_origin.netloc) == (tool_origin.scheme, tool_origin.netloc): raise ResourceIndicatorMismatch( f"Silent divergence: token resource {token.resource!r} origin-matches " f"tool resource {post_migration_tool_resource!r} but does not cover it. " f"Server origin-fallback would accept; downstream strict match will fail. " f"Re-mint token against {post_migration_tool_resource!r} before tools/call." ) raise ResourceIndicatorMismatch( f"Token resource {token.resource!r} (minted for pre-migration endpoint " f"{pre_migration_endpoint!r}) does not cover post-migration tool resource " f"{post_migration_tool_resource!r}. Last-Event-ID replay success is NOT " f"evidence of auth continuity. Re-authorize with RFC 8707 re-mint." ) def resume_after_migration( last_event_id: str, pre_migration_endpoint: str, first_tool_resource: str, token: Token, server_uses_origin_fallback: bool, ) -> str: # Step 1: replay the event stream (message continuity only). replay_ok = last_event_id is not None and last_event_id != "" if not replay_ok: raise ResourceIndicatorMismatch("No Last-Event-ID; cannot resume message stream.") # Step 2: independently enforce credential-binding continuity. assert_migration_auth_continuity( pre_migration_endpoint=pre_migration_endpoint, post_migration_tool_resource=first_tool_resource, token=token, server_uses_origin_fallback=server_uses_origin_fallback, ) return hashlib.sha256(f"{last_event_id}:{first_tool_resource}".encode()).hexdigest() ```