From 4f51bbaab41740a0c752dcb311aa274b52e6ae32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E6=98=8A?= Date: Mon, 18 May 2026 20:37:43 +0800 Subject: [PATCH] fix(mcp): comply with spec on protocol version negotiation The initialize handler returned JSON-RPC error -32602 for any client protocolVersion that did not exactly equal '2025-03-26'. This violates the MCP spec on version negotiation, which requires the server to respond with a version it does support and let the client decide whether to continue or disconnect. The strict-equality check broke every client newer than 2025-03-26 (e.g. Claude Code now sends '2025-11-25'), forcing users to either pin to an old client or patch the vendor. Fix: drop the rejection branch. The server already responds with kSupportedProtocolVersion in the result; that is the entire contract. --- src/mcp/mcp_server.cpp | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/mcp/mcp_server.cpp b/src/mcp/mcp_server.cpp index d707ca6..2213e9b 100644 --- a/src/mcp/mcp_server.cpp +++ b/src/mcp/mcp_server.cpp @@ -145,17 +145,10 @@ json McpServer::handleInitialize(const json& msg) { json id = msg.value("id", json(nullptr)); - // Validate client protocol version for compatibility + // Per MCP spec: always respond with the version we support; the client + // decides whether to continue or disconnect. Strict equality on the + // client's requested version was wrong and breaks newer clients. static constexpr const char* kSupportedProtocolVersion = "2025-03-26"; - json params = msg.value("params", json::object()); - if (params.contains("protocolVersion")) { - std::string clientVersion = params["protocolVersion"].get(); - if (clientVersion != kSupportedProtocolVersion) { - return makeError(id, -32602, - "Unsupported protocol version: " + clientVersion + - " (server supports " + kSupportedProtocolVersion + ")"); - } - } json result; result["protocolVersion"] = kSupportedProtocolVersion;