screenshot
Capture screenshots from Android devices for visual analysis. Save images locally or use them directly in automated testing workflows.
Instructions
Take a screenshot of the Android device. Returns the image for visual analysis. Optionally saves to a file path.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No | Device ID (optional if only one device) | |
| save_path | No | Local file path to save the screenshot PNG (optional) |
Implementation Reference
- src/adb.ts:228-230 (handler)The low-level ADB execution handler for the screenshot tool. It runs `screencap -p` and returns the buffer.
async screenshot(deviceId?: string): Promise<Buffer> { return this.execBuffer(["exec-out", "screencap", "-p"], deviceId); } - src/index.ts:94-122 (registration)MCP tool registration and high-level handler for "screenshot", which orchestrates capturing via ADB, compressing the image, and optionally saving it to disk.
server.tool( "screenshot", "Take a screenshot of the Android device. Returns the image for visual analysis. Optionally saves to a file path.", { device_id: z.string().optional().describe("Device ID (optional if only one device)"), save_path: z.string().optional().describe("Local file path to save the screenshot PNG (optional)"), }, async ({ device_id, save_path }) => { const raw = await adb.screenshot(device_id); const compressed = await compressScreenshot(raw); const base64 = compressed.toString("base64"); const metadata = await sharp(compressed).metadata(); if (save_path) { await adb.saveScreenshot(compressed, save_path); } const info = `Screenshot: ${metadata.width}x${metadata.height} (${Math.round(compressed.length / 1024)}KB)`; return { content: [ { type: "image", data: base64, mimeType: "image/png" }, { type: "text", text: save_path ? `${info}\nSaved to: ${save_path}` : info, }, ], }; }, );