install_packages
Install and manage npm packages with version control in specified project directories. Supports dev dependencies for streamlined Node.js development workflows.
Instructions
Install npm packages with version management
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dev | No | Install as dev dependency | |
| packages | Yes | Package names to install | |
| path | Yes | Project directory path |
Implementation Reference
- src/index.ts:964-990 (handler)The main handler function that validates the project path, checks for package.json, executes npm install command with optional dev flag, and returns success message with output or throws error.private async handleInstallPackages(args: InstallPackageArgs) { await this.validatePath(args.path); try { // Verify package.json exists const packageJsonPath = path.join(args.path, 'package.json'); await fs.access(packageJsonPath); // Install packages const installCmd = `npm install ${args.dev ? '--save-dev' : ''} ${args.packages.join(' ')}`; const { stdout, stderr } = await execAsync(installCmd, { cwd: args.path }); return { content: [ { type: 'text', text: `Packages installed successfully:\n${stdout}\n${stderr}`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to install packages: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:31-35 (schema)TypeScript interface defining the input arguments for the install_packages tool.interface InstallPackageArgs extends Record<string, unknown> { packages: string[]; path: string; dev?: boolean; }
- src/index.ts:249-272 (registration)Tool registration in ListToolsRequestSchema handler, including name, description, and JSON input schema.{ name: 'install_packages', description: 'Install npm packages with version management', inputSchema: { type: 'object', properties: { packages: { type: 'array', items: { type: 'string' }, description: 'Package names to install', }, path: { type: 'string', description: 'Project directory path', }, dev: { type: 'boolean', description: 'Install as dev dependency', default: false, }, }, required: ['packages', 'path'], }, },
- src/index.ts:397-398 (registration)Dispatch case in CallToolRequestSchema handler that routes to the install_packages handler function.case 'install_packages': return await this.handleInstallPackages(args as InstallPackageArgs);