@@ -58,8 +58,6 @@ func (b *StdioBridge) loop(ctx context.Context) {
58
58
go b .runStreamableWriter (ctx )
59
59
} else { // legacy SSE
60
60
b .postURL = b .baseURL // reset
61
- const legacyWorkerCount = 2
62
- b .wg .Add (legacyWorkerCount )
63
61
go b .runLegacyReader (ctx )
64
62
go b .runLegacyWriter (ctx )
65
63
}
@@ -75,8 +73,7 @@ func (b *StdioBridge) loop(ctx context.Context) {
75
73
76
74
// Header include Mcp-Session-Id if needed
77
75
func (b * StdioBridge ) detectTransport (ctx context.Context ) (string , error ) {
78
- initReq := map [string ]interface {}{"jsonrpc" : "2.0" , "id" : 1 , "method" : "initialize" , "params" : map [string ]interface {}{}}
79
- body , err := json .Marshal (initReq )
76
+ body , err := buildJSONRPCInitializeRequest ()
80
77
if err != nil {
81
78
logger .Errorf ("failed to marshal initialization request: %v" , err )
82
79
return "" , err
@@ -126,7 +123,11 @@ func (b *StdioBridge) handleInitializeResponse(resp *http.Response) {
126
123
// Streamable HTTP handlers
127
124
func (b * StdioBridge ) runStreamableReader (ctx context.Context ) {
128
125
defer b .wg .Done ()
129
- req , _ := http .NewRequestWithContext (ctx , "GET" , b .baseURL .String (), nil )
126
+ req , err := http .NewRequestWithContext (ctx , "GET" , b .baseURL .String (), nil )
127
+ if err != nil {
128
+ logger .Errorf ("Failed to create GET request: %v" , err )
129
+ return
130
+ }
130
131
req .Header .Set ("Accept" , "text/event-stream" )
131
132
copyHeaders (req .Header , b .headers )
132
133
resp , err := http .DefaultClient .Do (req )
@@ -159,7 +160,11 @@ func (b *StdioBridge) runStreamableWriter(ctx context.Context) {
159
160
logger .Errorf ("Invalid JSON input: %v" , err )
160
161
continue
161
162
}
162
- req , _ := http .NewRequestWithContext (ctx , "POST" , b .baseURL .String (), strings .NewReader (raw ))
163
+ req , err := http .NewRequestWithContext (ctx , "POST" , b .baseURL .String (), strings .NewReader (raw ))
164
+ if err != nil {
165
+ logger .Errorf ("Failed to create HTTP request: %v" , err )
166
+ continue
167
+ }
163
168
req .Header .Set ("Content-Type" , "application/json" )
164
169
req .Header .Set ("Accept" , "application/json, text/event-stream" )
165
170
copyHeaders (req .Header , b .headers )
@@ -275,10 +280,18 @@ func (b *StdioBridge) updatePostURL(path string) {
275
280
logger .Infof ("POST URL updated to %s" , b .postURL )
276
281
}
277
282
283
+ func buildJSONRPCInitializeRequest () ([]byte , error ) {
284
+ req := map [string ]interface {}{
285
+ "jsonrpc" : "2.0" ,
286
+ "id" : 1 ,
287
+ "method" : "initialize" ,
288
+ "params" : map [string ]interface {}{},
289
+ }
290
+ return json .Marshal (req )
291
+ }
292
+
278
293
func (b * StdioBridge ) sendInitialize (ctx context.Context ) {
279
- reqBody , err := json .Marshal (map [string ]interface {}{
280
- "jsonrpc" : "2.0" , "id" : 1 , "method" : "initialize" , "params" : map [string ]interface {}{},
281
- })
294
+ reqBody , err := buildJSONRPCInitializeRequest ()
282
295
if err != nil {
283
296
logger .Errorf ("Failed to marshal initialize request body: %v" , err )
284
297
return
0 commit comments