Skip to content

Return -32022 for strict-mode protocol version rejections - #15

Merged
jonpspri merged 1 commit into
mainfrom
fix/13-unsupported-protocol-version-code
Jul 26, 2026
Merged

Return -32022 for strict-mode protocol version rejections#15
jonpspri merged 1 commit into
mainfrom
fix/13-unsupported-protocol-version-code

Conversation

@jonpspri

Copy link
Copy Markdown
Collaborator

Summary

Fixes #13.

When the strict server (--protocol 2026-07-28 --strict) rejects an initialize for protocol-version reasons, it returned JSON-RPC -32602 ("Invalid params"). The draft spec requires an UnsupportedProtocolVersionError with code -32022 and data: {supported, requested} — the payload was already correct, only the code was wrong. Spec-conformant clients (e.g. MCP SDK negotiate_auto()) key on the code, so they misclassified the server's era during negotiation.

Changes

  • src/main.rs: mcp_initialize_response now uses the existing ERR_UNSUPPORTED_PROTOCOL_VERSION (-32022) constant for strict-mode version rejections. -32602 is kept for genuinely malformed params (mcp_invalid_params_response), and -32020 for header/body mismatches, per the issue's suggested fix.
  • Tests: test_strict_initialize_rejects_unsupported_version and test_strict_modern_only_rejects_all_initialize now assert -32022.
  • README: --strict section updated to name -32022.

Verification

  • cargo fmt --check, cargo clippy --all-targets clean; cargo test: 36/36 pass.
  • Replayed the issue's exact repro against --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"]}}}

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>
@jonpspri
jonpspri merged commit ce8046b into main Jul 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: strict 2026-07-28 mode rejects initialize with -32602 instead of spec-required -32022 UnsupportedProtocolVersionError

1 participant