Skip to main content
Glama

focus_window

Activate macOS applications and raise specific windows by title using fuzzy matching for app names. Switch between windows quickly to improve workflow efficiency.

Instructions

Activate an application and optionally raise a specific window by title. App name supports fuzzy matching.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
appYesApplication name to activate.
titleNoWindow title to raise. If omitted, the frontmost window of the application is activated.

Implementation Reference

  • The 'handleFocusWindow' function acts as the handler for the 'focus_window' tool. It parses input arguments, resolves the application name, and executes an AppleScript to activate the application and optionally raise a specific window.
    /** Handle focus_window tool call. */
    async function handleFocusWindow(
      args: Record<string, unknown>,
    ): Promise<CallToolResult> {
      const parsed = FocusWindowInputSchema.parse(args);
      const app = await resolveAppName(parsed.app);
      const safeApp = escapeAppleScriptString(app);
    
      // Activate the application
      let script = `tell application "${safeApp}" to activate`;
    
      // If a specific window title is requested, raise it via System Events
      if (parsed.title) {
        const safeTitle = escapeAppleScriptString(parsed.title);
        script += `
    delay 0.3
    tell application "System Events"
      tell process "${safeApp}"
        set frontmost to true
        try
          perform action "AXRaise" of (first window whose name is "${safeTitle}")
        on error
          error "Window titled \\"${safeTitle}\\" not found in ${safeApp}"
        end try
      end tell
    end tell`;
      }
    
      await runAppleScript(script);
    
      return {
        content: [
          {
            type: "text" as const,
            text: JSON.stringify({
              success: true,
              app: parsed.app,
              ...(parsed.title ? { title: parsed.title } : {}),
            }),
          },
        ],
      };
    }
  • 'FocusWindowInputSchema' defines the structure and validation for input arguments required by the 'focus_window' tool.
    const FocusWindowInputSchema = z.object({
      app: z.string().max(1_000).describe("Application name to activate."),
      title: z
        .string()
        .max(1_000)
        .optional()
        .describe(
          "Window title to raise. If omitted, the frontmost window of the application is activated.",
        ),
    });
  • The 'focus_window' tool is defined within the 'windowToolDefinitions' array, which provides the metadata and schema for the tool.
    {
      name: "focus_window",
      description:
        "Activate an application and optionally raise a specific window by title. App name supports fuzzy matching.",
      inputSchema: zodToToolInputSchema(FocusWindowInputSchema),
      annotations: {
        readOnlyHint: false,
        destructiveHint: false,
      },
    },
  • The 'focus_window' tool is registered in 'windowToolHandlers', mapping it to its handler function with queuing.
    focus_window: (args) => enqueue(() => handleFocusWindow(args)),
Behavior3/5

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

Annotations indicate this is not read-only and not destructive, which the description doesn't contradict. The description adds useful context beyond annotations: it explains the fuzzy matching behavior and clarifies that omitting 'title' activates the frontmost window. However, it lacks details on error handling, permissions, or system impacts.

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, well-structured sentence that front-loads the core purpose and efficiently adds key details (fuzzy matching). Every word earns its place with zero waste.

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 (activating windows), no output schema, and rich annotations, the description is mostly complete. It covers the main functionality and parameters well but could benefit from mentioning potential side effects or error cases to reach a 5.

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 adds minimal value beyond the schema—it mentions fuzzy matching for 'app' and implies the optional nature of 'title', but doesn't provide additional syntax or format details. Baseline 3 is appropriate here.

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 ('Activate an application and optionally raise a specific window by title') and distinguishes it from siblings like 'open_application' (which likely launches apps) and 'list_windows' (which only lists). It also mentions the unique 'fuzzy matching' feature for app names.

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

Usage Guidelines4/5

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

The description provides clear context for when to use it (activating apps/windows) and implies when not to use it (e.g., use 'open_application' for launching, 'list_windows' for listing). However, it doesn't explicitly name alternatives or state exclusions, so it falls short of a perfect 5.

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/antbotlab/mac-use-mcp'

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