capture_screenshot
Capture application window screenshots as PNG images, returning base64 data or saving to file for automated testing and documentation.
Instructions
Capture a screenshot of the application window. Returns base64-encoded PNG image data by default.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename | No | Optional filename (without extension) to save the screenshot. If not provided, a timestamp will be used. | |
| returnBase64 | No | Whether to return base64 image data (true) or save to file and return path (false). Default: true |
Implementation Reference
- src/tools/screenshot.ts:11-42 (handler)Primary handler function for the 'capture_screenshot' tool. Processes input parameters, invokes the TauriDriver's screenshot method, and returns a standardized ToolResponse with base64 data or file path.export async function captureScreenshot( driver: TauriDriver, params: ScreenshotParams = {} ): Promise<ToolResponse<{ path?: string; base64?: string; message: string }>> { try { const returnBase64 = params.returnBase64 ?? true; // Default to base64 for MCP const result = await driver.captureScreenshot(params.filename, returnBase64); if (returnBase64) { return { success: true, data: { base64: result, message: 'Screenshot captured successfully', }, }; } else { return { success: true, data: { path: result, message: `Screenshot saved to: ${result}`, }, }; } } catch (error) { return { success: false, error: error instanceof Error ? error.message : String(error), }; } }
- src/index.ts:232-260 (handler)MCP server CallToolRequest handler case for 'capture_screenshot'. Calls the tool function and formats the response, including special handling for image content in MCP format.case 'capture_screenshot': { const result = await captureScreenshot(driver, args as any); if (result.success && result.data?.base64) { // Return both text description and image return { content: [ { type: 'text', text: result.data.message, }, { type: 'image', data: result.data.base64, mimeType: 'image/png', }, ], }; } return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; }
- src/index.ts:84-101 (registration)Registration of the 'capture_screenshot' tool in the MCP server's ListToolsRequest handler, including name, description, and input schema.{ name: 'capture_screenshot', description: 'Capture a screenshot of the application window. Returns base64-encoded PNG image data by default.', inputSchema: { type: 'object', properties: { filename: { type: 'string', description: 'Optional filename (without extension) to save the screenshot. If not provided, a timestamp will be used.', }, returnBase64: { type: 'boolean', description: 'Whether to return base64 image data (true) or save to file and return path (false). Default: true', default: true, }, }, }, },
- src/tauri-driver.ts:99-115 (helper)Low-level implementation in TauriDriver class that captures the screenshot using WebDriverIO's takeScreenshot(), returns base64 or saves to file.async captureScreenshot(filename?: string, returnBase64: boolean = false): Promise<string> { this.ensureAppRunning(); const screenshot = await this.appState.browser!.takeScreenshot(); if (returnBase64) { return screenshot; } // Save to file const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const fileName = filename ? `${filename}.png` : `screenshot-${timestamp}.png`; const filePath = path.join(this.config.screenshotDir, fileName); await fs.writeFile(filePath, screenshot, 'base64'); return filePath; }