uninstall
Remove npm packages from a project by specifying the absolute path to the package directory and package names. Optionally uninstall globally.
Instructions
Remove packages from a project
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| packages | Yes | Package names to uninstall | |
| global | No | Uninstall from global |
Implementation Reference
- src/index.ts:436-457 (handler)The server.tool registration and handler for 'uninstall'. Invokes run() with ['uninstall', ...packages] and optionally '-g', then returns stdout+stderr as text content.
server.tool( "uninstall", "Remove packages from a project", { path: z.string().describe("Absolute path to the package directory"), packages: z.array(z.string()).describe("Package names to uninstall"), global: z.boolean().optional().describe("Uninstall from global"), }, async ({ path, packages, global: isGlobal }) => { const args = ["uninstall", ...packages]; if (isGlobal) args.push("-g"); try { const { stdout, stderr } = await run(args, path); return { content: [{ type: "text", text: stdout + stderr }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:439-443 (schema)Zod schema for uninstall tool: requires 'path' (string) and 'packages' (array of strings), optional 'global' boolean.
{ path: z.string().describe("Absolute path to the package directory"), packages: z.array(z.string()).describe("Package names to uninstall"), global: z.boolean().optional().describe("Uninstall from global"), }, - src/index.ts:436-457 (registration)Registration of the 'uninstall' tool on the MCP server via server.tool(...) with name 'uninstall' and description 'Remove packages from a project'.
server.tool( "uninstall", "Remove packages from a project", { path: z.string().describe("Absolute path to the package directory"), packages: z.array(z.string()).describe("Package names to uninstall"), global: z.boolean().optional().describe("Uninstall from global"), }, async ({ path, packages, global: isGlobal }) => { const args = ["uninstall", ...packages]; if (isGlobal) args.push("-g"); try { const { stdout, stderr } = await run(args, path); return { content: [{ type: "text", text: stdout + stderr }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, ); - src/index.ts:1295-1299 (registration)Secondary registration of 'uninstall' on sandbox (sandbox.tool call), using a noop handler.
sandbox.tool("uninstall", "Remove packages from a project", { path: z.string().describe("Absolute path to the package directory"), packages: z.array(z.string()).describe("Package names to uninstall"), global: z.boolean().optional().describe("Uninstall from global"), }, noop); - src/index.ts:26-38 (helper)The run() helper function that executes npm commands (execFile) with args, cwd, timeout, and env settings.
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); }