doctor
Run diagnostics to assess npm environment health, detect configuration issues, and identify missing dependencies or security problems.
Instructions
Run diagnostics to check npm environment health
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:892-906 (handler)The actual handler for the 'doctor' tool. It runs 'npm doctor' via the run() helper and captures stdout/stderr. Since 'npm doctor' can exit non-zero when checks fail, the catch block returns the error output instead of marking it as an isError.
// ── npm doctor ── server.tool( "doctor", "Run diagnostics to check npm environment health", {}, async () => { try { const { stdout, stderr } = await run(["doctor"]); return { content: [{ type: "text", text: stdout + stderr }] }; } catch (e: any) { // doctor may exit non-zero if checks fail return { content: [{ type: "text", text: e.stdout || e.stderr || e.message }] }; } }, ); - src/index.ts:893-906 (registration)Registration of the 'doctor' tool on the main server using server.tool() with name 'doctor', description 'Run diagnostics to check npm environment health', and an empty schema object (no input parameters).
server.tool( "doctor", "Run diagnostics to check npm environment health", {}, async () => { try { const { stdout, stderr } = await run(["doctor"]); return { content: [{ type: "text", text: stdout + stderr }] }; } catch (e: any) { // doctor may exit non-zero if checks fail return { content: [{ type: "text", text: e.stdout || e.stderr || e.message }] }; } }, ); - src/index.ts:1389-1389 (registration)Sandbox registration of the 'doctor' tool via sandbox.tool(). Uses a noop handler that returns 'sandbox' text, with empty schema (no parameters).
sandbox.tool("doctor", "Run diagnostics to check npm environment health", {}, noop); - src/index.ts:26-38 (helper)The run() helper function used by the doctor handler. It executes the npm CLI via execFile with a 120s timeout and 10MB buffer, passing NO_COLOR=1 env var and optional NPM_TOKEN auth args.
async function run( args: string[], cwd?: string, ): Promise<{ stdout: string; stderr: string }> { const fullArgs = [...args, ...npmrcArgs]; const opts: { cwd?: string; timeout: number; env: NodeJS.ProcessEnv; maxBuffer: number } = { timeout: 120_000, maxBuffer: 10 * 1024 * 1024, // 10MB buffer for large outputs env: { ...process.env, NO_COLOR: "1" }, }; if (cwd) opts.cwd = cwd; return exec(NPM, fullArgs, opts); }