From 098c60c7183aecd2edecb73e71018b6bac6ac0d7 Mon Sep 17 00:00:00 2001 From: Jonathan Springer Date: Sun, 26 Jul 2026 09:31:56 +0100 Subject: [PATCH] Return -32022 for strict-mode protocol version rejections The draft MCP spec requires version-mismatch rejections to use the UnsupportedProtocolVersionError code -32022 (with data.supported / data.requested), not JSON-RPC -32602, which is reserved for malformed params. The strict initialize path in fast-time-server used the wrong code, causing spec-conformant clients to misclassify the server during version negotiation. Use the existing ERR_UNSUPPORTED_PROTOCOL_VERSION constant in mcp_initialize_response, update the strict-mode tests, and correct the README. Fixes #13 Signed-off-by: Jonathan Springer --- mcp-servers/rust/fast-time-server/README.md | 3 ++- mcp-servers/rust/fast-time-server/src/main.rs | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mcp-servers/rust/fast-time-server/README.md b/mcp-servers/rust/fast-time-server/README.md index 6ee0e73..c3ff5c9 100644 --- a/mcp-servers/rust/fast-time-server/README.md +++ b/mcp-servers/rust/fast-time-server/README.md @@ -234,7 +234,8 @@ a mismatching `MCP-Protocol-Version` header is rejected with `HeaderMismatch` `--strict` makes the served set exact. `--protocol 2026-07-28 --strict` runs a pure `2026-07-28` server: every `initialize` call — including ones naming -`2025-11-25` — is rejected with JSON-RPC error `-32602` whose `data.supported` +`2025-11-25` — is rejected with an `UnsupportedProtocolVersionError` (`-32022`) +whose `data.supported` lists only the configured revisions, and `server/discover` advertises only `2026-07-28`. To run a strict server that still accepts the legacy handshake, enable both revisions explicitly: diff --git a/mcp-servers/rust/fast-time-server/src/main.rs b/mcp-servers/rust/fast-time-server/src/main.rs index aa61922..7b20b54 100644 --- a/mcp-servers/rust/fast-time-server/src/main.rs +++ b/mcp-servers/rust/fast-time-server/src/main.rs @@ -556,7 +556,7 @@ fn mcp_initialize_response( if config.strict && (!config.legacy || requested != Some(MCP_PROTOCOL_VERSION)) { return mcp_error_response( id, - -32602, + ERR_UNSUPPORTED_PROTOCOL_VERSION, "Unsupported protocol version", Some(json!({ "supported": config.supported_versions(), @@ -1739,7 +1739,7 @@ mod tests { assert_eq!(response.status(), StatusCode::OK); assert!(response.headers().get(SESSION_HEADER).is_none()); let body = response_json(response).await; - assert_eq!(body["error"]["code"], -32602); + assert_eq!(body["error"]["code"], -32022); assert_eq!(body["error"]["message"], "Unsupported protocol version"); assert_eq!( body["error"]["data"]["supported"], @@ -1776,7 +1776,7 @@ mod tests { assert_eq!(response.status(), StatusCode::OK); assert!(response.headers().get(SESSION_HEADER).is_none()); let body = response_json(response).await; - assert_eq!(body["error"]["code"], -32602); + assert_eq!(body["error"]["code"], -32022); assert_eq!(body["error"]["message"], "Unsupported protocol version"); assert_eq!( body["error"]["data"]["supported"],