[MLsys2026 Best Paper]: https://arxiv.org/abs/2506.08276. RAG on Everything with LEANN. Enjoy 97% storage savings while running a fast, accurate, and 100% private RAG application on your personal device.
Python aifaissgpt-osslangchainllama-indexllmlocalstorageoffline-firstollamaprivacypythonragretrieval-augmented-generationvector-databasevector-searchvectors
fix(mcp): answer `ping` with an empty result, not -32601 (#411)
Aakash Suresh9c612583f788
diff --git a/packages/leann-core/src/leann/mcp.py b/packages/leann-core/src/leann/mcp.pyindex 7713ec7..4818e54 100755--- a/packages/leann-core/src/leann/mcp.py+++ b/packages/leann-core/src/leann/mcp.py@@ -340,6 +340,18 @@ def handle_request(request):if method == "notifications/initialized":return None+ if method == "ping":+ # MCP requires a ping request to be answered with an empty result.+ # Without this it falls through to the -32601 branch below, which tells+ # a client its liveness probe is unsupported — a different wrong answer+ # from the silence #384 fixed, but still one that breaks keepalives+ # (issue #403).+ return {+ "jsonrpc": "2.0",+ "id": request_id,+ "result": {},+ }+if method == "tools/list":return {"jsonrpc": "2.0",diff --git a/tests/test_mcp_dispatch.py b/tests/test_mcp_dispatch.pynew file mode 100644index 0000000..4f7f868--- /dev/null+++ b/tests/test_mcp_dispatch.py@@ -0,0 +1,38 @@+"""JSON-RPC dispatch rules for the MCP server (see issue #403).++#384 stopped unknown *requests* from being answered with silence, which was+the cause of the client respawn loops. `ping` is not an unknown method though:+it is a required MCP utility, and the spec says a ping request is answered with+an empty result. Answering it with -32601 tells a client its liveness probe is+unsupported, which is a different wrong answer from the original silence.+"""++from leann.mcp import handle_request+++def test_ping_returns_an_empty_result():+ response = handle_request({"jsonrpc": "2.0", "id": 3, "method": "ping"})++ assert response is not None, "silence is what caused the respawn loops"+ assert response["id"] == 3+ assert response["result"] == {}+ assert "error" not in response+++def test_ping_with_params_is_still_a_ping():+ response = handle_request({"jsonrpc": "2.0", "id": 4, "method": "ping", "params": {}})++ assert response["result"] == {}+++def test_unknown_request_still_gets_method_not_found():+ """#384's behaviour must survive: an unknown request is an error, not silence."""+ response = handle_request({"jsonrpc": "2.0", "id": 9, "method": "server/discover"})++ assert response["error"]["code"] == -32601+++def test_notifications_get_no_response():+ """JSON-RPC 2.0: a notification has no id and must never be answered."""+ assert handle_request({"jsonrpc": "2.0", "method": "notifications/initialized"}) is None+ assert handle_request({"jsonrpc": "2.0", "method": "some/unknown/notification"}) is None