{"record":{"id":"6e1f731c6251f312","repo":"charmbracelet/crush","slug":"w-s-6e1f73","errorCode":null,"errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/agent/tools/mcp/init.go","lineNumber":1330,"sourceCode":"}\n\nfunc stdioCheck(old *exec.Cmd) error {\n\tctx, cancel := context.WithTimeout(context.Background(), time.Second*5)\n\tdefer cancel()\n\t// old.Args includes argv0 as the first element; exec.CommandContext\n\t// prepends old.Path as argv0, so we must skip it to avoid duplication\n\t// (e.g. \"npx npx -y pkg\" instead of \"npx -y pkg\").\n\targs := old.Args\n\tif len(args) > 0 {\n\t\targs = args[1:]\n\t}\n\tcmd := exec.CommandContext(ctx, old.Path, args...)\n\tcmd.Env = old.Env\n\tout, err := cmd.CombinedOutput()\n\tif err == nil || errors.Is(ctx.Err(), context.DeadlineExceeded) {\n\t\treturn nil\n\t}\n\treturn fmt.Errorf(\"%w: %s\", err, string(out))\n}\n","sourceCodeStart":1312,"sourceCodeEnd":1332,"githubUrl":"https://github.com/charmbracelet/crush/blob/7944b8e52225d8805e31eacbf7ef24856b0dfb7a/internal/agent/tools/mcp/init.go#L1312-L1332","documentation":"stdioCheck re-runs a stdio MCP server's command with a 5-second timeout as a health probe. If the process exits non-zero before the deadline, the exec error is wrapped together with the process's combined stdout/stderr output so the user sees why the server binary failed. Timeout-expired probes are treated as success (server may just be long-running).","triggerScenarios":"Configured stdio command (`npx -y pkg`, `uvx ...`, a local binary) fails immediately: binary not found, script crashes, missing arguments, bad interpreter, or node/python dependency resolution fails with an error printed to stdout/stderr.","commonSituations":"Package not published or wrong version in npx/uvx invocation; shebang or permissions broken on a local script; runtime (node/python) not installed; network failure downloading the package on first run.","solutions":["Copy the MCP command from your config and run it manually in a terminal to see the same error output","If using npx/uvx, verify the package name/version exists and the runtime (node/python) is installed","Fix the underlying exec error (chmod +x, correct path, install missing dependency)","If the command is a long-lived server that prints errors but keeps running, ensure it exits 0 during startup or suppress the probe by fixing the noisy early exit"],"exampleFix":"// before (crushrc)\nmcp fetch {\n  type stdio\n  command \"uvx\"\n  args [\"fetch-server-mcp\"]  # package name wrong\n}\n// after\nmcp fetch {\n  type stdio\n  command \"uvx\"\n  args [\"mcp-server-fetch\"]\n}","handlingStrategy":"validation","validationCode":"// probe the stdio command exactly as the library will\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\ndefer cancel()\nout, err := exec.CommandContext(ctx, cmd, args...).CombinedOutput()\nif err != nil && ctx.Err() != context.DeadlineExceeded {\n    return fmt.Errorf(\"stdio command fails: %v: %s\", err, out)\n}","typeGuard":null,"tryCatchPattern":"// treat startup probe failure as a config problem, surface the output\nif err := stdioCheck(serverCmd); err != nil {\n    return fmt.Errorf(\"MCP stdio server %q failed to start: %w\", name, err)\n}","preventionTips":["Run every npx/uvx MCP command manually once before adding it to config","Pin package versions (npx -y pkg@1.2.3) to avoid surprise failures","Ensure the runtime interpreter exists in the PATH of the environment running Crush"],"tags":["mcp","stdio","process","exec"],"backgroundTag":"command-exit-nonzero","analyzedSha":"7944b8e52225d8805e31eacbf7ef24856b0dfb7a","analyzedAt":"2026-08-29T12:48:59.079Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}