@@ -294,7 +294,7 @@ func (c *StreamableHTTP) SendRequest(
294294
295295 case "text/event-stream" :
296296 // Server is using SSE for streaming responses
297- return c .handleSSEResponse (ctx , resp .Body )
297+ return c .handleSSEResponse (ctx , resp .Body , false )
298298
299299 default :
300300 return nil , fmt .Errorf ("unexpected content type: %s" , resp .Header .Get ("Content-Type" ))
@@ -363,7 +363,8 @@ func (c *StreamableHTTP) sendHTTP(
363363
364364// handleSSEResponse processes an SSE stream for a specific request.
365365// It returns the final result for the request once received, or an error.
366- func (c * StreamableHTTP ) handleSSEResponse (ctx context.Context , reader io.ReadCloser ) (* JSONRPCResponse , error ) {
366+ // If ignoreResponse is true, it won't return when a response messge is received. This is for continuous listening.
367+ func (c * StreamableHTTP ) handleSSEResponse (ctx context.Context , reader io.ReadCloser , ignoreResponse bool ) (* JSONRPCResponse , error ) {
367368
368369 // Create a channel for this specific request
369370 responseChan := make (chan * JSONRPCResponse , 1 )
@@ -401,7 +402,9 @@ func (c *StreamableHTTP) handleSSEResponse(ctx context.Context, reader io.ReadCl
401402 return
402403 }
403404
404- responseChan <- & message
405+ if ! ignoreResponse {
406+ responseChan <- & message
407+ }
405408 })
406409 }()
407410
@@ -580,7 +583,12 @@ func (c *StreamableHTTP) createGETConnectionToServer(ctx context.Context) error
580583 return fmt .Errorf ("unexpected content type: %s" , contentType )
581584 }
582585
583- _ , err = c .handleSSEResponse (ctx , resp .Body )
586+ // When ignoreResponse is true, the function will never return expect context is done.
587+ // NOTICE: Due to the ambiguity of the specification, other SDKs may use the GET connection to transfer the response
588+ // messages. To be more compatible, we should handle this response, however, as the transport layer is message-based,
589+ // currently, there is no convenient way to handle this response.
590+ // So we ignore the response here. It's not a bug, but may be not compatible with other SDKs.
591+ _ , err = c .handleSSEResponse (ctx , resp .Body , true )
584592 if err != nil {
585593 return fmt .Errorf ("failed to handle SSE response: %w" , err )
586594 }
0 commit comments