@@ -234,8 +234,12 @@ func tryStreamableHTTPTransport(ctx context.Context, cancel context.CancelFunc,
234234 MaxRetries : 0 , // Don't retry on failure - we'll try other transports
235235 }
236236
237- // Try to connect - this will fail if the server doesn't support streamable HTTP
238- session , err := client .Connect (ctx , transport , nil )
237+ // Try to connect with a timeout - this will fail if the server doesn't support streamable HTTP
238+ // Use a short timeout to fail fast and try other transports
239+ connectCtx , connectCancel := context .WithTimeout (ctx , 5 * time .Second )
240+ defer connectCancel ()
241+
242+ session , err := client .Connect (connectCtx , transport , nil )
239243 if err != nil {
240244 return nil , fmt .Errorf ("streamable HTTP transport connect failed: %w" , err )
241245 }
@@ -271,8 +275,12 @@ func trySSETransport(ctx context.Context, cancel context.CancelFunc, url string,
271275 HTTPClient : httpClient ,
272276 }
273277
274- // Try to connect - this will fail if the server doesn't support SSE
275- session , err := client .Connect (ctx , transport , nil )
278+ // Try to connect with a timeout - this will fail if the server doesn't support SSE
279+ // Use a short timeout to fail fast and try other transports
280+ connectCtx , connectCancel := context .WithTimeout (ctx , 5 * time .Second )
281+ defer connectCancel ()
282+
283+ session , err := client .Connect (connectCtx , transport , nil )
276284 if err != nil {
277285 return nil , fmt .Errorf ("SSE transport connect failed: %w" , err )
278286 }
0 commit comments