take-screenshot
Capture Android device screenshots and save them to a local file path for development testing and debugging purposes.
Instructions
Capture device screenshot and save to a local file.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| outputPath | Yes | Local path to save the screenshot (e.g. screenshot.png) | |
| timeoutMs | No | Timeout in milliseconds |
Implementation Reference
- src/tools/deviceTool.js:20-23 (schema)Zod input schema for the take-screenshot tool defining outputPath and optional timeoutMs.const screenshotSchema = z.object({ outputPath: z.string().min(1).describe('Local path to save the screenshot (e.g. screenshot.png)'), timeoutMs: z.number().int().min(1000).max(20000).default(10000).describe('Timeout in milliseconds') });
- src/tools/deviceTool.js:94-107 (registration)MCP server registration of the take-screenshot tool, including inline handler function that uses ADB screencap to capture and save PNG screenshot.server.registerTool( 'take-screenshot', { title: 'Take User Screenshot', description: 'Capture device screenshot and save to a local file.', inputSchema: screenshotSchema }, async (params) => { const buffer = await runAdbCommandBinary(['exec-out', 'screencap', '-p'], params.timeoutMs); const absPath = path.resolve(params.outputPath); fs.writeFileSync(absPath, buffer); return { content: [{ type: 'text', text: `Screenshot saved to ${absPath}` }] }; } );
- src/tools/deviceTool.js:65-76 (helper)Helper to run ADB binary commands (like screencap), returning buffer; used by take-screenshot handler.async function runAdbCommandBinary(args, timeoutMs) { try { const { stdout } = await execFileAsync('adb', args, { timeout: timeoutMs, encoding: 'buffer', maxBuffer: 20 * 1024 * 1024 }); return stdout; } catch (error) { throw new Error(`adb ${args.join(' ')} failed: ${error.message}`); } }