Skip to content

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

Open
elang2 wants to merge 3 commits into
modelcontextprotocol:mainfrom
elang2:fix/server-discover-500
Open

elang2 wants to merge 3 commits into
modelcontextprotocol:mainfrom
elang2:fix/server-discover-500

Conversation

@elang2

@elang2 elang2 commented Aug 9, 2026

Copy link
Copy Markdown

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 HttpServletStatelessServerTransport returns 200 for everything, including unrecognized methods like server/discover. OpenAI's hosted MCP client hits this path and surfaces a 424 external_connector_error to 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

  • 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

@morad3741

Copy link
Copy Markdown

hi, honest question, why this repo looks dead? no commits/merged PRs in last month or so, is it really dead?

@elang2

elang2 commented Aug 11, 2026

Copy link
Copy Markdown
Author

hi, honest question, why this repo looks dead? no commits/merged PRs in last month or so, is it really dead?

no idea. i will there was more traction and active reviews

@Kehrlann

Copy link
Copy Markdown
Contributor

Summer time in Europe, everyone was basically off. We're back online.

@Kehrlann Kehrlann added the v3 v3 covering the 2026-07-28 spec label Aug 26, 2026
…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.
@elang2
elang2 force-pushed the fix/server-discover-500 branch from b61c538 to 449a7d6 Compare September 1, 2026 01:00

Copy link
Copy Markdown

Potential protocol-version compatibility issue: the new HTTP 404 mapping is unconditional, but the requirement is introduced by the 2026-07-28 Streamable HTTP rules.

The implementation maps every JSON-RPC METHOD_NOT_FOUND (-32601) to HTTP 404 regardless of the request's MCP protocol version. The added tests even send MCP-Protocol-Version: 2025-03-26 and now expect 404.

For 2026-07-28, the spec explicitly says an unimplemented RPC method MUST return HTTP 404 + -32601. Older Streamable HTTP revisions did not define that method-level 404 rule (their 404 discussion is primarily the legacy HTTP+SSE fallback path).

Could this mapping be gated on the request/negotiated protocol version, with a regression showing legacy versions retain their previous JSON-RPC-over-200 behavior while 2026-07-28 gets 404?

Otherwise this PR changes HTTP semantics for legacy clients while describing the change as 2026-07-28 conformance.

AI-assisted review; I checked the current PR head against the versioned transport specs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v3 v3 covering the 2026-07-28 spec

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

4 participants