Serdar Gökay created CAMEL-27516:
------------------------------------
Summary: camel-mcp-server - mark a tool call refused by the
authorization check in the result's _meta, so that a client can tell it from a
tool error
Key: CAMEL-27516
URL: https://issues.apache.org/jira/browse/CAMEL-27516
Project: Camel
Issue Type: Improvement
Components: camel-mcp-server, camel-ai
Reporter: Serdar Gökay
h2. Problem
Since CAMEL-24831, CAMEL-25405 and CAMEL-27144, a tool route can refuse a
caller ({{authorizationPolicy}}, {{allowedRoles}}). Inside Camel the refusal is
typed: {{AiToolResult.AuthorizationDenied}}, the WARN,
{{AiToolAuthorizationDeniedEvent}}, and since CAMEL-25404 visible to
onException, tracing and metrics.
At the MCP boundary the type is lost. {{McpServerBridge}} answers {{new
McpToolCallResult(denied.message(), true)}}, and the engines turn that into a
{{CallToolResult}} with {{isError: true}} and one text block. A tool that
failed answers the same shape with the generic execution error:
{noformat}
refused: {"isError": true, "content": [{"type": "text", "text": "Access
denied: not authorized to call tool 'orderCosts'"}]}
failed: {"isError": true, "content": [{"type": "text", "text": "<generic
execution error>"}]}
{noformat}
A client or gateway in front of the server can tell the two apart only by
matching the sentence, which may change in any release. The MCP specification
asks clients to log tool usage for audit purposes, and a refused call is the
entry an audit needs most.
h2. Proposal
On a refused call, the bridge puts one key in the result's {{_meta}}; the text
and {{isError}} stay as they are.
{noformat}
{"isError": true,
"content": [{"type": "text", "text": "Access denied: not authorized to call
tool 'orderCosts'"}],
"_meta": {"org.apache.camel/authorization": "denied"}}
{noformat}
* The key name is a suggestion; it follows the {{_meta}} rule of the MCP
specification (a reverse-DNS prefix that is not reserved). A constant in
{{McpServerConstants}} documents it.
* One branch carries it: the {{AiToolResult.AuthorizationDenied}} case in
{{McpServerBridge}}, so every refusal is marked, by {{allowedRoles}} or by any
{{AuthorizationPolicy}} (OPA, OpenFGA, Cedar, Keycloak, a user's own).
* No detail goes with it: not the roles asked for, not the policy, not the
caller. What the model and the client learn is only that the call was refused,
which the text already says.
* {{McpToolCallResult}} gains an optional {{meta}} map (the existing
constructors stay), and the three engines of camel-mcp-server (Vert.x modern
and legacy, stdio) pass it to {{CallToolResult.meta}}, which the MCP Java SDK
2.2.0 has. The Spring Boot and Quarkus engines (CAMEL-26360) can follow; until
then they answer as today.
h2. Why in Camel
* Camel is the only party that knows the call was refused; everyone after it
sees text.
* Every client of camel-mcp-server benefits: an agent gateway that audits
decisions, an MCP client that shows "not authorized" differently from "failed",
a test that asserts a refusal without matching a sentence.
* {{_meta}} is the protocol's place for this; no new field, no change for a
client that ignores it.
h2. Not in this issue
* Changing the refusal text or {{isError}}.
* Marking argument errors or execution errors.
* Leaving a refused tool out of {{tools/list}}.
I can provide the PR, with tests for each engine.
_Claude Code on behalf of etzel-mes_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)