{"record":{"id":"f1ac8f01472f90a4","repo":"dagger/dagger","slug":"failed-to-get-tools-w","errorCode":null,"errorMessage":"failed to get tools: %w","messagePattern":"failed to get tools: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/mcpserver.go","lineNumber":84,"sourceCode":"\tfor _, tool := range llmTools {\n\t\t// Skipping methods that return ID\n\t\tif strings.HasSuffix(tool.Name, \"_id\") {\n\t\t\tcontinue\n\t\t}\n\n\t\tmcpTool, err := genMcpTool(tool)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tmcpTools = append(mcpTools, mcpserver.ServerTool{Tool: mcpTool, Handler: s.genMcpToolHandler(tool)})\n\t}\n\treturn mcpTools, nil\n}\n\nfunc (s mcpServer) setTools(ctx context.Context) error {\n\ttools, err := s.env.Tools(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get tools: %w\", err)\n\t}\n\tmcpTools, err := s.convertToMcpTools(tools)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to convert tools to MCP: %w\", err)\n\t}\n\ts.SetTools(mcpTools...)\n\treturn nil\n}\n\nfunc (s mcpServer) run(ctx context.Context) error {\n\tctx, cancel := context.WithCancel(ctx)\n\tdefer cancel()\n\n\tif err := s.setTools(ctx); err != nil {\n\t\treturn err\n\t}\n\n\terrCh := make(chan error)","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/core/mcpserver.go#L66-L102","documentation":"Returned by mcpServer.setTools (core/mcpserver.go) when s.env.Tools(ctx) fails to enumerate the tools exposed by the LLM's MCP environment. setTools runs at server startup and after every tool call, so any failure resolving the tool list aborts the MCP server operation. The engine-side cause is wrapped via %w.","triggerScenarios":"setTools is invoked (on run startup, or after each tool call from genMcpToolHandler) and env.Tools(ctx) returns an error — engine query failure, canceled context, or broken module/session state.","commonSituations":"Context canceled while listing tools after a call; engine connection dropped mid-session; the bound module/environment is in a bad state after a failed module load.","solutions":["Inspect the wrapped error for the root cause (context canceled, query failure, etc.).","Verify the engine connection is alive and retry the dagger mcp command.","If it fires after every tool call, check the state of the bound module/environment — rebind tools and restart.","Ensure no surrounding code cancels the context prematurely."],"exampleFix":"// before\nctx, cancel := context.WithCancel(parent)\ndefer cancel() // cancels ctx, breaking post-call setTools\n// after\nctx, cancel := context.WithCancel(parent)\n// keep ctx alive for the lifetime of the MCP server session","handlingStrategy":"try-catch","validationCode":"if err := ctx.Err(); err != nil {\n    return fmt.Errorf(\"cannot list tools: context done: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := s.setTools(ctx); err != nil {\n    if errors.Is(err, context.Canceled) {\n        return nil // shutting down; not a real failure\n    }\n    return fmt.Errorf(\"refresh tools failed: %w\", err)\n}","preventionTips":["Keep the server context alive for the whole MCP session; don't cancel mid-call.","Monitor engine connectivity for long-running mcp sessions.","Log wrapped causes to distinguish session teardown from real tool-listing failures."],"tags":["mcp","tools","engine","go"],"backgroundTag":"tool-listing-failed","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}