diff options
| author | Michael Peter Christen <mc@yacy.net> | 2025-10-12 23:22:17 +0200 |
|---|---|---|
| committer | Michael Peter Christen <mc@yacy.net> | 2025-10-12 23:22:17 +0200 |
| commit | d61b3b85e7c23de9762d7e3613795f08162adbbf (patch) | |
| tree | d7be385e14308ce21cd257afbd63198f15fa881f /source | |
| parent | bc72f36c0b2c394802b3a41c7a821f871650679d (diff) | |
code cleanup
Diffstat (limited to 'source')
| -rw-r--r-- | source/net/yacy/http/servlets/MCPSearchServlet.java | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/source/net/yacy/http/servlets/MCPSearchServlet.java b/source/net/yacy/http/servlets/MCPSearchServlet.java index 7734559e0..ffca72aac 100644 --- a/source/net/yacy/http/servlets/MCPSearchServlet.java +++ b/source/net/yacy/http/servlets/MCPSearchServlet.java @@ -127,7 +127,7 @@ public class MCPSearchServlet extends HttpServlet { private JSONObject handleRequest(final JSONObject requestObject) { final Object id = requestObject.opt("id"); final String jsonrpc = requestObject.optString("jsonrpc", JSONRPC_VERSION); - final String method = requestObject.optString("method", ""); + String method = requestObject.optString("method", ""); if (!JSONRPC_VERSION.equals(jsonrpc)) { return errorResponse(id, -32600, "Unsupported JSON-RPC version"); @@ -136,10 +136,19 @@ public class MCPSearchServlet extends HttpServlet { if (method == null || method.isEmpty()) { return errorResponse(id, -32600, "Missing method"); } + + // because of unclear specification of the method tag, we skip everything before a slash or a dot + int slash = method.indexOf('/'); + int dot = method.indexOf('.'); + if (slash > 0) { + method = method.substring(slash + 1); + } else if (dot > 0) { + method = method.substring(dot + 1); + } if (id == JSONObject.NULL || id == null) { // Notification: acknowledge silently - if ("notifications/ping".equals(method)) { + if ("ping".equals(method)) { return null; } // No response for other notifications either @@ -149,16 +158,10 @@ public class MCPSearchServlet extends HttpServlet { switch (method) { case "initialize": return handleInitialize(id, requestObject.optJSONObject("params")); - case "tools/initialize": - return handleInitialize(id, requestObject.optJSONObject("params")); case "list": return handleToolsList(id); - case "tools/list": - return handleToolsList(id); case "call": return handleToolsCall(id, requestObject.optJSONObject("params")); - case "tools/call": - return handleToolsCall(id, requestObject.optJSONObject("params")); default: return errorResponse(id, -32601, "Unknown method: " + method); } |
