Repository navigation
Inject tool annotations into context during list filtering - #4129
Merged
Merged
Conversation
The tools/list response filter calls AuthorizeWithJWTClaims for each tool to decide whether to include it in the filtered response. However, it was passing the original request context which has no tool annotations. This caused Cedar policies with `when` clauses on resource attributes (e.g. resource.readOnlyHint) to always fail, filtering out all tools regardless of their annotations. The fix injects each tool's annotations into the context before the authorization check, matching what AnnotationEnrichmentMiddleware already does for tools/call requests. Co-Authored-By: Claude Opus 4.6 <[email protected]>
yrobla
approved these changes
Mar 13, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4129 +/- ##
==========================================
- Coverage 68.10% 68.07% -0.03%
==========================================
Files 461 461
Lines 46700 46704 +4
==========================================
- Hits 31804 31794 -10
- Misses 12131 12135 +4
- Partials 2765 2775 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
rdimitrov
approved these changes
Mar 13, 2026
9 tasks
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.
Summary
tools/listresponse, it callsAuthorizeWithJWTClaimsper tool to decide visibility. It was passing the originaltools/listrequest context, which contains no tool annotations. Cedar policies withwhenclauses on resource attributes (e.g.resource.readOnlyHint == true) always evaluated to an error (attribute not found), causing all tools to be filtered out regardless of their annotations.AnnotationEnrichmentMiddlewarealready does fortools/callrequests. Uses existinghasAnyHintandconvertMCPAnnotationhelpers from the same package.Type of change
Test plan
task test)Verified with brood-box using a local
go.modreplace directive pointing to this branch. With--mcp-authz-profile safe-tools:readOnlyHint: truefrom github, context7) correctly appear; destructive/open-world tools (slack) correctly remain blockedDoes this introduce a user-facing change?
Yes. Cedar authz policies that use annotation-based
whenclauses (e.g.resource.readOnlyHint == true) now work correctly duringtools/listfiltering. Previously, all tools were incorrectly filtered out.Special notes for reviewers
The fix is minimal — 10 lines added in
filterToolsResponse(). The root issue is thatAnnotationEnrichmentMiddlewareonly enrichestools/callrequests (by design), but the list filter was makingcall_toolauthorization decisions without the same enrichment. The helpershasAnyHintandconvertMCPAnnotationare already inannotation_cache.goin the same package.Generated with Claude Code