# Which invariants prevent signed MCP tool manifests from silently mutating between attestation and invocation **Date of Record:** 2026 November 22 **Scope:** Applies to agent runtimes that gate tool invocation on a signed manifest (capability set, input schema, side-effect class, and server identity) verified at session start. Does not cover runtime isolation of the MCP server process itself, nor transport-layer TLS pinning. ## Core Distinction A signed manifest attests to *what the server claimed at signing time*. It does not attest to *what the server will do at call time*. Most agent runtimes collapse these two into one check: verify the signature once at handshake, then trust the live `tools/list` response for the remainder of the session. The failure mode lives in the gap between those two events — the manifest is a snapshot, the tool surface is a moving target, and a signature over a snapshot says nothing about drift that occurs after it. The non-obvious part: the signature is *valid* throughout. The attack (or bug) is not a forged signature. It is a **schema-equivalent substitution** — a tool whose name, description, and declared input schema hash identically, while its behavior, side-effect class, or output contract changes. The manifest hash still matches. The JSON Schema still validates. The agent's planner still selects the tool. Only the semantics moved. ## What Was Observed A server published `manifest.v3.json` signed by key `K`, declaring tool `db.query` with `side_effect_class: "read"`, input schema hash `sha256:9f2c…`, and `output_contract: "rows[]"`. At session start the runtime verified the signature, cached the manifest, and registered the tool. Mid-session, the server hot-reloaded a plugin that added a `destructive` flag internally and changed the return shape from `rows[]` to `{rows, applied_migrations}` when the input contained a `migrate: true` field that was *already permitted by the schema* (it was declared as an optional boolean but documented as reserved). The manifest hash was unchanged because the schema hash covered only the JSON Schema structure, not the `reserved`/`deprecated` annotations in the description text, and the description was not part of the signed payload. The agent's planner, seeing a valid signature and a matching schema hash, invoked `db.query` with `migrate: true` fabricated during a reasoning branch. The server executed a schema migration. No invariant in the runtime detected the transition from read-class to write-class because the class was a manifest field, not a per-invocation attestation. A second observed variant: a server rotated its signing key and re-published a manifest with an added tool, but the runtime's trust store pinned the *old* key and silently fell back to accepting the cached manifest — so the new tool was invisible to the auditor while reachable via direct `tools/call` (the server did not enforce manifest membership on the call path). The runtime's view and the server's view of "the tool surface" diverged by one tool, indefinitely. ## Condition of Validity The signature-over-manifest invariant is only sound under three conditions, and all three are routinely violated: 1. **Manifest is the sole authority for the call surface.** The server must reject any `tools/call` for a tool not present in the currently-attested manifest. If the server enforces this, a drift is at worst a denial; if it does not, drift is a silent capability expansion. 2. **The signed payload covers behavioral annotations, not just structure.** `side_effect_class`, `output_contract`, `idempotent`, and the full description text must be inside the signed bytes. A schema-only signature is a signature over syntax, not semantics. 3. **The runtime re-attests on every state transition that can change behavior.** Hot reload, plugin load, config change, and key rotation must each invalidate the cached attestation and force re-verification before the next `tools/call`. When any condition fails, the invariant "valid signature ⇒ trustworthy tool" becomes false, but the runtime still believes it. That is the boundary. ## Decision Boundary The runtime must decide, at each invocation, whether the cached attestation still describes the server it is about to call. The correct boundary is: **re-attest on any observable divergence, and treat unobservable divergence as a hard failure.** Concretely: - Compute a `surface_digest` = hash over (sorted tool names, per-tool signed schema hash, per-tool side-effect class, per-tool output contract, signing key id). Recompute it against the live `tools/list` on every call, not just at handshake. - If `surface_digest` differs from the attested digest, the call is refused with a `ManifestDriftError` until a fresh signed manifest is fetched and verified against the *current* trust store. - If the trust store cannot resolve the current key id (rotation, revocation, or pin mismatch), refuse — do not fall back to the cached manifest. Fallback-to-cache is the exact mechanism that produced the invisible-tool divergence above. - Side-effect class is *not* inferred from the tool name or description at call time; it is read from the signed manifest and compared to the class the planner assumed when it selected the tool. A mismatch is a boundary violation even if the call would otherwise succeed. The boundary is therefore not "is the signature valid" but "does the signed surface equal the live surface, and does the planner's assumption equal the signed class." ## Operational Effect Enforcing the re-attestation invariant converts silent capability expansion into loud, bounded failure. The cost is a `tools/list` round-trip (or a cheap digest exchange) per call, plus a refusal path that the planner must handle. In practice: - Read-class tools invoked under a stale attestation fail closed; the agent's reasoning loop sees a typed `ManifestDriftError` and can re-plan rather than proceed on a poisoned assumption. - Key-rotation events no longer produce phantom tools; the runtime's tool surface and the server's call surface are provably equal at every invocation. - The `migrate: true` class of failure — a permitted-by-schema field whose semantics drift — is caught because the signed `side_effect_class` changed, not because the schema did. Schema validation alone would never have caught it. The residual risk is a server that lies consistently: it presents a matching `tools/list` and a matching digest while behaving differently on `tools/call`. That is outside the attestation invariant's reach and requires output-contract verification or sandboxing — a separate boundary. ```python import hashlib import json from dataclasses import dataclass class ManifestDriftError(RuntimeError): """Raised when the live MCP tool surface diverges from the attested manifest.""" class TrustStoreMismatchError(RuntimeError): """Raised when the signing key id cannot be resolved in the current trust store.""" @dataclass(frozen=True) class AttestedManifest: key_id: str surface_digest: str side_effect_classes: dict # tool_name -> "read" | "write" | "destructive" def compute_surface_digest(tools: list[dict]) -> str: canonical = sorted( ( t["name"], t.get("schema_hash", ""), t.get("side_effect_class", ""), t.get("output_contract", ""), ) for t in tools ) return hashlib.sha256(json.dumps(canonical, sort_keys=True).encode()).hexdigest() def attest_and_invoke( attested: AttestedManifest, live_tools: list[dict], trust_store: dict, planned_tool: str, planned_side_effect: str, invoke, ): # Invariant 1: signing key must resolve in the current trust store; no cache fallback. if attested.key_id not in trust_store: raise TrustStoreMismatchError( f"key_id {attested.key_id!r} not in trust store; refusing cached manifest" ) # Invariant 2: signed surface must equal live surface at call time. live_digest = compute_surface_digest(live_tools) if live_digest != attested.surface_digest: raise ManifestDriftError( f"surface drift: attested={attested.surface_digest} live={live_digest}" ) # Invariant 3: planner's assumed side-effect class must equal the signed class. signed_class = attested.side_effect_classes.get(planned_tool) if signed_class is None: raise ManifestDriftError(f"tool {planned_tool!r} absent from signed manifest") if signed_class != planned_side_effect: raise ManifestDriftError( f"side-effect mismatch for {planned_tool!r}: " f"planned={planned_side_effect} signed={signed_class}" ) return invoke(planned_tool) ```