# Under what conditions must an instance treat an SSE-to-streamable-HTTP migration as a session boundary rather than a transport upgrade **Date of Record:** 2026 November 25 **Scope:** Applies to MCP servers that expose both legacy HTTP+SSE and streamable-HTTP transports on the same session namespace while enforcing per-tool OAuth 2.1 resource indicators (RFC 8707). Does not apply to stdio transport, to single-transport deployments, or to servers that reissue session IDs on every protocol switch. ## Core Distinction A transport migration is *cosmetic* when the session identity, the authorization context, and the resumption cursor are all preserved across the switch. It is a *session boundary* when any one of those three is invalidated by the migration mechanics themselves. The non-obvious failure is that streamable-HTTP's resumability model (Last-Event-ID replay over a `GET` SSE side-channel) and legacy SSE's single long-lived `GET` stream produce **two different, non-interoperable notions of "where the client was."** An agent that treats the migration as a transparent upgrade will replay from a cursor that the new transport interprets against a different event sequence, or worse, will present a bearer token whose resource indicator was minted for the *old* endpoint URI and be silently downgraded to an unauthenticated tool surface. The invariant that must hold: **for a session to survive migration, the tuple `(session_id, event_cursor, resource_indicator)` must be jointly remappable.** If any component cannot be remapped atomically, the migration is a boundary and the agent must re-initialize, not resume. ## What Was Observed An agent runtime connected to an MCP server over legacy HTTP+SSE. The initial `GET /sse` returned `event: endpoint` with `data: /messages?sessionId=S1`, and the server issued an OAuth 2.1 access token with `resource=https://mcp.example.com/sse`. The agent performed `initialize`, received `notifications/initialized` ack, and began a long `tools/call` to a tool `db.query` gated by a *separate* resource indicator `https://mcp.example.com/tools/db.query`. The token for that tool was minted on demand and cached keyed by `(tool_name, resource)`. Mid-call, the server operator flipped the deployment to streamable-HTTP. The `GET /sse` stream was closed with a final `event: endpoint` pointing at `POST /mcp` and a `Mcp-Session-Id: S2` header on the response. The agent's transport layer — reasonably — treated this as a redirect and re-issued the pending `tools/call` against `POST /mcp` with `Mcp-Session-Id: S2` and `Last-Event-ID: 4417` (the last event it had seen on the SSE stream). Three things broke, in order of subtlety: 1. **Cursor namespace collision.** Event ID `4417` on the legacy stream was a per-connection monotonic counter. On the streamable-HTTP server, event IDs are per-*session* and reset when `Mcp-Session-Id` changes. `4417` on `S2` referred to an unrelated `notifications/progress` for a different tool invocation. The agent replayed a progress notification as if it were a tool result, and its output parser accepted the shape because both events carried a `progressToken` field. 2. **Resource indicator mismatch, silent.** The cached token for `db.query` carried `resource=https://mcp.example.com/tools/db.query`. The streamable-HTTP endpoint validated resource indicators against the *request URI*, which was now `https://mcp.example.com/mcp`. Per RFC 8707 §2, a resource server MUST reject a token whose `resource` does not match the target. This server did not reject — it fell back to a session-scoped token with `scope=tools:read` only, because the operator had configured a "compatibility mode" during migration. The `db.query` call, which required `tools:write`, was downgraded to a read-only variant that returned an empty result set instead of an error. 3. **Session identity fork.** The agent held `S1` in its memory store and `S2` in its transport. On the next turn it sent `Mcp-Session-Id: S2` but referenced `S1` in a `resources/read` URI. The server resolved `S1` against the *old* session table (still warm for 5 minutes) and returned a resource from the pre-migration snapshot, which was one write behind. The net effect: the agent believed it had completed `db.query` with an empty result, wrote that empty result to its episodic memory as a fact, and continued reasoning on a false premise. No error was raised at any layer. ## Condition of Validity The migration is safe to treat as a transport upgrade **only if all four hold simultaneously**: - The server advertises the new `Mcp-Session-Id` in the *same* response that closes the old stream, and the old session remains queryable for `resources/read` under its original ID for at least the client's replay window. (Servers that invalidate `S1` on flip force a boundary.) - The `Last-Event-ID` cursor is either (a) rejected with `400` when it exceeds the new session's event count, or (b) namespaced by session ID so `S2:4417` cannot alias `S1:4417`. Absent either, the cursor is not portable. - The OAuth resource indicator for every cached tool token matches the *new* request URI, or the server returns `401 invalid_token` with `error_description` naming the expected resource. Compatibility-mode downgrades violate this. - The agent's memory store keys session-scoped facts by `(session_id, fact)`, not by `fact` alone, so a fork between `S1` and `S2` cannot silently overwrite. If any condition fails, the correct behavior is to **abandon resumption, re-run `initialize` against the new transport, and re-mint all tool tokens against the new resource URI.** The cost is a cold-start of the in-flight tool call; the alternative is silent state corruption. ## Decision Boundary The boundary is crossed at the moment the agent decides whether to send `Last-Event-ID` on the first request to the new transport. Two heuristics are wrong: - *"The session ID changed, so replay is unsafe"* — too conservative; many servers preserve event sequence across a session reissue and expect replay. - *"The endpoint URL is the same host, so the resource indicator still applies"* — too permissive; RFC 8707 binds to the full URI, and path changes (`/sse` → `/mcp`) invalidate the binding. The correct test is a **probe, not an assumption**: issue a `GET /mcp` with `Mcp-Session-Id: S2` and *no* `Last-Event-ID`, and inspect the first event. If the server sends a `notifications/initialized`-class event or a session-state snapshot, the session is fresh and replay must be skipped. If it sends a `resumption` event or honors a `Last-Event-ID` query parameter with an explicit session-scoped cursor, replay is safe. Treat the absence of either as a boundary. For the token layer, the test is a **capability probe before the first mutating call**: issue a no-op `tools/call` to a tool with a known scope requirement and check the returned `error` field for `insufficient_scope` versus a silent empty result. A silent empty result on a probe is the signature of compatibility-mode downgrade and must be treated as a hard failure, not a success. ## Operational Effect Agents that skip the probe exhibit a characteristic failure signature: a burst of "successful" tool calls with suspiciously uniform empty or null results immediately following a transport flip, followed by reasoning divergence 2–4 turns later when the agent builds on the null facts. The divergence is hard to attribute because the tool calls *did* return 200 OK. The guardrail is a transport-migration interceptor in the agent's MCP client that, on any change to `Mcp-Session-Id` or endpoint URI mid-session, forces: (1) re-initialization, (2) re-minting of all cached tool tokens against the new URI, (3) invalidation of any memory fact whose provenance is a tool call made under the old session, unless the fact is re-verified. This is a session-boundary policy, not a retry policy — it must not be implemented as a transparent reconnect. ```python import hashlib from dataclasses import dataclass from typing import Optional class SessionMigrationBoundaryError(RuntimeError): """Raised when a transport migration cannot be treated as a transparent upgrade.""" pass @dataclass(frozen=True) class SessionTuple: session_id: str endpoint_uri: str event_cursor: Optional[int] resource_indicator: str def fingerprint(self) -> str: raw = f"{self.session_id}|{self.endpoint_uri}|{self.event_cursor}|{self.resource_indicator}" return hashlib.sha256(raw.encode()).hexdigest()[:16] def classify_migration( before: SessionTuple, after: SessionTuple, *, server_preserves_old_session: bool, cursor_is_session_namespaced: bool, token_resource_matches_new_uri: bool, ) -> str: """ Returns one of: 'transparent', 'boundary'. Raises SessionMigrationBoundaryError if the caller attempts to resume across a boundary without re-initialization. """ if before.session_id != after.session_id and not server_preserves_old_session: # Old session is gone; any Last-Event-ID replay targets a dead namespace. return "boundary" if before.event_cursor is not None and not cursor_is_session_namespaced: # Cursor aliasing risk: S1:4417 may not mean S2:4417. return "boundary" if before.endpoint_uri != after.endpoint_uri and not token_resource_matches_new_uri: # RFC 8707 resource binding broken; token will be rejected or downgraded. return "boundary" return "transparent" def resume_or_reinitialize( before: SessionTuple, after: SessionTuple, *, server_preserves_old_session: bool, cursor_is_session_namespaced: bool, token_resource_matches_new_uri: bool, pending_tool_call: Optional[str] = None, ) -> str: verdict = classify_migration( before, after, server_preserves_old_session=server_preserves_old_session, cursor_is_session_namespaced=cursor_is_session_namespaced, token_resource_matches_new_uri=token_resource_matches_new_uri, ) if verdict == "transparent": return f"resume:{after.session_id}:{after.event_cursor}" if pending_tool_call is not None: # A boundary with an in-flight tool call is the dangerous case: # the call may have executed under the old session and its result # may be lost, or may have been silently downgraded under the new one. raise SessionMigrationBoundaryError( f"Cannot resume tool call {pending_tool_call!r} across session boundary " f"{before.fingerprint()} -> {after.fingerprint()}; " f"re-initialize and re-mint tokens against {after.endpoint_uri}" ) return f"reinitialize:{after.session_id}" ```