adb_screenshot
Capture screenshots from connected Android devices remotely. Specify output path and device ID to save screenshots efficiently using the MCP server protocol.
Instructions
Take a screenshot of the connected Android device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_id | No | Device ID/serial (optional, uses first device if not specified) | |
| output_path | No | Local path to save the screenshot (default: screenshot.png) | screenshot.png |
Implementation Reference
- src/index.ts:143-173 (handler)The handler function for the 'adb_screenshot' tool. It executes ADB commands to capture a screenshot on the Android device, pull it to the local machine at the specified output_path, and cleans up the temporary file on the device.case "adb_screenshot": { const { output_path = "screenshot.png", device_id } = args as { output_path?: string; device_id?: string; }; const deviceArg = device_id ? `-s ${device_id}` : ""; const tempPath = "/sdcard/screenshot.png"; // Take screenshot on device await execAsync(`adb ${deviceArg} shell screencap -p ${tempPath}`); // Pull screenshot to local machine const { stdout, stderr } = await execAsync(`adb ${deviceArg} pull ${tempPath} ${output_path}`); // Clean up temp file on device await execAsync(`adb ${deviceArg} shell rm ${tempPath}`); if (stderr && stderr.includes("error")) { throw new McpError(ErrorCode.InternalError, `Screenshot failed: ${stderr}`); } return { content: [ { type: "text", text: `Screenshot saved to ${output_path}`, }, ], }; }
- src/index.ts:51-69 (schema)The input schema definition for the 'adb_screenshot' tool, registered in the ListTools handler. Defines optional parameters output_path (default: 'screenshot.png') and device_id.{ name: "adb_screenshot", description: "Take a screenshot of the connected Android device", inputSchema: { type: "object", properties: { output_path: { type: "string", description: "Local path to save the screenshot (default: screenshot.png)", default: "screenshot.png", }, device_id: { type: "string", description: "Device ID/serial (optional, uses first device if not specified)", }, }, required: [], }, },
- src/index.ts:29-114 (registration)The ListToolsRequestHandler where the 'adb_screenshot' tool is registered by including it in the tools list.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "adb_connect_wifi", description: "Connect to an Android device over WiFi using ADB", inputSchema: { type: "object", properties: { ip_address: { type: "string", description: "IP address of the Android device", }, port: { type: "string", description: "Port number (default: 5555)", default: "5555", }, }, required: ["ip_address"], }, }, { name: "adb_screenshot", description: "Take a screenshot of the connected Android device", inputSchema: { type: "object", properties: { output_path: { type: "string", description: "Local path to save the screenshot (default: screenshot.png)", default: "screenshot.png", }, device_id: { type: "string", description: "Device ID/serial (optional, uses first device if not specified)", }, }, required: [], }, }, { name: "adb_list_devices", description: "List all connected ADB devices", inputSchema: { type: "object", properties: {}, required: [], }, }, { name: "adb_disconnect", description: "Disconnect from a WiFi ADB device", inputSchema: { type: "object", properties: { ip_address: { type: "string", description: "IP address of the device to disconnect from", }, port: { type: "string", description: "Port number (default: 5555)", default: "5555", }, }, required: ["ip_address"], }, }, { name: "adb_device_info", description: "Get information about a connected device", inputSchema: { type: "object", properties: { device_id: { type: "string", description: "Device ID/serial (optional, uses first device if not specified)", }, }, required: [], }, }, ], }; });