detox_init
Initialize end-to-end testing for React Native projects by creating folder structure and configuration for the Detox framework.
Instructions
Initialize Detox in a React Native project. Creates e2e folder structure and configuration.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | Yes | Path to React Native project root | |
| testRunner | No | jest |
Implementation Reference
- src/tools/index.ts:153-176 (handler)Complete definition of the detox_init tool, including its handler function that executes the Detox 'init' CLI command with optional testRunner argument.export const initTool: Tool = { name: "detox_init", description: "Initialize Detox in a React Native project. Creates e2e folder structure and configuration.", inputSchema: zodToJsonSchema(InitArgsSchema), handler: async (args: z.infer<typeof InitArgsSchema>) => { const parsed = InitArgsSchema.parse(args); const cliArgs: string[] = ["init"]; if (parsed.testRunner) { cliArgs.push("-r", parsed.testRunner); } const result = await executeDetoxCommand(cliArgs, { cwd: parsed.projectPath }); return { success: result.success, output: result.stdout, errors: result.stderr, message: result.success ? "Detox initialized successfully. Check the e2e folder for test files." : "Failed to initialize Detox.", }; }, };
- src/utils/validators.ts:38-43 (schema)Zod input schema for detox_init tool defining projectPath (required) and testRunner (optional, defaults to 'jest').export const InitArgsSchema = z.object({ projectPath: z.string().describe("Path to React Native project root"), testRunner: z.enum(["jest", "mocha"]).optional().default("jest"), }); export type InitArgs = z.infer<typeof InitArgsSchema>;
- src/tools/index.ts:432-432 (registration)The detox_init tool (initTool) is registered by inclusion in the allTools export array used by the MCP server.initTool,
- src/index.ts:40-48 (registration)MCP ListTools handler that registers all tools including detox_init by mapping from allTools.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: allTools.map((tool) => ({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema, })), }; });
- src/index.ts:50-94 (registration)MCP CallTool handler that dispatches to the specific tool handler (including detox_init) found by name in allTools.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, }; } });