Skip to content

Commit c24d985

Browse files
mathetakefindleyr
authored andcommitted
mcp/streamable: fixes broken DELETE request on connection close
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 392f719 commit c24d985

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mcp/streamable.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
133133
http.Error(w, "Accept must contain 'text/event-stream' for GET requests", http.StatusBadRequest)
134134
return
135135
}
136-
} else if !jsonOK || !streamOK {
136+
} else if (!jsonOK || !streamOK) && req.Method != http.MethodDelete {
137137
http.Error(w, "Accept must contain both 'application/json' and 'text/event-stream'", http.StatusBadRequest)
138138
return
139139
}

mcp/streamable_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ func TestStreamableServerTransport(t *testing.T) {
687687
},
688688
wantSessionID: true,
689689
},
690+
{
691+
method: "DELETE",
692+
wantStatusCode: http.StatusNoContent,
693+
},
690694
},
691695
},
692696
{
@@ -945,7 +949,9 @@ func (s streamableRequest) do(ctx context.Context, serverURL, sessionID string,
945949
req.Header.Set("Mcp-Session-Id", sessionID)
946950
}
947951
req.Header.Set("Content-Type", "application/json")
948-
req.Header.Set("Accept", "application/json, text/event-stream")
952+
if s.method != http.MethodDelete { // DELETE expects "No Content" response.
953+
req.Header.Set("Accept", "application/json, text/event-stream")
954+
}
949955
maps.Copy(req.Header, s.headers)
950956

951957
resp, err := http.DefaultClient.Do(req)

0 commit comments

Comments
 (0)