jeecgboot/JeecgBoot · warning · RuntimeException
不支持的运算符: {op}
Error message
不支持的运算符: {op} What it means
Inside the 'calculate' tool of the MCP demo, the operator switch accepts only '+', '-', '*', '/'. Any other operator string throws a RuntimeException that becomes a tool-call error returned to the MCP client. Note '/' with b==0 yields NaN rather than erroring.
Source
Thrown at jeecg-boot/jeecg-boot-module/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/mcp/McpDemoController.java:289
if (name == null || name.isEmpty()) {
name = "World";
}
yield "你好, " + name + "! 欢迎使用 JeecgBoot MCP 服务!";
}
case "get_time" -> {
yield "当前时间: " + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
}
case "calculate" -> {
double a = arguments.getDoubleValue("a");
double b = arguments.getDoubleValue("b");
String op = arguments.getString("operator");
if (op == null) op = "+";
double res = switch (op) {
case "+" -> a + b;
case "-" -> a - b;
case "*" -> a * b;
case "/" -> b != 0 ? a / b : Double.NaN;
default -> throw new RuntimeException("不支持的运算符: " + op);
};
yield String.format("%.2f %s %.2f = %.2f", a, op, b, res);
}
default -> throw new RuntimeException("未知工具: " + toolName);
};
return Map.of(
"content", List.of(Map.of(
"type", "text",
"text", result
))
);
}
/**
* 使用说明页面
*/
@IgnoreAuthView on GitHub (pinned to 96fb33f5ec)
Solutions
- Use one of +, -, *, /.
- If more operators are needed, extend the switch and document them in the tool schema.
Example fix
// before
default -> throw new RuntimeException("不支持的运算符: " + op);
// after - accept extra operators
case "%", "mod" -> b != 0 ? a % b : Double.NaN;
case "^", "**" -> Math.pow(a, b); Defensive patterns
Strategy: validation
Validate before calling
private static final Set<String> ALLOWED_OPS = Set.of("+","-","*","/","%","^");
String op = arguments.getString("operator");
if (op != null && !ALLOWED_OPS.contains(op)) {
// return a tool error: unsupported operator
} Try / catch
// tool-call errors are returned to the client as a content result; ensure the message // lists the allowed operators so the caller can self-correct.
Prevention
- Document allowed operators in the tool's input schema.
- Validate before the switch so the error message is actionable.
When it happens
Trigger: Client passes an operator like 'mod', '^', 'div', '**', or a localized symbol not in the switch.
Common situations: Client expects extended math; user-typed operator; locale-specific symbols.
Related errors
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/193ea18d99230628.
Report an issue: GitHub.