Skip to main content
Glama

ls

List installed npm packages in a project by specifying the absolute path. Filter by depth, global, all, or production dependencies to view dependency trees.

Instructions

List installed packages in a project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesAbsolute path to the package directory
packageNoSpecific package to look for
depthNoDependency tree depth (default: 0)
allNoShow all packages, not just top-level
globalNoList global packages
productionNoOnly show production dependencies

Implementation Reference

  • The async handler function that executes the 'ls' tool. It runs `npm ls --json` with optional parameters (package, depth, all, global, production) and returns the JSON output. It catches non-zero exit codes (expected when missing/extraneous packages exist) and returns stdout/stderr.
    async ({ path, package: pkg, depth, all, global: isGlobal, production }) => {
      const args = ["ls", "--json"];
      if (pkg) args.push(pkg);
      if (depth !== undefined) args.push("--depth", String(depth));
      if (all) args.push("--all");
      if (isGlobal) args.push("-g");
      if (production) args.push("--omit=dev");
      try {
        const { stdout } = await run(args, path);
        return { content: [{ type: "text", text: stdout }] };
      } catch (e: any) {
        // npm ls exits non-zero when there are missing/extraneous packages
        return { content: [{ type: "text", text: e.stdout || e.stderr || e.message }] };
      }
    },
  • Input schema for the 'ls' tool, defining Zod validations for path, package, depth, all, global, and production parameters.
    {
      path: z.string().describe("Absolute path to the package directory"),
      package: z.string().optional().describe("Specific package to look for"),
      depth: z.number().optional().describe("Dependency tree depth (default: 0)"),
      all: z.boolean().optional().describe("Show all packages, not just top-level"),
      global: z.boolean().optional().describe("List global packages"),
      production: z.boolean().optional().describe("Only show production dependencies"),
    },
  • src/index.ts:376-402 (registration)
    Registration of the 'ls' tool on the main `server` object using `server.tool("ls", ...)`. This is the primary registration where the tool is added to the MCP server with its schema and handler.
    server.tool(
      "ls",
      "List installed packages in a project",
      {
        path: z.string().describe("Absolute path to the package directory"),
        package: z.string().optional().describe("Specific package to look for"),
        depth: z.number().optional().describe("Dependency tree depth (default: 0)"),
        all: z.boolean().optional().describe("Show all packages, not just top-level"),
        global: z.boolean().optional().describe("List global packages"),
        production: z.boolean().optional().describe("Only show production dependencies"),
      },
      async ({ path, package: pkg, depth, all, global: isGlobal, production }) => {
        const args = ["ls", "--json"];
        if (pkg) args.push(pkg);
        if (depth !== undefined) args.push("--depth", String(depth));
        if (all) args.push("--all");
        if (isGlobal) args.push("-g");
        if (production) args.push("--omit=dev");
        try {
          const { stdout } = await run(args, path);
          return { content: [{ type: "text", text: stdout }] };
        } catch (e: any) {
          // npm ls exits non-zero when there are missing/extraneous packages
          return { content: [{ type: "text", text: e.stdout || e.stderr || e.message }] };
        }
      },
    );
  • src/index.ts:1277-1284 (registration)
    Sandbox registration of the 'ls' tool via `sandbox.tool("ls", ...)`. This is a secondary registration in the `createSandboxServer()` function, but uses a noop handler so it does not execute real logic.
    sandbox.tool("ls", "List installed packages in a project", {
      path: z.string().describe("Absolute path to the package directory"),
      package: z.string().optional().describe("Specific package to look for"),
      depth: z.number().optional().describe("Dependency tree depth"),
      all: z.boolean().optional().describe("Show all packages"),
      global: z.boolean().optional().describe("List global packages"),
      production: z.boolean().optional().describe("Only show production dependencies"),
    }, noop);
  • The `run()` helper function used by the 'ls' handler. It executes the npm CLI via `execFile`, adding npmrc args for authentication and setting a 10MB buffer and 120s timeout.
    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 present, and the description does not disclose behavioral traits such as whether it shows all dependencies, performance implications, or error handling. The minimal description leaves the agent uninformed about side effects or trustworthiness.

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?

The description is a single, front-loaded phrase with no unnecessary words. It is efficient, though it could be expanded slightly to include essential context without losing conciseness.

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 complexity (6 parameters, no output schema), the description fails to explain the output format, typical usage patterns, or how filtering parameters interact. The agent lacks sufficient information to use the tool effectively across scenarios.

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?

The input schema has 100% coverage with clear descriptions for all six parameters. The tool description adds no extra meaning beyond the schema. Baseline of 3 is appropriate as the description does not enhance the agent's understanding of parameter usage.

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 states the action 'List' and resource 'installed packages' clearly. Among siblings like install, uninstall, view, etc., it distinguishes itself as a listing operation. However, it does not explicitly differentiate from related commands like 'search' or 'outdated'.

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. The context signals list many sibling tools, but the description lacks any indication of prerequisites, scope, or substitution advice.

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