install
Install npm packages in a project directory, manage dependencies with options for dev, exact versions, global installs, or preview changes.
Instructions
Install packages in a project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| packages | No | Package names to install (empty = install all from package.json) | |
| saveDev | No | Save as devDependency | |
| saveExact | No | Save exact version instead of semver range | |
| global | No | Install globally | |
| dryRun | No | Preview install without making changes |
Implementation Reference
- src/index.ts:405-433 (handler)The implementation and registration of the 'install' tool. It defines the schema and executes the 'npm install' command using the 'run' helper function.
server.tool( "install", "Install packages in a project", { path: z.string().describe("Absolute path to the package directory"), packages: z.array(z.string()).optional().describe("Package names to install (empty = install all from package.json)"), saveDev: z.boolean().optional().describe("Save as devDependency"), saveExact: z.boolean().optional().describe("Save exact version instead of semver range"), global: z.boolean().optional().describe("Install globally"), dryRun: z.boolean().optional().describe("Preview install without making changes"), }, async ({ path, packages, saveDev, saveExact, global: isGlobal, dryRun }) => { const args = ["install"]; if (packages && packages.length > 0) args.push(...packages); if (saveDev) args.push("--save-dev"); if (saveExact) args.push("--save-exact"); if (isGlobal) args.push("-g"); if (dryRun) args.push("--dry-run"); try { const { stdout, stderr } = await run(args, path); return { content: [{ type: "text", text: stdout + stderr }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, );