fix: return HTTP 404 for METHOD_NOT_FOUND in stateless transport (#1072) - #1083
Open
elang2 wants to merge 1 commit into
Open
fix: return HTTP 404 for METHOD_NOT_FOUND in stateless transport (#1072)#1083elang2 wants to merge 1 commit into
elang2 wants to merge 1 commit into
Conversation
…elcontextprotocol#1072) The HttpServletStatelessServerTransport was returning HTTP 200 for all JSON-RPC responses, including METHOD_NOT_FOUND errors. Per the MCP Streamable HTTP specification (2026-07-28), an unrecognized method must return HTTP 404 with JSON-RPC error code -32601, not HTTP 500 or 200. This caused OpenAI's hosted MCP client to receive HTTP 500 (or 200 with an error body it could not process) when sending server/discover requests, resulting in HTTP 424 external_connector_error from the Responses API. The fix maps METHOD_NOT_FOUND (-32601) responses to HTTP 404 at the transport layer. All other JSON-RPC errors continue to use HTTP 200 per standard JSON-RPC conventions.
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
The 2026-07-28 Streamable HTTP spec requires that an unsupported RPC method return HTTP 404 with JSON-RPC error -32601, not HTTP 500. Right now
HttpServletStatelessServerTransportreturns 200 for everything, including unrecognized methods likeserver/discover. OpenAI's hosted MCP client hits this path and surfaces a 424external_connector_errorto users.This PR adds a
mapJsonRpcErrorToHttpStatus()helper that maps -32601 to 404. It's a small, isolated change that unblocks production traffic without waiting for full 2026-07-28 lifecycle support tracked in #1011.Test plan
testMissingHandlerReturnsMethodNotFoundErrorto verify HTTP 404 statustestUnknownMethodReturnsHttp404WithMethodNotFoundErrorforserver/discoverspecificallyFixes #1072