Skip to content

Commit 95201f2

Browse files
committed
fix: check if resp is nil on error for initialize methods
1 parent baa7153 commit 95201f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

client/transport/streamable_http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ func (c *StreamableHTTP) SendRequest(
252252
return nil, fmt.Errorf("failed to send request: %w", err)
253253
}
254254
}
255-
defer resp.Body.Close()
255+
// When sendHTTP fails and resp is nil but method is mcp.MethodInitialize
256+
// 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()
260+
}
256261

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

0 commit comments

Comments
 (0)