Skip to content

Commit 5ce7124

Browse files
committed
2 parents 9adb3e5 + 341c869 commit 5ce7124

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

internal/mcp/connection.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

internal/server/unified_http_backend_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,14 @@ func TestHTTPBackend_SessionIDPropagation(t *testing.T) {
243243
defer mockServer.Close()
244244

245245
// Create config
246+
// Add a dummy header to force plain JSON-RPC transport (SDK transports don't support custom headers)
247+
// This avoids the streamable/SSE transport attempts which don't work with simple mock servers
246248
cfg := &config.Config{
247249
Servers: map[string]*config.ServerConfig{
248250
"test-http": {
249-
Type: "http",
250-
URL: mockServer.URL,
251+
Type: "http",
252+
URL: mockServer.URL,
253+
Headers: map[string]string{"X-Test": "test"},
251254
},
252255
},
253256
}

0 commit comments

Comments
 (0)