Skip to main content
Glama

capture_window

Take screenshots of specific macOS windows by ID using yabai integration. Get window IDs from list_windows tool first, then capture images as base64-encoded PNG files with optional shadow inclusion.

Instructions

Capture a screenshot of a specific window by its ID. Returns the image as base64-encoded PNG. Use list_windows first to get window IDs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
window_idYesThe window ID to capture (from list_windows)
include_shadowNoInclude window shadow in the capture

Implementation Reference

  • The primary handler function implementing the capture_window tool logic. It processes input arguments, verifies the window, uses subprocess to run macOS 'screencapture' command on the window ID, encodes the resulting PNG to base64, and returns TextContent with description and ImageContent with the screenshot.
    async def handle_capture_window(arguments: dict) -> list[ImageContent | TextContent]:
        """Handle capture_window tool call."""
        try:
            window_id = arguments.get("window_id")
            include_shadow = arguments.get("include_shadow", True)
    
            if window_id is None:
                return [
                    TextContent(
                        type="text",
                        text="Error: window_id is required"
                    )
                ]
    
            # Refresh tracker to verify window exists
            tracker.refresh()
            window = tracker.get_window_by_id(window_id)
    
            if not window:
                return [
                    TextContent(
                        type="text",
                        text=f"Error: Window with ID {window_id} not found"
                    )
                ]
    
            # Create temporary file for screenshot
            temp_file = Path(f"/tmp/capture_win_{window_id}.png")
    
            # Build screencapture command
            cmd = ["screencapture", "-x"]  # -x: no sound
    
            if not include_shadow:
                cmd.append("-o")  # -o: no shadow
    
            cmd.extend(["-l", str(window_id)])  # -l: capture window by ID
            cmd.append(str(temp_file))
    
            # Capture the window
            result = subprocess.run(
                cmd,
                capture_output=True,
                text=True,
                timeout=10
            )
    
            if result.returncode != 0:
                return [
                    TextContent(
                        type="text",
                        text=f"Error capturing window: {result.stderr}"
                    )
                ]
    
            # Read and encode the image
            if not temp_file.exists():
                return [
                    TextContent(
                        type="text",
                        text="Error: Screenshot file not created"
                    )
                ]
    
            image_data = temp_file.read_bytes()
            base64_image = base64.b64encode(image_data).decode('utf-8')
    
            # Clean up temporary file
            temp_file.unlink()
    
            # Get window details for context
            app_name = window.get('app', 'Unknown')
            title = window.get('title', '(Untitled)')
    
            return [
                TextContent(
                    type="text",
                    text=f"Captured window: [{app_name}] {title} (ID: {window_id})"
                ),
                ImageContent(
                    type="image",
                    data=base64_image,
                    mimeType="image/png"
                )
            ]
    
        except subprocess.TimeoutExpired:
            return [
                TextContent(
                    type="text",
                    text="Error: Screenshot capture timed out"
                )
            ]
        except Exception as e:
            return [
                TextContent(
                    type="text",
                    text=f"Error capturing window: {str(e)}"
                )
            ]
  • Input JSON schema for the capture_window tool, specifying the required 'window_id' parameter and optional 'include_shadow' boolean.
    inputSchema={
        "type": "object",
        "properties": {
            "window_id": {
                "type": "integer",
                "description": "The window ID to capture (from list_windows)"
            },
            "include_shadow": {
                "type": "boolean",
                "description": "Include window shadow in the capture",
                "default": True
            }
        },
        "required": ["window_id"]
    }
  • Tool registration in list_tools(): defines the MCP Tool object for 'capture_window' with name, description, and input schema.
    Tool(
        name="capture_window",
        description="Capture a screenshot of a specific window by its ID. Returns the image as base64-encoded PNG. Use list_windows first to get window IDs.",
        inputSchema={
            "type": "object",
            "properties": {
                "window_id": {
                    "type": "integer",
                    "description": "The window ID to capture (from list_windows)"
                },
                "include_shadow": {
                    "type": "boolean",
                    "description": "Include window shadow in the capture",
                    "default": True
                }
            },
            "required": ["window_id"]
        }
    )
  • Dispatch registration in @app.call_tool(): routes calls to 'capture_window' to the handler function.
    elif name == "capture_window":
        return await handle_capture_window(arguments)
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the return format ('Returns the image as base64-encoded PNG') which is valuable, but doesn't mention potential limitations like window visibility requirements, performance impact, or error conditions. It provides basic behavioral context but could be more comprehensive.

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 perfectly concise with two sentences that each serve distinct purposes: the first states the tool's purpose and return format, the second provides usage guidance. There's no wasted language and it's front-loaded with the core functionality.

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

Completeness4/5

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

Given the tool's moderate complexity (screenshot capture with parameters), no annotations, and no output schema, the description does well by explaining the return format and workflow. However, it could provide more context about potential constraints or error cases. It's mostly complete but has minor gaps.

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 the schema already fully documents both parameters. The description mentions window IDs come from 'list_windows' which adds some context, but doesn't provide additional semantic meaning beyond what's in the schema descriptions. This meets the baseline for high schema coverage.

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

Purpose5/5

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

The description clearly states the specific action ('Capture a screenshot') and target resource ('a specific window by its ID'), distinguishing it from the sibling tool 'list_windows' which provides window IDs. It uses precise verbs and resources without being vague or tautological.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool ('Capture a screenshot of a specific window by its ID') and provides a clear alternative/pre-requisite ('Use list_windows first to get window IDs'). This gives complete guidance on tool selection and workflow.

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/huegli/capture-win-mcp'

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