run_build
Execute build commands in a specified directory using package managers like npm, yarn, or pnpm. Simplifies development workflows by automating build processes with error reporting for efficient debugging.
Instructions
Run build command in the current directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | No | Build command to run (e.g., "npm run build", "yarn build") | npm run build |
| directory | No | Directory to run the build in (default: current directory) |
Implementation Reference
- src/index.ts:166-188 (handler)The handler function that implements the 'run_build' tool logic. It runs the specified build command (default: 'npm run build') in the given directory using execSync and returns the output or throws an error.private async runBuild(args: any) { const command = args?.command || 'npm run build'; const directory = args?.directory || process.cwd(); try { const output = execSync(command, { cwd: directory, encoding: 'utf8', timeout: 300000 // 5 minutes }); return { content: [ { type: 'text', text: `Build successful!\nCommand: ${command}\nDirectory: ${directory}\nOutput:\n${output}` } ] }; } catch (error: any) { throw new Error(`Build failed: ${error.message}\nStderr: ${error.stderr || 'N/A'}`); } }
- src/index.ts:45-62 (schema)The schema definition for the 'run_build' tool, including name, description, and input schema with optional command and directory parameters.{ name: 'run_build', description: 'Run build command in the current directory', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Build command to run (e.g., "npm run build", "yarn build")', default: 'npm run build' }, directory: { type: 'string', description: 'Directory to run the build in (default: current directory)' } } } },
- src/index.ts:139-140 (registration)Registration of the 'run_build' tool handler in the switch statement within the CallToolRequestSchema request handler.case 'run_build': return await this.runBuild(args);