Skip to main content
Glama

list_windows

List all macOS windows organized by Spaces to identify which windows belong to each Space, providing detailed window information in JSON or summary format.

Instructions

List all windows organized by macOS Space. Returns detailed information about windows, spaces, and which windows belong to which Space.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNoOutput format: 'json' (structured data) or 'summary' (human-readable)json

Implementation Reference

  • Main handler function for the list_windows tool. Refreshes tracker data, handles JSON or summary output formats, and returns structured or human-readable window lists organized by macOS Spaces.
    async def handle_list_windows(arguments: dict) -> list[TextContent]:
        """Handle list_windows tool call."""
        try:
            # Refresh tracker data
            tracker.refresh()
    
            format_type = arguments.get("format", "json")
    
            if format_type == "json":
                # Return structured JSON data
                data = tracker.get_all_data()
                return [
                    TextContent(
                        type="text",
                        text=json.dumps(data, indent=2)
                    )
                ]
            else:  # summary format
                # Return human-readable summary
                data = tracker.get_all_data()
                windows_by_space = tracker.get_windows_by_space()
    
                summary_lines = []
                summary_lines.append(f"Total Spaces: {data['summary']['total_spaces']}")
                summary_lines.append(f"Total Windows: {data['summary']['total_windows']}")
                summary_lines.append("")
    
                # Create space map for quick lookup
                space_map = {s.get('index'): s for s in data['spaces']}
    
                for space_index in sorted(windows_by_space.keys()):
                    windows = windows_by_space[space_index]
                    space_info = space_map.get(space_index, {})
                    space_label = space_info.get('label', '(unlabeled)')
                    is_visible = space_info.get('is-visible', False)
                    visibility = "VISIBLE" if is_visible else "hidden"
    
                    summary_lines.append(f"Space {space_index}: {space_label} ({visibility})")
                    summary_lines.append(f"  {len(windows)} window(s)")
    
                    for window in windows:
                        app_name = window.get('app', 'Unknown')
                        title = window.get('title', '(Untitled)')
                        win_id = window.get('id', 0)
                        summary_lines.append(f"    - [{app_name}] {title} (ID: {win_id})")
    
                    summary_lines.append("")
    
                return [
                    TextContent(
                        type="text",
                        text="\n".join(summary_lines)
                    )
                ]
    
        except Exception as e:
            return [
                TextContent(
                    type="text",
                    text=f"Error listing windows: {str(e)}"
                )
            ]
  • Tool schema defining the list_windows tool, including name, description, and optional 'format' input parameter.
    Tool(
        name="list_windows",
        description="List all windows organized by macOS Space. Returns detailed information about windows, spaces, and which windows belong to which Space.",
        inputSchema={
            "type": "object",
            "properties": {
                "format": {
                    "type": "string",
                    "description": "Output format: 'json' (structured data) or 'summary' (human-readable)",
                    "enum": ["json", "summary"],
                    "default": "json"
                }
            },
            "required": []
        }
    ),
  • Tool dispatch logic in the call_tool handler that routes list_windows calls to the handle_list_windows function.
    if name == "list_windows":
        return await handle_list_windows(arguments)
  • Refreshes the tracker by querying yabai for current spaces and windows data, called by the list_windows handler.
    def refresh(self):
        """Refresh space and window data."""
        if self.has_yabai:
            self.spaces_data = self._query_yabai_spaces()
            self.windows_data = self._query_yabai_windows()
        else:
            raise RuntimeError("yabai not found. Install with: brew install koekeishiya/formulae/yabai")
  • Core utility that executes yabai query to list all windows, providing the raw data for the list_windows tool.
    def _query_yabai_windows(self) -> List[Dict]:
        """Query yabai for window information."""
        try:
            result = subprocess.run(
                ['yabai', '-m', 'query', '--windows'],
                capture_output=True,
                text=True,
                timeout=5
            )
            return json.loads(result.stdout)
        except Exception as e:
            print(f"Warning: Could not query yabai windows: {e}")
            return []
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the tool returns 'detailed information about windows, spaces, and which windows belong to which Space,' which gives some behavioral insight. However, it lacks critical details like whether this requires permissions, how data is sourced (real-time vs cached), performance characteristics, or error handling. For a tool with no annotations, this is insufficient.

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 two sentences with zero waste: the first states the purpose and scope, and the second specifies the return content. It's front-loaded with the core functionality and appropriately sized for a simple tool.

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

Completeness3/5

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

Given the tool's low complexity (1 optional parameter, no output schema, no annotations), the description is minimally complete. It covers what the tool does and what it returns, but lacks behavioral details that would be helpful for an agent (e.g., permissions, data freshness). Without annotations or output schema, it's adequate but has clear 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 fully documents the single parameter 'format' with its enum values and default. The description adds no parameter-specific information beyond what the schema provides, which is acceptable given the high coverage. Baseline 3 is appropriate as the schema handles the heavy lifting.

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 verb ('List') and resource ('windows organized by macOS Space'), specifies the scope ('all windows'), and distinguishes from the sibling tool 'capture_window' by focusing on listing rather than capturing. It's specific and unambiguous.

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?

The description provides no guidance on when to use this tool versus alternatives. It mentions the sibling tool 'capture_window' exists but gives no context on when to choose listing over capturing or other potential scenarios. Usage is implied but not explicitly stated.

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