detox_build
Build mobile apps for Detox end-to-end testing by executing configured build commands to prepare applications for React Native testing scenarios.
Instructions
Build the app for Detox testing. Runs the build command from your Detox configuration.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| configuration | No | Device configuration name | |
| configPath | No | Path to Detox config file | |
| ifMissing | No | Only build if app binary is missing | |
| silent | No | Don't fail if no build command exists | |
| cwd | No | Working directory |
Implementation Reference
- src/tools/index.ts:44-74 (handler)The complete tool definition for 'detox_build', including the handler function that parses input arguments and executes the 'detox build' CLI command via executeDetoxCommand.export const buildTool: Tool = { name: "detox_build", description: "Build the app for Detox testing. Runs the build command from your Detox configuration.", inputSchema: zodToJsonSchema(BuildArgsSchema), handler: async (args: z.infer<typeof BuildArgsSchema>) => { const parsed = BuildArgsSchema.parse(args); const cliArgs: string[] = ["build"]; if (parsed.configuration) { cliArgs.push("-c", parsed.configuration); } if (parsed.configPath) { cliArgs.push("-C", parsed.configPath); } if (parsed.ifMissing) { cliArgs.push("--if-missing"); } if (parsed.silent) { cliArgs.push("--silent"); } const result = await executeDetoxCommand(cliArgs, { cwd: parsed.cwd }); return { success: result.success, output: result.stdout, errors: result.stderr, duration: `${(result.duration / 1000).toFixed(1)}s`, }; }, };
- src/utils/validators.ts:4-10 (schema)Zod schema defining the input parameters for the detox_build tool.export const BuildArgsSchema = z.object({ configuration: z.string().optional().describe("Device configuration name"), configPath: z.string().optional().describe("Path to Detox config file"), ifMissing: z.boolean().optional().default(false).describe("Only build if app binary is missing"), silent: z.boolean().optional().default(false).describe("Don't fail if no build command exists"), cwd: z.string().optional().describe("Working directory"), });
- src/utils/cli-executor.ts:23-82 (helper)Helper function that executes the Detox CLI command by spawning 'npx detox' process, captures stdout/stderr, handles timeout and errors, used by detox_build handler.export async function executeDetoxCommand( args: string[], options: ExecutionOptions = {} ): Promise<ExecutionResult> { const startTime = Date.now(); const cwd = options.cwd || process.cwd(); const timeout = options.timeout || 300000; // 5 minutes default return new Promise((resolve) => { const proc = spawn("npx", ["detox", ...args], { cwd, shell: true, env: { ...process.env, ...options.env }, }); let stdout = ""; let stderr = ""; proc.stdout.on("data", (data) => { stdout += data.toString(); }); proc.stderr.on("data", (data) => { stderr += data.toString(); }); const timeoutId = setTimeout(() => { proc.kill("SIGTERM"); resolve({ success: false, stdout, stderr: stderr + "\nProcess timed out", exitCode: null, duration: Date.now() - startTime, }); }, timeout); proc.on("close", (code) => { clearTimeout(timeoutId); resolve({ success: code === 0, stdout, stderr, exitCode: code, duration: Date.now() - startTime, }); }); proc.on("error", (error) => { clearTimeout(timeoutId); resolve({ success: false, stdout, stderr: error.message, exitCode: null, duration: Date.now() - startTime, }); }); }); }
- src/tools/index.ts:429-442 (registration)Registration of detox_build as part of the allTools array exported for use in MCP server.export const allTools: Tool[] = [ buildTool, testTool, initTool, readConfigTool, listConfigurationsTool, validateConfigTool, createConfigTool, listDevicesTool, generateTestTool, generateMatcherTool, generateActionTool, generateExpectationTool, ];
- src/index.ts:50-94 (registration)MCP server request handler for calling tools, which finds and executes the detox_build handler when requested.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const tool = allTools.find((t) => t.name === name); if (!tool) { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } try { // Add project path to args if not specified const argsWithPath = { ...args, cwd: (args as any)?.cwd || PROJECT_PATH, projectPath: (args as any)?.projectPath || PROJECT_PATH, }; const result = await tool.handler(argsWithPath); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: JSON.stringify( { success: false, error: error.message, }, null, 2 ), }, ], isError: true, }; } });