From c24d9856c455dd89d3e83a009838f68138ef5c5d Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 26 Aug 2025 14:22:03 -0700 Subject: [PATCH] mcp/streamable: fixes broken DELETE request on connection close Signed-off-by: Takeshi Yoneda --- mcp/streamable.go | 2 +- mcp/streamable_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mcp/streamable.go b/mcp/streamable.go index f56b708..a92ab49 100644 --- a/mcp/streamable.go +++ b/mcp/streamable.go @@ -133,7 +133,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque http.Error(w, "Accept must contain 'text/event-stream' for GET requests", http.StatusBadRequest) return } - } else if !jsonOK || !streamOK { + } else if (!jsonOK || !streamOK) && req.Method != http.MethodDelete { http.Error(w, "Accept must contain both 'application/json' and 'text/event-stream'", http.StatusBadRequest) return } diff --git a/mcp/streamable_test.go b/mcp/streamable_test.go index 52f6172..d08a0c7 100644 --- a/mcp/streamable_test.go +++ b/mcp/streamable_test.go @@ -687,6 +687,10 @@ func TestStreamableServerTransport(t *testing.T) { }, wantSessionID: true, }, + { + method: "DELETE", + wantStatusCode: http.StatusNoContent, + }, }, }, { @@ -945,7 +949,9 @@ func (s streamableRequest) do(ctx context.Context, serverURL, sessionID string, req.Header.Set("Mcp-Session-Id", sessionID) } req.Header.Set("Content-Type", "application/json") - req.Header.Set("Accept", "application/json, text/event-stream") + if s.method != http.MethodDelete { // DELETE expects "No Content" response. + req.Header.Set("Accept", "application/json, text/event-stream") + } maps.Copy(req.Header, s.headers) resp, err := http.DefaultClient.Do(req)