Skip to main content
Glama
Radek44
by Radek44

capture_screenshot

Capture screenshots of Tauri application windows for testing and automation. Saves images to files or returns base64-encoded PNG data to verify UI elements and document application behavior.

Instructions

Capture a screenshot of the application window. Returns base64-encoded PNG image data by default.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameNoOptional filename (without extension) to save the screenshot. If not provided, a timestamp will be used.
returnBase64NoWhether to return base64 image data (true) or save to file and return path (false). Default: true

Implementation Reference

  • Primary handler function for the capture_screenshot tool. Processes input parameters, calls the low-level driver screenshot method, handles base64 vs file output, and returns standardized ToolResponse.
    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:85-101 (registration)
    Registers the capture_screenshot tool in the MCP server's listTools response, 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, }, }, }, },
  • MCP CallToolRequestSchema handler dispatch for capture_screenshot: invokes the tool handler and specially formats the response to include image content if base64 is returned.
    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), }, ], }; }
  • Low-level helper in TauriDriver class that performs the actual screenshot capture using WebDriverIO's takeScreenshot(), optionally saving to file or returning base64 PNG data.
    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; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Radek44/mcp-tauri-automation'

If you have feedback or need assistance with the MCP directory API, please join our Discord server