Skip to main content
Glama

android_screenshot

Capture screenshots from Android devices for debugging, documentation, or testing purposes using ADB commands.

Instructions

Capture a screenshot from the Android device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputPathNoLocal path to save the screenshot (optional). If not provided, returns base64 encoded image.
deviceSerialNoSpecific device serial number to target (optional)

Implementation Reference

  • src/index.ts:41-57 (registration)
    Registration of the 'android_screenshot' tool in the ListToolsRequestSchema handler, including name, description, and input schema definition.
    { name: 'android_screenshot', description: 'Capture a screenshot from the Android device', inputSchema: { type: 'object', properties: { outputPath: { type: 'string', description: 'Local path to save the screenshot (optional). If not provided, returns base64 encoded image.', }, deviceSerial: { type: 'string', description: 'Specific device serial number to target (optional)', }, }, }, },
  • src/index.ts:464-465 (registration)
    Tool dispatch/registration in the CallToolRequestSchema switch statement, mapping 'android_screenshot' to the screenshotHandler function.
    case 'android_screenshot': return await screenshotHandler(this.adb, args);
  • TypeScript interface defining the input arguments for the screenshot handler, matching the MCP inputSchema.
    interface ScreenshotArgs { outputPath?: string; deviceSerial?: string; }
  • The MCP tool handler function 'screenshotHandler' that processes arguments, calls ADB screenshot, and formats the response as text or base64 image.
    export async function screenshotHandler( adb: ADBWrapper, args: any ): Promise<{ content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> }> { const { outputPath, deviceSerial } = args as ScreenshotArgs; try { const result = await adb.screenshot(outputPath, deviceSerial); if (typeof result === 'string') { // Path returned return { content: [ { type: 'text', text: `Screenshot saved to: ${result}`, }, ], }; } else { // Buffer returned - encode as base64 const base64 = result.toString('base64'); return { content: [ { type: 'text', text: 'Screenshot captured successfully', }, { type: 'image', data: base64, mimeType: 'image/png', }, ], }; } } catch (error) { throw new Error(`Screenshot failed: ${error instanceof Error ? error.message : String(error)}`); } }
  • Core implementation in ADBWrapper.screenshot method: executes ADB screencap, pulls the image, handles file or buffer output, and cleans up.
    async screenshot(outputPath?: string, deviceSerial?: string): Promise<string | Buffer> { const device = await this.getTargetDevice(deviceSerial); const devicePath = '/sdcard/screenshot.png'; // Take screenshot on device await this.exec(['shell', 'screencap', '-p', devicePath], device); if (outputPath) { // Pull screenshot to local path await this.exec(['pull', devicePath, outputPath], device); // Clean up device screenshot await this.exec(['shell', 'rm', devicePath], device); return outputPath; } else { // Pull screenshot to temp and read as buffer const tempPath = join(tmpdir(), `screenshot_${Date.now()}.png`); await this.exec(['pull', devicePath, tempPath], device); await this.exec(['shell', 'rm', devicePath], device); const buffer = await readFile(tempPath); // Clean up temp file await rm(tempPath, { force: true }); return buffer; } }

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/jduartedj/android-mcp-server'

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