Skip to content

fix: return HTTP 404 for METHOD_NOT_FOUND in stateless transport (#1072) - #1078

Open
elang2 wants to merge 1 commit into
modelcontextprotocol:mainfrom
elang2:fix/server-discover-500
Open

fix: return HTTP 404 for METHOD_NOT_FOUND in stateless transport (#1072)#1078
elang2 wants to merge 1 commit into
modelcontextprotocol:mainfrom
elang2:fix/server-discover-500

Conversation

@elang2

@elang2 elang2 commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • Map JSON-RPC error code -32601 (METHOD_NOT_FOUND) to HTTP 404 in HttpServletStatelessServerTransport
  • Previously all responses returned HTTP 200, even for unrecognized methods like server/discover
  • The 2026-07-28 MCP Streamable HTTP spec mandates HTTP 404 for unknown methods
  • Added mapJsonRpcErrorToHttpStatus() helper — extensible for future error-to-status mappings

Test plan

  • Updated testMissingHandlerReturnsMethodNotFoundError to verify HTTP 404 status
  • Added testUnknownMethodReturnsHttp404WithMethodNotFoundError for server/discover specifically
  • All 340 mcp-core tests pass
  • All 937 mcp-test integration tests pass (BUILD SUCCESS)

Fixes #1072

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[2026-07-28] Java SDK 2.0.0 returns HTTP 500 for OpenAI server/discover requests

1 participant