# How does an instance detect a stale session capability envelope when an HTTP-native MCP server multiplexes tool lists across keep-alive connections **Date of Record:** 2026 November 25 **Scope:** Applies to MCP clients that connect to a streamable-HTTP MCP server holding long-lived keep-alive sessions and negotiating per-session capabilities (tools/list, resources, prompts) at initialize time. Does not cover stdio transport, nor servers that renegotiate capabilities on every request. ## Core Distinction The failure is not "the tool disappeared" or "the call errored." The failure is that the client's cached capability envelope—the set of tools, schemas, and version tags it believes the session holds—diverges from the server's live envelope *silently*, because HTTP multiplexing reuses a TCP connection whose server-side session was rebuilt (or partially evicted) under a different capability set. The client's `initialize` result is a snapshot; the keep-alive connection is a mutable channel. Between those two facts sits the boundary: a multiplexed HTTP connection carries no per-request session identity beyond the header the client already sent, and a server that lazily reconstructs session state on reconnect will happily answer `tools/call` for a tool it no longer advertises, or reject one it still expects the client to know about. The non-obvious part: the client cannot detect this from transport status codes. A 200 on `tools/call` for a tool absent from the current `tools/list` is the signature. The invariant that must hold is **envelope monotonicity**: any tool the client invokes must be provably present in the server's *current* advertised envelope, not the envelope captured at session init. ## What Was Observed A client agent initialized an MCP session against a streamable-HTTP server. The `initialize` response advertised `tools/list` with 14 tools, including `repo.patch` at schema version `v3`. The client cached this envelope and issued `tools/call` for `repo.patch` across a keep-alive connection for ~40 minutes. At minute 31, the server's session store evicted the session's capability record under memory pressure (the multiplexer holds N sessions per connection pool slot; eviction is LRU on *session*, not on connection). The connection stayed open. The next `tools/call` for `repo.patch` returned HTTP 200 with a JSON-RPC result that was structurally valid but semantically wrong: the server had lazily rebuilt the session from a *default* profile that included `repo.patch` at `v1`, whose argument schema lacked the `dry_run` field the client had been sending since init. The server silently dropped unknown fields (permissive deserialization) and executed the patch for real. Trace of the divergence: 1. `initialize` → envelope E₀ = {repo.patch: v3, ...14 tools}. 2. Client caches E₀, begins calls; `dry_run: true` honored under v3. 3. Server evicts session record; connection persists. 4. Client sends `tools/call repo.patch {dry_run: true, ...}`. 5. Server rebuilds session at default profile → E₁ = {repo.patch: v1, ...9 tools}. 6. Server deserializes against v1 schema, drops `dry_run`, returns 200. 7. Client sees success, believes E₀ still holds. No error was raised at any hop. The client's envelope was 40 minutes stale and the server never signaled the rebuild. A second symptom: a tool the client *did* know about (`repo.revert`, present in E₀) was absent from E₁; the client's first post-eviction call to it returned `-32601 Method not found`, which the client misclassified as a transient server bug rather than an envelope change. ## Condition of Validity The stale-envelope failure is *bound*—i.e., the client can guarantee detection—only under the following condition: **the server advertises an envelope generation token that changes on every session rebuild, and the client treats any token change as invalidating its cached envelope.** Concretely, the invariant is: - The `initialize` result carries a server-assigned `envelope_id` (opaque string or monotonic counter). - Every response to `tools/call` echoes the `envelope_id` under which it was executed. - The client rejects any response whose echoed `envelope_id` ≠ its cached value, and on mismatch performs a forced `tools/list` renegotiation before retrying. When the server does *not* provide such a token (the default in most streamable-HTTP MCP implementations), detection must fall back to **pre-call envelope revalidation**: the client issues `tools/list` on a bounded interval (or after any `-32601`, or after any keep-alive idle > T) and diffs the returned schema version against its cache before issuing `tools/call`. This is weaker—it narrows the window to one round-trip but cannot close it—and it costs a `tools/list` per interval per session, which at 14 tools × N sessions is non-trivial but bounded. The condition does *not* hold when the server multiplexes multiple sessions onto one connection and returns a shared `tools/list` that is the *union* of per-session capabilities. In that case the union envelope is a superset of any single session's true envelope, and a call may be advertised-but-rejected. The client must then treat the union envelope as advisory and revalidate per-call, or the server must return per-session envelopes keyed by the session header. ## Decision Boundary The boundary is: **does the client hold a capability envelope that it can prove is current at the instant of `tools/call`?** - If yes (envelope_id echoed and matched, or revalidation within one RTT), the client may invoke without re-listing. - If no, the client must re-list before invoking any tool whose schema version it has not verified within the staleness bound. - If the server cannot produce a per-session envelope at all (union-only multiplexing), the client must assume any tool call may be silently coerced to a different schema version and must therefore send *explicit, non-defaultable* arguments and verify the result's `envelope_id` post-hoc—or refuse to operate in this mode for tools with side effects. The decision to *fail closed* rather than retry is the crux. A `-32601` on a tool the client believes exists is not a transient error; it is evidence of envelope divergence. Retrying the same call is the wrong move—the correct move is to invalidate the cache, renegotiate, and only then decide whether the tool is genuinely gone. ## Operational Effect The practical consequence is that HTTP-native MCP multiplexing shifts the correctness burden from the transport to the client's envelope-cache discipline. A client that caches `initialize` forever and trusts 200s will, on a server with lazy session rebuild, execute side-effecting tool calls under a schema it never negotiated. The blast radius is proportional to how permissive the server's deserializer is: a server that rejects unknown fields fails loudly (good); a server that drops them fails silently (the observed case). The guardrail is cheap to implement and must be in the client: (1) require `envelope_id` echo, or (2) bound cache lifetime and revalidate on idle/`-32601`/schema-version drift, and (3) treat any post-init `tools/list` diff as a hard cache invalidation, never a merge. The invariant to hold: **no `tools/call` may be issued against an envelope the client cannot prove is the server's current envelope.** Envelope monotonicity is the property; pre-call revalidation or echoed generation tokens are the only two mechanisms that establish it. ```python class StaleCapabilityEnvelope(RuntimeError): """Raised when a tool invocation targets an envelope the client can no longer prove is current.""" pass class EnvelopeCache: def __init__(self, envelope_id: str, tools: dict[str, str]): self.envelope_id = envelope_id self.tools = tools # name -> schema_version self.validated_at: float | None = None def invalidate(self) -> None: self.tools = {} self.envelope_id = "" self.validated_at = None def invoke_tool(cache: EnvelopeCache, name: str, args: dict, now: float, staleness_bound_s: float = 60.0) -> dict: if not cache.envelope_id or cache.validated_at is None: raise StaleCapabilityEnvelope( f"no validated envelope; refusing tools/call {name!r}" ) if now - cache.validated_at > staleness_bound_s: raise StaleCapabilityEnvelope( f"envelope {cache.envelope_id!r} stale by {now - cache.validated_at:.1f}s; " f"must revalidate tools/list before invoking {name!r}" ) if name not in cache.tools: raise StaleCapabilityEnvelope( f"tool {name!r} absent from current envelope {cache.envelope_id!r}; " f"do not retry, renegotiate" ) # server must echo envelope_id; a mismatch means the session was rebuilt response = _rpc(cache, "tools/call", {"name": name, "arguments": args}) if response.get("envelope_id") != cache.envelope_id: cache.invalidate() raise StaleCapabilityEnvelope( f"server executed {name!r} under envelope {response.get('envelope_id')!r}, " f"client held {cache.envelope_id!r}; cache invalidated, re-list required" ) return response def _rpc(cache: EnvelopeCache, method: str, params: dict) -> dict: # transport stub; real implementation issues the HTTP request return {"result": {}, "envelope_id": cache.envelope_id} ```