{"record":{"id":"193ea18d99230628","repo":"jeecgboot/JeecgBoot","slug":"op","errorCode":null,"errorMessage":"不支持的运算符: {op}","messagePattern":"不支持的运算符: (.+?)","errorType":"validation","errorClass":"RuntimeException","httpStatus":null,"severity":"warning","filePath":"jeecg-boot/jeecg-boot-module/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/mcp/McpDemoController.java","lineNumber":289,"sourceCode":"                if (name == null || name.isEmpty()) {\n                    name = \"World\";\n                }\n                yield \"你好, \" + name + \"! 欢迎使用 JeecgBoot MCP 服务!\";\n            }\n            case \"get_time\" -> {\n                yield \"当前时间: \" + LocalDateTime.now().format(DateTimeFormatter.ofPattern(\"yyyy-MM-dd HH:mm:ss\"));\n            }\n            case \"calculate\" -> {\n                double a = arguments.getDoubleValue(\"a\");\n                double b = arguments.getDoubleValue(\"b\");\n                String op = arguments.getString(\"operator\");\n                if (op == null) op = \"+\";\n                double res = switch (op) {\n                    case \"+\" -> a + b;\n                    case \"-\" -> a - b;\n                    case \"*\" -> a * b;\n                    case \"/\" -> b != 0 ? a / b : Double.NaN;\n                    default -> throw new RuntimeException(\"不支持的运算符: \" + op);\n                };\n                yield String.format(\"%.2f %s %.2f = %.2f\", a, op, b, res);\n            }\n            default -> throw new RuntimeException(\"未知工具: \" + toolName);\n        };\n        \n        return Map.of(\n                \"content\", List.of(Map.of(\n                        \"type\", \"text\",\n                        \"text\", result\n                ))\n        );\n    }\n\n    /**\n     * 使用说明页面\n     */\n    @IgnoreAuth","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-boot-module/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/mcp/McpDemoController.java#L271-L307","documentation":"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.","triggerScenarios":"Client passes an operator like 'mod', '^', 'div', '**', or a localized symbol not in the switch.","commonSituations":"Client expects extended math; user-typed operator; locale-specific symbols.","solutions":["Use one of +, -, *, /.","If more operators are needed, extend the switch and document them in the tool schema."],"exampleFix":"// before\ndefault -> throw new RuntimeException(\"不支持的运算符: \" + op);\n// after - accept extra operators\ncase \"%\", \"mod\" -> b != 0 ? a % b : Double.NaN;\ncase \"^\", \"**\" -> Math.pow(a, b);","handlingStrategy":"validation","validationCode":"private static final Set<String> ALLOWED_OPS = Set.of(\"+\",\"-\",\"*\",\"/\",\"%\",\"^\");\nString op = arguments.getString(\"operator\");\nif (op != null && !ALLOWED_OPS.contains(op)) {\n    // return a tool error: unsupported operator\n}","typeGuard":null,"tryCatchPattern":"// tool-call errors are returned to the client as a content result; ensure the message\n// lists the allowed operators so the caller can self-correct.","preventionTips":["Document allowed operators in the tool's input schema.","Validate before the switch so the error message is actionable."],"tags":["mcp","calculate","validation","demo"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}