@@ -23,20 +23,19 @@ import (
23
23
// while sending requests over regular HTTP POST calls. The client handles
24
24
// automatic reconnection and message routing between requests and responses.
25
25
type 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
40
39
}
41
40
42
41
type ClientOption func (* SSEMCPClient )
@@ -47,12 +46,6 @@ func WithHeaders(headers map[string]string) ClientOption {
47
46
}
48
47
}
49
48
50
- func WithSSEReadTimeout (timeout time.Duration ) ClientOption {
51
- return func (sc * SSEMCPClient ) {
52
- sc .sseReadTimeout = timeout
53
- }
54
- }
55
-
56
49
// NewSSEMCPClient creates a new SSE-based MCP client with the given base URL.
57
50
// Returns an error if the URL is invalid.
58
51
func NewSSEMCPClient (baseURL string , options ... ClientOption ) (* SSEMCPClient , error ) {
@@ -62,13 +55,12 @@ func NewSSEMCPClient(baseURL string, options ...ClientOption) (*SSEMCPClient, er
62
55
}
63
56
64
57
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 ),
72
64
}
73
65
74
66
for _ , opt := range options {
@@ -128,12 +120,9 @@ func (c *SSEMCPClient) readSSE(reader io.ReadCloser) {
128
120
br := bufio .NewReader (reader )
129
121
var event , data string
130
122
131
- ctx , cancel := context .WithTimeout (context .Background (), c .sseReadTimeout )
132
- defer cancel ()
133
-
134
123
for {
135
124
select {
136
- case <- ctx . Done () :
125
+ case <- c . done :
137
126
return
138
127
default :
139
128
line , err := br .ReadString ('\n' )
0 commit comments