Skip to main content
Glama

prune

Remove extraneous packages not listed in package.json from a project directory. Optionally remove devDependencies and preview changes before making them.

Instructions

Remove extraneous packages not listed in package.json

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the package directory
productionNoRemove devDependencies
dryRunNoPreview changes without making them

Implementation Reference

  • Primary handler for the 'prune' tool. Runs `npm prune` with optional --omit=dev and --dry-run flags, executing via the `run()` helper.
    // ── npm prune ──
    server.tool(
      "prune",
      "Remove extraneous packages not listed in package.json",
      {
        path: z.string().describe("Absolute path to the package directory"),
        production: z.boolean().optional().describe("Remove devDependencies"),
        dryRun: z.boolean().optional().describe("Preview changes without making them"),
      },
      async ({ path, production, dryRun }) => {
        const args = ["prune"];
        if (production) args.push("--omit=dev");
        if (dryRun) args.push("--dry-run");
        try {
          const { stdout, stderr } = await run(args, path);
          return { content: [{ type: "text", text: stdout + stderr || "Prune complete" }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • Input schema for the 'prune' tool: path (required), production (optional boolean), dryRun (optional boolean).
    {
      path: z.string().describe("Absolute path to the package directory"),
      production: z.boolean().optional().describe("Remove devDependencies"),
      dryRun: z.boolean().optional().describe("Preview changes without making them"),
    },
  • src/index.ts:956-978 (registration)
    Registration of the 'prune' tool via server.tool() on the main McpServer instance.
    server.tool(
      "prune",
      "Remove extraneous packages not listed in package.json",
      {
        path: z.string().describe("Absolute path to the package directory"),
        production: z.boolean().optional().describe("Remove devDependencies"),
        dryRun: z.boolean().optional().describe("Preview changes without making them"),
      },
      async ({ path, production, dryRun }) => {
        const args = ["prune"];
        if (production) args.push("--omit=dev");
        if (dryRun) args.push("--dry-run");
        try {
          const { stdout, stderr } = await run(args, path);
          return { content: [{ type: "text", text: stdout + stderr || "Prune complete" }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • src/index.ts:1401-1405 (registration)
    Stub/placeholder registration of 'prune' tool in the sandbox server (createSandboxServer), using a noop handler.
    sandbox.tool("prune", "Remove extraneous packages", {
      path: z.string().describe("Absolute path to the package directory"),
      production: z.boolean().optional().describe("Remove devDependencies"),
      dryRun: z.boolean().optional().describe("Preview changes"),
    }, noop);
  • The `run()` helper function that executes npm commands as child processes. Used by the prune tool handler.
    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);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose any behavioral traits beyond the core action. It does not mention side effects, required permissions, or what happens if package.json is missing, leaving the agent with incomplete behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence of 8 words with no fluff or redundancy. It is immediately understandable and front-loaded with the core action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite 100% schema coverage, the description lacks contextual details such as typical use cases, error conditions, or return value. For a tool with no output schema, the description should provide more guidance on what the agent can expect after invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% parameter description coverage, so the schema already explains the three parameters. The description adds no additional meaning beyond the schema, meeting the baseline but not exceeding it.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'remove' and the object 'extraneous packages not listed in package.json', which is specific to the npm prune command. This distinguishes it from siblings like 'uninstall' which removes explicitly specified packages.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool instead of alternatives such as 'uninstall' or 'dedupe'. The description does not mention conditions for use, prerequisites, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikusnuz/npm-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server