Skip to main content
Glama

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
NameRequiredDescriptionDefault
device_idNoDevice serial number. If omitted, uses the only connected device.

Implementation Reference

  • 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);
  • 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),
            }],
          };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/divineDev-dotcom/android_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server