get_screen_size
Retrieve the screen resolution in pixels from a connected Android device to determine display dimensions for UI automation and testing.
Instructions
Get the screen resolution (width x height in pixels) of the connected Android device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No | Device serial number. If omitted, uses the only connected device. |
Implementation Reference
- src/adb/device-manager.ts:109-125 (handler)The actual implementation of getScreenSize, which queries the device using 'wm size'.
async getScreenSize(deviceId?: string): Promise<{ width: number; height: number }> { const resolvedId = await this.resolveDeviceId(deviceId); // Check cached session first const session = this.sessions.get(resolvedId); if (session && session.screenWidth > 0 && session.screenHeight > 0) { return { width: session.screenWidth, height: session.screenHeight }; } const result = await adbShell(['wm', 'size'], resolvedId); const match = result.stdout.match(/(\d+)x(\d+)/); if (!match) { throw new Error(`Failed to parse screen size from: ${result.stdout}`); } const width = parseInt(match[1], 10); - src/controllers/device-tools.ts:64-80 (registration)Registration of the 'get_screen_size' MCP tool, including schema and tool handler.
server.registerTool( 'get_screen_size', { description: 'Get the screen resolution (width x height in pixels) of the connected Android device', inputSchema: { device_id: z.string().optional().describe('Device serial number. If omitted, uses the only connected device.'), }, }, async ({ device_id }) => { return await metrics.measure('get_screen_size', device_id || 'default', async () => { const size = await deviceManager.getScreenSize(device_id); return { content: [{ type: 'text' as const, text: JSON.stringify({ success: true, screen: size }, null, 2), }], };