address review comments

Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
Takeshi Yoneda 2025-08-27 12:00:37 -07:00 • committed by Robert Findley
commit a76bae3a11
2 changed files with 5 additions and 4 deletions

View file

@ -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) && req.Method != http.MethodDelete {
} else if (!jsonOK || !streamOK) && req.Method != http.MethodDelete { // TODO: consolidate with handling of http method below.
http.Error(w, "Accept must contain both 'application/json' and 'text/event-stream'", http.StatusBadRequest)
return
}

View file

@ -690,6 +690,9 @@ func TestStreamableServerTransport(t *testing.T) {
{
method: "DELETE",
wantStatusCode: http.StatusNoContent,
// Delete request expects 204 No Content with empty body. So override
// the default "accept: application/json, text/event-stream" header.
headers: map[string][]string{"Accept": nil},
},
},
},
@ -949,9 +952,7 @@ func (s streamableRequest) do(ctx context.Context, serverURL, sessionID string,
req.Header.Set("Mcp-Session-Id", sessionID)
}
req.Header.Set("Content-Type", "application/json")
if s.method != http.MethodDelete { // DELETE expects "No Content" response.
req.Header.Set("Accept", "application/json, text/event-stream")
}
req.Header.Set("Accept", "application/json, text/event-stream")
maps.Copy(req.Header, s.headers)
resp, err := http.DefaultClient.Do(req)