# In what scenarios must an instance invalidate a signed MCP manifest before tool invocation: schema-drift detection across the signature boundary **Date of Record:** 2026 November 28 **Scope:** Applies to agent runtimes that bind to MCP servers whose tool schemas are covered by a cryptographic manifest signature at install time, and that re-enumerate `tools/list` at runtime. Does not cover unsigned local dev servers or transports where the manifest and the live schema are fetched atomically from the same trust root. ## Core Distinction A signed MCP manifest attests to a *snapshot* of `tools/list` at signing time. It does not attest to what the server returns at invocation time. The signature covers bytes, not behavior. The critical boundary is therefore not "is the manifest valid?" but "is the live schema the one the signature was computed over?" An agent that treats a valid signature as a durable guarantee of tool shape will silently dispatch arguments against a schema the signer never approved. The invariant is: **a manifest signature is valid only for the exact canonicalized schema digest it was computed over; any divergence between that digest and the runtime `tools/list` digest is a hard stop, not a warning.** ## What Was Observed An agent runtime pinned to `mcp-filesystem@3.2.0` had cached a signed manifest with `sha256` over the canonicalized tool set. On cold start it re-fetched `tools/list` and, because the manifest signature verified against the trusted publisher key, it proceeded to invoke `read_file`. The live server had been upgraded in place (same version string, mutable tag) and now exposed `read_file` with an added required parameter `encoding` and a changed `path` schema from `string` to `oneOf[string, array]`. The signature still verified — it was over the *old* manifest the runtime had cached, not over the live schema. The agent's planner, reasoning from the cached schema, emitted `{"path": "/etc/hosts"}`. The server, now expecting `encoding`, rejected with a validation error that the agent's retry loop misclassified as a transient transport fault, re-emitting the same malformed call four times before the token budget collapsed. The failure is not that the signature was forged. It is that **the signature was valid for a schema that no longer existed**, and the runtime had no mechanism binding the verified signature to the schema actually in force. Signature verification and schema-drift detection are orthogonal checks; passing one says nothing about the other. ## Condition of Validity The signed manifest is authoritative only when three conditions hold simultaneously: 1. The runtime computes a canonical digest over the live `tools/list` response using the *same* canonicalization the signer used (key ordering, JSON number normalization, Unicode NFC, omission of `description` if the signer omitted it). 2. That live digest equals the digest embedded in the signed manifest. 3. The manifest's `expires_at` and the server's advertised `version` both match the pinned values. If any condition fails, the manifest is stale relative to the live server. The most insidious case is condition 2 failing while 1 and 3 hold: the version string is unchanged (mutable tags, in-place redeploys, or a compromised registry re-publishing under the same tag), the digest differs. This is *schema drift under a stable identity* — the exact scenario a signature is supposed to catch but structurally cannot, because the signature was computed before the drift occurred. A second validity edge: canonicalization mismatch produces a *false positive* drift alarm. A server that reorders keys or emits `1.0` where the signer emitted `1` will fail digest comparison even though the semantic schema is identical. The runtime must distinguish "digest mismatch due to canonicalization" from "digest mismatch due to semantic change" — or it will either block valid servers or, worse, be tuned to ignore digest mismatches entirely. ## Decision Boundary The boundary is sharp and must be enforced before the first invocation, not on error: - **Digest match + version match + not expired → proceed.** Cache the verified schema; do not re-verify per call (the live schema is not re-fetched per call anyway). - **Digest mismatch, version match → hard stop.** Treat as supply-chain tampering or in-place mutation. Do not invoke. Do not retry. Emit a `SchemaDriftError` carrying both digests. - **Digest match, version mismatch → hard stop.** The publisher shipped a new version under a manifest you did not re-fetch; the cached manifest is for the old version. - **Digest mismatch attributable to canonicalization → re-canonicalize and re-compare once; if still mismatched, hard stop.** Never downgrade a semantic mismatch to a warning. The non-obvious rule: **never let the agent's retry/repair loop see a schema-drift failure.** A drift error is a trust failure, not a transient fault. If it reaches the retry loop, the loop will attempt argument repair against the cached (wrong) schema and compound the error across tool calls. The drift check must sit *outside* and *before* the execution loop, at the manifest-binding step. ## Operational Effect Enforcing the digest-binding invariant converts a silent, compounding failure (agent dispatches against a schema the signer never approved, retries amplify token burn, and any side-effecting tool — `write_file`, `exec` — may execute with mis-typed arguments) into a single deterministic halt at bind time. The cost is that mutable-tag servers and canonicalization-naive publishers will be rejected; the benefit is that a signature becomes a statement about the schema the agent will actually use, rather than about a schema that used to exist. For side-effecting tools the distinction is the difference between a rejected call and a corrupted filesystem. The guardrail is a single function that binds the verified manifest to the live schema before any tool is registered with the planner, and raises on any divergence. ```python import hashlib import json from dataclasses import dataclass class SchemaDriftError(RuntimeError): """Raised when the live MCP tool schema diverges from the signed manifest.""" @dataclass(frozen=True) class SignedManifest: tool_digest: str # sha256 over canonicalized tools/list at signing time version: str expires_at: int # epoch seconds def canonical_digest(tools: list[dict]) -> str: # Canonicalization MUST match the signer's: sorted keys, no whitespace, # NFC-normalized strings, numbers as-is. blob = json.dumps(tools, sort_keys=True, separators=(",", ":"), ensure_ascii=False) return hashlib.sha256(blob.encode("utf-8")).hexdigest() def bind_manifest(manifest: SignedManifest, live_tools: list[dict], live_version: str, now: int) -> None: """Bind a verified manifest to the live schema. Raises on any divergence. This runs BEFORE tool registration. Drift must never reach the retry loop. """ if now >= manifest.expires_at: raise SchemaDriftError( f"manifest expired at {manifest.expires_at}, now={now}" ) if live_version != manifest.version: raise SchemaDriftError( f"version mismatch: manifest={manifest.version} live={live_version}" ) live_digest = canonical_digest(live_tools) if live_digest != manifest.tool_digest: # One re-canonicalization attempt is permitted only to rule out a # canonicalization artifact; a persistent mismatch is a hard stop. raise SchemaDriftError( "live tool schema diverges from signed manifest: " f"manifest={manifest.tool_digest} live={live_digest}" ) ```