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

Function TestMCPHTTP_E2E_ErrorHandling

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

Source from the content-addressed store, hash-verified

295}
296
297func TestMCPHTTP_E2E_ErrorHandling(t *testing.T) {
298 t.Parallel()
299
300 // Setup Coder server
301 coderClient, closer, api := coderdtest.NewWithAPI(t, &coderdtest.Options{
302 IncludeProvisionerDaemon: true,
303 })
304 defer closer.Close()
305
306 _ = coderdtest.CreateFirstUser(t, coderClient)
307
308 // Create MCP client
309 mcpURL := api.AccessURL.String() + mcpserver.MCPEndpoint
310 mcpClient, err := mcpclient.NewStreamableHttpClient(mcpURL,
311 transport.WithHTTPHeaders(map[string]string{
312 "Authorization": "Bearer " + coderClient.SessionToken(),
313 }))
314 require.NoError(t, err)
315 defer func() {
316 if closeErr := mcpClient.Close(); closeErr != nil {
317 t.Logf("Failed to close MCP client: %v", closeErr)
318 }
319 }()
320
321 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
322 defer cancel()
323
324 // Start and initialize client
325 err = mcpClient.Start(ctx)
326 require.NoError(t, err)
327
328 initReq := mcp.InitializeRequest{
329 Params: mcp.InitializeParams{
330 ProtocolVersion: mcp.LATEST_PROTOCOL_VERSION,
331 ClientInfo: mcp.Implementation{
332 Name: "test-client-errors",
333 Version: "1.0.0",
334 },
335 },
336 }
337
338 _, err = mcpClient.Initialize(ctx, initReq)
339 require.NoError(t, err)
340
341 // Test calling non-existent tool
342 toolReq := mcp.CallToolRequest{
343 Params: mcp.CallToolParams{
344 Name: "nonexistent_tool",
345 Arguments: map[string]any{},
346 },
347 }
348
349 _, err = mcpClient.CallTool(ctx, toolReq)
350 require.Error(t, err, "Should get error when calling non-existent tool")
351 require.Contains(t, err.Error(), "nonexistent_tool", "Should mention the tool name in error message")
352
353 t.Logf("Error handling test successful: Got expected error for non-existent tool")
354}

Callers

nothing calls this directly

Calls 11

NewWithAPIFunction · 0.92
CreateFirstUserFunction · 0.92
InitializeMethod · 0.80
CloseMethod · 0.65
LogfMethod · 0.65
StartMethod · 0.65
CallToolMethod · 0.65
StringMethod · 0.45
SessionTokenMethod · 0.45
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected