fix(initialize scenario): return 202 No Content for notifications (closes #274)#299
Open
adityachilka1 wants to merge 1 commit into
Open
Conversation
nbarbettini
reviewed
May 21, 2026
| this.handleInitialize(request, res); | ||
| } else if (request.method === 'tools/list') { | ||
| this.handleToolsList(request, res); | ||
| } else if (request.id == null) { |
Contributor
There was a problem hiding this comment.
Can this condition be made more explicit: check that it is in fact a notifications/initialized notification and not something else?
…oses modelcontextprotocol#274) The transport spec (2025-11-25 § 2.1, point 4) requires that a server reply to a JSON-RPC notification with 202 Accepted and no body. The fall-through branch in the initialize scenario test server returned 200 with `{"jsonrpc":"2.0","id":null,"result":{}}` for all non-initialize, non-tools/list requests - including `notifications/initialized`. Branch on `request.id == null` (notification) and emit 202 with no body in that case. Non-notification requests still get the prior placeholder 200-response behavior. Closes modelcontextprotocol#274.
1f0db44 to
6f51715
Compare
Author
|
Good call. Narrowed the condition to check the exact method ( Force-pushed - single-commit PR, one-line diff from the previous revision. Typecheck and lint clean. |
Contributor
|
This LGTM 👍 |
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.
Closes #274.
The bug
The initialize scenario test server had a fall-through branch for post-negotiation
requests:
When the client POSTs
notifications/initialized(noidfield), thatfalls into the else branch and the server replied with
{"jsonrpc":"2.0","id":undefined,"result":{}}. That violates the transportspec (2025-11-25 § 2.1, point 4):
Strict clients that reject 200-with-body-for-notification were failing against
the scenario.
The fix
Insert a branch for
request.id == nullbefore the 200-placeholder else:} else if (request.method === 'tools/list') { this.handleToolsList(request, res); + } else if (request.id == null) { + res.writeHead(202); + res.end(); } else { res.writeHead(200, { 'Content-Type': 'application/json' });== nullcatches bothid: null(explicitly passed) andid-omitted (theJSON.parse result for a notification payload).
Verification
Both pass clean.
No other behavioral changes
idstill hit the 200-placeholder else branch.notifications/initialized) changes -from 200+JSON to 202+empty.