gnodet-bot commented on code in PR #30619:
URL: https://github.com/apache/camel/pull/30619#discussion_r4659933217


##########
dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java:
##########
@@ -1020,12 +1020,70 @@ public static boolean isMcpStdioEnabled(boolean 
mcpStdio, Properties profileProp
                 && 
"stdio".equalsIgnoreCase(profileProperties.getProperty("camel.server.mcp-transport",
 "").trim());
     }
 
+    /**
+     * Whether the ai-tool routes are served over MCP stdio: with the option, 
or with camel.server.mcp-transport=stdio
+     * from any property source that the run reads up front: --prop, a JVM 
system property, an environment variable or
+     * the profile properties (CAMEL-27404). The run decides it before 
starting, as it logs to stderr then.
+     */
+    public static boolean isMcpStdioEnabled(RunRequest request, Properties 
profileProperties) {
+        if (request.mcpStdio) {
+            return true;
+        }
+        String transport = serverProperty(request, profileProperties, 
"mcp-transport", "mcpTransport");
+        return transport != null && "stdio".equalsIgnoreCase(transport.trim());
+    }
+
+    /**
+     * Whether the ai-tool routes are served over MCP, with 
camel.server.mcp-enabled from --prop, a JVM system property,
+     * an environment variable or the profile properties. Over HTTP, the run 
does not depend on it: camel-main resolves
+     * it at runtime, turns the HTTP server on and downloads camel-mcp-server 
and camel-platform-http-main on demand.
+     */
     boolean isAiToolMcpServerEnabled(Properties profileProperties) {
         if (isMcpStdioEnabled(profileProperties)) {
             return true;
         }
-        return profileProperties != null
-                && 
"true".equalsIgnoreCase(profileProperties.getProperty("camel.server.mcp-enabled",
 "").trim());
+        return isTrue(serverProperty(request, profileProperties, 
"mcp-enabled", "mcpEnabled"));
+    }
+
+    /**
+     * A camel.server option (by its dashed or camelCase name) from the 
sources that camel-main reads, in the order that
+     * wins there: --prop, JVM system property, environment variable, profile 
properties.
+     */
+    static String serverProperty(RunRequest request, Properties 
profileProperties, String dashed, String camelCase) {
+        String answer = null;
+        for (String option : new String[] { dashed, camelCase }) {
+            answer = propertyOfAnySource(request, profileProperties, 
"camel.server." + option);
+            if (answer != null) {
+                break;
+            }
+        }
+        return answer;
+    }
+
+    private static String propertyOfAnySource(RunRequest request, Properties 
profileProperties, String key) {
+        String answer = argumentProperty(request, key);
+        if (answer == null) {
+            answer = System.getProperty(key);
+        }
+        if (answer == null) {
+            answer = System.getenv(key.toUpperCase(Locale.ROOT).replace('.', 
'_').replace('-', '_'));

Review Comment:
   ⚠️ **Narrower env-var lookup than `IOHelper.lookupEnvironmentVariable`**
   
   `IOHelper.lookupEnvironmentVariable(key)` tries three forms: raw uppercase, 
dots/dashes → underscores, and camelCase → dash normalization. This hand-rolled 
call only tries one (dots/dashes → underscores). Users relying on a camelCase 
env-var form for `camel.server.mcp-*` options will get silent lookup misses.
   
   Consider: `answer = IOHelper.lookupEnvironmentVariable(key);`
   
   `IOHelper` is already on the classpath in `camel-jbang-run`.



##########
dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunPipeline.java:
##########
@@ -1020,12 +1020,70 @@ public static boolean isMcpStdioEnabled(boolean 
mcpStdio, Properties profileProp
                 && 
"stdio".equalsIgnoreCase(profileProperties.getProperty("camel.server.mcp-transport",
 "").trim());
     }
 
+    /**
+     * Whether the ai-tool routes are served over MCP stdio: with the option, 
or with camel.server.mcp-transport=stdio
+     * from any property source that the run reads up front: --prop, a JVM 
system property, an environment variable or
+     * the profile properties (CAMEL-27404). The run decides it before 
starting, as it logs to stderr then.
+     */
+    public static boolean isMcpStdioEnabled(RunRequest request, Properties 
profileProperties) {
+        if (request.mcpStdio) {
+            return true;
+        }
+        String transport = serverProperty(request, profileProperties, 
"mcp-transport", "mcpTransport");
+        return transport != null && "stdio".equalsIgnoreCase(transport.trim());
+    }
+
+    /**
+     * Whether the ai-tool routes are served over MCP, with 
camel.server.mcp-enabled from --prop, a JVM system property,
+     * an environment variable or the profile properties. Over HTTP, the run 
does not depend on it: camel-main resolves
+     * it at runtime, turns the HTTP server on and downloads camel-mcp-server 
and camel-platform-http-main on demand.
+     */
     boolean isAiToolMcpServerEnabled(Properties profileProperties) {
         if (isMcpStdioEnabled(profileProperties)) {
             return true;
         }
-        return profileProperties != null
-                && 
"true".equalsIgnoreCase(profileProperties.getProperty("camel.server.mcp-enabled",
 "").trim());
+        return isTrue(serverProperty(request, profileProperties, 
"mcp-enabled", "mcpEnabled"));
+    }
+
+    /**
+     * A camel.server option (by its dashed or camelCase name) from the 
sources that camel-main reads, in the order that
+     * wins there: --prop, JVM system property, environment variable, profile 
properties.
+     */
+    static String serverProperty(RunRequest request, Properties 
profileProperties, String dashed, String camelCase) {
+        String answer = null;
+        for (String option : new String[] { dashed, camelCase }) {
+            answer = propertyOfAnySource(request, profileProperties, 
"camel.server." + option);
+            if (answer != null) {
+                break;
+            }
+        }
+        return answer;
+    }
+
+    private static String propertyOfAnySource(RunRequest request, Properties 
profileProperties, String key) {
+        String answer = argumentProperty(request, key);
+        if (answer == null) {
+            answer = System.getProperty(key);
+        }
+        if (answer == null) {
+            answer = System.getenv(key.toUpperCase(Locale.ROOT).replace('.', 
'_').replace('-', '_'));
+        }
+        if (answer == null && profileProperties != null) {
+            answer = profileProperties.getProperty(key);
+        }
+        return answer;
+    }
+
+    private static String argumentProperty(RunRequest request, String key) {

Review Comment:
   💡 **Duplication with `argumentOrProfileProperty`**
   
   The loop body here (lines 1078–1086) is character-for-character identical to 
the first half of the existing instance method `argumentOrProfileProperty` 
(lines 1126–1133). Consider refactoring `argumentOrProfileProperty` to delegate:
   
   ```java
   private String argumentOrProfileProperty(Properties profileProperties, 
String key) {
       String answer = argumentProperty(request, key);
       return answer != null ? answer : (profileProperties != null ? 
profileProperties.getProperty(key) : null);
   }
   ```



##########
components/camel-ai/camel-mcp-server/src/main/docs/mcp-server.adoc:
##########
@@ -218,7 +218,14 @@ Tag patterns support wildcards: use `+*+` to expose all 
tagged tools, or a
 prefix pattern like `+crm*+` to expose all tags starting with `crm`:
 
 The MCP endpoint is then served at `http://<host>:<port>/mcp` on the Camel
-main HTTP server. Any MCP client can connect over streamable HTTP, for
+main HTTP server.
+
+On Camel JBang (`camel run`), `camel.server.mcp-enabled = true` turns the HTTP 
server on by itself, so
+`camel.server.enabled = true` can be left out, and `camel-mcp-server` and 
`camel-platform-http-main` are downloaded on
+demand. As `camel.server.enabled`, the `camel.server.mcp-*` options work from 
every property source:
+`application.properties`, `--prop`, JVM system properties (`-D`) and 
environment variables, for example
+`camel run tools.yaml --prop camel.server.mcp-enabled=true --mcp-tags=crm`. 
Set `camel.server.enabled = false` to keep
+the HTTP server off. On Camel Main, set `camel.server.enabled = true` as shown 
above. Any MCP client can connect over streamable HTTP, for

Review Comment:
   📝 **Run-on sentence** — "Set `camel.server.enabled = false` to keep the HTTP 
server off." and "On Camel Main, set `camel.server.enabled = true` as shown 
above." are two separate topics on the same line. Consider splitting them into 
distinct sentences or a new paragraph.



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