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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| package | No | Specific package to look for | |
| depth | No | Dependency tree depth (default: 0) | |
| all | No | Show all packages, not just top-level | |
| global | No | List global packages | |
| production | No | Only show production dependencies |
Implementation Reference
- src/index.ts:376-402 (handler)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 }] }; } }, );