Skip to content

fix: return 400 instead of 500 when body read fails in stateless mode#817

Open
roncodingenthusiast wants to merge 1 commit intomodelcontextprotocol:mainfrom
roncodingenthusiast:fix/body-read-500-to-400
Open

fix: return 400 instead of 500 when body read fails in stateless mode#817
roncodingenthusiast wants to merge 1 commit intomodelcontextprotocol:mainfrom
roncodingenthusiast:fix/body-read-500-to-400

Conversation

@roncodingenthusiast
Copy link

@roncodingenthusiast roncodingenthusiast commented Feb 23, 2026

Summary

Changes http.StatusInternalServerError to http.StatusBadRequest when io.ReadAll(req.Body) fails during stateless mode initialization in the streamable HTTP handler.

Fixes #816

Rationale

Body read failures are client-side errors (disconnection, timeout, incomplete request), not server errors. Returning 500 is misleading and causes unnecessary alert fatigue for users monitoring their MCP servers.

This makes the behavior consistent with servePOST which already returns 400 for the same error condition.

Testing

  • Existing tests pass
  • This is a one-line change affecting only the HTTP status code returned

@jba jba requested review from jba and maciej-kisiel February 24, 2026 16:08
Copy link
Contributor

@jba jba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. Will let Maciej approve.

Co-authored-by: Cursor <cursoragent@cursor.com>
Made-with: Cursor
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.

Streamable HTTP handler returns 500 instead of 400 when body read fails

3 participants