Skip to content

Commit ef2e795

Browse files
committed
fix: proper handling
1 parent 95201f2 commit ef2e795

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

client/transport/streamable_http.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,14 @@ func (c *StreamableHTTP) SendRequest(
252252
return nil, fmt.Errorf("failed to send request: %w", err)
253253
}
254254
}
255+
256+
// Only proceed if we have a valid response.
255257
// When sendHTTP fails and resp is nil but method is mcp.MethodInitialize
256258
// defer resp.Body.Close() fails with nil pointer dereference.
257-
// TODO: Restructure this fallthrough logic properly.
258-
if resp != nil {
259-
defer resp.Body.Close()
259+
if resp == nil {
260+
return nil, fmt.Errorf("failed to send request: %w", err)
260261
}
262+
defer resp.Body.Close()
261263

262264
// Check if we got an error response
263265
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusAccepted {

0 commit comments

Comments
 (0)