Skip to main content
Glama
Radek44
by Radek44

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
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, 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), }; } }
  • 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, }, }, }, },
  • 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; }

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