Skip to main content
Glama

ls

List installed npm packages in a project directory to view dependencies, check specific packages, or examine dependency trees with configurable depth and scope options.

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 implementation of the 'ls' tool which lists installed packages in an npm project using 'npm ls'.
    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 }] };
        }
      },
    );

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