Skip to content

fix(client): fall back on legacy JSON-RPC errors - #1141

Open
j45856021-dev wants to merge 1 commit into
modelcontextprotocol:mainfrom
j45856021-dev:fix/legacy-http-protocol-fallback
Open

fix(client): fall back on legacy JSON-RPC errors#1141
j45856021-dev wants to merge 1 commit into
modelcontextprotocol:mainfrom
j45856021-dev:fix/legacy-http-protocol-fallback

Conversation

@j45856021-dev

Copy link
Copy Markdown

Summary

  • Fall back from server/discover to legacy initialize for JSON-RPC errors that do not positively identify a modern server.
  • Keep authentication, transport, lifecycle configuration, and recognized modern-protocol errors actionable instead of downgrading them.
  • Add a regression test for the deployed -32000 unsupported MCP-Protocol-Version response, plus guards for modern capability and header errors.
  • Clarify ClientLifecycleMode::Auto behavior in the README.

This addresses the JSON-RPC interoperability cases in #1040 and is a narrower alternative to #1133 after the review concern that Err(_) also catches 401/403 and client-side failures.

Motivation and Context

The 2026-07-28 compatibility guidance says a client should fall back when a legacy server returns an error that is not a recognized modern JSON-RPC error. Some deployed legacy servers reject the modern protocol header before dispatch with an implementation-defined response such as:

-32000 Bad Request: The MCP-Protocol-Version header value 2026-07-28 is not supported.

Current Auto handling only falls back for METHOD_NOT_FOUND, so these servers fail even though the configured legacy protocol works. This change limits the broader fallback to JsonRpcError; transport and authorization failures still surface unchanged.

How Has This Been Tested?

  • cargo fmt --all --check
  • cargo test -p rmcp --test test_client_lifecycle_modes --features client
  • cargo test -p rmcp --test test_discover_http_client_startup --features client,reqwest,transport-streamable-http-client-reqwest,transport-streamable-http-server
  • cargo clippy -p rmcp --test test_client_lifecycle_modes --features client -- -D warnings

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: e006650d-d10e-432f-aaa2-15a763fdf4b6
@j45856021-dev
j45856021-dev requested a review from a team as a code owner August 5, 2026 21:59
@github-actions github-actions Bot added T-documentation Documentation improvements T-test Testing related changes T-core Core library changes T-service Service layer changes labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-documentation Documentation improvements T-service Service layer changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant