Skip to content

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

Merged
maciej-kisiel merged 1 commit intomodelcontextprotocol:mainfrom
roncodingenthusiast:fix/body-read-500-to-400
Feb 27, 2026
Merged

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

Conversation

@roncodingenthusiast
Copy link
Contributor

@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
@maciej-kisiel maciej-kisiel force-pushed the fix/body-read-500-to-400 branch from 17423c1 to a080230 Compare February 27, 2026 14:11
@maciej-kisiel maciej-kisiel merged commit 4e8b6ca into modelcontextprotocol:main Feb 27, 2026
9 checks passed
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