Return -32601 for unknown MCP methods instead of an empty response - #1338
Merged
Conversation
Per JSON-RPC 2.0, a request carrying an id must receive a response; the server previously returned null for unknown methods, which surfaced as an HTTP 200 with an empty body through HTTP transports. Notifications (requests without an id) are still silently dropped. This also makes MCP 2026-07-28 clients' auto mode fall back to the legacy handshake via a clean, deterministic -32601 on the server/discover probe instead of relying on a synthesized parse error from the empty body. https://issues.amazon.com/issues/APPDEV-2256
This was referenced Aug 29, 2026
Open
adwsingh
approved these changes
Aug 29, 2026
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.
What behavior changes?
A request with an unknown JSON-RPC method that carries an
idnow receives a proper error response:{"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found: nonexistent/method"},"id":4}Previously both dispatch switches in
McpServicereturnednullfor unknown methods, so the request got no response at all (over HTTP transports that surfaces as a 200 with an empty body). Notifications — known or unknown, identified by the absence of anid— are still silently dropped, and all known methods are unchanged.Why is this change needed?
JSON-RPC 2.0 requires that every request carrying an
idreceive a response. Beyond spec correctness, this is groundwork for MCP protocol revision 2026-07-28 (#1337, PR 1 of the ladder proposed there): the Python SDK ≥ 2.0.0 probes servers withserver/discoverand falls back to the legacyinitializehandshake when the probe fails. Today that fallback only works because the client synthesizes a parse error from the empty body — with this change it triggers off a clean, deterministic-32601, which is one of the documented legacy-server signals. The description of #1304 records this same empty-response symptom forinitializewith an unrecognized version.How was this validated?
McpServerTest: unknown method with an integer id and with a string id (the id is echoed with its original type — it is modeled as aDocument), unknown and known notifications produce no output,ping/tools/listunaffected. Moduletestandcheck(spotless, spotbugs, integration suite) green.mcp==1.28.1(full legacy flow unchanged) andmcp==2.0.0(mode=autostill connects, now falling back via the clean error; verified on the wire).What should reviewers focus on?
methodNotFound(JsonRpcRequest)helper inMcpServiceand its two call sites (both dispatch paths).validate()requires anidon any method not prefixednotifications/, so an id-less request with an unknown non-notification method is rejected as a validation error rather than treated as a notification per strict JSON-RPC. Flagged in MCP server: support protocol revision 2026-07-28 (stateless / modern era) #1337.Additional Links
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.