flutter_launch_emulator
Launch a Flutter emulator for testing mobile applications by specifying the emulator ID, enabling developers to run and debug their Flutter projects on virtual devices.
Instructions
Launch a Flutter emulator
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emulatorId | Yes | Emulator ID to launch |
Implementation Reference
- src/tools/flutter.ts:428-459 (handler)Handler function that launches the specified Flutter emulator. Validates input using Zod schema, checks emulator ID format, executes 'flutter emulators --launch [emulatorId]' with 3-minute timeout, handles errors, and returns structured success response.handler: async (args: any) => { const validation = FlutterEmulatorLaunchSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { emulatorId } = validation.data; // Validate emulator ID format (alphanumeric, underscores, dots, dashes) if (!/^[a-zA-Z0-9._-]+$/.test(emulatorId)) { throw new Error(`Invalid emulator ID format. Emulator ID can only contain alphanumeric characters, dots, underscores, and dashes: ${emulatorId}`); } const result = await processExecutor.execute( 'flutter', ['emulators', '--launch', emulatorId], { timeout: 180000 } // 3 minutes timeout for emulator launch ); if (result.exitCode !== 0) { throw new Error(`Failed to launch emulator: ${result.stderr || result.stdout}`); } return { success: true, data: { emulatorId, status: 'launched', output: result.stdout, }, }; }
- src/tools/flutter.ts:43-50 (schema)Zod schema for validating input parameters of flutter_launch_emulator tool (emulatorId: non-empty string). Referenced in the handler for runtime validation.* Zod validation schema for flutter_launch_emulator tool. * Validates emulator ID parameter. * * @type {z.ZodObject} */ const FlutterEmulatorLaunchSchema = z.object({ emulatorId: z.string().min(1), });
- src/tools/flutter.ts:418-460 (registration)Registers the flutter_launch_emulator tool in the tools Map within createFlutterTools function, defining name, description, JSON inputSchema, and handler.tools.set('flutter_launch_emulator', { name: 'flutter_launch_emulator', description: 'Launch a Flutter emulator', inputSchema: { type: 'object', properties: { emulatorId: { type: 'string', minLength: 1, description: 'Emulator ID to launch' } }, required: ['emulatorId'] }, handler: async (args: any) => { const validation = FlutterEmulatorLaunchSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { emulatorId } = validation.data; // Validate emulator ID format (alphanumeric, underscores, dots, dashes) if (!/^[a-zA-Z0-9._-]+$/.test(emulatorId)) { throw new Error(`Invalid emulator ID format. Emulator ID can only contain alphanumeric characters, dots, underscores, and dashes: ${emulatorId}`); } const result = await processExecutor.execute( 'flutter', ['emulators', '--launch', emulatorId], { timeout: 180000 } // 3 minutes timeout for emulator launch ); if (result.exitCode !== 0) { throw new Error(`Failed to launch emulator: ${result.stderr || result.stdout}`); } return { success: true, data: { emulatorId, status: 'launched', output: result.stdout, }, }; } });