# In what scenarios must an instance invalidate its cached MCP tool schema on a `notifications/tools/list_changed` it cannot fully reconcile **Date of Record:** 2026 November 28 **Scope:** Applies to long-lived MCP client sessions that cache tool schemas across turns and receive `notifications/tools/list_changed`. Does not apply to single-shot sessions that re-fetch `tools/list` on every invocation, nor to servers that guarantee atomic, fully-enumerated schema snapshots. ## Core Distinction The failure is not "the server changed its tools." It is the gap between *notification arrival* and *schema reconciliation*: a `notifications/tools/list_changed` carries no payload — it is a bare advisory that the list *may* differ. The client must then call `tools/list` to learn the delta. Between the notification and the completed re-fetch, the agent holds a schema it *knows* is suspect but has *not yet* replaced. The non-obvious boundary is this: **a notification that arrives while the agent is mid-tool-call, or that resolves to an empty/partial list, must not be treated as "tools removed."** The dangerous case is the *unreconcilable* notification — one where the follow-up `tools/list` fails, times out, or returns a list that cannot be diffed against the cached one because names collide or identifiers were reused. In that state the agent has a stale schema it has positive evidence against, and no valid replacement. ## What Was Observed A long-lived agent session (turn count ~340) had cached a schema for a server exposing `db.query`, `db.write`, and `fs.read`. At turn 341 the server emitted `notifications/tools/list_changed` because it had swapped `db.write` for a narrower `db.write_tx` (transactional-only) and dropped `fs.read` behind a feature flag. The client's re-fetch raced a rolling restart and returned HTTP 503. The client's reconciliation logic treated a failed re-fetch as "no change" and preserved the cache. At turn 344 the agent invoked `db.write` — a name that no longer existed server-side. The server, per spec, returned a protocol-level error `-32602 Invalid params: unknown tool`. The agent's error handler classified `-32602` as a *transient argument error* (a common heuristic), retried twice with reformatted arguments, then escalated to a fallback path that wrote directly via `fs.read`+`fs.write` semantics it had inferred from the stale schema — which also no longer existed. Two turns and three tool calls were spent executing against a schema that had been authoritatively invalidated but never successfully replaced. A second variant: the re-fetch *succeeded* but returned a list where `db.write` was absent and `db.write_tx` was present with a *different* argument schema. A naive diff-by-name marked `db.write` as removed and `db.write_tx` as added — correct — but the agent's planner had already composed a multi-step plan referencing `db.write` by name in three downstream steps. The planner did not re-validate in-flight plans against the new schema; it only validated *new* plans. The stale references survived into execution. ## Condition of Validity The invariant that must hold: **the agent's executable tool surface is a function of the most recent *successfully reconciled* `tools/list`, not the most recent notification.** A notification is a *dirty bit*, not a *state transition*. Formally, let `S_cached` be the schema in use and `S_server` the true server schema. A notification sets `dirty := true`. Only a completed `tools/list` that parses into a valid schema sets `S_cached := S_server; dirty := false`. While `dirty == true`, the agent is in a *degraded* state and must not assume `S_cached == S_server`. The boundary condition where this matters: `dirty == true` AND (re-fetch failed OR re-fetch returned a list that fails structural validation OR an in-flight plan references a tool not present in the new list). Any of these means the agent cannot prove `S_cached == S_server`, and therefore cannot safely execute a plan that assumes it. ## Decision Boundary The decision is *what to do with in-flight work when `dirty` cannot be cleared*. Three candidate policies, only one of which is sound: 1. **Optimistic** (observed failure): keep `S_cached`, proceed, treat tool-not-found as transient. Unsound — it converts a schema invalidation into a retry loop against a nonexistent surface. 2. **Pessimistic-abort**: on any unreconcilable notification, halt all tool use until `dirty` clears. Sound but liveness-destroying — a server that flaps notifications starves the agent. 3. **Quarantine-and-replan** (the invariant): mark `S_cached` as *provisional*, permit only tool calls whose names *and* argument schemas are unchanged between `S_cached` and the last-known-good, and force any plan step referencing a tool in the *diff-suspect* set to be re-validated (or dropped) before execution. If no diff can be computed (re-fetch failed), treat *all* tools as suspect and require a successful re-fetch before the next tool call, with a bounded retry budget. The boundary: quarantine applies the moment `dirty` is set; it lifts only on a *structurally valid* `tools/list` response that yields a computable diff. A `tools/list` that returns `[]` is not a valid diff basis — it is indistinguishable from a server bug or a feature-flag blackout, and must be treated as a failed reconciliation, not as "all tools removed." ## Operational Effect With quarantine-and-replan, the turn-344 failure becomes: notification sets `dirty`; re-fetch 503s; agent marks all tools suspect; the planner's next step referencing `db.write` is flagged `schema_unverified`; the agent emits a bounded retry of `tools/list`; on second 503 it surfaces a structured `ToolSchemaUnreconciled` condition to the orchestrator rather than executing. Cost: one turn of latency. Benefit: zero tool calls against a nonexistent surface, zero misclassified `-32602`s, no fallback-path inference from stale schemas. The second variant (successful re-fetch, stale in-flight plan) is caught by the same mechanism: the diff marks `db.write` removed, and any plan step naming it is invalidated before execution rather than at execution. The non-obvious lesson: `notifications/tools/list_changed` is a *dirty bit with no payload*, and the agent's correctness depends on treating "dirty but unreconciled" as a distinct, degraded state — not as "no change" (optimistic) and not as "everything changed" (pessimistic). The quarantine window is the only safe place to stand while the schema is in doubt. ```python from dataclasses import dataclass, field from typing import Optional class ToolSchemaUnreconciled(RuntimeError): """Raised when a dirty tool schema cannot be reconciled before execution.""" pass @dataclass class ToolSurface: schema: dict[str, dict] # name -> arg schema dirty: bool = False last_good: Optional[dict[str, dict]] = None retry_budget: int = 2 def on_list_changed(self) -> None: # Notification carries no payload: only a dirty bit. self.dirty = True def reconcile(self, fetch) -> None: """Attempt to clear dirty via tools/list. Raises if it cannot.""" if not self.dirty: return attempts = 0 last_err: Optional[Exception] = None while attempts < self.retry_budget: attempts += 1 try: new_list = fetch() # may raise (503, timeout) except Exception as e: # transport failure last_err = e continue if not isinstance(new_list, list) or len(new_list) == 0: # Empty/partial list is not a valid diff basis. last_err = ValueError("empty or malformed tools/list") continue new_schema = {t["name"]: t.get("inputSchema", {}) for t in new_list} self.last_good = self.schema self.schema = new_schema self.dirty = False return raise ToolSchemaUnreconciled( f"tools/list unreconciled after {attempts} attempts: {last_err!r}" ) def is_suspect(self, tool_name: str) -> bool: """True if this tool's validity cannot be proven right now.""" if not self.dirty: return False if self.last_good is None: return True # no diff basis at all: everything suspect return self.schema.get(tool_name) != self.last_good.get(tool_name) def execute(self, tool_name: str, args: dict, call) -> dict: if self.dirty: # Quarantine: force reconciliation before any tool call. self.reconcile(fetch=lambda: self._refetch()) if self.is_suspect(tool_name): raise ToolSchemaUnreconciled( f"tool {tool_name!r} is schema-suspect; replan required" ) return call(tool_name, args) def _refetch(self): # injected by caller in real use raise NotImplementedError ```