Return -32022 for strict-mode protocol version rejections - #15
Merged
Conversation
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 <jps@s390x.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #13.
When the strict server (
--protocol 2026-07-28 --strict) rejects aninitializefor protocol-version reasons, it returned JSON-RPC-32602("Invalid params"). The draft spec requires anUnsupportedProtocolVersionErrorwith code-32022anddata: {supported, requested}— the payload was already correct, only the code was wrong. Spec-conformant clients (e.g. MCP SDKnegotiate_auto()) key on the code, so they misclassified the server's era during negotiation.Changes
src/main.rs:mcp_initialize_responsenow uses the existingERR_UNSUPPORTED_PROTOCOL_VERSION(-32022) constant for strict-mode version rejections.-32602is kept for genuinely malformed params (mcp_invalid_params_response), and-32020for header/body mismatches, per the issue's suggested fix.test_strict_initialize_rejects_unsupported_versionandtest_strict_modern_only_rejects_all_initializenow assert-32022.--strictsection updated to name-32022.Verification
cargo fmt --check,cargo clippy --all-targetsclean;cargo test: 36/36 pass.--protocol 2026-07-28 --strict:{"jsonrpc":"2.0","id":2,"error":{"code":-32022,"message":"Unsupported protocol version","data":{"requested":"2025-11-25","supported":["2026-07-28"]}}}