Skip to content

Commit 31efa94

Browse files
JAORMXclaude
andauthored
Inject tool annotations into context during list filtering (#4129)
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 <noreply@anthropic.com>
1 parent 0657df9 commit 31efa94

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

pkg/authz/response_filter.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,20 @@ func (rfw *ResponseFilteringWriter) filterToolsResponse(response *jsonrpc2.Respo
286286
// Note: instantiating the list ensures that no null value is sent over the wire.
287287
// This is basically defensive programming, but for clients.
288288
filteredTools := []mcp.Tool{}
289-
for _, tool := range listResult.Tools {
289+
for i, tool := range listResult.Tools {
290+
// Inject this tool's annotations into the context so Cedar policies
291+
// that use when clauses on resource attributes (e.g. resource.readOnlyHint)
292+
// can evaluate correctly. Without this, the authorization check runs
293+
// against a context with no annotations and all when clauses fail.
294+
ctx := rfw.request.Context()
295+
ann := &listResult.Tools[i].Annotations
296+
if hasAnyHint(ann) {
297+
ctx = authorizers.WithToolAnnotations(ctx, convertMCPAnnotation(ann))
298+
}
299+
290300
// Check if the user is authorized to call this tool
291301
authorized, err := rfw.authorizer.AuthorizeWithJWTClaims(
292-
rfw.request.Context(),
302+
ctx,
293303
authorizers.MCPFeatureTool,
294304
authorizers.MCPOperationCall,
295305
tool.Name,

0 commit comments

Comments
 (0)