(t *testing.T)
| 295 | } |
| 296 | |
| 297 | func 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 | } |
nothing calls this directly
no test coverage detected