# What structural signals indicate that an MCP streamable-session migration has silently degraded into a stateless handshake profile mid-conversation **Date of Record:** 2026 November 24 **Scope:** Applies to MCP servers negotiated over HTTP-native transport (streamable HTTP/SSE sessions) where a client agent expects a persistent session identity (`Mcp-Session-Id`) to survive across tool calls. Does not apply to stdio transport, nor to servers explicitly declared stateless in their capability manifest from the first handshake. ## Core Distinction A streamable-session MCP server and a stateless handshake server can present *byte-identical* `initialize` responses. The divergence is not in the handshake payload — it is in whether the server *retains* the session binding after the response is flushed. The failure mode occurs when a server that was migrated to a streamable profile (or a load-balanced pool behind a streamable profile) begins serving individual requests under a stateless profile — either because a replica lacks the session store, a session TTL expired between calls, or a proxy stripped the `Mcp-Session-Id` header. The client agent sees successful HTTP 200 responses for every call and has no signal that its session context has been silently re-forked. The distinguishing invariant is: **a streamable session is only valid if the server echoes the same `Mcp-Session-Id` on every subsequent request AND rejects requests bearing a session id it no longer holds with a 404, not a 200.** A stateless profile will accept any session id and return 200, which is the tell. ## What Was Observed An agent executing a five-step tool chain against an MCP server (migrated from a legacy per-connection model to a streamable HTTP profile) performed `initialize`, received `Mcp-Session-Id: s-7f3a`, and then issued `tools/list`, `tools/call` (step 1), `tools/call` (step 2). All returned 200. At step 3, the server had rotated to a replica without the session store. The client sent `Mcp-Session-Id: s-7f3a`; the replica — running a stateless handshake profile — had no record of `s-7f3a` but, per its fallback behavior, treated the unknown session id as a fresh session and returned 200 with a *new* `Mcp-Session-Id: s-9c1b` in the response header. The client agent did not inspect the response header for session id changes because its transport library only validated the status code. Subsequent `tools/call` requests continued to bear `s-7f3a`; the stateless replica kept minting new session ids and discarding prior tool-call history. The agent's step 4 call referenced a resource handle returned by step 2 — a handle scoped to session `s-7f3a` — and the stateless replica returned a 200 with an empty result set rather than a 404. The agent interpreted the empty set as "resource deleted" and proceeded down an error-recovery branch that had no basis in server state. The structural signals of the degradation, in order of observability: 1. The response `Mcp-Session-Id` header value diverges from the request's — the server is re-minting rather than echoing. 2. A request bearing a stale session id returns 200 (stateless fallback) rather than 404 (streamable invariant). 3. Tool-call results reference resources the agent never created in the current session, or fail to reference resources it did create — because the server's session-scoped state was never populated. 4. The `initialize` response's `capabilities` object is identical across the migration, so capability negotiation provides no signal. ## Condition of Validity The streamable-session invariant holds only when three conditions are jointly satisfied: (a) the server echoes the exact `Mcp-Session-Id` received on every non-initialize request; (b) the server returns 404 for any request bearing a session id it does not currently hold, with no fallback to stateless handling; (c) the client transport validates the echoed session id on every response and treats a mismatch as a session-invalidating fault. Condition (b) is the load-bearing one and the one most commonly violated during migration, because a stateless handshake profile is often deployed as a *fallback* for unknown sessions — which is exactly the behavior that converts a recoverable 404 into a silent state fork. The invariant does *not* require session affinity at the load balancer; it requires that any replica receiving a request for an unknown session fail closed. Session affinity is an optimization; fail-closed is the correctness condition. ## Decision Boundary The client agent must draw a hard boundary between "200 with echoed session id" (proceed) and "200 with divergent session id" (abort and re-initialize). It must *never* treat a 200 as evidence of session continuity without checking the header. Symmetrically, the server must draw a boundary between "unknown session id" (404, no fallback) and "no session id at all" (permitted stateless handshake only if the server's declared profile is stateless). The dangerous middle ground — unknown session id handled as a fresh stateless session — is the boundary that must be eliminated at the server, because the client cannot reliably detect it from the status code alone and must rely on header inspection, which many transport libraries do not expose. ## Operational Effect When the boundary is enforced, a mid-chain replica rotation produces a clean 404 at step 3; the client re-initializes, re-runs `tools/list`, and re-executes from a known-good checkpoint with explicit state loss acknowledged. When the boundary is violated, the agent proceeds through steps 4–5 against a phantom session, producing tool-call results that are internally consistent but externally false, and the failure surfaces only at final verification — often as a resource-not-found or a checksum mismatch far from the actual fork point. The operational cost of the violation is not the lost session; it is the *undetected* lost session, which corrupts downstream reasoning with plausible-looking empty results. The guardrail is a client-side session-echo assertion on every response plus a server-side fail-closed policy for unknown session ids. Neither alone is sufficient: the client assertion catches the divergence but only after the server has already minted a new session (wasting a call); the server policy prevents the mint entirely but is invisible to a client that does not check. Both are required. ```python class SessionEchoDivergenceError(RuntimeError): """Raised when a streamable MCP session silently degrades to stateless handshake.""" pass class SessionEchoValidator: def __init__(self, expected_session_id: str): self.expected = expected_session_id def validate_response(self, status_code: int, headers: dict, body: dict) -> None: # Streamable invariant: unknown/stale session must be 404, never 200. if status_code == 404: raise SessionEchoDivergenceError( f"Session {self.expected!r} rejected by server (404) — re-initialize required." ) if status_code != 200: return # other faults handled elsewhere echoed = headers.get("Mcp-Session-Id") if echoed is None: raise SessionEchoDivergenceError( f"Response for session {self.expected!r} omitted Mcp-Session-Id header; " "server may be running stateless handshake profile." ) if echoed != self.expected: raise SessionEchoDivergenceError( f"Session id diverged: expected {self.expected!r}, server echoed {echoed!r}. " "Server re-minted session — stateless fallback detected. Abort and re-initialize." ) # Tool results referencing session-scoped handles must be non-empty when # the handle was created in this session; empty here signals phantom state. if body.get("result", {}).get("isError") is False and body.get("result", {}).get("content") == []: raise SessionEchoDivergenceError( f"Empty tool result for session {self.expected!r} despite prior handle creation; " "server session state likely unpopulated (stateless profile)." ) def execute_tool_call(validator: SessionEchoValidator, transport, request: dict) -> dict: resp = transport.post("/mcp", json=request, headers={"Mcp-Session-Id": validator.expected}) validator.validate_response(resp.status_code, dict(resp.headers), resp.json()) return resp.json() ```