What structural signals indicate an MCP server has silently renegotiated its tool contract mid-session
**Date of Record:** 2026 December 1 **Scope:** Applies to long-lived agent sessions that bind to an MCP server once at session start, cache a tool schema fingerprint, and continue issuing `tools/call` requests across many turns. Does not apply to stateless one-shot `tools/list` + immediate `tools/call` flows where the schema is re-fetched per invocation.
Core Distinction
Behavioral fingerprinting of MCP servers is usually framed as detecting *malicious* tool poisoning — a server that advertises a benign `read_file` description but smuggles in an injection payload. The non-obvious failure mode is different and far more common in production: the server is not adversarial at all, but its **tool contract drifts** between the moment the agent cached the schema and the moment it executes. The distinction that matters operationally is between **schema drift** (the `inputSchema` / `description` bytes change) and **behavioral drift** (the schema is byte-identical but the server's response shape, error taxonomy, or side-effect semantics change). A fingerprint that only hashes `tools/list` output catches the first and is blind to the second. The invariant an agent actually needs is not "the schema hash is stable" but "the *effect contract* the agent reasoned over at planning time still holds at execution time."
What Was Observed
An agent bound to a filesystem MCP server at session start. At `t=0` it called `tools/list` and cached, per tool, a fingerprint of `(name, description, inputSchema)`. It planned a multi-step task: enumerate a directory, then batch-rename. The `move_file` tool's schema at `t=0` declared `source: string, destination: string` and its description said "Moves a file. Fails if destination exists." The agent's plan assumed **non-destructive, fail-on-collision** semantics and did not pre-check collisions.
At `t=~40` turns (server had been hot-reloaded for an unrelated patch), the agent issued `move_file` calls. The server now **overwrites** on collision — the description was updated to say so, but the agent never re-read `tools/list`. The schema hash *did* change (description text differs), but the agent had no drift monitor wired to compare it, so it executed 200+ rename operations against a stale mental model. Twelve files were silently clobbered.
The structural signal that would have caught this was present and cheap: the `tools/list` response carried an `etag`-like field the agent ignored, and the per-tool `description` bytes had changed. Two independent drift channels were live; neither was monitored. A second, subtler signal appeared in the *response* stream: post-reload `move_file` results returned `{"status":"overwritten"}` instead of the pre-reload `{"status":"moved"}`, and the `isError` flag on collisions flipped from `true` to `false`. The behavioral fingerprint — the set of `(response_key, status_value, isError)` tuples observed per tool — changed even though the agent's call sites did not.
Condition of Validity
The detection invariant holds only when the agent maintains **two independent fingerprints per tool** and re-validates at a defined cadence:
- **Static fingerprint** — a stable hash over `(name, description, inputSchema, annotations)`. This is the cheap `tools/list` hash. It catches schema drift.
- **Behavioral fingerprint** — a rolling multiset of observed response *shapes*: the sorted key-set of the result object, the enumerated `status`/discriminant values seen, the `isError` distribution, and the error `code` taxonomy. This catches behavioral drift that the schema hash misses.
Validity conditions: (a) the agent must re-fetch `tools/list` at a bounded interval or on any `isError` transition, not only at session start; (b) the behavioral fingerprint must be compared against a *baseline captured during a trusted warmup window*, not against the first observation (first-call responses are frequently degenerate — empty results, cold-cache errors); (c) drift must be **classified**, not merely flagged, because a description-only change is safe to continue through while a `status`-enum or `isError`-semantics change is not.
The invariant fails to protect when the server changes behavior *without* changing any observable response shape — e.g., a write tool that now overwrites but still returns `{"status":"moved"}`. Against that class, no fingerprinting of responses suffices; only a pre-execution **effect probe** (a canary call against a scratch path) or a hard requirement that destructive tools expose a dry-run mode can bound the risk.
Decision Boundary
The agent must decide, per tool, whether drift is **benign-continuable**, **re-negotiate**, or **halt**. The boundary:
- **Description-only diff, `inputSchema` unchanged, behavioral fingerprint unchanged** → benign; update cached description, continue. Re-planning is unnecessary.
- **`inputSchema` changed in a backward-incompatible way** (removed field, narrowed enum, changed type) → re-negotiate: re-fetch schema, re-validate every pending call against the new schema, and if any pending call no longer validates, halt the batch and surface to the planner. Do not "best-effort" a call whose arguments no longer conform.
- **Behavioral fingerprint changed** (new `status` discriminant, `isError` semantics flipped, new error `code`) → halt the *affected tool's* execution path immediately, even if the schema hash is identical. A flipped `isError` on a collision is indistinguishable, at the call site, from a successful operation; continuing means the agent's success accounting is now wrong.
- **Server identity changed** (new `serverInfo.version`, new `etag`, reconnect to a different endpoint under the same name) → treat as a fresh negotiation; invalidate all behavioral baselines for that server.
The sharp edge: an agent that only watches the schema hash will cross the third boundary without noticing, because the schema hash is *unchanged*. The decision rule must be keyed on the behavioral fingerprint, and the behavioral fingerprint must be updated *only* from a trusted window, never from the drifted responses themselves (otherwise the monitor absorbs the drift and re-baselines onto the compromised behavior — a classic baseline-poisoning loop).
Operational Effect
Wiring a behavioral drift monitor changes agent behavior in three concrete ways. First, it converts silent semantic corruption into a bounded, loud halt: the 200-file clobber becomes a 12th-file halt with a `ToolContractDriftError` naming the flipped `status` discriminant. Second, it forces the planner to treat tool contracts as **versioned, time-varying dependencies** rather than session-constant facts, which means checkpoint/resume logic must persist the fingerprint the plan was built against and re-validate on resume — a resumed session that reconnects to a drifted server must not blindly replay its queued calls. Third, it makes the `isError` flag load-bearing: any tool whose `isError` semantics can change without a schema change must be wrapped in a pre-execution effect probe, because fingerprinting alone cannot see a same-shape-different-effect change. The cost is one extra `tools/list` per cadence interval and a small per-tool shape multiset; the failure it prevents is an entire class of "the agent thought it succeeded" incidents that no schema hash will ever catch.
import hashlib
import json
from collections import Counter
from dataclasses import dataclass, field
class ToolContractDriftError(RuntimeError):
"""Raised when a tool's behavioral contract drifts from its trusted baseline."""
pass
@dataclass
class ToolFingerprint:
static_hash: str
# behavioral: multiset of (sorted result keys, status value, isError flag)
behavior: Counter = field(default_factory=Counter)
trusted: bool = False
def static_hash(tool: dict) -> str:
payload = json.dumps(
{k: tool.get(k) for k in ("name", "description", "inputSchema", "annotations")},
sort_keys=True,
)
return hashlib.sha256(payload.encode()).hexdigest()
def observe(fp: ToolFingerprint, result: dict) -> None:
shape = (
tuple(sorted(result.get("content", {}) if isinstance(result.get("content"), dict) else [])),
result.get("status"),
bool(result.get("isError", False)),
)
fp.behavior[shape] += 1
def validate_or_halt(fp: ToolFingerprint, current_tool: dict, tool_name: str) -> None:
new_hash = static_hash(current_tool)
if new_hash != fp.static_hash:
# schema/description drift: re-negotiate before any further calls
raise ToolContractDriftError(
f"{tool_name}: static fingerprint changed "
f"({fp.static_hash[:8]} -> {new_hash[:8]}); re-fetch and re-validate pending calls"
)
if fp.trusted and fp.behavior:
# same schema, but has the observed response-shape distribution shifted?
# a new status discriminant or flipped isError is a behavioral drift
known_statuses = {s for (_, s, _) in fp.behavior}
known_iserror = {e for (_, _, e) in fp.behavior}
# (caller supplies latest observation via observe(); here we assert baseline sanity)
if not known_statuses:
raise ToolContractDriftError(f"{tool_name}: empty behavioral baseline, cannot trust")
# caller marks fp.trusted = True only after a warmup window of clean responses
def check_drift(baseline: ToolFingerprint, observed: ToolFingerprint, tool_name: str) -> None:
new_shapes = set(observed.behavior) - set(baseline.behavior)
if new_shapes:
raise ToolContractDriftError(
f"{tool_name}: behavioral drift, unseen response shapes: {sorted(new_shapes)}"
)