Take User Screenshot
take-screenshotCapture an Android device screenshot and save it to a local file. Specify the output path and optional timeout.
Instructions
Capture device screenshot and save to a local file.
Input 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:101-107 (handler)The handler function that captures a device screenshot by running 'adb exec-out screencap -p', then saves the binary output to the specified local file path.
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:20-23 (schema)Zod schema defining the input parameters for take-screenshot: outputPath (required string) and optional timeoutMs (1000-20000ms, default 10000).
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)Registration of the 'take-screenshot' tool on the MCP server via server.registerTool() with title, description, inputSchema, and handler.
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 function that executes an ADB command and returns binary buffer output, used by the screenshot handler to capture raw PNG data.
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}`); } } - src/index.js:30-30 (registration)Entry-point call that registers all device tools including 'take-screenshot' on the MCP server.
registerDeviceTool(server);