(t *testing.T)
| 354 | } |
| 355 | |
| 356 | func TestMCPHTTP_E2E_ConcurrentRequests(t *testing.T) { |
| 357 | t.Parallel() |
| 358 | |
| 359 | // Setup Coder server |
| 360 | coderClient, closer, api := coderdtest.NewWithAPI(t, &coderdtest.Options{ |
| 361 | IncludeProvisionerDaemon: true, |
| 362 | }) |
| 363 | defer closer.Close() |
| 364 | |
| 365 | _ = coderdtest.CreateFirstUser(t, coderClient) |
| 366 | |
| 367 | // Create MCP client |
| 368 | mcpURL := api.AccessURL.String() + mcpserver.MCPEndpoint |
| 369 | mcpClient, err := mcpclient.NewStreamableHttpClient(mcpURL, |
| 370 | transport.WithHTTPHeaders(map[string]string{ |
| 371 | "Authorization": "Bearer " + coderClient.SessionToken(), |
| 372 | })) |
| 373 | require.NoError(t, err) |
| 374 | defer func() { |
| 375 | if closeErr := mcpClient.Close(); closeErr != nil { |
| 376 | t.Logf("Failed to close MCP client: %v", closeErr) |
| 377 | } |
| 378 | }() |
| 379 | |
| 380 | ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong) |
| 381 | defer cancel() |
| 382 | |
| 383 | // Start and initialize client |
| 384 | err = mcpClient.Start(ctx) |
| 385 | require.NoError(t, err) |
| 386 | |
| 387 | initReq := mcp.InitializeRequest{ |
| 388 | Params: mcp.InitializeParams{ |
| 389 | ProtocolVersion: mcp.LATEST_PROTOCOL_VERSION, |
| 390 | ClientInfo: mcp.Implementation{ |
| 391 | Name: "test-client-concurrent", |
| 392 | Version: "1.0.0", |
| 393 | }, |
| 394 | }, |
| 395 | } |
| 396 | |
| 397 | _, err = mcpClient.Initialize(ctx, initReq) |
| 398 | require.NoError(t, err) |
| 399 | |
| 400 | // Test concurrent tool listings |
| 401 | const numConcurrent = 5 |
| 402 | eg, egCtx := errgroup.WithContext(ctx) |
| 403 | |
| 404 | for range numConcurrent { |
| 405 | eg.Go(func() error { |
| 406 | reqCtx, reqCancel := context.WithTimeout(egCtx, testutil.WaitLong) |
| 407 | defer reqCancel() |
| 408 | |
| 409 | tools, err := mcpClient.ListTools(reqCtx, mcp.ListToolsRequest{}) |
| 410 | if err != nil { |
| 411 | return err |
| 412 | } |
| 413 |
nothing calls this directly
no test coverage detected