Repository navigation
Conversation
The POST handler dispatched messages without "jsonrpc": "2.0" (missing or "1.0") and requests or notifications whose method was not a string. Add checkJSONRPCVersion and apply it in processMessage and in the POST route, before a session is created, answering -32600 with id null and HTTP 400. Client responses must carry "jsonrpc": "2.0" as well. The stdio transport goes through the same route and gets the same answer. Fixes #344 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LmhsFjk8W96X2PvmShmDm9
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The legacy POST path dispatched messages that are not JSON-RPC 2.0:
{"jsonrpc":"1.0","id":1,"method":"tools/list"}, and the same body withoutjsonrpc, returned 200 with a tool list;{"jsonrpc":"2.0","id":1,"method":5}returned-32601 "Method 5 not found";{"jsonrpc":"2.0","method":5}returned 202.JSON-RPC 2.0 requires
"jsonrpc": "2.0"and a stringmethod; anything else is an Invalid Request.Fix
New
checkJSONRPCVersion(message)insrc/handlers.tsreturns a-32600error withid: nullwhenjsonrpc !== "2.0", or when amethodis present and is not a string. It is used:processMessage, before dispatch (after the existing batch refusal);/mcproute next tocheckRequestId, so the answer is HTTP 400 and no session is opened for the message (for example aninitializewithoutjsonrpc).Client responses (no
method, withresult/error) are still accepted, but they must carry"jsonrpc": "2.0"too. The stdio transport sends every message through the same route viainject, so it returns the same error; there is a stdio test for that.Tests
test/legacy-post-bodies.test.ts: the invalid-body table now includesjsonrpc"1.0", missing, or numeric; numeric or nullmethodon requests and notifications; aninitializewithoutjsonrpc; client responses withoutjsonrpcor with"1.0". All are checked with and without SSE, for 400,-32600,id: nulland noMcp-Session-Id.test/stdio.test.ts: the same cases over stdio, plus a valid request afterwards.Overlap with open PRs
#323 (fix/318,
checkRequestIdinsrc/handlers.ts) and #324 (fix/319, batch handling inprocessMessage) change the same area. This PR does not depend on either. The diff is a new function next tocheckRequestId, two lines inprocessMessageand one check in the route, so any conflict should be easy to resolve whichever PR merges first.Fixes #344
🤖 Generated with Claude Code
https://claude.ai/code/session_01LmhsFjk8W96X2PvmShmDm9