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
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | Device ID (optional) | |
| format | No | Screenshot format (default: png) |
Implementation Reference
- src/tools/screen.ts:14-91 (handler)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' }; } }
- src/index.ts:89-106 (schema)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 || {}));
- src/types/index.ts:9-13 (schema)TypeScript interface defining the input options for screenshot operations, used by the handler.export interface ScreenshotOptions { deviceId?: string; format?: 'png' | 'jpg'; quality?: number; }