This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 7d4f014af590 CAMEL-27516: camel-mcp-server - mark a tool call refused
by the authorization check in the result's _meta (#30764)
7d4f014af590 is described below
commit 7d4f014af590fd0ac714b59ad16e6cc1c30d345f
Author: Serdar Gökay <[email protected]>
AuthorDate: Thu Nov 26 10:58:14 2026 +0300
CAMEL-27516: camel-mcp-server - mark a tool call refused by the
authorization check in the result's _meta (#30764)
A tool call that the authorizationPolicy or allowedRoles check of an
ai-tool route refuses is answered over MCP as
isError with a short refusal, the same shape as a tool that failed. A
client or a gateway in front of the server
could tell the two apart only by the text.
The bridge now puts "org.apache.camel/authorization": "denied" in the _meta
of the result of a refused call. The
text and isError are unchanged. McpToolCallResult gains an optional meta
map, and the Vert.x and stdio engines pass
it to the _meta of the MCP result.
* CAMEL-27516: camel-mcp-server - the meta component of McpToolCallResult
gets a @since tag instead of a note in its @param
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/catalog/docs/ai-tool-component.adoc | 3 +++
.../org/apache/camel/catalog/docs/mcp-server.adoc | 7 ++++++
.../src/main/docs/ai-tool-component.adoc | 3 +++
.../component/mcp/server/McpServerBridge.java | 5 +++-
.../component/mcp/server/McpServerConstants.java | 16 ++++++++++++
.../component/mcp/server/McpToolCallResult.java | 22 ++++++++++++++--
.../component/mcp/server/McpServerBridgeTest.java | 29 ++++++++++++++++++++++
.../camel-mcp-server/src/main/docs/mcp-server.adoc | 7 ++++++
.../mcp/server/stdio/StdioMcpServerEngine.java | 9 ++++---
.../mcp/server/vertx/McpModernCatalog.java | 3 +++
.../mcp/server/vertx/VertxMcpServerEngine.java | 3 +++
.../server/main/McpServerMainAllowedRolesTest.java | 8 +++++-
.../mcp/server/stdio/McpStdioHarnessMain.java | 5 ++++
.../mcp/server/stdio/StdioMcpServerProcessIT.java | 20 +++++++++++++++
.../mcp/server/vertx/VertxMcpModernClientTest.java | 18 ++++++++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 9 +++++++
16 files changed, 160 insertions(+), 7 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-tool-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-tool-component.adoc
index ef9326864c8f..3250c86284fe 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-tool-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/ai-tool-component.adoc
@@ -641,6 +641,9 @@ context.getManagementStrategy().addEventNotifier(new
EventNotifierSupport() {
The event is emitted best-effort: when no `EventNotifier` is registered
nothing is published, and a failure to notify
never affects the refusal returned to the model.
+On Camel Main and Camel JBang, a client of the xref:others:mcp-server.adoc[MCP
server] can tell a refused call from a
+tool error as well: the result of the call carries a mark in its `_meta`
field, see the Security section of that page.
+
=== Tool search visibility
`searchable` controls whether a route tool is sent to the model immediately or
only after a producer with tool search enabled finds it. The default is
`false`, so the tool stays directly visible. `searchable=true` omits the tool
from the initial model request and makes it eligible for search together with
remote MCP tools.
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
index 5ebc474dac0e..55b4fb902b48 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/mcp-server.adoc
@@ -547,6 +547,13 @@ following rules:
message; the cause is logged server-side and never sent to the client.
Argument validation messages (missing or invalid parameters) are returned
as-is.
+* *Refused calls*: a tool call that the authorization check of the tool
refuses (the
+ `authorizationPolicy` or `allowedRoles` option of the
+ xref:ROOT:ai-tool-component.adoc[ai-tool] route) is answered as a tool error
with a
+ short generic refusal. On Camel Main and Camel JBang the result also carries
+ `"org.apache.camel/authorization": "denied"` in its `_meta` field, so that a
client can
+ tell a refused call from a failed one without reading the text. The entry
names
+ neither the roles, the policy nor the caller.
* *Returned content*: the result of a tool, resource or prompt is passed to the
client and the model as it is. Data that a route reads from a source
outsiders can write may
contain prompt injection; the route author decides what goes in.
diff --git
a/components/camel-ai/camel-ai-tool/src/main/docs/ai-tool-component.adoc
b/components/camel-ai/camel-ai-tool/src/main/docs/ai-tool-component.adoc
index ef9326864c8f..3250c86284fe 100644
--- a/components/camel-ai/camel-ai-tool/src/main/docs/ai-tool-component.adoc
+++ b/components/camel-ai/camel-ai-tool/src/main/docs/ai-tool-component.adoc
@@ -641,6 +641,9 @@ context.getManagementStrategy().addEventNotifier(new
EventNotifierSupport() {
The event is emitted best-effort: when no `EventNotifier` is registered
nothing is published, and a failure to notify
never affects the refusal returned to the model.
+On Camel Main and Camel JBang, a client of the xref:others:mcp-server.adoc[MCP
server] can tell a refused call from a
+tool error as well: the result of the call carries a mark in its `_meta`
field, see the Security section of that page.
+
=== Tool search visibility
`searchable` controls whether a route tool is sent to the model immediately or
only after a producer with tool search enabled finds it. The default is
`false`, so the tool stays directly visible. `searchable=true` omits the tool
from the initial model request and makes it eligible for search together with
remote MCP tools.
diff --git
a/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerBridge.java
b/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerBridge.java
index d564430c6d09..b7f006771f2a 100644
---
a/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerBridge.java
+++
b/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerBridge.java
@@ -91,6 +91,8 @@ public class McpServerBridge extends ServiceSupport
implements CamelContextAware
private static final String GENERIC_READ_TIMEOUT_ERROR = "Resource read
timed out";
private static final String GENERIC_PROMPT_ERROR = "Prompt execution
failed";
private static final String GENERIC_PROMPT_TIMEOUT_ERROR = "Prompt
execution timed out";
+ private static final Map<String, Object> AUTHORIZATION_DENIED_META
+ = Map.of(McpServerConstants.META_AUTHORIZATION,
McpServerConstants.META_AUTHORIZATION_DENIED);
private final McpServerConfiguration configuration;
private final RegistryListener listener = new RegistryListener();
@@ -881,8 +883,9 @@ public class McpServerBridge extends ServiceSupport
implements CamelContextAware
return new McpToolCallResult(error.message(), true);
} else if (result instanceof AiToolResult.AuthorizationDenied
denied) {
// The denial message is already generic and caller-safe, so
it is safe to return to the MCP client.
+ // The _meta entry lets the client tell the refusal from a
tool error without reading the message.
LOG.warn("MCP tool '{}' call denied by the authorization
check", spec.getName());
- return new McpToolCallResult(denied.message(), true);
+ return new McpToolCallResult(denied.message(), true, null,
AUTHORIZATION_DENIED_META);
} else {
AiToolResult.ExecutionError error =
(AiToolResult.ExecutionError) result;
// never leak raw route exception messages to remote MCP
clients
diff --git
a/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerConstants.java
b/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerConstants.java
index dce029848cbf..e08f0c94f060 100644
---
a/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerConstants.java
+++
b/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpServerConstants.java
@@ -71,6 +71,22 @@ public final class McpServerConstants {
*/
public static final long DEFAULT_SESSION_IDLE_TTL = 300_000;
+ /**
+ * Key in the {@code _meta} field of a tool call result that the MCP
server sets, with the value
+ * {@link #META_AUTHORIZATION_DENIED}, when the authorization check of the
tool refused the call. An MCP client can
+ * tell a refused call from a tool error by this key, without reading the
text of the result.
+ *
+ * @since 4.24
+ */
+ public static final String META_AUTHORIZATION =
"org.apache.camel/authorization";
+
+ /**
+ * Value of {@link #META_AUTHORIZATION} for a call that the authorization
check of the tool refused.
+ *
+ * @since 4.24
+ */
+ public static final String META_AUTHORIZATION_DENIED = "denied";
+
private McpServerConstants() {
}
}
diff --git
a/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpToolCallResult.java
b/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpToolCallResult.java
index a57bead1e003..cfb397799f25 100644
---
a/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpToolCallResult.java
+++
b/components/camel-ai/camel-mcp-server-api/src/main/java/org/apache/camel/component/mcp/server/McpToolCallResult.java
@@ -16,6 +16,10 @@
*/
package org.apache.camel.component.mcp.server;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
/**
* Result of an MCP tool invocation, pre-sanitized by the bridge: the text is
safe to return to a remote MCP client and
* never contains raw route exception messages.
@@ -23,12 +27,26 @@ package org.apache.camel.component.mcp.server;
* @param text the tool output, or a safe error message when
{@code isError} is true
* @param isError whether the invocation failed
* @param structuredContent typed JSON output when the tool declares an output
schema, otherwise {@code null}
+ * @param meta entries for the {@code _meta} field of the result,
otherwise {@code null}
*
* @since 4.22
*/
-public record McpToolCallResult(String text, boolean isError, Object
structuredContent) {
+public record McpToolCallResult(String text, boolean isError, Object
structuredContent, Map<String, Object> meta) {
+
+ /**
+ * Canonical constructor; defensively copies the meta entries into an
unmodifiable map.
+ *
+ * @since 4.24
+ */
+ public McpToolCallResult {
+ meta = meta == null ? null : Collections.unmodifiableMap(new
LinkedHashMap<>(meta));
+ }
public McpToolCallResult(String text, boolean isError) {
- this(text, isError, null);
+ this(text, isError, null, null);
+ }
+
+ public McpToolCallResult(String text, boolean isError, Object
structuredContent) {
+ this(text, isError, structuredContent, null);
}
}
diff --git
a/components/camel-ai/camel-mcp-server-api/src/test/java/org/apache/camel/component/mcp/server/McpServerBridgeTest.java
b/components/camel-ai/camel-mcp-server-api/src/test/java/org/apache/camel/component/mcp/server/McpServerBridgeTest.java
index 08b4a7fe3d67..e1bed0569825 100644
---
a/components/camel-ai/camel-mcp-server-api/src/test/java/org/apache/camel/component/mcp/server/McpServerBridgeTest.java
+++
b/components/camel-ai/camel-mcp-server-api/src/test/java/org/apache/camel/component/mcp/server/McpServerBridgeTest.java
@@ -101,6 +101,10 @@ class McpServerBridgeTest extends CamelTestSupport {
exchange.getMessage().setBody("identity-captured");
});
+ from("ai-tool:order_costs?tags=crm&description=Costs of a
production order&allowedRoles=finance")
+ .routeId("order-costs-route")
+ .setBody(constant("costs=42"));
+
from("ai-tool:getWeather?tags=crm&description=Get weather"
+
"&outputSchema={\"type\":\"object\",\"properties\":{\"temperature\":{\"type\":\"number\"},\"unit\":{\"type\":\"string\"}},\"required\":[\"temperature\",\"unit\"]}")
.routeId("weather-route")
@@ -202,6 +206,7 @@ class McpServerBridgeTest extends CamelTestSupport {
assertThat(result.isError()).isTrue();
assertThat(result.text()).contains("customerId");
+ assertThat(result.meta()).isNull();
}
@Test
@@ -212,6 +217,7 @@ class McpServerBridgeTest extends CamelTestSupport {
assertThat(result.text())
.doesNotContain("secret internal detail")
.isEqualTo("Tool execution failed");
+ assertThat(result.meta()).isNull();
}
@Test
@@ -222,6 +228,29 @@ class McpServerBridgeTest extends CamelTestSupport {
assertThat(result.text()).contains("timed out");
}
+ @Test
+ void testCallToolRefusedByTheAuthorizationCheckIsMarkedInMeta() {
+ McpToolCallContext callContext = new McpToolCallContext(null, "bob",
List.of("sales"));
+
+ McpToolCallResult result =
engine.tools().get("order_costs").handler().call(Map.of(), callContext);
+
+ assertThat(result.isError()).isTrue();
+ assertThat(result.text()).isEqualTo("Access denied: not authorized to
call tool 'order_costs'");
+ assertThat(result.meta()).containsOnly(
+ Map.entry(McpServerConstants.META_AUTHORIZATION,
McpServerConstants.META_AUTHORIZATION_DENIED));
+ }
+
+ @Test
+ void testCallToolAllowedByTheAuthorizationCheckHasNoMeta() {
+ McpToolCallContext callContext = new McpToolCallContext(null, "alice",
List.of("finance"));
+
+ McpToolCallResult result =
engine.tools().get("order_costs").handler().call(Map.of(), callContext);
+
+ assertThat(result.isError()).isFalse();
+ assertThat(result.text()).isEqualTo("costs=42");
+ assertThat(result.meta()).isNull();
+ }
+
@Test
void testToolRemovedAndReAddedOnRouteLifecycle() throws Exception {
context.getRouteController().stopRoute("query-db-route");
diff --git a/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
b/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
index 5ebc474dac0e..55b4fb902b48 100644
--- a/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
+++ b/components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc
@@ -547,6 +547,13 @@ following rules:
message; the cause is logged server-side and never sent to the client.
Argument validation messages (missing or invalid parameters) are returned
as-is.
+* *Refused calls*: a tool call that the authorization check of the tool
refuses (the
+ `authorizationPolicy` or `allowedRoles` option of the
+ xref:ROOT:ai-tool-component.adoc[ai-tool] route) is answered as a tool error
with a
+ short generic refusal. On Camel Main and Camel JBang the result also carries
+ `"org.apache.camel/authorization": "denied"` in its `_meta` field, so that a
client can
+ tell a refused call from a failed one without reading the text. The entry
names
+ neither the roles, the policy nor the caller.
* *Returned content*: the result of a tool, resource or prompt is passed to the
client and the model as it is. Data that a route reads from a source
outsiders can write may
contain prompt injection; the route author decides what goes in.
diff --git
a/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerEngine.java
b/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerEngine.java
index cebff18c1a8f..ac299d7014fb 100644
---
a/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerEngine.java
+++
b/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerEngine.java
@@ -489,10 +489,13 @@ public class StdioMcpServerEngine extends ServiceSupport
implements McpServerEng
.callHandler((exchange, request) -> {
Map<String, Object> arguments = request.arguments() !=
null ? request.arguments() : Map.of();
McpToolCallResult result = tool.handler().call(arguments);
- return McpSchema.CallToolResult.builder()
+ McpSchema.CallToolResult.Builder builder =
McpSchema.CallToolResult.builder()
.addTextContent(result.text())
- .isError(result.isError())
- .build();
+ .isError(result.isError());
+ if (result.meta() != null) {
+ builder.meta(result.meta());
+ }
+ return builder.build();
})
.build();
}
diff --git
a/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/McpModernCatalog.java
b/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/McpModernCatalog.java
index a5ec4c0090c8..9fd883592ca8 100644
---
a/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/McpModernCatalog.java
+++
b/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/McpModernCatalog.java
@@ -102,6 +102,9 @@ final class McpModernCatalog {
if (result.structuredContent() != null) {
builder.structuredContent(result.structuredContent());
}
+ if (result.meta() != null) {
+ builder.meta(result.meta());
+ }
return McpSyncResponse.result(builder.build());
}));
changes.broadcast(new ServerChange.ToolsListChanged());
diff --git
a/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/VertxMcpServerEngine.java
b/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/VertxMcpServerEngine.java
index 3f0fe09dd192..568370112338 100644
---
a/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/VertxMcpServerEngine.java
+++
b/components/camel-ai/camel-mcp-server/src/main/java/org/apache/camel/component/mcp/server/vertx/VertxMcpServerEngine.java
@@ -299,6 +299,9 @@ public class VertxMcpServerEngine extends ServiceSupport
implements McpServerEng
if (result.structuredContent() != null) {
builder.structuredContent(result.structuredContent());
}
+ if (result.meta() != null) {
+ builder.meta(result.meta());
+ }
return builder.build();
}
diff --git
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/main/McpServerMainAllowedRolesTest.java
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/main/McpServerMainAllowedRolesTest.java
index 9c80f7bad7fd..39f851e5b675 100644
---
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/main/McpServerMainAllowedRolesTest.java
+++
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/main/McpServerMainAllowedRolesTest.java
@@ -37,6 +37,7 @@ import io.vertx.ext.auth.JWTOptions;
import io.vertx.ext.auth.jwt.JWTAuth;
import io.vertx.ext.auth.jwt.JWTAuthOptions;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mcp.server.McpServerConstants;
import org.apache.camel.main.Main;
import org.apache.camel.test.AvailablePortFinder;
import org.junit.jupiter.api.AfterAll;
@@ -49,7 +50,8 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* The {@code allowedRoles} option of an {@code ai-tool} route over a real MCP
call: the Camel Main HTTP server
* authenticates the caller with a signed JWT, the MCP bridge puts the roles
of the token on the tool exchange, and the
- * tool answers the caller who has the role and refuses the one who has not.
+ * tool answers the caller who has the role and refuses the one who has not.
The refusal carries its mark in the
+ * {@code _meta} of the result.
*/
class McpServerMainAllowedRolesTest {
@@ -120,6 +122,7 @@ class McpServerMainAllowedRolesTest {
assertThat(result.isError()).isNotEqualTo(Boolean.TRUE);
assertThat(result.content().toString()).contains("costs=42");
+ assertThat(result.meta()).isNull();
} finally {
client.closeGracefully();
}
@@ -139,6 +142,9 @@ class McpServerMainAllowedRolesTest {
.contains("Access denied: not authorized to call tool
'order_costs'")
.doesNotContain("costs=42")
.doesNotContain("finance");
+ // the mark a client tells the refusal from a tool error by,
without reading the text
+ assertThat(result.meta()).containsOnly(
+ Map.entry(McpServerConstants.META_AUTHORIZATION,
McpServerConstants.META_AUTHORIZATION_DENIED));
} finally {
client.closeGracefully();
}
diff --git
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/McpStdioHarnessMain.java
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/McpStdioHarnessMain.java
index f064b90fb83f..c7f118ed53de 100644
---
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/McpStdioHarnessMain.java
+++
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/McpStdioHarnessMain.java
@@ -64,6 +64,11 @@ public final class McpStdioHarnessMain {
.to("stream:out")
.setBody(constant("printed"));
+ // over stdio no caller has roles, so this tool refuses every
call
+ from("ai-tool:order_costs?tags=" + tags + "&description=Costs
of a production order"
+ + "&allowedRoles=finance")
+ .setBody(constant("costs=42"));
+
// Fixed resource and URI-template routes exercise the real
MCP stdio protocol.
from("ai-resource:stdio_config?resourceUri=camel:///stdio/config&tags=" + tags
+ "&description=A fixed stdio resource&title=Fixed stdio
resource")
diff --git
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerProcessIT.java
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerProcessIT.java
index a98b5a3aa926..290355be314f 100644
---
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerProcessIT.java
+++
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/stdio/StdioMcpServerProcessIT.java
@@ -30,6 +30,7 @@ import
io.modelcontextprotocol.client.transport.ServerParameters;
import io.modelcontextprotocol.client.transport.StdioClientTransport;
import io.modelcontextprotocol.json.McpJsonDefaults;
import io.modelcontextprotocol.spec.McpSchema;
+import org.apache.camel.component.mcp.server.McpServerConstants;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -171,6 +172,25 @@ class StdioMcpServerProcessIT {
}
}
+ @Test
+ void testStdioMcpServerMarksACallRefusedByTheAuthorizationCheck() {
+ McpSyncClient client = null;
+ try {
+ client = createClient();
+ client.initialize();
+
+ McpSchema.CallToolResult result = client.callTool(new
McpSchema.CallToolRequest("order_costs", Map.of()));
+ assertThat(result.isError()).isEqualTo(Boolean.TRUE);
+ assertThat(textOf(result)).isEqualTo("Access denied: not
authorized to call tool 'order_costs'");
+ assertThat(result.meta()).containsOnly(
+ Map.entry(McpServerConstants.META_AUTHORIZATION,
McpServerConstants.META_AUTHORIZATION_DENIED));
+ } finally {
+ if (client != null) {
+ client.closeGracefully();
+ }
+ }
+ }
+
@Test
void
testStdioMcpServerStartsWhenTheContextClassLoaderCannotSeeTheJsonMapper() {
McpSyncClient client = null;
diff --git
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/vertx/VertxMcpModernClientTest.java
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/vertx/VertxMcpModernClientTest.java
index c61f0ec368a9..df3f6db47650 100644
---
a/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/vertx/VertxMcpModernClientTest.java
+++
b/components/camel-ai/camel-mcp-server/src/test/java/org/apache/camel/component/mcp/server/vertx/VertxMcpModernClientTest.java
@@ -37,6 +37,7 @@ import org.apache.camel.component.mcp.server.McpProtocolEra;
import org.apache.camel.component.mcp.server.McpResourceReadHandler;
import org.apache.camel.component.mcp.server.McpResourceReadResult;
import org.apache.camel.component.mcp.server.McpResourceTemplateReadHandler;
+import org.apache.camel.component.mcp.server.McpServerConstants;
import org.apache.camel.component.mcp.server.McpServerInfo;
import org.apache.camel.component.mcp.server.McpServerPrompt;
import org.apache.camel.component.mcp.server.McpServerResource;
@@ -138,6 +139,23 @@ class VertxMcpModernClientTest {
assertThat(engine.sessionCount()).isZero();
}
+ @Test
+ void aToolResultCarriesItsMeta() {
+ engine.toolAdded(tool("guarded", arguments -> new McpToolCallResult(
+ "Access denied", true, null,
+ Map.of(McpServerConstants.META_AUTHORIZATION,
McpServerConstants.META_AUTHORIZATION_DENIED))));
+
+ McpSchema.CallToolResult result =
client.tool("guarded").arguments(Map.of("city", "Rome")).call();
+
+ assertThat(result.isError()).isTrue();
+
assertThat(result.content()).singleElement().isInstanceOfSatisfying(McpSchema.TextContent.class,
+ text -> assertThat(text.text()).isEqualTo("Access denied"));
+ // next to the entry the server adds to every result of this protocol
version
+ assertThat(result.meta())
+ .containsEntry(McpServerConstants.META_AUTHORIZATION,
McpServerConstants.META_AUTHORIZATION_DENIED)
+ .containsKey(McpSchema.MetaKeys.SERVER_INFO);
+ }
+
@Test
void readsResourcesAndTemplates() {
assertThat(client.resources().list().resources()).extracting(McpSchema.Resource::uri)
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index 345486cc25c5..0d4329074f07 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -953,6 +953,15 @@ Serving 2026-07-28 is a preview, built on an API of the
MCP Java SDK that may st
`modern` serves only 2026-07-28. The new option `camel.server.mcp-stateless =
true` also serves the clients that open
with `initialize` without a session. The MCP Java SDK is upgraded to 2.2.0.
+=== camel-mcp-server - a tool call refused by the authorization check is
marked in _meta
+
+On Camel Main and Camel JBang, the result of a tool call that the
`authorizationPolicy` or `allowedRoles` check of the
+tool refused now carries `"org.apache.camel/authorization": "denied"` in its
`_meta` field. The text and `isError` are
+as before.
+
+The record `McpToolCallResult` has a new component `meta` for this, and its
constructors are as before. A custom
+`McpServerEngine` passes `meta()`, when it is not null, to the `_meta` of the
result.
+
=== camel-oauth - the scp claim is included in scope checks
JWT validation and token introspection now read scopes from both the standard
`scope` claim and the