mcp/streamable: fixes broken DELETE request on connection close
Signed-off-by: Takeshi Yoneda <t.y.mathetake@gmail.com>
This commit is contained in:
parent
392f719bd1
commit
c24d9856c4
2 changed files with 8 additions and 2 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue