@@ -23,20 +23,19 @@ import (
2323// while sending requests over regular HTTP POST calls. The client handles
2424// automatic reconnection and message routing between requests and responses.
2525type SSEMCPClient struct {
26- baseURL * url.URL
27- endpoint * url.URL
28- httpClient * http.Client
29- requestID atomic.Int64
30- responses map [int64 ]chan RPCResponse
31- mu sync.RWMutex
32- done chan struct {}
33- initialized bool
34- notifications []func (mcp.JSONRPCNotification )
35- notifyMu sync.RWMutex
36- endpointChan chan struct {}
37- capabilities mcp.ServerCapabilities
38- headers map [string ]string
39- sseReadTimeout time.Duration
26+ baseURL * url.URL
27+ endpoint * url.URL
28+ httpClient * http.Client
29+ requestID atomic.Int64
30+ responses map [int64 ]chan RPCResponse
31+ mu sync.RWMutex
32+ done chan struct {}
33+ initialized bool
34+ notifications []func (mcp.JSONRPCNotification )
35+ notifyMu sync.RWMutex
36+ endpointChan chan struct {}
37+ capabilities mcp.ServerCapabilities
38+ headers map [string ]string
4039}
4140
4241type ClientOption func (* SSEMCPClient )
@@ -47,12 +46,6 @@ func WithHeaders(headers map[string]string) ClientOption {
4746 }
4847}
4948
50- func WithSSEReadTimeout (timeout time.Duration ) ClientOption {
51- return func (sc * SSEMCPClient ) {
52- sc .sseReadTimeout = timeout
53- }
54- }
55-
5649// NewSSEMCPClient creates a new SSE-based MCP client with the given base URL.
5750// Returns an error if the URL is invalid.
5851func NewSSEMCPClient (baseURL string , options ... ClientOption ) (* SSEMCPClient , error ) {
@@ -62,13 +55,12 @@ func NewSSEMCPClient(baseURL string, options ...ClientOption) (*SSEMCPClient, er
6255 }
6356
6457 smc := & SSEMCPClient {
65- baseURL : parsedURL ,
66- httpClient : & http.Client {},
67- responses : make (map [int64 ]chan RPCResponse ),
68- done : make (chan struct {}),
69- endpointChan : make (chan struct {}),
70- sseReadTimeout : 30 * time .Second ,
71- headers : make (map [string ]string ),
58+ baseURL : parsedURL ,
59+ httpClient : & http.Client {},
60+ responses : make (map [int64 ]chan RPCResponse ),
61+ done : make (chan struct {}),
62+ endpointChan : make (chan struct {}),
63+ headers : make (map [string ]string ),
7264 }
7365
7466 for _ , opt := range options {
@@ -128,12 +120,9 @@ func (c *SSEMCPClient) readSSE(reader io.ReadCloser) {
128120 br := bufio .NewReader (reader )
129121 var event , data string
130122
131- ctx , cancel := context .WithTimeout (context .Background (), c .sseReadTimeout )
132- defer cancel ()
133-
134123 for {
135124 select {
136- case <- ctx . Done () :
125+ case <- c . done :
137126 return
138127 default :
139128 line , err := br .ReadString ('\n' )
0 commit comments