Repository navigation
Every federated list was announcing a cache scope that does not exist - #88
Merged
Merged
Conversation
MCP's caching rules define `cacheScope` as exactly two values, "public"
and "private", and require the hint on every complete list result. fold
builds its list results itself — federated, merged, and filtered per
principal — so they never reach the SDK handlers that fill those fields
in for an ordinary server. Every tools/list, prompts/list,
resources/list and resources/templates/list went out with
`"cacheScope": ""`, which is neither.
It never became an incident because the accompanying ttlMs is 0, the
spec's "immediately stale", so a conforming client re-fetches regardless.
But the two hints disagreed, and the one that would have contained the
damage is the one fold was not deliberately setting: a client applying
the documented "absent means public" default to an empty string would
have treated a list fold had filtered per principal as shareable with
anyone — the specification's own example of what must be private.
The scope is now computed from configuration, once per routing snapshot,
and is private whenever two callers can legitimately receive different
lists: any policy rule, any tenant, or any upstream whose credential is
caller-derived.
defaultDecision deliberately does not appear in that condition, and
getting there took two wrong turns worth recording. Reading it as
evidence of filtering is wrong because a default with no rules serves
every caller the same list — the whole federation under allow, nothing
at all under deny — so neither varies by who is asking. It also would
have split two documents that are the same engine: policy.New sets
defaultAllow only for the literal "allow", so `{}` and
`{"defaultDecision":"deny"}` both deny everything, and no rule that gave
them different scopes could be coherent.
ttlMs stays 0. A reload, a discovery sync, or a policy change can alter
what a caller is entitled to see at any moment; fold does emit
list_changed on all three, which is the invalidation signal the spec
pairs with a TTL, but choosing a lifetime here would choose it for every
deployment at once, and the conservative value is the one that cannot
serve a stale entitlement.
One limitation is documented rather than papered over: a list can also
vary by the capability profile a client declared, because an upstream may
register a different tool set for a client that supports MCP Apps. That
is a content-negotiation axis — HTTP would say Vary — and the caching
section defines no equivalent, so cacheScope cannot express it. private
would be the wrong instrument, bounding sharing across authorization
contexts rather than across client capabilities. ttlMs 0 is what contains
it.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 3 of the audit follow-up — though not the phase that was planned. Independent of #84 and #87.
The planned feature was not buildable, and that is the first finding
The plan called for a read-through cache on
readOnlyHinttool calls. Checking the specification rather than the plan:tools/callis absent, andCallToolResultis the one result type in the Go SDK that does not embedCacheable. MCP excludes tool calls from caching deliberately. The plan also said to honour the upstream's cache hint as a ceiling — impossible, since tool-call results carry no hints — and named the fieldscache_ttl/cache_scope, which are a Python framework's API rather than the spec'sttlMs/cacheScope.Building it would have meant fold inventing cache semantics for an operation the spec declines, keyed on
readOnlyHint— a side-effect hint never defined as a cacheability signal.What the same investigation found instead
Probing fold's actual wire output rather than reasoning about it: every federated list carried
"cacheScope": "". Neither permitted value. fold constructs its list results itself, so it never reaches the SDK handlers that fill the field in for an ordinary server.ttlMs: 0meant this never caused an incident — conforming clients re-fetch regardless. But the two hints disagreed, and the one that would have contained the damage was the one fold was not setting. A client applying the SDK's documented "absent means public" default to an empty string would treat a list fold had filtered per principal as shareable with anyone. That is the spec's own example of what must be private:Now computed from configuration, once per routing snapshot:
"private"whenever two callers can legitimately receive different lists — any policy rule, any tenant, or any caller-derived upstream — and"public"only for a federation that serves one list to everyone.defaultDecisionis deliberately not in that conditionTwo wrong turns to get there, both worth reviewing:
defaultDecision == "deny". Wrong:policy.NewsetsdefaultAllowonly for the literal"allow", so an unset value denies —policy: {}would have been marked public while the engine refused every caller.{}public but{"defaultDecision":"deny"}private, when those are the same deny-all engine.The resolution is neither: a default with no rules serves every caller the same list — the whole federation under
allow, nothing underdeny. Neither varies by who is asking, so the field simply does not belong in the condition. It is the only version where two identical configurations get the same answer.A limitation documented rather than papered over
A list can also vary by the capability profile a client declared — an upstream may register a different tool set for a client supporting MCP Apps, which is why fold keys root sessions and list-cache entries by profile. Two callers in the same authorization context can therefore get different
tools/listbytes.That is a content-negotiation axis; HTTP would say
Vary. The MCP caching section defines no equivalent, socacheScopecannot express it, and"private"would be the wrong instrument — it bounds sharing across authorization contexts, not across client capabilities. What contains it in practice isttlMs: 0. Written up indocs/configuration.mdrather than left to be discovered.ttlMsstays 0A reload, a discovery sync, or a policy change can alter what a caller may see at any moment. fold emits
list_changedon all three — the invalidation signal the spec pairs with a TTL — but choosing a lifetime here chooses it for every deployment at once, and the conservative value is the one that cannot serve a stale entitlement.Verification
go test -race ./...green; lint 0 issues; gofmt / vet / tidy clean""and absent are indistinguishable after unmarshalling intomcp.Cacheable, so a struct-level test could not have caught the original defectpublic,private}, and the field is present) runs on every case separately from the expected-value check, so a future third value fails even if someone updates thewantTestPlainFederationMatchesTheUpstreamsOwnCacheHintsasserts a plain federation is byte-identical to hitting the upstream directly — not a tautology, since the SDK stamps"public"on its own handlers and fold intercepting before them is exactly why the field was emptyFuzzListCacheScope(1.6M execs) asserting no config document yields a value outside the permitted setDeferred, with reasons
Honouring upstream
ttlMs/cacheScopewhen filling fold's own list cache — socacheTtlMscannot silently outlive an upstream's declared freshness. Blocked on a real structural issue:state.ListCache.GetOrFill(ctx, key, ttl, fill)takes the TTL before running the fill, and the hint only exists after it. That means changing astate.Providerinterface with two implementations plus the Redis paths — its own change with its own reload/churn matrix, not a rider on a wire fix.resources/readcaching — cacheable per spec, and fold does not do it. The genuine opportunity the original phase 3 was reaching for, with normative backing.🤖 Generated with Claude Code