Repository navigation
Answer MCP notifications with 202 and no body - #560
Merged
Merged
Conversation
The MCP message endpoint answered a notification, such as notifications/initialized, with a JSON-RPC response whose id was null. A notification gets no response in JSON-RPC, and MCP's Streamable HTTP transport answers it with HTTP 202 and an empty body. Strict clients reject the response: Codex drops the server at startup and shows none of its tools. A message without an id now returns 202 with no body. Requests are unchanged.
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 this changes
McpController::messagenow answers a JSON-RPC notification (a messagewith a string
methodand noid) with HTTP 202 and an empty body.Requests are unchanged. A message with no
methodstill gets the existingJSON-RPC error.
Why
When an MCP client connects, it sends
notifications/initialized. Theendpoint answered it with HTTP 200 and this body:
{"jsonrpc":"2.0","id":null,"result":{}}JSON-RPC 2.0 gives a notification no response, and the MCP Streamable HTTP
transport says the server answers an accepted notification with 202 and no
body (spec).
Claude Code and Grok tolerate the reply, but Codex does not. Its MCP client
logs
Deserialize error: data did not match any variant of untagged enum JsonRpcMessage, when send initialized notification, drops the server,and shows none of the NativePHP docs tools. This was on Codex 0.162.1.
To reproduce:
Today this prints
HTTP/2 200and the body above. With this change itprints
202and no body.Tests
tests/Feature/McpNotificationTest.phpcoversnotifications/initialized,another notification, and a message with no method.
I could not run the suite locally, because
composer installneeds theFlux Pro credentials. Both changed files pass
php -lon PHP 8.4. Thetests workflow runs on push, so it needs a maintainer to run it.