Files
codex/codex-rs/rmcp-client
thomas 9f4c20aadc Handle legacy MCP discovery prevalidation errors (#35840)
## Why

Some legacy MCP servers reject `server/discover` before creating a session and
return a null-ID JSON-RPC error with a non-JSON content type or without echoing
the rejected protocol version. These responses prevented the client from
falling back to legacy initialization.

## What changed

- Parse HTTP 400 discovery errors without a session ID regardless of their
  declared content type.
- Fall back to `initialize` when error code `-32000` reports a missing session
  or advertises only known legacy protocol versions, including supported
  versions other than `2025-06-18`.
- Continue rejecting unrelated error codes, correlated responses, non-400
  statuses, malformed version lists, and lists containing modern or unknown
  versions.

## Testing

Added MCP discovery coverage for legacy error variants, server-selected legacy
protocol versions, non-JSON content types, and non-legacy rejection cases.

GitOrigin-RevId: 4d3ee2d7d852ce0d0ab3f486da23cb653a7ff5ca
2026-07-28 22:57:09 +00:00
..