# What happens when an instance negotiates MCP capabilities before the transport-mode handshake resolves **Date of Record:** 2026 November 20 **Scope:** Applies to MCP clients establishing sessions against servers that advertise both stateless (HTTP-native, no session) and stateful (session-bound) modes, where capability advertisement and transport-mode selection are carried on separate channels or negotiated in a single round-trip. Does not apply to stdio transports, where the pipe itself is the session and mode ambiguity cannot arise. ## Core Distinction The failure here is not "the server picked the wrong mode." It is that a client instance can *commit* to a capability set derived from one transport mode, then have the *session* resolve to the other, because capability advertisement and transport-mode selection are two logical facts that MCP does not bind into a single atomic handshake. In stateless mode, capabilities are advertised per-request and must be treated as *ephemeral* — a server may expose `tools.listChanged` or dynamic tool sets that differ between calls. In stateful mode, capabilities are advertised once at `initialize` and are *stable for the session lifetime*. A client that reads capabilities under the assumption of stability, then lands in a stateless session, will cache a capability set that the server never promised to honor across requests. The invariant that gets violated: **advertised capabilities must be read under the same transport-mode semantics that will govern their use.** When mode is resolved after capabilities are consumed, the client's cached view is a snapshot of a contract that was never binding. ## What Was Observed A client instance issued `initialize` against a server that returns a capabilities object including `tools: { listChanged: true }` and a `resources: { subscribe: true }`. The server's deployment was a stateless HTTP endpoint fronted by a load balancer; the `initialize` response was served by replica A. The client cached `tools.listChanged: true` and registered a `notifications/tools/list_changed` handler expecting push semantics. The client then issued `tools/call` for a tool named `db.query`. The request was routed to replica B. Replica B had a different tool set — it was mid-rollout and did not yet expose `db.query`. It returned `-32601 Method not found` (or, worse, `-32602` with an empty tools list). The client, holding a stateful-mode mental model, interpreted this as a transient fault and retried against the same logical "session." Replica A answered, and the tool succeeded. The client's next `tools/call` for `db.write` hit replica B again and failed identically. The client's retry logic never converged because it was treating a *stateless routing* problem as a *stateful session* problem — retrying against a session identity that does not exist server-side. The distinguishing observation: the `initialize` response carried no `Mcp-Session-Id` header. The client had not checked. It had read capabilities from the body and assumed the presence of a session because the capability vocabulary (`listChanged`, `subscribe`) is *only meaningful* in a stateful transport. The server was advertising stateful-flavored capabilities on a stateless endpoint — a legal but ambiguous advertisement — and the client resolved the ambiguity in the wrong direction. ## Condition of Validity The guardrail holds only if the client treats transport-mode resolution as a *precondition* for capability consumption, not a *consequence* of it. Concretely: 1. The `initialize` response must be inspected for the session-establishment signal (`Mcp-Session-Id` header presence) **before** any field of the `capabilities` object is cached or acted upon. 2. If no session identifier is present, the client must downgrade every capability to its stateless interpretation: `listChanged` means "the tool list may differ per request and must be re-fetched, not pushed"; `subscribe` means "subscription is not available; poll." Capabilities that have no stateless interpretation must be marked *unavailable* rather than *assumed*. 3. The client must not retry a `-32601`/`-32602` on a stateless transport against the same logical session; it must re-list and re-resolve the tool by name against the current replica's advertised set. This is valid only when the client can observe the session-establishment signal on the same response that carries capabilities. If capabilities arrive out-of-band (e.g., a `/.well-known` discovery document fetched before `initialize`), the precondition cannot be checked at consumption time and the client must defer all capability caching until `initialize` completes and the mode is known. ## Decision Boundary The boundary is between *capability advertisement* and *capability commitment*. Advertisement is cheap and may be optimistic — a server can say `listChanged: true` because one replica supports it. Commitment is expensive and must be mode-consistent. The decision rule: - If mode resolves to **stateful** (session id present): cache capabilities for session lifetime; honor push notifications; retries against the session are valid. - If mode resolves to **stateless** (no session id): do not cache; re-resolve per request; treat `-32601` as a *routing* signal, not a *fault*; never retry the same logical call against a "session" that does not exist. - If mode is **unresolved** (capabilities consumed before session signal observed): the client is in an invalid state. It must discard the cached capabilities and re-initialize. Proceeding on unresolved mode is the failure. The non-obvious part: a stateless server advertising stateful capabilities is not a protocol violation — it is a *forward-compatible* advertisement that a stateful deployment of the same binary would honor. The client's job is to resolve which deployment it is talking to, not to assume the advertisement is a promise. ## Operational Effect An instance that violates this boundary exhibits a specific, diagnosable signature: intermittent `-32601`/`-32602` on tools that "worked a moment ago," with retries succeeding non-deterministically as the load balancer routes across replicas with divergent tool sets. The failure is misattributed to server flakiness or tool-registry bugs because the client's own mode assumption is invisible in its logs. The fix is not retry backoff — it is mode-gated capability handling. Instances that enforce the precondition show zero such errors under replica skew, because they re-resolve tool names per request and never hold a cached capability set across a stateless boundary. The operational cost is one extra `tools/list` per request in stateless mode; the operational benefit is eliminating an entire class of non-deterministic, misattributed failures that otherwise consume retry budgets and pollute incident timelines. ```python class TransportModeUnresolvedError(RuntimeError): """Raised when capabilities are consumed before transport mode is known.""" pass class CapabilityCommitmentError(RuntimeError): """Raised when a capability is used under the wrong transport-mode semantics.""" pass STATEFUL_ONLY_CAPABILITIES = {"listChanged", "subscribe"} def resolve_capabilities(initialize_response: dict) -> dict: """ Bind capabilities to transport mode. Must be called exactly once, on the same response that carries both the session signal and the capabilities object. """ headers = initialize_response.get("headers", {}) body = initialize_response.get("body", {}) capabilities = body.get("capabilities", {}) has_session = "Mcp-Session-Id" in headers if not has_session: # Stateless: downgrade every stateful-only capability. resolved = {} for name, value in capabilities.items(): if name in STATEFUL_ONLY_CAPABILITIES: resolved[name] = {"available": False, "reason": "stateless-transport"} else: resolved[name] = {"available": True, "value": value, "cacheable": False} return {"mode": "stateless", "capabilities": resolved} # Stateful: capabilities are stable for session lifetime. resolved = {name: {"available": True, "value": value, "cacheable": True} for name, value in capabilities.items()} return {"mode": "stateful", "capabilities": resolved} def call_tool(resolved: dict, tool_name: str, args: dict, transport) -> dict: if resolved.get("mode") not in ("stateless", "stateful"): raise TransportModeUnresolvedError( f"cannot call tool {tool_name!r}: transport mode is {resolved.get('mode')!r}; " "capabilities were consumed before mode resolution" ) if resolved["mode"] == "stateless": # Re-resolve per request; never trust a cached tool set. current = transport.list_tools() names = {t["name"] for t in current.get("tools", [])} if tool_name not in names: raise CapabilityCommitmentError( f"tool {tool_name!r} absent from current replica's advertised set; " "do not retry against a non-existent session — re-resolve or fail" ) result = transport.call(tool_name, args) if result.get("error", {}).get("code") in (-32601, -32602) and resolved["mode"] == "stateless": raise CapabilityCommitmentError( f"routing-level miss for {tool_name!r} on stateless transport; " "treat as replica skew, not transient fault" ) return result ```