{"record":{"id":"153c6ec567ca0670","repo":"charmbracelet/crush","slug":"failed-to-wait-for-mcp-initialization-w-153c6e","errorCode":null,"errorMessage":"failed to wait for MCP initialization: %w","messagePattern":"failed to wait for MCP initialization: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/app/app.go","lineNumber":320,"sourceCode":"\t\t})\n\t\tspinner.Start()\n\t}\n\n\t// Helper function to stop spinner once.\n\tstopSpinner := func() {\n\t\tif !hideSpinner && spinner != nil {\n\t\t\tspinner.Stop()\n\t\t\tspinner = nil\n\t\t}\n\t}\n\n\t// Non-interactive runs get a single shot at the tool palette, so wait for\n\t// MCP initialization to settle before reading MCP tools. The coordinator\n\t// waits again for the same reason (it is the gate the client/server path\n\t// goes through); doing it here too surfaces the failure before we create a\n\t// session, and lets the UpdateModels below see every MCP tool.\n\tif err := mcp.WaitForInit(ctx); err != nil {\n\t\treturn fmt.Errorf(\"failed to wait for MCP initialization: %w\", err)\n\t}\n\n\t// force update of agent models before running so mcp tools are loaded\n\tapp.AgentCoordinator.UpdateModels(ctx)\n\n\tdefer stopSpinner()\n\n\tsess, err := app.resolveSession(ctx, continueSessionID, useLast)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create session for non-interactive mode: %w\", err)\n\t}\n\n\tif continueSessionID != \"\" || useLast {\n\t\tslog.Info(\"Continuing session for non-interactive run\", \"session_id\", sess.ID)\n\t\t// If no explicit model override was requested, restore the\n\t\t// model/provider from the last assistant message in the\n\t\t// session, provided it is still available.\n\t\tif largeModel == \"\" && smallModel == \"\" {","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/app/app.go#L302-L338","documentation":"Non-interactive runs must have the full MCP tool palette available before a session is created, so RunNonInteractive calls mcp.WaitForInit(ctx) to block until MCP servers finish initializing. If initialization does not settle before the context is done (timeout, cancellation, or an MCP server erroring during startup), this error is returned.","triggerScenarios":"An MCP server defined in config fails to launch (bad command, missing binary), hangs during handshake, or ctx is cancelled/times out before all MCP clients initialize.","commonSituations":"MCP server command typo or not on PATH in crushrc/crush.json; slow-starting MCP server exceeding the run timeout; running `crush run` in CI where MCP servers need network access that is blocked.","solutions":["Test the MCP server command manually (it must be executable and on PATH)","Remove or fix broken `mcp` entries in crushrc/crush.json","Increase the context timeout or MCP init timeout for slow servers","Run with SLOG_LEVEL=debug to see which MCP client failed"],"exampleFix":"// before\n{\"mcp\": {\"fs\": {\"command\": \"mcp-server-filesystem\"}}} // binary not installed\n// after\n{\"mcp\": {\"fs\": {\"command\": \"npx\", \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/tmp\"]}}}","handlingStrategy":"validation","validationCode":"for name, m := range cfg.MCP {\n\tif m.Command != \"\" {\n\t\tif _, err := exec.LookPath(m.Command); err != nil {\n\t\t\treturn fmt.Errorf(\"mcp %q command not found: %w\", name, err)\n\t\t}\n\t}\n}","typeGuard":null,"tryCatchPattern":"ctx, cancel := context.WithTimeout(ctx, 60*time.Second)\ndefer cancel()\nif err := app.RunNonInteractive(ctx, w, prompt, \"\", \"\", true, \"\", false); err != nil {\n\tif strings.Contains(err.Error(), \"MCP initialization\") {\n\t\treturn fmt.Errorf(\"mcp servers failed to start; check `mcp` config: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Smoke-test every MCP server command manually before adding it to config","Give MCP init a generous timeout in CI pipelines","Remove unused MCP servers from crushrc to shrink init surface"],"tags":["go","mcp","initialization","timeout"],"backgroundTag":"mcp-init-timeout","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}