etzel-mes opened a new pull request, #30764:
URL: https://github.com/apache/camel/pull/30764

   # Description
   
   A tool route can refuse a caller (`authorizationPolicy`, and `allowedRoles` 
since CAMEL-27144). Inside Camel the refusal is typed 
(`AiToolResult.AuthorizationDenied`, the `WARN`, 
`AiToolAuthorizationDeniedEvent`). At the MCP boundary the type is lost: the 
result is `isError: true` with one text block, the same shape as a tool that 
failed. A client or a gateway in front of the server can tell the two apart 
only by matching the sentence.
   
   This change puts one entry in the `_meta` of the result of a refused call. 
The text and `isError` stay as they are:
   
   ```json
   {"isError": true,
    "content": [{"type": "text", "text": "Access denied: not authorized to call 
tool 'order_costs'"}],
    "_meta": {"org.apache.camel/authorization": "denied"}}
   ```
   
   - One branch sets it: the `AiToolResult.AuthorizationDenied` case in 
`McpServerBridge`, so a refusal by `allowedRoles` and by any 
`AuthorizationPolicy` is marked alike. An argument error, an execution error 
and a timeout are not marked.
   - The entry carries no detail: not the roles, not the policy, not the 
caller. It says what the text already says.
   - `McpToolCallResult` gains an optional `meta` component; the two existing 
constructors stay. The Vert.x engine (both for the protocol versions that open 
with `initialize` and for 2026-07-28) and the stdio engine pass it to the 
`_meta` of the MCP result.
   - `McpServerConstants.META_AUTHORIZATION` and `META_AUTHORIZATION_DENIED` 
name the key and its value.
   
   One point to settle in review, the prefix of the key. The MCP specification 
says a `_meta` key prefix SHOULD use reverse DNS notation ("`com.example/` 
rather than `example.com/`", since 2025-11-25), so this change uses 
`org.apache.camel/`. Camel already has one `_meta` key with the other form, 
`camel.apache.org/deterministic` on the tool listing of camel-jbang-mcp 
(`RepeatedToolCalls.DETERMINISTIC_META_KEY`). I kept to the specification, and 
I am happy to change this key to `camel.apache.org/authorization` if you prefer 
one prefix across Camel.
   
   Tests:
   
   - `McpServerBridgeTest`: a refused call carries the entry; an allowed call, 
an argument error and an execution error carry none.
   - `McpServerMainAllowedRolesTest`: over a real MCP call on Camel Main with a 
signed token, the refused caller's result has the entry and the allowed 
caller's result has none.
   - `VertxMcpModernClientTest`: with the MCP Java SDK client for protocol 
version 2026-07-28, the result carries the entry next to the server-info entry 
the SDK adds to every result of that version.
   - `StdioMcpServerProcessIT`: over stdio, where no caller has roles, a tool 
with `allowedRoles` refuses and the result has the entry.
   
   Documentation: the Security section of the MCP server page, a pointer under 
"Observing denials" of the ai-tool page, and an entry in the 4.24 upgrade guide.
   
   The Spring Boot and Quarkus engines live in their own repositories and are 
not part of this change.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   I built and tested the two changed modules (`camel-mcp-server-api`, 
`camel-mcp-server`) with the formatter, not the whole tree. Of the integration 
tests of `camel-mcp-server`, `McpServerOpenAIAgentIT` did not run here: the 
pull of its Ollama image stalled.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   _Claude Code on behalf of etzel-mes_
   
   cc @davsclaus @oscerd
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to