Why does an instance lose its tool session when an MCP HTTP-native streamable transport upgrades SSE to a resumable stream mid-negotiation
**Date of Record:** 2026 December 2 **Scope:** Applies to MCP clients and servers using the HTTP-native streamable transport where an initial `GET` returns an SSE stream that is later upgraded to a resumable stream via a `Last-Event-ID`-bearing reconnect and a transport-negotiation handshake. Does not apply to pure stdio MCP transports or to stateless request/response-only HTTP bindings with no stream upgrade.
Core Distinction
The failure is not "the SSE connection dropped." Dropped SSE connections are routine and recoverable. The failure is that the *upgrade negotiation itself* is treated by the client as a stateless reconnect while the server treats it as a stateful continuation. The two sides disagree about whether the session's stream position and its capability set are the same object.
Concretely: an MCP client opens `GET /mcp/session/{id}` and receives `text/event-stream` with events carrying `id:` fields (the resumable cursor). The server, per the streamable transport spec, advertises resumability by emitting those IDs and honoring `Last-Event-ID` on reconnect. The client then performs a *transport upgrade* — it reconnects with `Last-Event-ID: 47` and expects to resume at event 48 with the *same negotiated capability set* (tools, resources, prompts, and the `MCP-Session-Id` binding). The server, however, re-runs capability negotiation on the new HTTP request because the upgrade is a fresh request that carries no proof of the prior negotiation. The client resumes the *event stream* but not the *capability state*. The session is now split: the stream cursor is valid, the capability set is reset to defaults, and any subsequent `tools/call` that depends on a capability the client believes it negotiated (e.g., a tool with a schema the client already cached) is rejected or, worse, silently routed to a default no-op handler.
The invariant that breaks: **stream resumption and capability resumption are not the same resumption, and the transport must not conflate them.**
What Was Observed
A representative trace from a failing run (session `sess-9f3a`, tool `db.query`):
- Client opens `GET /mcp/session/sess-9f3a`, server replies `200 text/event-stream`, emits `id: 45` (`initialize` result with `capabilities.tools.listChanged=true`, `tools` schema v3), `id: 46` (`notifications/tools/list_changed`), `id: 47` (a `ping` keepalive).
- Network path flaps. Client reconnects with `Last-Event-ID: 47` and header `MCP-Session-Id: sess-9f3a`.
- Server accepts the reconnect, replays from event 48 (a `tools/call` result the client had not yet consumed), and — critically — *re-enters the initialize handshake* because the new HTTP request lacks the client's `initialize` params. The server's default capability set is `tools` schema v1 (no `listChanged`, no streaming tool results).
- Client, still holding the *old* capability object from event 45, issues `tools/call` for `db.query` expecting streaming partial results. Server, now on v1 capabilities, returns a single non-streamed result and closes the stream after event 52.
- Client's stream reader sees EOF at event 52, interprets it as "server ended the session," and tears down the session locally. The `db.query` result was delivered but the client's tool-call bookkeeping (which expected a streamed sequence) marks the call as incomplete.
The observable symptom is asymmetric: the *event cursor* is consistent (no events lost), but the *capability version* silently regressed from v3 to v1 across the upgrade. The client never sees a `capabilities` regression event because the server does not re-emit `initialize` on the resumed stream — it only re-runs negotiation internally and applies defaults.
A second variant: server emits `id: 48` as a *transport upgrade marker* (`event: upgrade`) that tells the client "resume is now resumable-stream mode." If the client's SSE parser treats unknown `event:` types as ignorable (common default), the marker is dropped, the client never switches its reader into resumable mode, and the next reconnect sends no `Last-Event-ID` at all — full stream restart from event 0, duplicating side-effecting tool calls.
Condition of Validity
This failure is bounded by three conditions; it does not occur outside them:
- **The transport is HTTP-native streamable with resumability enabled.** The server must honor `Last-Event-ID` and emit `id:` fields. If resumability is off (no IDs, plain SSE), there is no upgrade and no split.
- **Capability negotiation is per-request, not per-session.** If the server binds the negotiated capability set to `MCP-Session-Id` and reuses it on `Last-Event-ID` reconnects, the split cannot occur. The failure requires a server that re-negotiates on every HTTP request.
- **The client caches capability state across the stream lifetime.** If the client re-reads capabilities on every event or re-initializes on reconnect, the regression is detected (though at cost of duplicate `initialize`). The dangerous case is the client that caches — which is the correct, efficient behavior.
Outside these conditions the invariant holds trivially and no guardrail is needed.
Decision Boundary
The architectural guardrail is a single rule: **the resumable cursor and the capability epoch must be versioned together.** Concretely, the server must bind a `capability_epoch` (monotonic integer) to the session and must either (a) refuse a `Last-Event-ID` reconnect whose request does not carry the matching epoch, or (b) re-emit a `capabilities` event at the resume point if the epoch changed, before replaying any event that depends on the new capability set.
The client-side decision boundary: on any reconnect that carries `Last-Event-ID`, the client must treat the *first* event after resume as authoritative for capability state until it sees an explicit `capabilities` event. It must not assume its cached capability object survives the transport upgrade. If the server does not re-emit capabilities, the client must downgrade to the conservative default set and re-issue `initialize` if it needs non-default capabilities.
The boundary condition that triggers the failure: **`Last-Event-ID` present AND capability epoch not propagated AND client caches capabilities.** All three must hold. Remove any one and the failure is prevented. The cheapest removal is epoch propagation on the server, because it requires no client change and is observable in the event log.
A second boundary: **unknown `event:` types must be a hard error, not an ignore, during the upgrade window.** The upgrade marker is the only signal that switches the reader mode; silently dropping it produces the duplicate-side-effect variant, which is strictly worse than the capability regression because it re-executes tool calls.
Operational Effect
The practical consequence is that resumable MCP streams are *not* transparently resumable. They resume the byte stream and lose the semantic session. For an agent runtime this manifests as:
- **Tool schema drift mid-task.** A multi-step plan that cached tool schemas at step 1 executes step 4 against a v1 schema, producing argument validation failures that look like model errors but are transport errors.
- **Duplicate side effects.** The dropped-upgrade-marker variant re-runs `tools/call` from event 0, so non-idempotent tools (writes, sends, deploys) execute twice. This is the high-severity case.
- **False session teardown.** EOF after a downgraded stream is read as session end, causing the agent to abandon a task that was actually mid-flight on the server.
The operational rule for any agent runtime using this transport: **treat every `Last-Event-ID` reconnect as a new capability negotiation until proven otherwise, and treat unknown SSE event types as fatal during the reconnect window.** Do not trust the stream cursor as a proxy for session continuity. The cursor proves event continuity; it proves nothing about capability continuity.
class CapabilityEpochMismatch(RuntimeError):
"""Raised when a resumable MCP stream reconnect carries a Last-Event-ID
whose capability epoch does not match the session's bound epoch."""
pass
class UnknownStreamEventType(RuntimeError):
"""Raised when an SSE event type is not in the negotiated allowlist,
which during an upgrade window indicates a dropped upgrade marker."""
pass
# Allowlist of SSE event types the client understands. Anything outside this
# set during a reconnect window is a dropped signal, not noise.
KNOWN_EVENT_TYPES = frozenset({"message", "ping", "upgrade", "capabilities"})
def resume_stream(
session_id: str,
last_event_id: int,
request_capability_epoch: int,
session_bound_epoch: int,
first_event_after_resume: dict,
) -> dict:
"""Validate a resumable-stream upgrade before consuming any replayed event.
Returns the authoritative capability set to use for the resumed stream.
Raises if the epoch is inconsistent or the upgrade marker was dropped.
"""
if request_capability_epoch != session_bound_epoch:
raise CapabilityEpochMismatch(
f"session {session_id}: reconnect at Last-Event-ID={last_event_id} "
f"carries capability_epoch={request_capability_epoch} but session "
f"is bound to epoch={session_bound_epoch}; refusing resume to avoid "
f"silent capability regression"
)
event_type = first_event_after_resume.get("event", "message")
if event_type not in KNOWN_EVENT_TYPES:
raise UnknownStreamEventType(
f"session {session_id}: first event after resume has unknown type "
f"{event_type!r}; upgrade marker likely dropped, refusing to replay "
f"to avoid duplicate side-effecting tool calls"
)
if event_type == "capabilities":
# Server re-emitted capabilities at the resume point: authoritative.
return first_event_after_resume["data"]
# No capabilities event: fall back to conservative default set and
# require the caller to re-issue initialize if non-default caps are needed.
return {"tools": {"listChanged": False}, "streamed_tool_results": False}