Skip to main content
Glama

diff

Diff npm packages: compare two package versions, or a local package against its published registry version. Specify versions via range or array, or provide local path.

Instructions

Show diff between package versions or between local and registry

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packageNoPackage spec for comparison (e.g. pkg@1.0.0..pkg@2.0.0)
specsNoTwo package specs to compare (e.g. ['pkg@1.0.0', 'pkg@2.0.0'])
pathNoAbsolute path to local package (compares local vs registry)
diffNameOnlyNoOnly show file names that changed

Implementation Reference

  • The handler function for the 'diff' tool. It constructs npm diff CLI arguments (--diff for package specs, --diff-name-only option), executes the npm diff command via the run() helper, and returns the stdout as text content or an error message.
      async ({ package: pkg, specs, path, diffNameOnly }) => {
        const args = ["diff"];
        if (specs && specs.length > 0) {
          for (const s of specs) args.push(`--diff=${s}`);
        } else if (pkg) {
          args.push(`--diff=${pkg}`);
        }
        if (diffNameOnly) args.push("--diff-name-only");
        try {
          const { stdout } = await run(args, path);
          return { content: [{ type: "text", text: stdout || "No differences found" }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • Schema/registration for the 'diff' tool showing its name, description, and input parameters defined with Zod (package, specs, path, diffNameOnly).
    server.tool(
      "diff",
      "Show diff between package versions or between local and registry",
      {
        package: z.string().optional().describe("Package spec for comparison (e.g. pkg@1.0.0..pkg@2.0.0)"),
        specs: z.array(z.string()).optional().describe("Two package specs to compare (e.g. ['pkg@1.0.0', 'pkg@2.0.0'])"),
        path: z.string().optional().describe("Absolute path to local package (compares local vs registry)"),
        diffNameOnly: z.boolean().optional().describe("Only show file names that changed"),
      },
  • src/index.ts:661-689 (registration)
    Full registration of the 'diff' tool on the MCP server with server.tool(). Includes schema, description, and handler.
    // ── npm diff ──
    server.tool(
      "diff",
      "Show diff between package versions or between local and registry",
      {
        package: z.string().optional().describe("Package spec for comparison (e.g. pkg@1.0.0..pkg@2.0.0)"),
        specs: z.array(z.string()).optional().describe("Two package specs to compare (e.g. ['pkg@1.0.0', 'pkg@2.0.0'])"),
        path: z.string().optional().describe("Absolute path to local package (compares local vs registry)"),
        diffNameOnly: z.boolean().optional().describe("Only show file names that changed"),
      },
      async ({ package: pkg, specs, path, diffNameOnly }) => {
        const args = ["diff"];
        if (specs && specs.length > 0) {
          for (const s of specs) args.push(`--diff=${s}`);
        } else if (pkg) {
          args.push(`--diff=${pkg}`);
        }
        if (diffNameOnly) args.push("--diff-name-only");
        try {
          const { stdout } = await run(args, path);
          return { content: [{ type: "text", text: stdout || "No differences found" }] };
        } catch (e: any) {
          return {
            content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }],
            isError: true,
          };
        }
      },
    );
  • Helper function 'run' that executes npm commands using promisified execFile. Used by the diff handler to run 'npm diff'.
    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:1337-1342 (registration)
    Sandbox registration of the 'diff' tool with a noop handler (used in sandbox/smithery mode).
    sandbox.tool("diff", "Show diff between package versions", {
      package: z.string().optional().describe("Package spec for comparison"),
      specs: z.array(z.string()).optional().describe("Two package specs to compare"),
      path: z.string().optional().describe("Absolute path to local package"),
      diffNameOnly: z.boolean().optional().describe("Only show file names that changed"),
    }, noop);
Behavior2/5

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

No annotations provided, and description lacks behavioral details. It doesn't state if the tool is read-only, fetches registry data, or has side effects. The agent cannot infer safety or network usage.

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

Conciseness4/5

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

Single 12-word sentence that front-loads the verb and resource. No wasted words, though slightly more structure (e.g., listing modes) could improve readability without adding length.

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?

With 4 parameters, no output schema, and no annotations, the description is insufficient. It doesn't explain the two comparison modes (package spec vs local path) or the behavior of 'diffNameOnly'.

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 coverage is 100% with parameter descriptions. The description adds no extra meaning beyond the schema, meeting the baseline for high coverage.

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?

Description clearly states verb 'show diff' and resources 'package versions' or 'local vs registry'. This distinguishes it from sibling tools like 'version', 'publish', or 'view'.

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 on when to use diff vs alternatives. For example, it doesn't mention that 'view' shows current version or 'outdated' lists newer versions, leaving the agent to guess.

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