Skip to content

mcp: reject unsupported protocol versions with -32022 when stateless - #1547

Merged
guglielmo-san merged 2 commits into
mainfrom
serob/handle-stateless-usupported-protocol-version
Nov 26, 2026
Merged

guglielmo-san merged 2 commits into
mainfrom
serob/handle-stateless-usupported-protocol-version

Conversation

@nahapetyan-serob

Copy link
Copy Markdown
Contributor

When the server supports 2026-07-28 or later, that check now answers with a
JSON-RPC -32022 error with the supported versions and
the requested one, for modern and legacy requests alike.
MCPGODEBUG=plaintextversionrejection=1 restores the previous behavior.

Fixes #1542

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Ignoring the body read error in mcp/streamable.go causes oversized requests to receive 400/-32022 instead of the documented 413 response when the configured size limit is reached.

1 open issue
What changed in this PR

This PR addresses #1542 by making stateless Streamable HTTP servers that support modern protocols return structured version-rejection errors for unsupported legacy versions.

Changes:

  • Return JSON-RPC -32022 with supported and requested versions instead of a plain-text 400.
  • Add MCPGODEBUG=plaintextversionrejection=1 to restore the previous behavior.
  • Add regression tests and document the compatibility option.
File Description
mcp/​streamable.go Implements structured version rejection and the compatibility option.
mcp/​streamable_test.go Tests version rejection, supported requests, and compatibility behavior.
internal/​docs/​mcpgodebug.src.md Documents the option and its planned removal.
docs/​mcpgodebug.md Updates the generated compatibility-option documentation.

Review effort: Balanced

Comment thread mcp/streamable.go Resolved
Comment thread mcp/streamable.go Resolved
@guglielmo-san
guglielmo-san merged commit 4b1a524 into main Nov 26, 2026
10 checks passed
@guglielmo-san
guglielmo-san deleted the serob/handle-stateless-usupported-protocol-version branch November 26, 2026 12:48
Tangerg added a commit to Tangerg/go-sdk that referenced this pull request Dec 2, 2026
Brings the fork up to upstream main at 723d70e, which is v1.9.0 plus
fourteen later commits. Upstream changes: modelcontextprotocol#1238, modelcontextprotocol#1511, modelcontextprotocol#1515, modelcontextprotocol#1517,
modelcontextprotocol#1521, modelcontextprotocol#1523, modelcontextprotocol#1524, modelcontextprotocol#1527, modelcontextprotocol#1533, modelcontextprotocol#1537, modelcontextprotocol#1539, modelcontextprotocol#1540, modelcontextprotocol#1544, modelcontextprotocol#1547,
modelcontextprotocol#1549, modelcontextprotocol#1550, modelcontextprotocol#1553, modelcontextprotocol#1554, modelcontextprotocol#1558, modelcontextprotocol#1560, modelcontextprotocol#1561, modelcontextprotocol#1562.

Fork-side adaptations:

- internal/jsonrpc2: the -32600 reply to a duplicate in-flight ID
  (modelcontextprotocol#1550) is written off the read loop and holds its admission slot
  until written, like every other reply under MaxIncomingRequests.
- mcp: ClientSession.initialize takes the session state lock that
  upstream added, and still projects the negotiated version to the
  connection.
- mcp: the fork's copies of hintomitempty, nowrapinvalidparams and
  nomethodnotfoundcodeinerror go away with upstream's removal (modelcontextprotocol#1533).
- extensions/skills: reads the protocol version from the fork's
  json.RawMessage Meta.
- Tests: the duplicate-ID admission test drains the new reply, and the
  client cancellation test runs on 2025-11-25 only, because 2026-07-28
  clients reject every standalone server request (modelcontextprotocol#1537, modelcontextprotocol#1540, modelcontextprotocol#1554).
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.

Streamable HTTP: unsupported protocol version below 2026-07-28 still gets a plain-text 400, not -32022 (#1173 still reproduces)

3 participants