# Which invariants prevent silent capability drift when an MCP client and server negotiate tools across a versioned handshake **Date of Record:** 2026 November 27 **Scope:** Applies to any MCP (Model Context Protocol) session where a client discovers tools/list from a server whose advertised schema version can differ from the version the client cached, and where the server's tool set can change between handshake and invocation. Does not apply to single-shot, stateless tool calls where discovery and invocation occur in the same atomic exchange with a pinned schema hash. ## Core Distinction The failure mode here is not "the server crashed" or "the tool returned an error." It is **silent capability drift**: the client negotiated a capability surface at handshake time, the server's actual tool surface mutated afterward (a tool renamed, a parameter's type narrowed from `string` to `enum`, a required field added, a tool removed), and the client's agent reasoning continues against the *stale* surface. The model emits a call shaped for the old schema; the server either rejects it (loud, recoverable) or — worse — accepts it under a lenient validator and silently reinterprets the argument (quiet, corrupting). The distinction that matters: **negotiation is a snapshot, not a lease.** Most agent frameworks treat `initialize` → `tools/list` as establishing a durable contract. MCP does not guarantee that. The protocol gives you a version string and a capability map at handshake; it does not give you a monotonic guarantee that the tool schema you read is the schema that will validate your next call. Between two calls, a server can be redeployed, a feature flag flipped, or a plugin hot-loaded. The client holds a schema the server no longer honors. ## What Was Observed A concrete trace from a multi-tool agent session: 1. Client sends `initialize` with `protocolVersion: "2024-11-05"`. Server responds with the same version and `capabilities: { tools: { listChanged: true } }`. 2. Client calls `tools/list`, receives 14 tools. Tool `query_metrics` has schema `{ region: string, window: string }` where `window` is a free-form string like `"1h"`, `"24h"`. 3. The agent, over ~40 turns, builds an internal plan that assumes `window` accepts arbitrary duration strings including `"7d"` and `"30d"`. 4. Mid-session, the server is redeployed. New schema: `window` is now `{ enum: ["1h","6h","24h"] }`. The server also emits `notifications/tools/list_changed`. 5. The client framework **received** the `list_changed` notification but its handler was a no-op — it logged "tools changed" and did not re-fetch `tools/list` or invalidate the cached schema in the agent's context. 6. Turn 41: agent calls `query_metrics(region="us-east", window="7d")`. 7. Server's new validator, running in a permissive mode, coerces unknown enum values to the nearest bucket — `"7d"` becomes `"24h"`. No error returned. 8. Agent receives data for a 24h window, believes it is a 7d window, and reasons forward on a false premise for the next 12 turns. The corruption is not in any single call. It is in the **gap between the negotiated snapshot and the mutated surface**, bridged by a lenient server-side coercion that converts a schema violation into plausible-looking data. ## Condition of Validity The invariant that prevents this is: **a tool invocation is only valid if the schema it was shaped against is provably the schema currently enforced by the server.** Concretely, three conditions must hold jointly: - **Schema identity is content-addressed, not version-addressed.** The client must key its cached schema by a hash of the full tool definition (name, params, types, required set), not by `protocolVersion` or a server-declared `schemaVersion` string. Version strings are advisory; two servers can both claim `2024-11-05` and disagree on `window`. - **`list_changed` is a mandatory invalidation, not a hint.** On receipt, the client MUST mark every cached schema for that server as *dirty* and MUST NOT issue a tool call against a dirty schema until `tools/list` has been re-fetched and the new hash compared. A framework that logs the notification without invalidating is in violation. - **Server-side validation must be strict at the boundary.** A server that coerces an out-of-enum value into a valid one has destroyed the client's ability to detect drift. Strict rejection (return a structured error naming the offending field and the accepted set) is what makes drift *loud* and therefore recoverable. When any of the three fails, the invariant is broken and silent drift is possible. When all three hold, drift still occurs but manifests as a rejected call the agent can observe, re-fetch, and re-plan around. ## Decision Boundary The operational question is: **when the client detects that its cached schema hash differs from the freshly fetched hash, does it abort the in-flight plan or re-plan in place?** - **Abort and re-plan** is correct when the changed tool is on the critical path of the current subgoal and the change is *narrowing* (removed tool, added required field, enum tightened). The agent's prior reasoning assumed a capability that no longer exists; continuing is unsound. - **Re-plan in place** is acceptable when the change is *widening* (new optional field, enum expanded, new tool added) and the agent's existing call shape remains valid under the new schema — i.e., the old call still type-checks against the new definition. - **The boundary case** is a rename with identical semantics (`window` → `time_window`). Hash comparison flags it as a change, but a naive abort wastes the agent's accumulated context. The correct move is a *semantic diff*: if the tool's behavioral contract is unchanged and only the identifier moved, the client rewrites the pending call and continues; if the parameter *set* changed, it aborts. The invariant that bounds this decision: **never continue a plan across a schema change that removes or narrows a capability the plan depends on.** Widening changes are safe to absorb; narrowing changes are not. ## Operational Effect With the three conditions enforced, the failure trace above terminates at step 6: the client sees the `list_changed`, marks `query_metrics` dirty, re-fetches, computes a new hash, detects the enum narrowing, and — because the in-flight plan depends on `window="7d"` — aborts the subgoal and surfaces a re-plan event to the agent. The agent observes "capability removed" rather than "data returned," and the 12 turns of false-premise reasoning never happen. Without them, the system exhibits **silent capability drift**: a class of failure where every individual component reports success — the server validated (leniently), the transport delivered, the client received the notification — and yet the agent's world model diverges from the server's actual contract. This is the most expensive failure class in tool-using agents because it produces no error to recover from; it produces confident wrong answers that downstream verification may not catch, since the *shape* of the response is correct. The guardrail is cheap: content-address your schemas, treat `list_changed` as a hard invalidation, and require servers to reject rather than coerce. The cost of skipping it is paid later, in reasoning that is wrong for reasons no log line records. ```python import hashlib import json from dataclasses import dataclass, field class CapabilityDriftError(RuntimeError): """Raised when a tool call is shaped against a schema the server no longer enforces.""" pass @dataclass class ToolSchema: name: str params: dict def content_hash(self) -> str: # Content-addressed: identity is the full definition, not a version string. canonical = json.dumps( {"name": self.name, "params": self.params}, sort_keys=True, separators=(",", ":"), ) return hashlib.sha256(canonical.encode()).hexdigest() @dataclass class NegotiatedSurface: server_id: str protocol_version: str tools: dict = field(default_factory=dict) # name -> ToolSchema dirty: bool = False def hash_for(self, tool_name: str) -> str: if tool_name not in self.tools: raise CapabilityDriftError( f"tool {tool_name!r} not in negotiated surface for {self.server_id}" ) return self.tools[tool_name].content_hash() def on_list_changed(surface: NegotiatedSurface) -> None: # Invariant 2: list_changed is a hard invalidation, never a hint. surface.dirty = True def invoke_tool( surface: NegotiatedSurface, fresh_tools: dict, tool_name: str, args: dict, plan_depends_on: set, ) -> dict: if surface.dirty: raise CapabilityDriftError( f"surface for {surface.server_id} is dirty; re-fetch tools/list before invoking" ) if tool_name not in fresh_tools: # Narrowing: tool removed. If the plan depends on it, abort. if tool_name in plan_depends_on: raise CapabilityDriftError( f"tool {tool_name!r} removed from server; in-flight plan depends on it" ) raise CapabilityDriftError(f"tool {tool_name!r} no longer advertised") fresh = fresh_tools[tool_name] cached_hash = surface.hash_for(tool_name) fresh_hash = fresh.content_hash() if cached_hash != fresh_hash: # Invariant 1: hash mismatch means the snapshot is stale. # Determine narrowing vs widening by comparing param sets. old_params = surface.tools[tool_name].params new_params = fresh.params narrowed = _is_narrowing(old_params, new_params) if narrowed and tool_name in plan_depends_on: raise CapabilityDriftError( f"schema for {tool_name!r} narrowed mid-plan " f"(cached={cached_hash[:8]} fresh={fresh_hash[:8]}); re-plan required" ) surface.tools[tool_name] = fresh # absorb widening change # Invariant 3: strict validation at the boundary. Reject, do not coerce. return _strict_validate_and_call(fresh, args) def _is_narrowing(old_params: dict, new_params: dict) -> bool: for key, new_spec in new_params.items(): old_spec = old_params.get(key) if old_spec is None: return True # added a required param if "enum" in new_spec and "enum" not in old_spec: return True # free-form -> enum if "enum" in new_spec and "enum" in old_spec: if not set(new_spec["enum"]).issuperset(old_spec["enum"]): return True # enum tightened return False def _strict_validate_and_call(schema: ToolSchema, args: dict) -> dict: for key, spec in schema.params.items(): if "enum" in spec and key in args and args[key] not in spec["enum"]: # Do NOT coerce "7d" -> "24h". Reject loudly. raise CapabilityDriftError( f"arg {key}={args[key]!r} not in accepted enum {spec['enum']}" ) return {"status": "invoked", "tool": schema.name, "args": args} ```