fix: negotiate MCP protocol version instead of hardcoding
The initialize handler hardcoded protocolVersion "2024-11-05", which causes newer MCP clients (e.g. Claude Code) to reject the connection when they negotiate "2025-11-25" or later. Echo the client's requested version if it is in the supported set, otherwise fall back to the latest supported version. This keeps backwards compatibility with older clients while allowing newer ones to connect. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -42,6 +42,50 @@ class TestHandleRequest:
|
||||
assert resp["result"]["serverInfo"]["name"] == "mempalace"
|
||||
assert resp["id"] == 1
|
||||
|
||||
def test_initialize_negotiates_client_version(self):
|
||||
from mempalace.mcp_server import handle_request
|
||||
|
||||
resp = handle_request(
|
||||
{
|
||||
"method": "initialize",
|
||||
"id": 1,
|
||||
"params": {"protocolVersion": "2025-11-25"},
|
||||
}
|
||||
)
|
||||
assert resp["result"]["protocolVersion"] == "2025-11-25"
|
||||
|
||||
def test_initialize_negotiates_older_supported_version(self):
|
||||
from mempalace.mcp_server import handle_request
|
||||
|
||||
resp = handle_request(
|
||||
{
|
||||
"method": "initialize",
|
||||
"id": 1,
|
||||
"params": {"protocolVersion": "2025-03-26"},
|
||||
}
|
||||
)
|
||||
assert resp["result"]["protocolVersion"] == "2025-03-26"
|
||||
|
||||
def test_initialize_unknown_version_falls_back_to_latest(self):
|
||||
from mempalace.mcp_server import handle_request
|
||||
|
||||
resp = handle_request(
|
||||
{
|
||||
"method": "initialize",
|
||||
"id": 1,
|
||||
"params": {"protocolVersion": "9999-12-31"},
|
||||
}
|
||||
)
|
||||
from mempalace.mcp_server import SUPPORTED_PROTOCOL_VERSIONS
|
||||
|
||||
assert resp["result"]["protocolVersion"] == SUPPORTED_PROTOCOL_VERSIONS[0]
|
||||
|
||||
def test_initialize_missing_version_uses_oldest(self):
|
||||
from mempalace.mcp_server import handle_request, SUPPORTED_PROTOCOL_VERSIONS
|
||||
|
||||
resp = handle_request({"method": "initialize", "id": 1, "params": {}})
|
||||
assert resp["result"]["protocolVersion"] == SUPPORTED_PROTOCOL_VERSIONS[-1]
|
||||
|
||||
def test_notifications_initialized_returns_none(self):
|
||||
from mempalace.mcp_server import handle_request
|
||||
|
||||
|
||||
Reference in New Issue
Block a user