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 74ef95d1c15e CAMEL-26932: camel-jbang-plugin-mcp - camel mcp without 
JBang says how to run the MCP server instead (#30023)
74ef95d1c15e is described below

commit 74ef95d1c15ea2e7ec3c8dab08b9bd5bff911d3c
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 20:21:15 2026 +0100

    CAMEL-26932: camel-jbang-plugin-mcp - camel mcp without JBang says how to 
run the MCP server instead (#30023)
    
    camel mcp always runs the MCP server with JBang; without JBang, as with the 
launcher, it failed as an internal error
    (exit 70) with a 23-line stack trace. It now exits with 1 and says that 
JBang is not installed, and how to run the
    server without it (java -jar camel-jbang-mcp-<version>-runner.jar, as the 
MCP server documentation shows).
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 dsl/camel-jbang/camel-jbang-plugin-mcp/pom.xml     | 11 ++++++
 .../dsl/jbang/core/commands/mcp/McpCommand.java    | 18 ++++++++-
 .../jbang/core/commands/mcp/McpCommandTest.java    | 44 ++++++++++++++++++++++
 3 files changed, 71 insertions(+), 2 deletions(-)

diff --git a/dsl/camel-jbang/camel-jbang-plugin-mcp/pom.xml 
b/dsl/camel-jbang/camel-jbang-plugin-mcp/pom.xml
index d1d1fd6824d2..a989e4e270d5 100644
--- a/dsl/camel-jbang/camel-jbang-plugin-mcp/pom.xml
+++ b/dsl/camel-jbang/camel-jbang-plugin-mcp/pom.xml
@@ -45,6 +45,17 @@
             <groupId>org.apache.camel</groupId>
             <artifactId>camel-jbang-core</artifactId>
         </dependency>
+
+        <dependency>
+            <groupId>org.junit.jupiter</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommand.java
 
b/dsl/camel-jbang/camel-jbang-plugin-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommand.java
index 5023f1627453..d2f95ff9ddb7 100644
--- 
a/dsl/camel-jbang/camel-jbang-plugin-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommand.java
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommand.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.dsl.jbang.core.commands.mcp;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -23,6 +24,7 @@ import org.aesh.command.CommandDefinition;
 import org.aesh.command.option.Option;
 import org.apache.camel.dsl.jbang.core.commands.CamelCommand;
 import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.common.CliException;
 import org.apache.camel.dsl.jbang.run.common.VersionHelper;
 
 @CommandDefinition(name = "mcp", description = "MCP server for AI coding 
assistants", generateHelp = true)
@@ -42,6 +44,9 @@ public class McpCommand extends CamelCommand {
     @Option(name = "version", description = "Camel MCP server version to use 
(default: current Camel version)")
     String version;
 
+    // the JBang command, which runs the MCP server
+    String jbang = "jbang";
+
     public McpCommand(CamelJBangMain main) {
         super(main);
     }
@@ -54,7 +59,7 @@ public class McpCommand extends CamelCommand {
         }
 
         List<String> cmd = new ArrayList<>();
-        cmd.add("jbang");
+        cmd.add(jbang);
         cmd.add("-Dquarkus.log.level=" + logLevel);
         if (http) {
             cmd.add("-Dquarkus.http.host-enabled=true");
@@ -64,7 +69,16 @@ public class McpCommand extends CamelCommand {
 
         ProcessBuilder pb = new ProcessBuilder(cmd);
         pb.inheritIO();
-        Process process = pb.start();
+        Process process;
+        try {
+            process = pb.start();
+        } catch (IOException e) {
+            // without JBang this was an internal error (exit 70) with a stack 
trace (CAMEL-26932)
+            throw CliException.failure("camel mcp runs the MCP server with 
JBang, which is not installed (" + e.getMessage()
+                                       + "). Install JBang 
(https://www.jbang.dev), or run the server without it: java -jar"
+                                       + " camel-jbang-mcp-" + mcpVersion + 
"-runner.jar (see the Camel MCP server"
+                                       + " documentation)");
+        }
         return process.waitFor();
     }
 }
diff --git 
a/dsl/camel-jbang/camel-jbang-plugin-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommandTest.java
 
b/dsl/camel-jbang/camel-jbang-plugin-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommandTest.java
new file mode 100644
index 000000000000..698fe2b69b07
--- /dev/null
+++ 
b/dsl/camel-jbang/camel-jbang-plugin-mcp/src/test/java/org/apache/camel/dsl/jbang/core/commands/mcp/McpCommandTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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 org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
+import org.apache.camel.dsl.jbang.core.common.CliException;
+import org.apache.camel.dsl.jbang.core.common.CliExitCode;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/**
+ * camel mcp without JBang says what to do instead (CAMEL-26932).
+ */
+class McpCommandTest {
+
+    @Test
+    void withoutJBangSaysHowToRunTheServer() {
+        McpCommand command = new McpCommand(new CamelJBangMain());
+        command.jbang = "no-such-jbang-command-26932";
+        command.version = "4.24.0";
+
+        assertThatThrownBy(command::doCall)
+                .isInstanceOfSatisfying(CliException.class,
+                        e -> 
assertThat(e.getExitCode()).isEqualTo(CliExitCode.FAILURE))
+                .hasMessageContaining("which is not installed")
+                .hasMessageContaining("java -jar 
camel-jbang-mcp-4.24.0-runner.jar");
+    }
+}

Reply via email to