Skip to main content
Glama

adb_screenshot

Capture device screenshots using Android Debug Bridge for remote device management and screen operations.

Instructions

Take a screenshot of the device screen

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceIdNoDevice ID (optional)
formatNoScreenshot format (default: png)

Implementation Reference

  • Core handler function for adb_screenshot tool. Captures screenshot via ADB screencap, pulls file to local directory, cleans up on device, and returns file paths and info.
    async takeScreenshot(options: ScreenshotOptions = {}) {
      try {
        const deviceId = options.deviceId;
        const format = options.format || 'png';
        
        // Check if device is connected
        const connected = await this.adbClient.isDeviceConnected(deviceId);
        if (!connected) {
          return {
            success: false,
            error: 'Device not connected',
            message: 'Cannot take screenshot - device is not connected'
          };
        }
    
        // Take screenshot on device
        const screenshotPath = `/sdcard/screenshot.${format}`;
        const result = await this.adbClient.executeCommand(`shell screencap -p ${screenshotPath}`, deviceId);
        
        if (!result.success) {
          return {
            success: false,
            error: result.error,
            message: 'Failed to capture screenshot on device'
          };
        }
    
        // Use fixed filename for easy access
        const filename = `current_screenshot.${format}`;
        const adbPath = this.configManager.getAdbPath(filename);
        const mcpPath = this.configManager.getMcpPath(filename);
        
        const pullResult = await this.adbClient.executeCommand(`pull ${screenshotPath} ${adbPath}`, deviceId);
        
        if (!pullResult.success) {
          return {
            success: false,
            error: pullResult.error,
            message: 'Failed to pull screenshot from device'
          };
        }
    
        // Clean up device screenshot
        await this.adbClient.executeCommand(`shell rm ${screenshotPath}`, deviceId);
    
        // Try to read the file to verify it was downloaded and get file info
        let fileSize = 'Unknown';
        let fileExists = false;
        try {
          const stats = await fs.stat(mcpPath);
          fileSize = `${Math.round(stats.size / 1024)} KB`;
          fileExists = true;
        } catch (error) {
          console.warn('Could not read screenshot file stats:', error);
        }
    
        return {
          success: true,
          data: { 
            adbPath,
            mcpPath,
            filename,
            format,
            fileSize,
            fileExists,
            deviceId: deviceId || this.adbClient.getDefaultDevice(),
            pullInfo: pullResult.output
          },
          message: `Screenshot saved to ${adbPath} (readable at ${mcpPath})`
        };
      } catch (error: any) {
        return {
          success: false,
          error: error.message,
          message: 'Failed to take screenshot'
        };
      }
    }
  • Input schema definition for the adb_screenshot tool registered in the MCP server tool list.
    {
      name: 'adb_screenshot',
      description: 'Take a screenshot of the device screen',
      inputSchema: {
        type: 'object',
        properties: {
          deviceId: {
            type: 'string',
            description: 'Device ID (optional)',
          },
          format: {
            type: 'string',
            enum: ['png', 'jpg'],
            description: 'Screenshot format (default: png)',
          },
        },
        required: [],
      },
  • src/index.ts:441-442 (registration)
    Registration and dispatch point in the tool call handler switch statement, routing adb_screenshot calls to ScreenTools.takeScreenshot.
    case 'adb_screenshot':
      return await this.handleToolCall(this.screenTools.takeScreenshot(args || {}));
  • TypeScript interface defining the input options for screenshot operations, used by the handler.
    export interface ScreenshotOptions {
      deviceId?: string;
      format?: 'png' | 'jpg';
      quality?: number;
    }

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/richard0913/adb-mcp'

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