Skip to main content
Glama

cache

Manage the npm cache: clear outdated packages to free disk space, verify cache integrity to prevent corruption, or list cached contents to inspect stored packages.

Instructions

Manage the npm cache

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesAction: clean (clear cache), verify (check integrity), ls (list contents)
forceNoForce clean (required for clean action)

Implementation Reference

  • The tool handler for 'cache' - calls 'npm cache <action>' with optional --force flag, returns stdout/stderr or error.
    server.tool(
      "cache",
      "Manage the npm cache",
      {
        action: z.enum(["clean", "verify", "ls"]).describe("Action: clean (clear cache), verify (check integrity), ls (list contents)"),
        force: z.boolean().optional().describe("Force clean (required for clean action)"),
      },
      async ({ action, force }) => {
        const args = ["cache", action];
        if (action === "clean" && force) args.push("--force");
        try {
          const { stdout, stderr } = await run(args);
          return { content: [{ type: "text", text: stdout + stderr || "Done" }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • Input schema for 'cache' tool - requires 'action' enum (clean/verify/ls) and optional 'force' boolean.
    {
      action: z.enum(["clean", "verify", "ls"]).describe("Action: clean (clear cache), verify (check integrity), ls (list contents)"),
      force: z.boolean().optional().describe("Force clean (required for clean action)"),
  • src/index.ts:909-929 (registration)
    Registration of the 'cache' tool on the primary 'server' McpServer instance via server.tool().
    server.tool(
      "cache",
      "Manage the npm cache",
      {
        action: z.enum(["clean", "verify", "ls"]).describe("Action: clean (clear cache), verify (check integrity), ls (list contents)"),
        force: z.boolean().optional().describe("Force clean (required for clean action)"),
      },
      async ({ action, force }) => {
        const args = ["cache", action];
        if (action === "clean" && force) args.push("--force");
        try {
          const { stdout, stderr } = await run(args);
          return { content: [{ type: "text", text: stdout + stderr || "Done" }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • src/index.ts:1391-1394 (registration)
    Registration of the 'cache' tool in the sandbox/exported createSandboxServer() (stub/noop handler).
    sandbox.tool("cache", "Manage the npm cache", {
      action: z.enum(["clean", "verify", "ls"]).describe("Action"),
      force: z.boolean().optional().describe("Force clean"),
    }, noop);
  • Helper 'run' function used by the cache 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);
    }
Behavior2/5

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

No annotations exist, so the description must fully disclose behavior. It does not mention that 'clean' is destructive, that 'verify' checks integrity without side effects, or that 'ls' lists contents. The description provides no behavioral traits beyond the generic term 'manage'.

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

Conciseness3/5

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

The description is very short (two words) but not structured as a proper sentence. It is concise but under-specified, lacking crucial details that a complete sentence would provide.

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?

Given the tool supports three distinct actions and has a required force flag, the description is insufficient. It does not explain output, error conditions, or effects, and without an output schema, the agent lacks essential context for correct 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?

Schema description coverage is 100% and already explains the 'action' enum and 'force' parameter. The description adds no additional semantics beyond the schema, meeting the baseline of 3.

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

Purpose4/5

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

The description clearly identifies the resource (npm cache) but uses the vague verb 'manage'. It does not distinguish from sibling tools like 'ls' or 'install', but the schema's action enum provides specificity. Accordingly, it is clear but lacks sibling differentiation.

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 guidance is provided on when to use this tool versus alternatives (e.g., when to clean vs verify, or when to use other tools like 'install' for cache-related tasks). There are no hints about 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