@@ -58,8 +58,6 @@ func (b *StdioBridge) loop(ctx context.Context) {
5858 go b .runStreamableWriter (ctx )
5959 } else { // legacy SSE
6060 b .postURL = b .baseURL // reset
61- const legacyWorkerCount = 2
62- b .wg .Add (legacyWorkerCount )
6361 go b .runLegacyReader (ctx )
6462 go b .runLegacyWriter (ctx )
6563 }
@@ -75,8 +73,7 @@ func (b *StdioBridge) loop(ctx context.Context) {
7573
7674// Header include Mcp-Session-Id if needed
7775func (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 ()
8077 if err != nil {
8178 logger .Errorf ("failed to marshal initialization request: %v" , err )
8279 return "" , err
@@ -126,7 +123,11 @@ func (b *StdioBridge) handleInitializeResponse(resp *http.Response) {
126123// Streamable HTTP handlers
127124func (b * StdioBridge ) runStreamableReader (ctx context.Context ) {
128125 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+ }
130131 req .Header .Set ("Accept" , "text/event-stream" )
131132 copyHeaders (req .Header , b .headers )
132133 resp , err := http .DefaultClient .Do (req )
@@ -159,7 +160,11 @@ func (b *StdioBridge) runStreamableWriter(ctx context.Context) {
159160 logger .Errorf ("Invalid JSON input: %v" , err )
160161 continue
161162 }
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+ }
163168 req .Header .Set ("Content-Type" , "application/json" )
164169 req .Header .Set ("Accept" , "application/json, text/event-stream" )
165170 copyHeaders (req .Header , b .headers )
@@ -275,10 +280,18 @@ func (b *StdioBridge) updatePostURL(path string) {
275280 logger .Infof ("POST URL updated to %s" , b .postURL )
276281}
277282
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+
278293func (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 ()
282295 if err != nil {
283296 logger .Errorf ("Failed to marshal initialize request body: %v" , err )
284297 return
0 commit comments