{"record":{"id":"12136488473facd2","repo":"jeecgboot/JeecgBoot","slug":"toolname","errorCode":null,"errorMessage":"未知工具: {toolName}","messagePattern":"未知工具: \\{toolName\\}","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":293,"sourceCode":"            }\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\n    @GetMapping(\"/info\")\n    @Operation(summary = \"MCP Server 使用说明\")\n    public Map<String, Object> info(HttpServletRequest request) {\n        log.info(\"[MCP Server] Hello 接口被访问\");","sourceCodeStart":275,"sourceCodeEnd":311,"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#L275-L311","documentation":"handleToolsCall() dispatches tools/call by toolName across only 'hello', 'get_time', 'calculate'. Any other toolName throws a RuntimeException that becomes a tool-call error in the MCP response.","triggerScenarios":"A client invokes a tool not present in the static TOOLS list; a typo in the tool name; client/server tool list out of sync.","commonSituations":"Generic MCP client cached an old tool list; typo; tool was renamed.","solutions":["Call only hello, get_time, or calculate.","Re-fetch tools via tools/list to sync the client.","If you add a tool, register it in both the TOOLS array and the switch."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"private static final Set<String> TOOL_NAMES = Set.of(\"hello\",\"get_time\",\"calculate\");\nString toolName = params.getString(\"name\");\nif (!TOOL_NAMES.contains(toolName)) {\n    // return tool error: unknown tool, hint tools/list\n}","typeGuard":null,"tryCatchPattern":"// Return the error as a tool result (isError=true) so the MCP client surfaces it.\nreturn Map.of(\"content\", List.of(Map.of(\"type\",\"text\",\"text\",\"未知工具: \"+toolName)), \"isError\", true);","preventionTips":["Derive TOOL_NAMES from the same array used in tools/list to avoid drift.","Have clients call tools/list before invoking tools/call."],"tags":["mcp","tools","validation","demo"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}