run_test
Execute test commands in a specified directory using the Build MCP Server. Simplifies development workflows by running tests with defined commands, supporting npm, yarn, and pnpm, and providing detailed error reporting.
Instructions
Run tests in the current directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | No | Test command to run (e.g., "npm test", "yarn test") | npm test |
| directory | No | Directory to run tests in (default: current directory) |
Implementation Reference
- src/index.ts:190-212 (handler)The main handler function for the 'run_test' tool. It executes the test command (default 'npm test') in the specified directory using execSync, captures output, and returns success or throws error with details.private async runTest(args: any) { const command = args?.command || 'npm test'; const directory = args?.directory || process.cwd(); try { const output = execSync(command, { cwd: directory, encoding: 'utf8', timeout: 300000 // 5 minutes }); return { content: [ { type: 'text', text: `Tests passed!\nCommand: ${command}\nDirectory: ${directory}\nOutput:\n${output}` } ] }; } catch (error: any) { throw new Error(`Tests failed: ${error.message}\nStderr: ${error.stderr || 'N/A'}`); } }
- src/index.ts:63-80 (schema)The schema definition for the 'run_test' tool, including inputSchema with optional command (default 'npm test') and directory parameters, registered in the ListTools response.{ name: 'run_test', description: 'Run tests in the current directory', inputSchema: { type: 'object', properties: { command: { type: 'string', description: 'Test command to run (e.g., "npm test", "yarn test")', default: 'npm test' }, directory: { type: 'string', description: 'Directory to run tests in (default: current directory)' } } } },
- src/index.ts:141-142 (registration)The registration/dispatch point in the CallToolRequestSchema handler switch statement, which routes calls to the runTest method.case 'run_test': return await this.runTest(args);