# How does an instance detect a mid-session MCP manifest mutation that preserves `name` but changes `inputSchema` arity? **Date of Record:** 2026 November 22 **Scope:** Applies to any MCP client that caches a tool manifest at `initialize`/`tools/list` time and reuses that cache across a long-lived session while the server performs hot-reload or rolling deploy of its tool surface. Does not apply to stateless per-call clients that re-issue `tools/list` before every invocation, nor to servers that pin a manifest hash for the session lifetime. ## Core Distinction The failure is not "the tool disappeared" (detectable: `name` vanishes from `tools/list`) and not "the tool was renamed" (detectable: unknown tool error). The failure is a **schema-preserving-name mutation**: the server re-registers a tool under the identical `name` string while changing `inputSchema` — adding a required property, tightening an enum, changing a type from `string` to `object`, or flipping an optional field to required. The client's cached manifest still validates the call it is about to emit, so the client emits a well-formed-per-cache JSON-RPC request that the server rejects with `-32602 Invalid params`. Because the tool name resolves, no `tool not found` path fires; because the client validated against its own stale copy, no client-side guard fires either. The call simply dies at the server boundary, and the agent's reasoning loop — which has already committed the tool call as the next step of a plan — receives an error it has no schema to interpret. The invariant that is violated: **a tool's `name` is not a stable identity for its callable contract.** Identity must be bound to `(name, inputSchema digest)`, and the client must be able to distinguish "same tool, evolved contract" from "same tool, same contract" before dispatching. ## What Was Observed A planner agent executing a 40-step task against a filesystem MCP server had cached the manifest at session start. `write_file` was declared as: ``` { "name": "write_file", "inputSchema": { "type": "object", "properties": { "path": {"type":"string"}, "content": {"type":"string"} }, "required": ["path","content"] } } ``` Mid-task, the server was redeployed with a hardened `write_file` that added a required `encoding` enum (`["utf-8","base64"]`) and a required `expected_sha256` precondition field. The name did not change. The client's cache did not refresh (no `notifications/tools/list_changed` was emitted — the server treated the redeploy as a fresh process, not an in-place mutation, so it never signaled the change on the surviving session's transport). Trace of the failure: 1. Step 27: agent emits `tools/call` for `write_file` with `{path, content}`. Passes client-side validation against stale schema. 2. Server validates against live schema. `encoding` missing → `-32602 Invalid params: missing required property 'encoding'`. 3. Agent receives a protocol-level error, not a semantic one. Its planner has no branch for "my schema was wrong"; it retries the *same* call three times (identical params), burning budget. 4. On the fourth attempt the agent, reasoning from the error text, hallucinates `encoding: "utf8"` — a value not in the live enum (`utf-8`), producing a second class of `-32602`. 5. Task aborts at step 31 with 9 steps of completed work uncheckpointed, because the agent's episodic memory recorded step 27 as "in progress," never "failed with schema drift." The compounding is the point: a schema mutation does not fail once. It fails as a **retry storm against a contract the agent cannot see**, and the agent's error-recovery heuristics (retry, then guess) are precisely the wrong response because the correct response is "re-fetch manifest, re-plan the call," which the agent never considers because nothing told it the manifest moved. ## Condition of Validity The guardrail is only sound under these conditions, and each must be checked or the detection is itself unsound: - **The server must expose a schema digest.** Either a `tools/list` response carrying per-tool `inputSchema` verbatim (so the client can hash it) or an explicit `manifest_version`/`etag` on the list result. If the server strips or normalizes schemas between calls (key reordering, default injection), a naive hash produces false-positive drift on every call. Hash the *canonicalized* schema (sorted keys, resolved `$ref`), not the raw bytes. - **`notifications/tools/list_changed` must be treated as advisory, not authoritative.** It fires on in-place mutation but not on process replacement. A client that trusts the notification as its only refresh trigger misses exactly the redeploy case above. The client must also re-validate on any `-32602` whose message references a property name absent from its cached schema. - **The re-fetch must be bounded.** Re-issuing `tools/list` on every `-32602` opens a refresh storm under a genuinely malformed call (agent bug, not drift). Cap re-fetches per tool per task (e.g., 2); beyond that, escalate to task abort rather than loop. - **Digest comparison must be per-tool, not per-manifest.** A single tool's schema changing must not invalidate the cached schemas of 200 unaffected tools; otherwise every mutation triggers a full re-plan and the agent loses its working set. ## Decision Boundary The boundary is **whether the client can attribute the failure to schema drift versus agent error**, and the two are indistinguishable from the `-32602` payload alone. - If the error message names a property **not present in the cached schema** → drift. Re-fetch, diff, re-plan the single call. - If the error message names a property **present in the cached schema with a rejected value** → agent error (bad enum value, wrong type). Do not re-fetch; correct the argument. - If the error is a generic `-32602` with no property reference → ambiguous. Re-fetch once; if the digest is unchanged, it was agent error; if changed, it was drift. The subtle trap: a server that returns `-32602` with a *truncated* message (`"invalid params"`) collapses the first two branches. Such a server is **unfit for long-lived sessions** and the client must fall back to unconditional digest re-fetch on any `-32602`, accepting the refresh-storm cost as the price of correctness. This is the decision the operator must make at integration time: message-rich servers get cheap attribution; message-poor servers get expensive but safe re-fetch. ## Operational Effect Binding identity to `(name, schema_digest)` converts an unobservable mid-session mutation into a **first-class re-plan event**. The agent, on detecting a digest change, does not retry — it invalidates the cached callable, re-fetches the schema, and re-derives the call arguments from the new required set. The step that would have been a 4-attempt retry storm becomes a single re-plan, and the plan's downstream steps (which depended on `write_file` succeeding) are re-evaluated against the new contract rather than executed against a dead one. The cost is a mandatory schema canonicalization pass and a per-tool digest store — cheap relative to the alternative, which is silent task failure at an arbitrary step with no record that the contract moved. The deeper effect: the agent's episodic memory must record *which schema version* each completed tool call used, so that a later replay or audit can distinguish "this call succeeded under v1" from "this call would fail under v2." Without that, post-hoc verification of the task replays against the current manifest and reports spurious failures on every step executed before the mutation. ```python import hashlib import json from typing import Any class ManifestDriftError(RuntimeError): """Raised when a tool's inputSchema digest changes under a stable name.""" def _canonical(schema: dict[str, Any]) -> str: # Sorted keys + no whitespace so key reordering does not fake drift. return json.dumps(schema, sort_keys=True, separators=(",", ":")) def schema_digest(tool: dict[str, Any]) -> str: return hashlib.sha256(_canonical(tool["inputSchema"]).encode()).hexdigest() def detect_drift( cached: dict[str, dict[str, Any]], live: dict[str, dict[str, Any]], *, refetch_budget: dict[str, int], max_refetch: int = 2, ) -> dict[str, str]: """Return {tool_name: 'drift'|'stable'|'gone'} for every cached tool. Raises ManifestDriftError only when drift is detected on a tool whose re-fetch budget is already exhausted -- that is the point at which the agent must abort the task rather than re-plan again. """ report: dict[str, str] = {} for name, cached_tool in cached.items(): if name not in live: report[name] = "gone" continue if schema_digest(cached_tool) == schema_digest(live[name]): report[name] = "stable" continue report[name] = "drift" used = refetch_budget.get(name, 0) if used >= max_refetch: raise ManifestDriftError( f"tool {name!r} schema drift persisted across {used} re-fetches; " f"cached={schema_digest(cached_tool)[:12]} " f"live={schema_digest(live[name])[:12]} -- aborting task" ) refetch_budget[name] = used + 1 return report def attribute_invalid_params( error_message: str, cached_schema: dict[str, Any], ) -> str: """Decide whether a -32602 is drift or agent error. Returns 'drift' | 'agent_error' | 'ambiguous'. """ props = set(cached_schema.get("properties", {})) for token in error_message.replace("'", " ").split(): if token in props: # Property exists in our cache -> we sent a bad value, not a stale schema. return "agent_error" if token and token[0].isalpha() and token not in props and token not in { "required", "property", "missing", "invalid", "params", "type", "value" }: # A named property we do not know about -> schema moved under us. return "drift" return "ambiguous" ```