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)