Skip to content

Commit 33c98f1

Browse files
authored
fix: Improve content type handling in streamable_http.go (#210)
1 parent b46fa54 commit 33c98f1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

client/transport/streamable_http.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/json"
88
"fmt"
99
"io"
10+
"mime"
1011
"net/http"
1112
"net/url"
1213
"strings"
@@ -206,7 +207,8 @@ func (c *StreamableHTTP) SendRequest(
206207
}
207208

208209
// Handle different response types
209-
switch resp.Header.Get("Content-Type") {
210+
mediaType, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type"))
211+
switch mediaType {
210212
case "application/json":
211213
// Single response
212214
var response JSONRPCResponse
@@ -248,13 +250,13 @@ func (c *StreamableHTTP) handleSSEResponse(ctx context.Context, reader io.ReadCl
248250
c.readSSE(ctx, reader, func(event, data string) {
249251

250252
// (unsupported: batching)
251-
253+
252254
var message JSONRPCResponse
253255
if err := json.Unmarshal([]byte(data), &message); err != nil {
254256
fmt.Printf("failed to unmarshal message: %v\n", err)
255257
return
256258
}
257-
259+
258260
// Handle notification
259261
if message.ID == nil {
260262
var notification mcp.JSONRPCNotification
@@ -269,7 +271,7 @@ func (c *StreamableHTTP) handleSSEResponse(ctx context.Context, reader io.ReadCl
269271
c.notifyMu.RUnlock()
270272
return
271273
}
272-
274+
273275
responseChan <- &message
274276
})
275277
}()

0 commit comments

Comments
 (0)