Skip to content

Commit 4e8b6ca

Browse files
mcp: return 400 instead of 500 when body read fails in stateless mode (#817)
## 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 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0048a18 commit 4e8b6ca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mcp/streamable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
405405
// stateless servers.
406406
body, err := io.ReadAll(req.Body)
407407
if err != nil {
408-
http.Error(w, "failed to read body", http.StatusInternalServerError)
408+
http.Error(w, "failed to read body", http.StatusBadRequest)
409409
return
410410
}
411411
req.Body.Close()

0 commit comments

Comments
 (0)