# Which invariants prevent MCP capability-negotiation drift from silently re-binding a stateless edge tool call to a stale server revision **Date of Record:** 2026 November 28 **Scope:** Applies to MCP clients invoking HTTP-native (stateless, request/response) tool servers at the edge where the server revision, tool schema, or `initialize` capability set can change between the client's cached negotiation snapshot and the moment of invocation. Does not apply to long-lived bidirectional MCP transports (stdio, persistent SSE sessions) where the session object itself pins the negotiated capability set for the connection lifetime. ## Core Distinction The distinction that matters is between **session-scoped capability negotiation** and **invocation-scoped capability assertion**. In a stateful MCP transport, `initialize` + `tools/list` produces a capability snapshot that is bound to the connection; every subsequent `tools/call` on that connection is guaranteed to be interpreted against the same schema version because the transport itself is the version anchor. In an HTTP-native stateless transport, there is no connection to anchor anything. The client holds a *cached* snapshot (schema hashes, tool names, parameter shapes, capability flags) and the edge server holds a *live* revision that the client cannot observe without re-negotiating. The gap between those two is where drift lives. The naive model — "the client negotiated once, therefore it knows the tool contract" — is a stateful assumption smuggled into a stateless protocol. The edge server is free to redeploy, roll back, or shard a new revision behind the same endpoint between any two requests. The client's cached `inputSchema` is a *claim about the past*, not a *guarantee about the present*. The invariant that must hold is not "the schema is stable" (it isn't) but "every invocation either matches the schema the server will actually enforce, or fails closed before side effects." ## What Was Observed A tool server exposing a single HTTP-native tool, `apply_discount`, was deployed at an edge endpoint behind a rolling revision scheme. Revision A accepted `{order_id: str, percent: int}` with `percent` constrained to `[1, 50]`. Revision B, rolled out to 30% of edge nodes over a 40-minute window, changed the contract to `{order_id: str, percent_bp: int}` (basis points, `[100, 5000]`) — a rename plus a unit change, with the old field deprecated but still *accepted* by B's parser for backward compatibility, silently coerced as `percent_bp = percent * 100`. The client agent had negotiated against revision A at cold start and cached the A schema. It then issued `tools/call` requests against the load-balanced endpoint. Because the endpoint was not sticky, roughly 30% of invocations landed on a B node. The failure trace: 1. Client sends `{order_id: "o-991", percent: 20}` with `Content-Type: application/json` and no schema-version header. 2. A-node: parses as A, applies 20% discount. Correct. 3. B-node: parses `percent: 20`, hits the backward-compat coercion branch, computes `percent_bp = 2000`, applies 20% discount. **Coincidentally identical result.** 4. Client sends `{order_id: "o-992", percent: 45}`. B-node coerces to `percent_bp = 4500`, applies 45%. Still identical. 5. Client, having seen two successes, *infers* the schema is stable and stops re-checking. It then sends a value the A schema would reject client-side (`percent: 60`) because a downstream retry loop bypassed local validation. A-node: rejects with `-32602 Invalid params`. B-node: coerces to `6000`, which is *outside* B's `[100, 5000]` bound, and B's validator — written to reject on `percent_bp` bounds but not on the coerced path — **accepts it** and applies a 60% discount. The observable symptom was not an error. It was a silent 60% discount on a subset of orders that landed on B nodes during the rollout window. The client's capability snapshot said `percent: int, max 50`. The server's live contract said `percent_bp: int, max 5000`. Neither side was "wrong" in isolation; the negotiation boundary between them was. The critical, non-obvious detail: **the backward-compatibility shim masked the drift during the window where it mattered most.** Had B rejected `percent` outright, the client would have seen a `-32602` on the first B-node hit and re-negotiated. The shim converted a loud schema mismatch into a silent semantic mismatch, and the coercion branch's own validator had a gap that let out-of-range values through only on the deprecated path. ## Condition of Validity The "negotiate once, invoke many" model is valid **only** under the conjunction of: - The transport is stateful and the session pins the negotiated revision (stdio, persistent SSE), **or** - The edge endpoint is revision-pinned by an explicit routing key the client controls (e.g., `Mcp-Session-Id` mapped to a revision, or a version path segment `/v3/`), **or** - The server enforces a strict schema-version handshake on *every* invocation and rejects any call whose declared schema hash does not match the live revision. When any of these fails — stateless transport, non-sticky load balancing, and a server that tolerates unknown/deprecated fields — the cached-snapshot model is invalid and the client is operating on a stale claim. The `apply_discount` incident satisfies all three failure conditions simultaneously. A second validity condition concerns the shim itself: a backward-compat coercion branch is only safe if the coerced value is re-validated against the *new* bounds after coercion. B's shim coerced `percent → percent_bp` but validated the raw input against the *old* bound before coercion, leaving the post-coercion value unvalidated. The invariant "coercion preserves the validator's domain" was violated. ## Decision Boundary The decision boundary is where the client must choose between **trusting the cached snapshot** and **re-asserting the contract per invocation**. The rule: - **Below the boundary (safe to trust cache):** stateful transport, or revision-pinned endpoint, or server that returns a `schema_hash` on every response that the client verifies against its cached hash. Here, per-invocation re-negotiation is wasteful and the cache is a valid anchor. - **Above the boundary (must re-assert):** stateless transport + non-sticky routing + server that accepts deprecated fields. Here, the client MUST either (a) send an explicit `schema_hash` / `revision` header and require the server to reject on mismatch, or (b) re-run `tools/list` and diff the schema before any invocation whose parameters are near a bound, or (c) refuse to invoke at all if the endpoint cannot be pinned. The boundary is crossed the moment the client observes *any* of: a response field it did not request, a coerced value in an echo field, a latency profile shift consistent with a different node class, or a load-balancer `X-Backend` header that differs from the cached one. The `apply_discount` client crossed it at step 4 and did not notice, because the two successes were *semantically identical* and therefore indistinguishable from stability. The guardrail is a **fail-closed schema assertion**: every invocation carries the schema hash the client believes is live; the server recomputes its live hash and returns `-32602` (or a dedicated `SCHEMA_DRIFT` error) on mismatch, before executing any tool logic. This converts the silent coercion into a loud, actionable rejection and forces re-negotiation. ## Operational Effect The operational effect of missing this invariant is **silent semantic divergence under partial rollout**: a fraction of invocations execute against a contract the client did not negotiate, with results that are plausible enough to pass downstream sanity checks. The blast radius is proportional to the rollout fraction and the semantic distance between revisions, and it is *invisible* to error-rate dashboards because the failures return HTTP 200 with well-formed payloads. The remediation that held was threefold: (1) the client was changed to send a `Mcp-Schema-Hash` header derived from its cached `tools/list` snapshot, and the server was changed to reject mismatches with a typed `SCHEMA_DRIFT` error before any side effect; (2) the backward-compat shim was rewritten to coerce *then* validate against the new bounds, closing the out-of-range gap; (3) the edge router was changed to pin `Mcp-Session-Id` to a revision for the duration of a negotiation epoch, so a client that re-negotiated mid-rollout could not be bounced back to the old revision on the next request. The general invariant: **in a stateless MCP transport, the negotiated capability set is a hypothesis, not a fact, and every invocation must either verify the hypothesis or fail closed before mutating state.** Backward-compatibility shims are the highest-risk surface for this invariant because they convert the loud failure (rejection) into the quiet one (coercion), and the quiet one is exactly what a probabilistic client will rationalize as success. ```python class SchemaDriftError(RuntimeError): """Raised when a stateless MCP invocation's declared schema hash does not match the live server revision, or when a backward-compat coercion produces a value outside the live validator's domain.""" pass def assert_schema_binding( declared_hash: str | None, live_hash: str, tool_name: str, ) -> None: if declared_hash is None: # Stateless transport with no assertion: cannot prove the client's # cached snapshot matches the live revision. Fail closed. raise SchemaDriftError( f"tool={tool_name!r}: invocation carried no Mcp-Schema-Hash; " f"live revision is {live_hash!r}. Refusing to execute against " f"an unverified contract." ) if declared_hash != live_hash: raise SchemaDriftError( f"tool={tool_name!r}: client negotiated {declared_hash!r} but " f"live revision is {live_hash!r}. Re-negotiate via tools/list " f"before invoking." ) def coerce_and_validate( raw: dict, live_bounds: tuple[int, int], tool_name: str, ) -> dict: # Backward-compat shim: percent -> percent_bp. The critical rule is # that coercion happens BEFORE validation, never after, so the # post-coercion value is what the live bound is checked against. if "percent" in raw and "percent_bp" not in raw: raw = {**raw, "percent_bp": raw["percent"] * 100} del raw["percent"] value = raw.get("percent_bp") lo, hi = live_bounds if value is None or not (lo <= value <= hi): raise SchemaDriftError( f"tool={tool_name!r}: post-coercion percent_bp={value!r} " f"outside live bounds [{lo}, {hi}]. Rejecting before side effect." ) return raw ```