Skip to content

Inject tool annotations into context during list filtering - #4129

Merged
JAORMX merged 1 commit into
mainfrom
fix/authz-list-filter-annotations
Mar 13, 2026
Merged

JAORMX merged 1 commit into
mainfrom
fix/authz-list-filter-annotations

Conversation

@JAORMX

@JAORMX JAORMX commented Mar 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Why: When the authz middleware filters a tools/list response, it calls AuthorizeWithJWTClaims per tool to decide visibility. It was passing the original tools/list request context, which contains no tool annotations. Cedar policies with when clauses 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.
  • What: For each tool in the list response, inject its annotations into the context before the authorization check — matching what AnnotationEnrichmentMiddleware already does for tools/call requests. Uses existing hasAnyHint and convertMCPAnnotation helpers from the same package.

Type of change

  • Bug fix

Test plan

  • Unit tests (task test)
  • Manual testing (describe below)

Verified with brood-box using a local go.mod replace directive pointing to this branch. With --mcp-authz-profile safe-tools:

  • Before: zero tools visible (only Slack resources appeared)
  • After: tools with matching annotations (readOnlyHint: true from github, context7) correctly appear; destructive/open-world tools (slack) correctly remain blocked

Does this introduce a user-facing change?

Yes. Cedar authz policies that use annotation-based when clauses (e.g. resource.readOnlyHint == true) now work correctly during tools/list filtering. Previously, all tools were incorrectly filtered out.

Special notes for reviewers

The fix is minimal — 10 lines added in filterToolsResponse(). The root issue is that AnnotationEnrichmentMiddleware only enriches tools/call requests (by design), but the list filter was making call_tool authorization decisions without the same enrichment. The helpers hasAnyHint and convertMCPAnnotation are already in annotation_cache.go in the same package.

Generated with Claude Code

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]>
@github-actions github-actions Bot added the size/XS Extra small PR: < 100 lines changed label Mar 13, 2026
@codecov

codecov Bot commented Mar 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.07%. Comparing base (0657df9) to head (1f560bd).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/authz/response_filter.go 66.66% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JAORMX
JAORMX merged commit 31efa94 into main Mar 13, 2026
43 checks passed
@JAORMX
JAORMX deleted the fix/authz-list-filter-annotations branch March 13, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants