MCPcopy Index your code
hub / github.com/coder/coder / TestMCPHTTP_E2E_ConcurrentRequests

Function TestMCPHTTP_E2E_ConcurrentRequests

coderd/mcp/mcp_e2e_test.go:356–427  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

354}
355
356func 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

Callers

nothing calls this directly

Calls 12

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
InitializeMethod · 0.80
WithContextMethod · 0.80
GoMethod · 0.80
CloseMethod · 0.65
LogfMethod · 0.65
StartMethod · 0.65
ListToolsMethod · 0.65
WaitMethod · 0.65
StringMethod · 0.45
SessionTokenMethod · 0.45

Tested by

no test coverage detected