# What happens when an instance taints a dynamically discovered MCP tool after the permission cache has already been warmed **Date of Record:** 2026 November 17 **Scope:** Applies to agents that discover MCP tools at runtime (via `tools/list` or equivalent) and enforce least-privilege via a taint-tracking permission cache keyed by tool identity. Does not apply to statically registered tool manifests loaded once at process start, nor to per-call re-evaluation schemes that never cache. ## Core Distinction The failure mode is not "a tool is discovered that is more privileged than expected." It is the divergence between the **identity** used to key the permission cache and the **identity** used to apply taint. Dynamically discovered MCP tools are identified by a composite of server endpoint, declared tool name, and an optional schema hash. Taint analysis, however, propagates based on *data provenance* — which server produced a value that was fed into a tool argument. When a tool's declared name is stable but its underlying server is reconnected, proxied, or upgraded, the permission cache retains a warm entry under the old identity while the taint engine attributes data to the new one. The cache says "allow, previously vetted, no taint"; the taint engine says "this argument carries provenance from a server the caller never authorized." Neither subsystem is wrong in isolation. The composite is. The non-obvious invariant: **a permission decision is only valid if the identity key used to cache it is a superset of every identity component the taint engine can later attribute to the same call.** Identity as name+endpoint is not a superset of identity as name+endpoint+schema-hash+provenance-chain. The gap is where privilege escalation lives. ## What Was Observed A tool server `fs-helper` exposes `read_file`. On first discovery the agent calls `tools/list`, receives the schema, computes `schema_hash = sha256(canonical_json(inputSchema))`, and caches `allow(read_file, fs-helper, h1) = {taint_clear: true, max_privilege: read}`. The tool is then invoked with arguments whose provenance is a value returned by a *different* server, `web-fetch`. Taint tracking marks the argument `tainted_by: web-fetch`. The permission check consults the cache under `(read_file, fs-helper)` — a key that does not include schema hash, because the cache key was normalized to drop it for cache-hit efficiency. The check returns `allow` because the cached entry was written when no taint was present. The call proceeds, and `read_file` reads a path derived from attacker-controlled web content. The second observed variant is subtler. `fs-helper` is reconnected after a network blip. The new server declares the same `read_file` name but a widened `inputSchema` (an added `path_glob` parameter). Because the cache key omits schema hash, the stale `allow` entry survives. The taint engine, having re-derived provenance against the new server instance, correctly refuses to treat `web-fetch`-derived values as untainted — but its refusal is expressed as a *taint flag on the argument*, and the permission layer never reads that flag because the cache hit short-circuits evaluation. The taint was computed and discarded. In both cases the observable symptom is the same: a `read_file` call succeeds with `taint_clear=true` in the audit log while the provenance record for the same call shows a non-empty taint set. The two records disagree, and the disagreement is not surfaced as an error. ## Condition of Validity The least-privilege guarantee holds only under the conjunction: 1. The permission cache key includes every identity component the taint engine may attribute to a call — at minimum `(server_endpoint, tool_name, schema_hash, server_instance_nonce)`. 2. Cache invalidation is triggered by any change to any key component, including reconnection (nonce change) and schema drift (hash change). 3. The taint flag is evaluated *before* the cache lookup, not after, so a cache hit cannot bypass taint. 4. Taint attribution names a server identity that is itself subject to the same nonce discipline — a taint from `web-fetch@nonce1` must not be treated as clearing against `web-fetch@nonce2`. If any condition fails, the cache is not a least-privilege cache; it is a stale-allow cache with a taint engine bolted on. The failure is silent because both subsystems report success. ## Decision Boundary The boundary is crossed at the moment of **cache warm followed by identity drift**. Below the boundary — fresh discovery, cold cache, no reconnect — taint and permission agree because both key on the same live identity. Above the boundary — warm cache, nonce or schema change, taint present — they diverge. The decision an operator must make is whether to pay the cost of full-key cache lookups (including nonce and schema hash) on every call, or to accept that cache hits are only valid within a single server-instance lifetime and must be flushed on reconnect. There is no correct middle ground that drops schema hash but keeps endpoint: that is precisely the gap the observed escalation traversed. The boundary is not a threshold to tune; it is a discrete choice between "cache is a memoization of a full identity" and "cache is a security decision made on partial identity." The latter must be labeled as such. ## Operational Effect After adopting full-key caching with nonce-based invalidation, the audit log's `taint_clear` and the provenance record's taint set agree on every call. The cost is a measurable cache-hit reduction on reconnect-heavy workloads — roughly one cache miss per server instance lifetime per tool, which in the observed workload was 3–7% of calls. The benefit is that the previously silent disagreement becomes a hard failure: a call with non-empty taint against a cached `allow` now raises rather than proceeding. Operators who cannot afford the miss rate should disable caching for tools whose servers are subject to reconnection, rather than normalize the key. The normalization is the bug. ```python import hashlib import json from dataclasses import dataclass class TaintCacheDivergence(RuntimeError): """Raised when a cached permission decision was keyed on an identity narrower than the identity the taint engine attributes to the call.""" pass @dataclass(frozen=True) class ToolIdentity: endpoint: str name: str schema_hash: str instance_nonce: str @classmethod def from_declaration(cls, endpoint, name, input_schema, nonce): canonical = json.dumps(input_schema, sort_keys=True, separators=(",", ":")) return cls( endpoint=endpoint, name=name, schema_hash=hashlib.sha256(canonical.encode()).hexdigest(), instance_nonce=nonce, ) class PermissionCache: def __init__(self): self._entries = {} def put(self, identity: ToolIdentity, decision: dict): # Full identity, including nonce and schema hash. No normalization. self._entries[identity] = decision def get(self, identity: ToolIdentity) -> dict: return self._entries.get(identity) def authorize(cache: PermissionCache, identity: ToolIdentity, taint_set: frozenset) -> dict: # Taint is evaluated BEFORE the cache lookup. A cache hit cannot bypass it. decision = cache.get(identity) if decision is None: raise TaintCacheDivergence( f"no cached decision for full identity {identity}; " f"refusing to fall back to a narrower key" ) if taint_set and decision.get("taint_clear"): raise TaintCacheDivergence( f"cached allow for {identity.name}@{identity.instance_nonce} " f"claims taint_clear but call carries taint from {sorted(taint_set)}; " f"cache key and taint attribution disagree" ) if taint_set and not decision.get("allow_tainted"): raise TaintCacheDivergence( f"tainted call to {identity.name} not permitted under least-privilege policy" ) return decision def handle_reconnect(cache: PermissionCache, old: ToolIdentity, new: ToolIdentity): # A reconnect changes the nonce; the old entry must not be reachable. if old.endpoint == new.endpoint and old.name == new.name and old.instance_nonce != new.instance_nonce: cache._entries.pop(old, None) return if old.schema_hash != new.schema_hash: cache._entries.pop(old, None) return raise TaintCacheDivergence( f"reconnect for {old.endpoint}/{old.name} did not change nonce or schema; " f"cannot prove identity stability" ) ```