Add annotation cache for tools/list to tools/call flow#4114
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4114 +/- ##
==========================================
- Coverage 68.84% 68.83% -0.02%
==========================================
Files 458 459 +1
Lines 46274 46319 +45
==========================================
+ Hits 31859 31884 +25
- Misses 11953 11975 +22
+ Partials 2462 2460 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The authz middleware now caches tool annotations from tools/list responses and injects them into context during tools/call requests. This bridges the gap where annotations are visible in tools/list but lost by the time tools/call arrives as a separate HTTP request. - Add AnnotationCache with concurrent-safe get/set operations - ResponseFilteringWriter populates cache during tools/list filtering - Middleware closure captures cache, injects annotations for tools/call - Graceful degradation when tools/call arrives before tools/list Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SetFromToolsList previously merged into the existing map, so tools whose annotations were removed in a subsequent tools/list response retained stale cached entries. Replace the entire map atomically to ensure eviction of removed tools. Also add a test for the eviction behavior and document the intentional omission of the Title field in convertMCPAnnotation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ee24ab8 to
3e16e84
Compare
JAORMX
commented
Mar 12, 2026
Collaborator
Author
JAORMX
left a comment
There was a problem hiding this comment.
Thanks for the review! Replied inline.
jhrozek
reviewed
Mar 12, 2026
Contributor
jhrozek
left a comment
There was a problem hiding this comment.
lgtm, two questions inline, not acking because Alejandro had another comment
aponcedeleonch
approved these changes
Mar 12, 2026
Member
aponcedeleonch
left a comment
There was a problem hiding this comment.
lgtm, Jakub had a comment about pagination that could be potentially worth looking into (?) as he mentioned, I don't know how real-world issue pagination is
jhrozek
approved these changes
Mar 12, 2026
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/listresponses but lost by the timetools/callarrives as a separate HTTP request. This adds an in-memory annotation cache that bridges the two operations, enabling Cedar/HTTP PDP policies to reference annotations duringtools/callauthorization.Type of change
Test plan
task test)task lint-fix)Changes
pkg/authz/annotation_cache.goAnnotationCachewith concurrent-safeGet/Set/SetFromToolsList, nil-safe on nil receiverpkg/authz/annotation_cache_test.gopkg/authz/response_filter.goResponseFilteringWritergainsannotationCachefield;filterToolsResponsepopulates cache from parsed tool listpkg/authz/middleware.goMiddlewareclosure creates per-proxy cache;tools/calllooks up annotations and injects viaWithToolAnnotationspkg/authz/response_filter_test.goNewResponseFilteringWritercall sites for new parameterDoes this introduce a user-facing change?
No — internal plumbing. Users benefit when Cedar policies reference tool annotations (e.g.
resource.readOnlyHint == true), which now work fortools/callafter atools/listhas populated the cache.Special notes for reviewers
Middlewareclosure, so each MCP server proxy has its own cache. Tool names are scoped to a single server, so this is correct.tools/callarrives before anytools/list,Getreturns nil and no annotations are injected — same behavior as before PR 1.AnnotationCachemethods handle nil receiver, so existing code passingniltoNewResponseFilteringWriterworks unchanged.SetFromToolsListruns before the authorization loop, so annotations for all tools (including ones that will be filtered out) are cached.Generated with Claude Code