detox_create_config
Generate a Detox configuration file to set up end-to-end testing for React Native mobile applications across specified platforms.
Instructions
Generate a new Detox configuration file for your React Native project.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | Yes | Path to project root | |
| platforms | Yes | Platforms to configure | |
| appName | No | Application name | |
| bundleId | No | iOS bundle identifier | |
| packageName | No | Android package name |
Implementation Reference
- src/tools/index.ts:262-291 (handler)The main handler function for the detox_create_config tool. It validates input args, generates a default Detox config using generateDefaultConfig, formats it as a .detoxrc.js module, writes it to the project path, and returns the config path and details.export const createConfigTool: Tool = { name: "detox_create_config", description: "Generate a new Detox configuration file for your React Native project.", inputSchema: zodToJsonSchema(CreateConfigArgsSchema), handler: async (args: z.infer<typeof CreateConfigArgsSchema>) => { const parsed = CreateConfigArgsSchema.parse(args); const config = generateDefaultConfig({ platforms: parsed.platforms, appName: parsed.appName, bundleId: parsed.bundleId, packageName: parsed.packageName, }); const configContent = `/** @type {import('detox').DetoxConfig} */ module.exports = ${JSON.stringify(config, null, 2)}; `; const configPath = `${parsed.projectPath}/.detoxrc.js`; await writeFile(configPath, configContent, "utf-8"); return { success: true, configPath, config, message: `Configuration created at ${configPath}`, }; }, };
- src/utils/validators.ts:69-77 (schema)Zod schema defining the input parameters for the detox_create_config tool, including required projectPath and platforms, and optional app details.export const CreateConfigArgsSchema = z.object({ projectPath: z.string().describe("Path to project root"), platforms: z.array(z.enum(["ios", "android"])).describe("Platforms to configure"), appName: z.string().optional().describe("Application name"), bundleId: z.string().optional().describe("iOS bundle identifier"), packageName: z.string().optional().describe("Android package name"), }); export type CreateConfigArgs = z.infer<typeof CreateConfigArgsSchema>;
- src/utils/config-parser.ts:225-285 (helper)Core helper function that constructs a complete default Detox configuration object based on the selected platforms, populating devices, apps, and configurations with standard paths and commands.export function generateDefaultConfig(options: { platforms: ("ios" | "android")[]; appName?: string; bundleId?: string; packageName?: string; }): DetoxConfig { const config: DetoxConfig = { testRunner: "jest", artifacts: { rootDir: "./artifacts", plugins: { screenshot: "failing", video: "failing", log: "failing", }, }, devices: {}, apps: {}, configurations: {}, }; const appName = options.appName || "MyApp"; if (options.platforms.includes("ios")) { config.devices!["ios.simulator"] = { type: "ios.simulator", device: { type: "iPhone 15" }, }; config.apps!["ios.debug"] = { type: "ios.app", binaryPath: `ios/build/Build/Products/Debug-iphonesimulator/${appName}.app`, build: `xcodebuild -workspace ios/${appName}.xcworkspace -scheme ${appName} -configuration Debug -sdk iphonesimulator -derivedDataPath ios/build`, }; config.configurations!["ios.sim.debug"] = { device: "ios.simulator", app: "ios.debug", }; } if (options.platforms.includes("android")) { config.devices!["android.emulator"] = { type: "android.emulator", avdName: "Pixel_4_API_30", }; config.apps!["android.debug"] = { type: "android.apk", binaryPath: "android/app/build/outputs/apk/debug/app-debug.apk", build: "cd android && ./gradlew assembleDebug assembleAndroidTest -DtestBuildType=debug", }; config.configurations!["android.emu.debug"] = { device: "android.emulator", app: "android.debug", }; } return config; }
- src/tools/index.ts:429-442 (registration)Registration of the detox_create_config tool (as createConfigTool) in the allTools array, which is imported into src/index.ts and used by the MCP server for listing and calling tools.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 the tool by name from allTools and invokes its handler.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, }; } });