# Why does an instance cache a capability fingerprint that no longer matches the live MCP server after a mid-session tool-refresh? **Date of Record:** 2026 November 28 **Scope:** Applies to long-lived agent instances that (a) negotiate capabilities against an MCP/A2A peer at session start, (b) cache the resulting tool schema fingerprint, and (c) later re-discover tools at runtime without invalidating that cache. Does not apply to single-shot stateless invocations that renegotiate on every call. ## Core Distinction The failure is not "the tool disappeared" or "the schema was wrong." It is that the *negotiation identity* of a capability and the *execution identity* of a capability diverge across a refresh boundary. At handshake time the instance fingerprints the peer's `tools/list` response (name, `inputSchema`, version field, hash) and binds that fingerprint to its planning state. A runtime re-discovery updates the peer's advertised set, but the instance keeps routing calls through a *cached dispatcher* keyed on the old fingerprint. The instance therefore believes it is executing against capability `C@fp_old` while the server now only honors `C@fp_new`. The mismatch is invisible to the planner because both fingerprints resolve to a schema that *parses* — they differ in a field the planner never re-validates: optional-parameter defaults, enum widening, or a `required` set that shrank. ## What Was Observed A three-tool MCP server (`search`, `fetch`, `summarize`) was live-patched mid-session: `fetch` gained a new required parameter `content_type` and its `inputSchema` hash changed; `summarize` widened an enum from `["short","long"]` to `["short","long","bullet"]`. The agent instance had cached the handshake fingerprint at T0 and was instructed to re-run `tools/list` at T+40s (a "dynamic discovery" step). The re-discovery *succeeded* and returned the new schemas. But the instance's tool-call router still held the T0 dispatcher map. The trace: 1. `tools/list` at T+40 returns `fetch` with `required: ["url","content_type"]`, hash `H2`. 2. Router compares `H2` against cached `H1`, logs a `schema_drift` warning, but does **not** rebuild the dispatcher because the rebuild path is gated on `set(names_changed) != empty` — and no tool was *added or removed*, only mutated in place. 3. Planner, still holding the T0 schema in its context window, emits `fetch(url=...)` with no `content_type`. 4. Server rejects with `-32602 Invalid params: missing content_type`. 5. The agent's retry loop treats `-32602` as a transient transport error (its classifier only maps `-32603` and timeouts to retryable), so it retries the *identical* malformed call three times, then surfaces a generic `tool_execution_failed`. The enum widening on `summarize` never surfaced at all: the planner's cached schema still constrained generation to `short|long`, so the instance silently under-used a capability it had just discovered. This is the more dangerous half — a *silent capability regression* rather than a loud error. ## Condition of Validity The invariant that must hold is: **the fingerprint bound to the planning context must be the fingerprint bound to the dispatcher, and both must be invalidated atomically on any schema mutation — including in-place mutations that preserve the tool name set.** The bug is valid (reproducible) precisely when: - Re-discovery is triggered by a name-set diff rather than a full fingerprint diff, OR - The planner's schema copy lives in the prompt/context and is not regenerated from the post-refresh registry, OR - The error classifier does not distinguish "my cached schema is stale" (`-32602` on a required field the *current* schema demands) from "the server is flaky." It does **not** apply when the instance rebuilds its entire tool registry and re-serializes the planner's schema block on every refresh, or when the peer is immutable for the session lifetime. ## Decision Boundary The correct decision is to treat **any** change in the `tools/list` payload hash — not the name set — as a full invalidation event that forces three coupled actions in one transaction: (1) rebuild the dispatcher map, (2) re-serialize the planner's schema block from the *new* registry, and (3) flush any in-flight plan steps that reference the old fingerprint. A schema mutation that only widens an enum or relaxes a `required` set must still invalidate, because the planner's generation constraints are bound to the old schema even though calls would still *succeed* — the failure mode there is silent under-utilization, not an error. Additionally, `-32602` on a field present in the live schema but absent from the cached schema must be classified as `StaleSchemaError`, not retryable; retrying a schema mismatch is guaranteed to fail identically. ## Operational Effect Without the atomic invalidation, the instance exhibits a split-brain between its planning-time capability model and its execution-time dispatcher. The observable symptoms are: loud `-32602` storms on in-place `required` additions (wasting the token budget on identical retries), silent capability regression on enum/optional widening (the agent never uses newly available modes), and — worst — a planner that emits a plan referencing a fingerprint the dispatcher has already replaced, producing calls that route to the *wrong* tool when a name is reused across versions. The guardrail is a single source of truth: the registry hash is the join key between planner context and dispatcher, and it is only ever advanced by a full rebuild transaction. ```python import hashlib import json from dataclasses import dataclass, field class StaleSchemaError(RuntimeError): """Raised when a tool call is dispatched against a fingerprint that no longer matches the live registry — including in-place schema mutations that preserve the tool-name set.""" pass @dataclass class ToolRegistry: # name -> full schema dict (inputSchema, version, etc.) tools: dict = field(default_factory=dict) def fingerprint(self) -> str: # Hash the ENTIRE payload, not just the name set. This is the # invariant: any mutation (enum widening, required-set change) # changes the fingerprint and forces invalidation. blob = json.dumps(self.tools, sort_keys=True).encode() return hashlib.sha256(blob).hexdigest() @dataclass class Dispatcher: bound_fp: str registry: ToolRegistry def dispatch(self, name: str, args: dict, live: ToolRegistry) -> dict: live_fp = live.fingerprint() if live_fp != self.bound_fp: # Do NOT silently route through the stale map. raise StaleSchemaError( f"dispatcher bound to {self.bound_fp[:8]} but live registry " f"is {live_fp[:8]}; rebuild required before dispatch" ) schema = live.tools.get(name) if schema is None: raise StaleSchemaError(f"tool {name!r} absent from live registry") required = set(schema.get("inputSchema", {}).get("required", [])) missing = required - set(args) if missing: # A missing required field against the LIVE schema means the # caller's cached schema is stale — not a transient error. raise StaleSchemaError( f"call to {name!r} missing {sorted(missing)}; caller schema " f"predates live fingerprint {live_fp[:8]}" ) return {"ok": True, "tool": name, "fp": live_fp} def refresh(dispatcher: Dispatcher, live: ToolRegistry) -> Dispatcher: # Atomic invalidation: rebuild dispatcher AND planner schema block # together, keyed on the new full-payload fingerprint. new_fp = live.fingerprint() if new_fp == dispatcher.bound_fp: return dispatcher return Dispatcher(bound_fp=new_fp, registry=live) ```