Skip to main content
Glama
infiniV

Android UI Assist MCP Server

take_android_screenshot

Capture screenshots from Android devices or emulators for UI analysis and testing purposes.

Instructions

Capture a screenshot from an Android device or emulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceIdNoThe ID of the Android device to capture a screenshot from. If not provided, uses the first available device.
formatNoThe image format for the screenshot. Currently only PNG is supported.png

Implementation Reference

  • src/server.ts:45-49 (registration)
    Registration of the 'take_android_screenshot' tool in the ListTools response, including name, description, and input schema reference.
    {
      name: 'take_android_screenshot',
      description: 'Capture a screenshot from an Android device or emulator',
      inputSchema: TakeScreenshotToolSchema,
    },
  • MCP CallTool handler switch case for 'take_android_screenshot', which parses input, calls takeScreenshot method, and formats the response as image and text content.
    case 'take_android_screenshot': {
      const input = TakeScreenshotInputSchema.parse(args);
      const result = await this.takeScreenshot(input);
      return {
        content: [
          {
            type: 'image',
            data: result.data,
            mimeType: 'image/png',
          },
          {
            type: 'text',
            text: `Android screenshot captured from ${result.deviceId}: ${result.width}x${result.height} pixels`,
          },
        ],
      };
    }
  • Private method that invokes captureScreenshotResponse from utils/screenshot and validates the output using TakeScreenshotOutputSchema.
    private async takeScreenshot(
      input: z.infer<typeof TakeScreenshotInputSchema>
    ): Promise<z.infer<typeof TakeScreenshotOutputSchema>> {
      const screenshot = await captureScreenshotResponse(input.deviceId);
    
      const result = {
        data: screenshot.data,
        format: screenshot.format,
        width: screenshot.width,
        height: screenshot.height,
        deviceId: screenshot.deviceId,
        timestamp: screenshot.timestamp,
      };
    
      return TakeScreenshotOutputSchema.parse(result);
    }
  • Helper function that captures the screenshot buffer via ADB, extracts PNG dimensions, converts to base64, and formats the response object.
    export async function captureScreenshotResponse(deviceId?: string): Promise<ScreenshotResponse> {
      try {
        // Capture screenshot as binary data (now returns Buffer directly)
        const buffer = captureScreenshot(deviceId);
    
        // Get image dimensions
        const { width, height } = getPNGDimensions(buffer);
    
        // Convert to base64
        const base64Data = binaryToBase64(buffer);
    
        // Return formatted response
        return {
          data: base64Data,
          format: 'png',
          width,
          height,
          deviceId: deviceId || 'default',
          timestamp: Date.now(),
        };
      } catch (error) {
        throw new Error(
          `Failed to capture screenshot: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Core handler function that validates the device, constructs and executes the ADB screencap command via execSync to retrieve the raw PNG screenshot buffer.
    export function captureScreenshot(deviceId?: string): Buffer {
      let targetDeviceId: string;
    
      try {
        if (deviceId) {
          // Verify the device exists
          const devices = getConnectedDevices();
          const device = devices.find(d => d.id === deviceId);
    
          if (!device) {
            throw new DeviceNotFoundError(deviceId);
          }
    
          if (device.status !== 'device') {
            throw new ADBCommandError(
              'DEVICE_NOT_AVAILABLE',
              `Device '${deviceId}' is not available (status: ${device.status})`,
              { device }
            );
          }
    
          targetDeviceId = deviceId;
        } else {
          // Use the first available device
          const device = getFirstAvailableDevice();
          targetDeviceId = device.id;
        }
    
        // Capture screenshot using binary command execution
        const command = targetDeviceId
          ? `-s ${targetDeviceId} exec-out screencap -p`
          : 'exec-out screencap -p';
        const screenshotData = executeADBCommandBinary(command);
    
        if (!screenshotData || screenshotData.length === 0) {
          throw new ScreenshotCaptureError(targetDeviceId);
        }
    
        return screenshotData;
      } catch (error) {
        if (error instanceof ADBCommandError) {
          throw error;
        }
        throw new ScreenshotCaptureError(
          deviceId || 'unknown',
          error instanceof Error ? error : undefined
        );
      }
    }
  • MCP tool schema definition for 'take_android_screenshot', used in tool registration and input validation.
    export const TakeScreenshotToolSchema = {
      type: 'object' as const,
      properties: {
        deviceId: {
          type: 'string' as const,
          description:
            'The ID of the Android device to capture a screenshot from. If not provided, uses the first available device.',
        },
        format: {
          type: 'string' as const,
          enum: ['png'],
          default: 'png',
          description: 'The image format for the screenshot. Currently only PNG is supported.',
        },
      },
      required: [] as string[],
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While it states what the tool does, it doesn't mention important behavioral aspects like whether this requires specific device states (unlocked, active display), what permissions are needed, whether it affects device operation, or what happens on failure. The description is minimal and lacks operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states the core purpose without any wasted words. It's appropriately sized for a straightforward tool and gets directly to the point with no unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a device interaction tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns (image data, file path, error conditions), doesn't mention operational constraints or prerequisites, and provides minimal context for a tool that interacts with physical/virtual devices. The completeness is inadequate given the complexity implied by device interaction.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the input schema already fully documents both parameters (deviceId with fallback behavior, format with enum constraint). The description adds no additional parameter semantics beyond what's already in the schema, so it meets the baseline for high schema coverage without adding value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('capture a screenshot') and target resource ('from an Android device or emulator'), providing a specific verb+resource combination. However, it doesn't differentiate from the sibling tool 'list_android_devices' - both work with Android devices but serve different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance about when to use this tool versus alternatives. It doesn't mention the sibling tool 'list_android_devices' which could be a prerequisite for obtaining device IDs, nor does it provide any context about when this operation is appropriate versus other device interaction methods.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/infiniV/Android-Ui-MCP'

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