get_device_dimensions
Retrieve screen dimensions of Android devices or emulators to enable precise UI automation and element interaction.
Instructions
Get the dimensions of the Android device/emulator screen.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No |
Implementation Reference
- puppeteer.py:610-648 (handler)The @mcp.tool()-decorated handler function that implements the get_device_dimensions tool. It retrieves Android device screen dimensions using ADB command 'wm size', parses the physical size, and returns a dictionary with success status, dimensions, and device ID.@mcp.tool() async def get_device_dimensions(device_id: str = None) -> dict: """Get the dimensions of the Android device/emulator screen.""" try: # Get device dimensions using adb cmd = ['adb'] if device_id: cmd.extend(['-s', device_id]) cmd.extend(['shell', 'wm', 'size']) result = subprocess.run(cmd, capture_output=True, text=True, check=True) output = result.stdout.strip() width, height = None, None if 'Physical size:' in output: size_part = output.split('Physical size:')[1].strip() width, height = map(int, size_part.split('x')) return { "success": True, "device_id": device_id or "default", "width": width, "height": height, "dimensions": f"{width}x{height}" if width and height else None } except subprocess.CalledProcessError as e: return { "success": False, "error": f"Failed to get device dimensions: {e}", "device_id": device_id or "default" } except Exception as e: return { "success": False, "error": f"Unexpected error: {e}", "device_id": device_id or "default" }
- puppeteer.py:610-610 (registration)The @mcp.tool() decorator registers the get_device_dimensions function as an MCP tool.@mcp.tool()