Bind a proposed call to the tool definition it saw, revalidate discovery, and understand the remaining race before execution.
A cached tool list is an old description of a capability
An MCP client may cache tool definitions to avoid repeatedly starting a server or fetching the same catalog. The optimization becomes dangerous when a model chooses an action from that old catalog and the server has changed. A tool can disappear, change its argument schema or retain the same schema while changing the meaning of a field. Cache freshness and permission to execute are separate questions.
This evergreen implementation guide uses a synthetic artifact tagging server. Version one accepts a timeout in seconds. Version two keeps the same numeric field but describes milliseconds. A request with timeout 30 remains structurally valid in both versions, yet its meaning differs by a factor of one thousand. No network server or model is contacted by the offline fixture.
The MCP 2026-07-28 protocol and current SDK documentation describe cache hints for discovery and other cacheable results. Older protocol revisions differ. Record the negotiated revision and inspect the SDK version in your deployment before implementing wire fields from this guide. The original client policy described here adds checks around execution; it is not a claim that every MCP SDK automatically enforces those checks.
Define the cache identity precisely
A cache entry needs the server identity, method and result-affecting parameters. Pagination cursors identify different requests. Authorization context matters for private results. The tool list for one principal must not be reused for another principal merely because both use the same endpoint. A public cache scope is a statement about the result's shareability, not an authorization grant for invoking its tools.
The protocol's ttlMs hint measures freshness from receipt. A zero or missing usable lifetime should not silently become an unlimited cache. Notifications can invalidate an entry before its lifetime ends. Conversely, a positive lifetime does not guarantee the server cannot change. Treating the hint as a lease that freezes tool behavior would create a guarantee the server has not provided.
Use a monotonic clock for an in-process elapsed-time calculation. A persisted cache needs a documented restart policy because a previous process's monotonic timestamp is not portable. The simplest safe policy is to treat persisted definitions as startup suggestions until they have been revalidated. If wall-clock expiry is retained for startup latency, clock changes and authorization changes still require conservative handling.
Bind a proposal to the definitions it saw
When constructing model input, save the exact tool definitions shown and an application-generated catalog generation. A later call proposal is associated with that generation. Before execution, refresh the relevant catalog under the current server and authorization context, then compare the selected definition with the saved one.
A practical fingerprint covers the fields whose changes could affect the choice or interpretation: name, description, input schema, relevant annotations and any application-defined contract version. Canonicalize the data deterministically before hashing. A fingerprint is an equality check over selected bytes, not a proof that the implementation is correct. If the server changes behavior without changing any advertised field, the fingerprint cannot detect it.
# Author: Sandeep Belgavi. Application policy, not an MCP SDK API.
import hashlib
import json
def fingerprint(tool):
fields = ("name", "description", "inputSchema", "annotations")
selected = {key: tool.get(key) for key in fields}
encoded = json.dumps(selected, sort_keys=True,
separators=(",", ":"), ensure_ascii=False)
return hashlib.sha256(encoded.encode("utf-8")).hexdigest()
def admit(shown, live):
if live is None:
return "tool_removed"
return "ready" if fingerprint(shown) == fingerprint(live) else "replan"If a definition changed, reject the stale proposal and ask for a fresh plan using the new catalog. Do not silently rename an argument or convert units based on an inferred mapping. Such transformations change the meaning of an already chosen action. A deterministic, versioned migration adapter is possible, but it needs its own explicit contract and tests.
Walk through the unit-change failure
At time zero, the client stores scan_artifact with timeout documented in seconds. At time ten, the server deploys a new definition using milliseconds. At time twenty, the model proposes timeout 30 from the old catalog. A naive client sends the request, and the new server interprets 30 milliseconds. The failure looks like a suddenly unreliable scanner rather than a stale planning contract.
The guarded client starts or contacts the server, obtains the live definition and compares it with the saved one. The description fingerprint differs, so it returns a replan outcome before calling the tool. The new model input makes the unit explicit. For a real API, also prefer unit-bearing field names such as timeout_ms, since an avoidable semantic ambiguity should be removed at the service contract itself.
If the tool was removed, the client reports that condition and refreshes discovery. It must not try a similarly named tool automatically. If discovery is temporarily unavailable, read-only catalog display may tolerate stale information while write execution remains unavailable. Define this distinction in the user experience: a visible cached capability is not necessarily an executable capability.
Do not mistake revalidation for atomic execution
There is still a time-of-check to time-of-use window between listing tools and calling one. Another deployment can happen in that interval. To close it, the server must support an appropriate version-bound contract or the application must route the call to an immutable implementation version. A client-side second list request cannot create server-side atomicity.
Where no version binding exists, use compatible deployments, stable semantic contracts and server-side argument validation. For consequential actions, retain review and authorization at execution time. The server should reject unsupported contract versions explicitly rather than guessing how old arguments should be interpreted. Revalidation reduces a class of stale proposals; it does not replace these controls.
Do not retry an ambiguous tool failure just because refreshing discovery succeeded. The first call may have performed an effect before the connection failed. Resolve that effect through an idempotency key or status lookup before issuing another call. This concern belongs to execution recovery, independently of whether the cached tool definition was current.
Treat pagination and invalidation as real state
A multi-page catalog is not automatically a consistent snapshot. A deployment between page requests can create duplicates, omissions or mixed definitions. Track page parameters and invalidate the whole assembled catalog when a cursor becomes invalid or when your consistency policy requires rebuilding from the first page. Deduplicate by tool identity while treating incompatible duplicate definitions as an error.
An invalidation notification should mark the relevant cache generation stale. If planning is already in progress, retain the generation used by that plan so the later execution check can detect the mismatch. Deleting the only copy of the shown definitions would remove the evidence needed to explain why a proposal was rejected.
Bound the cache by entry count or memory, and never store access tokens as loggable cache keys. Use an opaque authorization-context identifier derived inside the trusted client. Changing the principal, scope or server configuration should invalidate associated private entries. A cache hit metric without these dimensions can conceal incorrect sharing.
Verify stale plans with adversarial fixtures
Test unchanged definitions, a removed tool, a renamed argument, a description-only unit change and a changed authorization context. Verify that stale proposals are refused before effects are recorded. Test expiry at the exact boundary, notification invalidation during planning and a server restart after loading a persisted catalog.
Add a race fixture in which the server changes after revalidation. Its purpose is to demonstrate the remaining limitation, not to make a client-only guard appear stronger than it is. A good test suite records this unsupported case and verifies that the documented server contract is required to eliminate it.
Caching is worthwhile when discovery or startup latency is significant and the catalog is reasonably stable. It is unnecessary complexity for a small cheap local server whose definitions are fetched infrequently. Optimize after identifying the cost, keep the cache's scope explicit, and preserve the contract that connects what the model saw to what the application is prepared to execute.
Run the example yourself
The synthetic fixtures, expected output and tests behind this guide are in the companion code on GitHub; its README lists the prerequisites, exact commands, expected output and limits.