fix: silently ignore JSON-RPC notifications per spec#1
Open
mh0pe wants to merge 1 commit into
Open
Conversation
The MCP protocol sends `notifications/initialized` after the initialize handshake. Per JSON-RPC 2.0, notifications have no `id` field and must not receive a response. Previously, the server returned a -32601 "Method not found" error for any unrecognized method, including notifications. This caused MCP clients like Forge to interpret the error response as a connection failure, preventing tools/list from succeeding. The fix checks for `request_id is None` (indicating a notification) and silently skips it via `continue`, matching the JSON-RPC 2.0 spec: "The Server MUST NOT reply to a Notification." Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
id) instead of returning a-32601 Method not founderrorProblem
The MCP protocol sends
notifications/initializedafter theinitializehandshake. Per JSON-RPC 2.0 spec, notifications have noidfield and must not receive a response.The server was returning an error response for these notifications:
{"jsonrpc": "2.0", "id": null, "error": {"code": -32601, "message": "Method not found: notifications/initialized"}}This caused MCP clients (e.g., Forge) to interpret the error as a connection failure, preventing
tools/listfrom succeeding.Fix
Check for
request_id is Nonebefore dispatching, andcontinueto skip notifications silently. This matches the JSON-RPC 2.0 spec: "The Server MUST NOT reply to a Notification."Test plan
notifications/initializedis silently ignored (no error response)tools/listreturns all 7 tools successfully after notificationidstill work as expected