native_run_list_devices
List connected Android and iOS devices for mobile development, enabling device management and testing workflows.
Instructions
List connected devices using native-run (Android & iOS support)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| platform | No | android |
Implementation Reference
- src/tools/android/native-run.ts:95-138 (handler)The core handler function for the 'native_run_list_devices' tool. Validates input using Zod schema, checks if native-run is available, executes the 'native-run [platform] --list --json' command, parses the JSON output (with fallback to text parsing), and returns a structured response with device list.handler: async (args: any) => { const parsed = NativeRunListDevicesSchema.parse(args); if (!(await isNativeRunAvailable())) { throw new Error('native-run is not installed. Install with: npm install -g native-run'); } const result = await processExecutor.execute('native-run', [ parsed.platform, '--list', '--json' ]); if (result.exitCode !== 0) { throw new Error(`Failed to list ${parsed.platform} devices: ${result.stderr}`); } let devices = []; try { const output = JSON.parse(result.stdout); devices = output.devices || []; } catch (parseError) { // If JSON parsing fails, try to parse text output devices = result.stdout .split('\n') .filter((line: string) => line.trim() && !line.includes('Available targets')) .map((line: string, index: number) => ({ id: `device_${index}`, name: line.trim(), platform: parsed.platform, available: true })); } return { success: true, data: { platform: parsed.platform, devices, totalCount: devices.length, tool: 'native-run' }, }; }
- Zod validation schema for the input parameters of native_run_list_devices tool (platform: 'android' | 'ios', default 'android'). Used in the handler for input validation.const NativeRunListDevicesSchema = z.object({ platform: z.enum(['android', 'ios']).default('android'), });
- src/tools/android/native-run.ts:81-139 (registration)Primary registration of the native_run_list_devices tool within createNativeRunTools(), defining name, description, JSON inputSchema, and inline handler function.tools.set('native_run_list_devices', { name: 'native_run_list_devices', description: 'List connected devices using native-run (Android & iOS support)', inputSchema: { type: 'object', properties: { platform: { type: 'string', enum: ['android', 'ios'], default: 'android' } }, required: [] }, handler: async (args: any) => { const parsed = NativeRunListDevicesSchema.parse(args); if (!(await isNativeRunAvailable())) { throw new Error('native-run is not installed. Install with: npm install -g native-run'); } const result = await processExecutor.execute('native-run', [ parsed.platform, '--list', '--json' ]); if (result.exitCode !== 0) { throw new Error(`Failed to list ${parsed.platform} devices: ${result.stderr}`); } let devices = []; try { const output = JSON.parse(result.stdout); devices = output.devices || []; } catch (parseError) { // If JSON parsing fails, try to parse text output devices = result.stdout .split('\n') .filter((line: string) => line.trim() && !line.includes('Available targets')) .map((line: string, index: number) => ({ id: `device_${index}`, name: line.trim(), platform: parsed.platform, available: true })); } return { success: true, data: { platform: parsed.platform, devices, totalCount: devices.length, tool: 'native-run' }, }; } });
- src/tools/android.ts:977-994 (registration)Secondary registration in createAndroidTools() where native-run tools (including native_run_list_devices) are instantiated via createNativeRunTools() and merged into the comprehensive Android tools Map.const nativeRunTools = createNativeRunTools(); // Merge all tools for (const [name, tool] of gradleTools.entries()) { tools.set(name, tool); } for (const [name, tool] of lintTools.entries()) { tools.set(name, tool); } for (const [name, tool] of mediaTools.entries()) { tools.set(name, tool); } for (const [name, tool] of nativeRunTools.entries()) { tools.set(name, tool); }
- Helper function to check if native-run CLI is installed and available in system PATH. Used by the handler to validate prerequisites before execution.async function isNativeRunAvailable(): Promise<boolean> { try { await processExecutor.execute('native-run', ['--version']); return true; } catch { return false; } }