davsclaus commented on code in PR #25020:
URL: https://github.com/apache/camel/pull/25020#discussion_r3630059860


##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpOutputGuardrail.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.mcp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import io.quarkiverse.mcp.server.Content;
+import io.quarkiverse.mcp.server.TextContent;
+import io.quarkiverse.mcp.server.ToolOutputGuardrail;
+import io.quarkiverse.mcp.server.ToolResponse;
+
+/**
+ * Global output guardrail that performs secret redaction on tool responses 
and logs audit trail entries for tool
+ * results.
+ */
+@ApplicationScoped
+public class McpOutputGuardrail implements ToolOutputGuardrail {

Review Comment:
   Same issue as `McpAccessGuardrail` — this `ToolOutputGuardrail` 
implementation will never be invoked at runtime without per-tool 
`@ToolGuardrails(output = McpOutputGuardrail.class)` annotation on each `@Tool` 
method.
   
   This means secret redaction on tool responses and audit logging of tool 
results are non-functional.
   
   Also, `durationMs` is always `0` (line 86) since the output guardrail has no 
timing context — consider either omitting this field or documenting the 
limitation.



##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpAccessGuardrail.java:
##########
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.mcp;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import io.quarkiverse.mcp.server.ToolCallException;
+import io.quarkiverse.mcp.server.ToolInputGuardrail;
+import io.quarkiverse.mcp.server.ToolManager;
+import io.vertx.core.json.JsonObject;
+
+/**
+ * Global input guardrail that enforces authorization, input sanitization, and 
audit logging before every MCP tool call.
+ * <p>
+ * This is a defense-in-depth layer — even if {@link McpAccessFilter} is 
bypassed, this guardrail blocks unauthorized
+ * tool execution.
+ */
+@ApplicationScoped
+public class McpAccessGuardrail implements ToolInputGuardrail {

Review Comment:
   **Critical: This guardrail will never be invoked at runtime.**
   
   In the Quarkus MCP Server API, `ToolFilter` is auto-discovered as a global 
CDI bean (your `McpAccessFilter` works correctly), but `ToolInputGuardrail` 
requires explicit per-tool association via `@ToolGuardrails(input = 
McpAccessGuardrail.class)` on each `@Tool` method, or programmatic registration 
via `ToolManager.setInputGuardrails()`.
   
   I verified this against the [upstream 
source](https://github.com/quarkiverse/quarkus-mcp-server/blob/main/core/runtime/src/main/java/io/quarkiverse/mcp/server/ToolGuardrails.java)
 and [upstream 
tests](https://github.com/quarkiverse/quarkus-mcp-server/blob/main/transports/http/deployment/src/test/java/io/quarkiverse/mcp/server/test/tools/guardrails/ToolGuardrailsTest.java)
 — every tool that uses guardrails has an explicit `@ToolGuardrails` annotation.
   
   Without this wiring, the input sanitization, authorization defense-in-depth, 
and audit logging handled by this class are **completely non-functional**. The 
unit tests pass because they test the logic directly, bypassing the Quarkus 
CDI/MCP wiring.
   
   There are 266 `@Tool` methods in camel-jbang-mcp and zero `@ToolGuardrails` 
annotations. Options to fix:
   - Add `@ToolGuardrails` to every `@Tool` method (high churn)
   - Move this logic into the `ToolFilter` (which IS global) or a Vert.x/CDI 
interceptor
   - Check with the Quarkus MCP Server team if global guardrail support is 
planned



##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpAuditLogger.java:
##########
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.mcp;
+
+import java.time.Instant;
+
+import jakarta.enterprise.context.ApplicationScoped;
+
+import org.jboss.logging.Logger;
+
+/**
+ * Structured audit logger for MCP tool invocations.
+ * <p>
+ * Produces single-line JSON log entries to a dedicated logger category, 
allowing operators to route audit logs
+ * independently via Quarkus logging configuration.
+ */
+@ApplicationScoped
+public class McpAuditLogger {
+
+    static final String AUDIT_LOGGER_NAME = 
"org.apache.camel.mcp.security.audit";
+
+    private static final Logger AUDIT_LOG = 
Logger.getLogger(AUDIT_LOGGER_NAME);
+
+    public void logToolCall(
+            String tool, String connectionId, String clientName,
+            String accessLevel, String arguments) {
+        AUDIT_LOG.infof(
+                
"{\"event\":\"tool_call\",\"tool\":\"%s\",\"connectionId\":\"%s\","
+                        + 
"\"clientName\":\"%s\",\"accessLevel\":\"%s\",\"arguments\":%s,"
+                        + "\"timestamp\":\"%s\"}",
+                escape(tool), escape(connectionId), escape(clientName),
+                escape(accessLevel), arguments != null ? "\"" + 
escape(arguments) + "\"" : "null",
+                Instant.now().toString());
+    }
+
+    public void logToolResult(
+            String tool, String connectionId, boolean isError,
+            boolean redacted, long durationMs) {
+        AUDIT_LOG.infof(
+                
"{\"event\":\"tool_result\",\"tool\":\"%s\",\"connectionId\":\"%s\","
+                        + 
"\"outcome\":\"%s\",\"redacted\":%s,\"durationMs\":%d,"
+                        + "\"timestamp\":\"%s\"}",
+                escape(tool), escape(connectionId),
+                isError ? "error" : "success", redacted, durationMs,
+                Instant.now().toString());
+    }
+
+    public void logAccessDenied(
+            String tool, String connectionId, String clientName,
+            String requiredLevel, String currentLevel) {
+        AUDIT_LOG.warnf(
+                
"{\"event\":\"access_denied\",\"tool\":\"%s\",\"connectionId\":\"%s\","
+                        + 
"\"clientName\":\"%s\",\"requiredLevel\":\"%s\",\"currentLevel\":\"%s\","
+                        + "\"timestamp\":\"%s\"}",
+                escape(tool), escape(connectionId), escape(clientName),
+                escape(requiredLevel), escape(currentLevel),
+                Instant.now().toString());
+    }
+
+    static String escape(String value) {

Review Comment:
   Minor: this hand-rolled JSON escaping handles `\`, `"`, `\n`, `\r`, `\t` but 
misses `\b` (U+0008) and `\f` (U+000C), which are also required JSON escapes 
per RFC 8259. Consider using Jackson's `JsonStringEncoder` or Vert.x 
`JsonObject` for more robust output — both are already on the classpath.



-- 
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