{"record":{"id":"fb206021d7195c2c","repo":"jeecgboot/JeecgBoot","slug":"method-fb2060","errorCode":null,"errorMessage":"未知方法: {method}","messagePattern":"未知方法: \\{method\\}","errorType":"exception","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":184,"sourceCode":"            // 构建 JSON-RPC 2.0 响应\n            Map<String, Object> jsonRpcResponse = new LinkedHashMap<>();\n            jsonRpcResponse.put(\"jsonrpc\", \"2.0\");\n            jsonRpcResponse.put(\"id\", id);\n            \n            try {\n                Object result = switch (method) {\n                    case \"initialize\" -> handleInitialize(params);\n                    case \"initialized\", \"notifications/initialized\" -> handleInitialized();\n                    case \"tools/list\" -> handleToolsList();\n                    case \"tools/call\" -> handleToolsCall(params);\n                    case \"ping\" -> handlePing();\n                    case \"notifications/cancelled\" -> handleCancelled(params);\n                    default -> {\n                        if (method != null && method.startsWith(\"notifications/\")) {\n                            log.info(\"[MCP Server] 忽略未知通知: {}\", method);\n                            yield Map.of();\n                        }\n                        throw new RuntimeException(\"未知方法: \" + method);\n                    }\n                };\n                jsonRpcResponse.put(\"result\", result);\n            } catch (Exception e) {\n                log.error(\"[MCP Server] 处理请求失败\", e);\n                jsonRpcResponse.put(\"error\", Map.of(\n                        \"code\", -32603,\n                        \"message\", e.getMessage()\n                ));\n            }\n            \n            String responseJson = JSON.toJSONString(jsonRpcResponse);\n            log.info(\"[MCP Server] 返回: {}\", responseJson);\n            writer.write(responseJson);\n            \n        } catch (Exception e) {\n            log.error(\"[MCP Server] 解析请求失败\", e);\n            writer.write(\"{\\\"jsonrpc\\\":\\\"2.0\\\",\\\"id\\\":null,\\\"error\\\":{\\\"code\\\":-32700,\\\"message\\\":\\\"Parse error\\\"}}\");","sourceCodeStart":166,"sourceCodeEnd":202,"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#L166-L202","documentation":"McpDemoController implements a minimal MCP (Model Context Protocol) JSON-RPC 2.0 server. The switch dispatches only initialize, initialized, notifications/initialized, tools/list, tools/call, ping, notifications/cancelled. Any other method -- that is not a notifications/* (which is silently ignored) -- throws. The exception is caught and returned to the client as JSON-RPC error code -32603 (internal error) with the method name in the message.","triggerScenarios":"An MCP client sends a method the demo server doesn't implement: resources/*, prompts/*, completion/*, logging/*, or any future-spec method.","commonSituations":"Client uses newer MCP spec capabilities the demo lacks; a generic MCP client probing endpoints; custom method invocation.","solutions":["Check the 'method' field in the request and the log line '[MCP Server] 处理请求失败'.","If the client needs the capability, add a case branch and a handler.","If it is a notification, ensure the method starts with 'notifications/' so it is ignored instead of erroring.","Return a proper -32601 'method not found' instead of -32603 if you want spec-correct behavior."],"exampleFix":"// before\ndefault -> throw new RuntimeException(\"未知方法: \" + method);\n// after - spec-correct JSON-RPC method-not-found\ndefault -> {\n    if (method != null && method.startsWith(\"notifications/\")) { yield Map.of(); }\n    throw new RuntimeException(\"Method not found: \" + method); // map to code -32601\n}","handlingStrategy":"validation","validationCode":"private static final Set<String> SUPPORTED = Set.of(\n    \"initialize\",\"initialized\",\"notifications/initialized\",\n    \"tools/list\",\"tools/call\",\"ping\",\"notifications/cancelled\");\nif (method != null && !SUPPORTED.contains(method) && !method.startsWith(\"notifications/\")) {\n    // return JSON-RPC -32601 method not found instead of -32603\n}","typeGuard":null,"tryCatchPattern":"// The handler already catches Exception and maps to error code -32603.\n// Improve: distinguish method-not-found (-32601) from internal errors.\ntry { ... } catch (UnsupportedMethodException e) {\n    jsonRpcResponse.put(\"error\", Map.of(\"code\", -32601, \"message\", e.getMessage()));\n} catch (Exception e) {\n    jsonRpcResponse.put(\"error\", Map.of(\"code\", -32603, \"message\", e.getMessage()));\n}","preventionTips":["Keep the supported-method set in sync with the MCP spec version you target.","Return -32601 for unknown methods to be spec-correct.","Ignore unknown notifications silently rather than erroring."],"tags":["mcp","json-rpc","protocol","demo","validation"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}