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 5dee29087f67 CAMEL-26932: camel-jbang-mcp - the answers of the MCP 
server name its own tools, not those of camel ask (#30037)
5dee29087f67 is described below

commit 5dee29087f670ff3dfc98afa19b55da71b10c6e8
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 16:48:36 2026 +0100

    CAMEL-26932: camel-jbang-mcp - the answers of the MCP server name its own 
tools, not those of camel ask (#30037)
    
    The tools the MCP server shares with camel ask answer with the names of 
camel ask: "list_processes shows what runs",
    "Use list_examples to see the examples", "Use select_process to connect to 
one". The MCP server has none of these, so
    a client called a tool that does not exist. The answers and errors of the 
shared tools now name the tools of the
    server (camel_runtime_processes, camel_catalog_examples, 
camel_catalog_example_file, and the nameOrPid argument).
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../dsl/jbang/core/commands/mcp/AiTraceTools.java  |  5 +-
 .../jbang/core/commands/mcp/AuthoringTools.java    |  4 +-
 .../dsl/jbang/core/commands/mcp/McpToolNames.java  | 75 ++++++++++++++++++++++
 .../dsl/jbang/core/commands/mcp/RuntimeTools.java  |  4 +-
 .../jbang/core/commands/mcp/McpToolNamesTest.java  | 59 +++++++++++++++++
 5 files changed, 141 insertions(+), 6 deletions(-)

diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
index f641d53548d1..3cf96f77a0ce 100644
--- 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AiTraceTools.java
@@ -116,10 +116,11 @@ public class AiTraceTools {
     JsonObject executeRegistryTool(String toolName, ToolContext ctx, 
Map<String, String> args) {
         try {
             Object result = ToolRegistry.execute(toolName, ctx, args);
-            return RuntimeTools.toJsonObject(result);
+            return McpToolNames.of(RuntimeTools.toJsonObject(result));
         } catch (ToolExecutionException e) {
             // such as no answer from the integration: not the same as an 
integration without AI components
-            throw new ToolCallException("Failed to collect AI trace data (" + 
toolName + "): " + e.getMessage(), null);
+            throw new ToolCallException(
+                    "Failed to collect AI trace data (" + toolName + "): " + 
McpToolNames.of(e.getMessage()), null);
         }
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AuthoringTools.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AuthoringTools.java
index 5a59f7547d41..dabfcbe93e25 100644
--- 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AuthoringTools.java
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AuthoringTools.java
@@ -589,9 +589,9 @@ public class AuthoringTools {
                             e.getMessage());
                 }
             }
-            return RuntimeTools.toJsonObject(ToolRegistry.execute(tool, ctx, 
args));
+            return 
McpToolNames.of(RuntimeTools.toJsonObject(ToolRegistry.execute(tool, ctx, 
args)));
         } catch (ToolExecutionException e) {
-            throw new ToolCallException(e.getMessage(), e);
+            throw new ToolCallException(McpToolNames.of(e.getMessage()), e);
         }
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpToolNames.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpToolNames.java
new file mode 100644
index 000000000000..e0eacddf56b9
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpToolNames.java
@@ -0,0 +1,75 @@
+/*
+ * 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.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.camel.util.json.JsonObject;
+import org.apache.camel.util.json.Jsoner;
+
+/**
+ * The names of the tools of the MCP server in the answers of the tools it 
shares with camel ask: they name the tools of
+ * camel ask (list_processes, list_examples), which the MCP server does not 
have, so a client called a tool that does
+ * not exist (CAMEL-26932).
+ */
+final class McpToolNames {
+
+    private static final Map<String, String> NAMES = Map.of(
+            "list_processes", "camel_runtime_processes",
+            "list_examples", "camel_catalog_examples",
+            "get_example_file", "camel_catalog_example_file");
+
+    private static final Pattern NAME = Pattern.compile("\\b(" + 
String.join("|", NAMES.keySet()) + ")\\b");
+
+    // camel ask selects an integration with a tool of its own; a tool of the 
MCP server takes it as an argument
+    private static final String SELECT = "Use select_process to connect to 
one.";
+    private static final String SELECT_MCP = "Pass nameOrPid to the tool to 
pick one.";
+
+    private McpToolNames() {
+    }
+
+    /**
+     * The text with the tool names of camel ask replaced by those of the MCP 
server.
+     */
+    static String of(String text) {
+        if (text == null) {
+            return null;
+        }
+        String answer = text.replace(SELECT, SELECT_MCP);
+        Matcher m = NAME.matcher(answer);
+        StringBuilder sb = new StringBuilder();
+        while (m.find()) {
+            m.appendReplacement(sb, NAMES.get(m.group(1)));
+        }
+        m.appendTail(sb);
+        return sb.toString();
+    }
+
+    /**
+     * The answer with the tool names of camel ask replaced by those of the 
MCP server.
+     */
+    static JsonObject of(JsonObject answer) {
+        if (answer == null) {
+            return null;
+        }
+        String json = answer.toJson();
+        String renamed = of(json);
+        return renamed.equals(json) ? answer : (JsonObject) 
Jsoner.deserialize(renamed, new JsonObject());
+    }
+}
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeTools.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeTools.java
index aeaf8f809a7c..33415ec71e6a 100644
--- 
a/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeTools.java
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/RuntimeTools.java
@@ -102,9 +102,9 @@ public class RuntimeTools {
         ctx.selectProcess(p.pid());
         try {
             Object result = ToolRegistry.execute(registryToolName, ctx, args);
-            return toJsonObject(result);
+            return McpToolNames.of(toJsonObject(result));
         } catch (ToolExecutionException e) {
-            throw new ToolCallException(e.getMessage(), e);
+            throw new ToolCallException(McpToolNames.of(e.getMessage()), e);
         }
     }
 
diff --git 
a/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpToolNamesTest.java
 
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpToolNamesTest.java
new file mode 100644
index 000000000000..da6a50f955ea
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpToolNamesTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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 io.quarkiverse.mcp.server.ToolCallException;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * The answers of the MCP server name its own tools, not those of camel ask 
(CAMEL-26932).
+ */
+class McpToolNamesTest {
+
+    @Test
+    void theToolsOfCamelAskAreNamedAsTheToolsOfTheServer() {
+        assertThat(McpToolNames.of("No running Camel process matches 'orders'; 
list_processes shows what runs"))
+                .isEqualTo("No running Camel process matches 'orders'; 
camel_runtime_processes shows what runs");
+        assertThat(McpToolNames.of("Example not found: nope. Use list_examples 
to see the examples."))
+                .isEqualTo("Example not found: nope. Use 
camel_catalog_examples to see the examples.");
+        assertThat(McpToolNames.of("No process selected. Use select_process to 
connect to one."))
+                .isEqualTo("No process selected. Pass nameOrPid to the tool to 
pick one.");
+        // only whole names
+        
assertThat(McpToolNames.of("my_list_processes_x")).isEqualTo("my_list_processes_x");
+    }
+
+    @Test
+    void anAnswer() {
+        JsonObject answer = new JsonObject();
+        answer.put("hint", "list_processes shows it once it is up");
+
+        
assertThat(McpToolNames.of(answer).getString("hint")).isEqualTo("camel_runtime_processes
 shows it once it is up");
+    }
+
+    @Test
+    void anUnknownExampleNamesTheExampleToolOfTheServer() {
+        // CAMEL-26932: the answer said "Use list_examples", a tool the MCP 
server does not have
+        assertThatThrownBy(() -> AuthoringTools.call("get_example_file",
+                AuthoringTools.args("example", "no-such-example-26932", 
"file", "x")))
+                .isInstanceOf(ToolCallException.class)
+                .hasMessageNotContaining("list_examples");
+    }
+}

Reply via email to