Croway commented on code in PR #28683:
URL: https://github.com/apache/camel/pull/28683#discussion_r4412968028
##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/AuthoringTools.java:
##########
@@ -397,9 +398,51 @@ public JsonObject camel_eval_expression(
@ToolArg(description = "e.g. ${random(1,10)} or ${body} ?:
'none'", required = true) String expression,
@ToolArg(description = "simple (default), jsonpath, xpath, jq",
required = false) String language,
@ToolArg(description = "Message body", required = false) String
body,
- @ToolArg(description = NAME_DESC, required = false) String name) {
+ @ToolArg(description = NAME_DESC, required = false) String name,
+ // Object, so the schema takes any JSON: a client sends a JSON
object, or the text of key=value lines
+ @ToolArg(description =
org.apache.camel.dsl.jbang.core.commands.ai.AuthoringTools.EVAL_HEADERS_DESC,
+ required = false) Object headers,
+ @ToolArg(description =
org.apache.camel.dsl.jbang.core.commands.ai.AuthoringTools.EVAL_VARIABLES_DESC,
+ required = false) Object variables,
+ @ToolArg(description =
org.apache.camel.dsl.jbang.core.commands.ai.AuthoringTools.EVAL_PREDICATE_DESC,
+ required = false) Boolean predicate,
+ @ToolArg(description =
org.apache.camel.dsl.jbang.core.commands.ai.AuthoringTools.EVAL_RESULT_TYPE_DESC,
+ required = false) String resultType) {
return call("camel_eval_expression", args("expression", expression,
"language", language, "body", body,
- "name", name));
+ "name", name, "headers", limited("headers",
jsonText(headers)), "variables",
+ limited("variables", jsonText(variables)), "predicate",
predicate, "resultType", resultType));
+ }
+
+ /**
+ * The text of an argument held to the length limit of the string
arguments: McpSecurityInterceptor checks the
+ * arguments that are strings, and a JSON object is not one.
+ */
+ String limited(String argument, String text) {
+ int max = securityConfig != null
+ ? securityConfig.getMaxArgumentLength() :
McpSecurityConfig.DEFAULT_MAX_ARGUMENT_LENGTH;
+ if (text != null && text.length() > max) {
+ throw new ToolCallException(
+ "Argument '" + argument + "' is " + text.length() + "
characters long as JSON, over the limit of "
+ + max + "; nothing was done. Pass
fewer or shorter values, or raise"
+ + "
camel.mcp.security.max-argument-length");
+ }
+ return text;
+ }
+
+ /**
+ * An argument that is a JSON object or text, as the text the shared tool
reads. The server hands a JSON object over
+ * as a Map of Maps, Lists, strings, numbers and booleans, which is the
JSON of the object for Jsoner.
+ */
+ static String jsonText(Object value) {
+ if (value == null || value instanceof String) {
+ return (String) value;
+ }
+ try {
+ return Jsoner.serialize(value);
+ } catch (IllegalArgumentException e) {
+ // not a value Jsoner knows: its own text, which the shared tool
reads or refuses with the reason
+ return value.toString();
+ }
Review Comment:
_Claude Code on behalf of Croway_
The fallback should not be reached: for an argument declared as `Object`,
the Quarkus MCP server hands over the JSON-native values (`Map`, `List`,
`String`, `Number`, `Boolean`), which Jsoner serializes. If a log is wanted,
note that this class uses JBoss Logging (`org.jboss.logging.Logger`), so the
suggestion as written would log a literal `{}`; it would be `LOG.debugf(e,
"Jsoner cannot serialize a %s argument, its toString() is used",
value.getClass().getSimpleName());`.
--
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]