Skip to content

Renumber draft error codes to follow spec PR #2907 (-32020/-32021/-32022) #1657

@halter73

Description

@halter73

Context

Upstream spec PR modelcontextprotocol/modelcontextprotocol#2907 ("Define error code allocation policy and renumber draft error codes") partitions the JSON-RPC -32000..-32099 implementation-defined range and renumbers the three error codes introduced in the 2026-07-28 draft so they stop colliding with existing SDK usage:

Code Old (current) New (#2907)
HeaderMismatch -32001 -32020
MissingRequiredClientCapability -32003 -32021
UnsupportedProtocolVersion -32004 -32022

The renumber is draft-only and non-breaking as long as it lands before the 2026-07-28 revision is ratified — none of these codes exist in a released spec version. The PR body explicitly lists "csharp-sdk constants (draft-gated)" as a post-merge follow-up.

This renumber also resolves a real collision in our HTTP transport: StreamableHttpHandler returns -32001 (HTTP 404) for the legacy stateful "Session not found" case, which currently overlaps draft HeaderMismatch -32001 (HTTP 400). Moving HeaderMismatch to -32020 removes that overlap.

What to change (once #2907 merges)

  • src/ModelContextProtocol.Core/McpErrorCode.cs: HeaderMismatch = -32020, MissingRequiredClientCapability = -32021, UnsupportedProtocolVersion = -32022.
  • Doc comments referencing the literal codes in UnsupportedProtocolVersionException.cs, MissingRequiredClientCapabilityException.cs, and the -32001/-32003/-32004 comments in McpClientImpl.cs, StreamableHttpClientSessionTransport.cs, AutoDetectingClientSessionTransport.cs, McpSessionHandler.cs.
  • The IsModernServerError-style recognition set in StreamableHttpClientSessionTransport.cs (currently matches UnsupportedProtocolVersion/MissingRequiredClientCapability/HeaderMismatch) — values update automatically via the enum, but verify the comments.
  • The legacy -32001 "Session not found" usage at StreamableHttpHandler.cs:292 can stay as-is; it no longer collides once HeaderMismatch moves.
  • Bump the conformance pin / re-validate once upstream conformance ships matching code expectations (see also the conformance code-expectation PRs the #2907 author lists as follow-ups).

Blocked on

  • #2907 merging upstream. Until then we keep the current codes so we stay aligned with the published draft schema and the other Tier-1 SDKs.

Tracking follow-up to #1610.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions