Skip to main content
Glama
rogerheykoop

Safari Screenshot MCP Server

by rogerheykoop

take_screenshot

Capture webpage screenshots using Safari on macOS by providing a URL, with options for dimensions, zoom, and save location.

Instructions

Take a screenshot of a webpage using Safari on macOS

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesURL to capture
outputPathNoPath where the screenshot will be saved (default: ./screenshots/[hostname]-[timestamp].png)
widthNoWindow width in pixels (default: 1024)
heightNoWindow height in pixels (default: 768)
waitTimeNoTime to wait for page load in seconds (default: 3)
zoomLevelNoZoom level (1 = 100%, 0.5 = 50%, 2 = 200%)

Implementation Reference

  • Core handler function that opens the URL in Safari, waits, takes a screenshot using screencapture, verifies it, and cleans up Safari windows.
    export async function takeScreenshot(options: ScreenshotOptions): Promise<ScreenshotResult> {
    	const { url, outputPath, width = 1024, height = 768, waitTime = 3, zoomLevel = 1 } = options;
    
    	try {
    		// Create screenshots directory if it doesn't exist
    		const dir = path.dirname(outputPath);
    		await fs.mkdir(dir, { recursive: true });
    
    		// Open URL in Safari
    		await execAsync(`open -a Safari "${url}"`);
    
    		// Wait for page load
    		await new Promise((resolve) => setTimeout(resolve, waitTime * 1000));
    
    		// Take screenshot using screencapture
    		const command = [
    			'screencapture',
    			'-x', // Disable interactive mode
    			width && height ? `-R 0,0,${width},${height}` : '', // Set window size
    			outputPath,
    		]
    			.filter(Boolean)
    			.join(' ');
    
    		await execAsync(command);
    
    		// Verify screenshot was created
    		const stats = await fs.stat(outputPath);
    		if (stats.size < 1000) {
    			throw new Error('Screenshot appears to be empty or too small');
    		}
    
    		return {
    			success: true,
    			path: outputPath,
    		};
    	} catch (error) {
    		throw error instanceof Error ? error : new Error(String(error));
    	} finally {
    		// Clean up Safari windows
    		await execAsync('osascript -e \'tell application "Safari" to close every window\'').catch(() => {});
    	}
    }
  • Defines the MCP tool schema for 'take_screenshot' including input properties, descriptions, defaults, and required fields.
    const SCREENSHOT_TOOL: Tool = {
    	name: 'take_screenshot',
    	description: 'Take a screenshot of a webpage using Safari on macOS',
    	inputSchema: {
    		type: 'object',
    		properties: {
    			url: {
    				type: 'string',
    				description: 'URL to capture',
    			},
    			outputPath: {
    				type: 'string',
    				description: 'Path where the screenshot will be saved (default: ./screenshots/[hostname]-[timestamp].png)',
    				default: '',
    			},
    			width: {
    				type: 'number',
    				description: 'Window width in pixels (default: 1024)',
    				default: 1024,
    			},
    			height: {
    				type: 'number',
    				description: 'Window height in pixels (default: 768)',
    				default: 768,
    			},
    			waitTime: {
    				type: 'number',
    				description: 'Time to wait for page load in seconds (default: 3)',
    				default: 3,
    			},
    			zoomLevel: {
    				type: 'number',
    				description: 'Zoom level (1 = 100%, 0.5 = 50%, 2 = 200%)',
    				default: 1,
    			},
    		},
    		required: ['url'],
    	},
    };
  • src/index.ts:94-98 (registration)
    Registers the 'take_screenshot' tool in the MCP server capabilities.
    capabilities: {
    	tools: {
    		take_screenshot: SCREENSHOT_TOOL,
    	},
    },
  • src/index.ts:103-105 (registration)
    Registers the handler for listing tools, which advertises 'take_screenshot'.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
    	tools: [SCREENSHOT_TOOL],
    }));
  • Dispatcher case in CallToolRequestHandler that validates args, calls takeScreenshot, and returns success response.
    case 'take_screenshot': {
    	if (!isScreenshotArgs(args)) {
    		throw new Error('Invalid arguments for take_screenshot');
    	}
    	const outputPath = args.outputPath || `./screenshots/${new URL(args.url).hostname}-${Date.now()}.png`;
    	const result = await takeScreenshot({
    		url: args.url,
    		outputPath,
    		width: args.width,
    		height: args.height,
    		waitTime: args.waitTime,
    		zoomLevel: args.zoomLevel,
    	});
    	return {
    		content: [
    			{
    				type: 'text',
    				text: `Screenshot saved to: ${result.path}`,
    			},
    		],
    		isError: false,
    	};
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only mentions the action and environment. It lacks details on permissions needed, file system impact, error handling, or rate limits, leaving behavioral gaps for a tool that saves files.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with no wasted words, clearly front-loading the core functionality. It's appropriately sized for the tool's complexity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., success/failure, file path) or address potential issues like network errors or file permissions, which are critical for a screenshot tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds no extra parameter meaning beyond implying URL capture, aligning with the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('take a screenshot') and target resource ('webpage'), specifying the browser ('Safari') and platform ('macOS'). It's specific but lacks sibling differentiation since no sibling tools are provided, preventing a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives, such as other screenshot methods or tools for different browsers/platforms. The description states what it does but offers no context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/rogerheykoop/mcp-safari-screenshot'

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