Skip to main content
Glama

capture_screenshot

Take a screenshot of an Android device screen to capture visual content for display or analysis. Returns a base64-encoded PNG image that shows current on-screen activity.

Instructions

Capture a screenshot of the current Android device screen. Returns a base64-encoded PNG image that can be displayed or analyzed visually. Use this to see what is currently on screen.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
save_to_diskNoSave the screenshot to disk as well
device_idNoDevice serial number

Implementation Reference

  • The actual implementation of the screenshot capture logic using ADB and Sharp for image processing.
    export async function captureScreenshot(
      deviceId?: string,
      options?: { save?: boolean; resize?: { width: number; height: number } }
    ): Promise<ScreenshotResult> {
      const resolved = await deviceManager.resolveDeviceId(deviceId);
    
      // Capture raw PNG via exec-out (faster than pull)
      const rawBuffer = await adbExecOut(['screencap', '-p'], resolved, 15000);
    
      if (!rawBuffer || rawBuffer.length < 100) {
        throw new Error('Screenshot capture returned empty or invalid data');
      }
    
      // Process with sharp
      let image = sharp(rawBuffer);
      const metadata = await image.metadata();
      const width = metadata.width || 0;
      const height = metadata.height || 0;
    
      // Optionally resize
      if (options?.resize) {
        image = image.resize(options.resize.width, options.resize.height, { fit: 'inside' });
      }
    
      const processedBuffer = await image.png({ quality: 80 }).toBuffer();
      const base64 = processedBuffer.toString('base64');
    
      const result: ScreenshotResult = {
        base64,
        width,
        height,
        timestamp: Date.now(),
      };
    
      // Optionally save to disk
      if (options?.save) {
        const config = getConfig();
        const dir = config.screenshotDir;
        if (!existsSync(dir)) {
          mkdirSync(dir, { recursive: true });
        }
        const filename = `screenshot_${resolved}_${Date.now()}.png`;
        const filepath = join(dir, filename);
        writeFileSync(filepath, processedBuffer);
        result.savedPath = filepath;
        log.info('Screenshot saved', { filepath, deviceId: resolved });
      }
    
      log.info('Screenshot captured', { width, height, sizeKb: Math.round(processedBuffer.length / 1024), deviceId: resolved });
      return result;
    }
  • MCP tool registration for 'capture_screenshot' which bridges the MCP request to the screenshot implementation.
    server.registerTool(
      'capture_screenshot',
      {
        description: 'Capture a screenshot of the current Android device screen. Returns a base64-encoded PNG image that can be displayed or analyzed visually. Use this to see what is currently on screen.',
        inputSchema: {
          save_to_disk: z.boolean().optional().default(false).describe('Save the screenshot to disk as well'),
          device_id: z.string().optional().describe('Device serial number'),
        },
      },
      async ({ save_to_disk, device_id }) => {
        return await metrics.measure('capture_screenshot', device_id || 'default', async () => {
          const result = await captureScreenshot(device_id, { save: save_to_disk });
    
          // Store for diffing
          const deviceKey = device_id || 'default';
          const rawBuffer = await captureScreenshotBuffer(device_id);
          lastScreenshots.set(deviceKey, rawBuffer);
    
          const content: Array<{ type: 'text'; text: string } | { type: 'image'; data: string; mimeType: string }> = [];
    
          // Return the image as both image content and text metadata
          content.push({
            type: 'image' as const,
            data: result.base64,
            mimeType: 'image/png',
          });
    
          content.push({
            type: 'text' as const,
            text: JSON.stringify({
              success: true,
              width: result.width,
              height: result.height,
              timestamp: result.timestamp,
              ...(result.savedPath ? { savedPath: result.savedPath } : {}),
            }, null, 2),
          });
    
          return { content };
        });
      }
    );
Behavior4/5

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

With no annotations provided, the description carries the full burden and successfully discloses the return format (base64-encoded PNG) and capabilities (can be displayed or analyzed visually). It implies synchronous capture of current state but omits prerequisites like device connection status or permissions.

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?

Three sentences with zero waste: first establishes action, second discloses return format (critical given no output schema), third provides usage intent. Front-loaded with the core action and appropriately sized.

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

Completeness4/5

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

Compensates effectively for the missing output schema by detailing the base64 PNG return format. With 100% schema coverage and no complex nested objects, the description provides sufficient context for tool selection, though it could mention device state requirements (e.g., screen on).

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?

Schema description coverage is 100% (both save_to_disk and device_id are fully described in the schema), establishing the baseline. The description does not add parameter-specific semantics, but none are needed given complete schema documentation.

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

Purpose5/5

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

The description uses a specific verb ('Capture') with clear resource ('screenshot of the current Android device screen') and distinguishes from siblings like analyze_screen (analysis) and detect_elements_visually (element detection) by focusing on full-screen image capture.

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

Usage Guidelines4/5

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

Provides clear when-to-use guidance ('Use this to see what is currently on screen'), establishing the tool's role in visual state inspection. Lacks explicit alternative naming (e.g., when to prefer analyze_screen over capture_screenshot) or exclusion criteria.

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/divineDev-dotcom/android_mcp'

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