config
List all npm configuration or get a specific key's value. Read-only operation ensures safe configuration inspection.
Instructions
View npm configuration (read-only for safety)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Action: list (show all config), get (get specific key) | |
| key | No | Config key to get (required for get action) |
Implementation Reference
- src/index.ts:939-953 (handler)The handler function that executes the 'config' tool logic. It builds npm config args (list/get), runs the npm command, and returns the output.
async ({ action, key }) => { const args = ["config", action]; if (action === "get" && key) args.push(key); if (action === "list") args.push("--json"); try { const { stdout } = await run(args); return { content: [{ type: "text", text: stdout }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:935-937 (schema)Zod schema defining the 'config' tool inputs: action (enum list/get) and optional key.
{ action: z.enum(["list", "get"]).describe("Action: list (show all config), get (get specific key)"), key: z.string().optional().describe("Config key to get (required for get action)"), - src/index.ts:932-953 (registration)Primary registration of the 'config' tool on the main MCP server using server.tool().
server.tool( "config", "View npm configuration (read-only for safety)", { action: z.enum(["list", "get"]).describe("Action: list (show all config), get (get specific key)"), key: z.string().optional().describe("Config key to get (required for get action)"), }, async ({ action, key }) => { const args = ["config", action]; if (action === "get" && key) args.push(key); if (action === "list") args.push("--json"); try { const { stdout } = await run(args); return { content: [{ type: "text", text: stdout }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:26-38 (helper)The 'run' helper function used by the config handler to execute npm commands via execFile.
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); } - src/index.ts:1396-1399 (registration)Secondary registration of the 'config' tool in a sandbox environment (noop handler, likely for testing/preview).
sandbox.tool("config", "View npm configuration", { action: z.enum(["list", "get"]).describe("Action"), key: z.string().optional().describe("Config key to get"), }, noop);