install_packages
Install npm packages with version management in Node.js projects to manage dependencies and development tools.
Instructions
Install npm packages with version management
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| packages | Yes | Package names to install | |
| path | Yes | Project directory path | |
| dev | No | Install as dev dependency |
Implementation Reference
- src/index.ts:964-990 (handler)The main handler function that executes the installation of npm packages in the specified project directory. It validates the path, checks for package.json, runs 'npm install' with optional --save-dev flag, and returns success message with output.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: array of packages, project path, and optional dev flag.interface InstallPackageArgs extends Record<string, unknown> { packages: string[]; path: string; dev?: boolean; }
- src/index.ts:249-272 (registration)Tool registration in the ListTools response, including name, description, and detailed inputSchema for MCP protocol compliance.{ 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 the CallToolRequest handler that routes 'install_packages' calls to the specific handler function.case 'install_packages': return await this.handleInstallPackages(args as InstallPackageArgs);