run_build
Execute build commands like npm run build or yarn build to compile projects, supporting multiple package managers and providing error reporting for development workflows.
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 main handler function that runs the build command using execSync with configurable command and directory, returning success output or throwing 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:48-61 (schema)JSON schema defining the input parameters for the run_build tool: command (string, default 'npm run build') and optional directory (string).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:45-62 (registration)Tool registration in the ListToolsRequestSchema handler, providing name, description, and input schema.{ 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)Handler dispatch for 'run_build' in the CallToolRequestSchema switch statement, calling the runBuild method.case 'run_build': return await this.runBuild(args);