From 4e8b6ca17d1d00d4f5b230dbd5bf7012dc142fde Mon Sep 17 00:00:00 2001 From: Ronald Date: Fri, 27 Feb 2026 09:15:33 -0500 Subject: [PATCH] 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 --- mcp/streamable.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcp/streamable.go b/mcp/streamable.go index 36ae5b1..d78697d 100644 --- a/mcp/streamable.go +++ b/mcp/streamable.go @@ -405,7 +405,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque // stateless servers. body, err := io.ReadAll(req.Body) if err != nil { - http.Error(w, "failed to read body", http.StatusInternalServerError) + http.Error(w, "failed to read body", http.StatusBadRequest) return } req.Body.Close()