Repository navigation
policy: gate on what a tool says it does - #57
Merged
Merged
Conversation
Expressing "read anything, write nothing" meant naming every read-only tool and re-deriving the list per upstream, which fails open the moment an upstream adds one. toolKind gates on the MCP annotations fold has been ignoring: readOnly requires readOnlyHint, nonDestructive additionally admits tools whose destructiveHint is false. Unlike argument constraints, annotations arrive with the list, so this filters lists as well as denying calls — the enforcement pair stays intact for it. The spec's defaults are taken as written rather than improved. readOnlyHint defaults to false and destructiveHint to true, so an unannotated tool is neither read-only nor non-destructive and fails both gates. The improvement nobody should make here is admitting unannotated tools to a read-only grant. Unknown annotations deny, which is fail-safe in the direction the rest of the engine already fails. That covers more cases than the design record anticipated: an upstream whose list caching is disabled because its credential is caller-derived has nothing to consult, and neither does a name the upstream does not list. Both refuse, and toolKind therefore does not compose with passthrough or token-exchange — documented rather than discovered. There is no separate annotation index, which the design record expected. At list time fold is already holding the tool, so annotations are read from the item; at call time they resolve from the same cached list the egress path decodes, only when a rule actually gates on kind. A second index keyed by upstream and name would have been a third thing to invalidate in step with the cache, in exchange for avoiding a linear scan of an already-decoded slice on a path about to make a network call anyway. The README says plainly what this is: a hygiene control for federations you operate, not a security boundary, because the annotations are declared by the very server being gated. Against an upstream you do not control the boundary is names, and no amount of toolKind substitutes for it. Phase 3 of docs/design-policy-depth.md. Per-item decide is unchanged at 77 ns with zero allocations for documents using none of this; conformance 40/40. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
CI's linter caught what the refactor left behind: listFilter.decide took an upstream id and a name it no longer used, because each caller's closure captures the item it is deciding about. Removing them is the whole change. 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
docs/design-policy-depth.md, following #55 and #56.Expressing "read anything, write nothing" meant naming every read-only tool and re-deriving that list per upstream — an allowlist that fails open the moment an upstream adds one.
toolKindgates on the MCP annotations fold has been ignoring:{ "server": "*", "methods": ["tools/call"], "toolKind": "readOnly" }readOnlyrequiresreadOnlyHint;nonDestructiveadditionally admits tools whosedestructiveHintis false. Unlike argument constraints, annotations arrive with the list, so this filters lists as well as denying calls — the enforcement pair stays intact.What this is not
A hygiene control, not a security boundary. The annotations are declared by the very server being gated, so an upstream that labels
delete_everythingas read-only is believed. It is for federations your organization operates, where the risk is an operator forgetting to update an allowlist. Against a server you do not control, the boundary isnames— the README says this in those words rather than implying the gate holds.Taking the spec at its word
readOnlyHintdefaults to false anddestructiveHintto true, so an unannotated tool is neither read-only nor non-destructive and fails both gates. fold does not "improve" those defaults; the improvement would be admitting every unannotated tool to a read-only grant. The integration test drives a real upstream with an unannotated tool for exactly this reason.Unknown annotations deny — fail-safe in the direction the rest of the engine fails. That covers more than the design anticipated: an upstream whose list caching is disabled (caller-derived credential) has nothing to consult, and so does a name the upstream does not list. Both refuse, so
toolKinddoes not compose withpassthrough/token-exchange, which is now documented and tested rather than discovered.One shape change from the design
There is no separate annotation index. At list time fold already holds the tool, so annotations are read from the item; at call time they resolve from the same cached list the egress path decodes, and only when a rule gates on kind. A second index keyed by upstream and name would have been a third thing to invalidate in step with the cache, in exchange for avoiding a linear scan of an already-decoded slice on a path about to make a network call anyway.
Verification
make check(race) green,make conformance40/40, per-item decide unchanged at 77 ns / 0 allocs for documents using none of this. Three new policy unit tests (including the full annotation truth table) and two integration tests against an upstream publishing real annotations.Phase 4 — the docs pass across
defaults.mdand the rest — is what remains.🤖 Generated with Claude Code