Skip to main content
Glama

focus_window

Bring a window to the foreground by partial title match. Switch focus before actions, or activate a Chrome tab by URL when a tool lacks windowTitle support.

Instructions

Bring a window to the foreground by partial title match (case-insensitive). Use when a tool does not accept a windowTitle param, or when you need to switch focus before a sequence of actions. Use chromeTabUrlContains to activate a specific Chrome/Edge tab by URL substring before focusing — only the active tab's title appears in the windows list. If CDP is unavailable, chromeTabUrlContains is silently skipped — check response.hints.warnings. Returns WindowNotFound if no match exists; call desktop_discover to see available titles. Caveats: On some apps focus may be immediately stolen back (modal dialogs, UAC prompts) — verify with desktop_state after focusing. Win11 foreground refusal (UIPI cross-elevation / admin-only target / call from a background process or service) returns code:'ForegroundRestricted' ok:false instead of silently failing — recover by switching to a tool that does not require foreground transfer: desktop_act / click_element use UIA InvokePattern (no foreground needed); keyboard BG path bypasses foreground for terminal-class targets only (Windows Terminal / cmd / PowerShell — keyboard with windowTitle on non-terminal apps still hits the same ForegroundRestricted refusal). browser_* tools target by tabId/selector, not windowTitle.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYesPartial window title to search for (case-insensitive). A shown window (a minimised one counts) is taken before a hidden one with the same text; a hidden one — on another virtual desktop — only when nothing shown matches.
cdpPortNoCDP port for chromeTabUrlContains (default 9222)
includeNoOptional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients).
forceFocusNoWhen set, use AttachThreadInput-based foreground escalation on the first attempt. When omitted (default), focus_window first tries the standard SetForegroundWindow path and auto-escalates to force-focus only if Win11 refused the default attempt (issue #197). Override env: DESKTOP_TOUCH_FORCE_FOCUS=1 sets the implicit default to true. If both default and force paths fail, focus_window now returns ok:false code:'ForegroundRestricted' instead of the previous silent ok:true with windowChanged:false.
chromeTabUrlContainsNoWhen set, activate the Chrome/Edge tab whose URL contains this substring before focusing the window. Requires Chrome/Edge running with --remote-debugging-port (default 9222). Use this when the target is a Chrome tab that is not currently active — the active tab title is the only one visible in the window title list.

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed2 schema fields changedv2.3.1
    • addedInput schema / $schema
      Added value: +"http://json-schema.org/draft-07/schema#"
    • removedInput schema / additionalProperties
      Removed value: -false
  2. Changed1 schema field changedv2.2.0
    • changedInput schema / properties / title / description
      Previous value: -"Partial window title to search for (case-insensitive)"New value: +"Partial window title to search for (case-insensitive). A shown window (a minimised one counts) is taken before a hidden one with the same text; a hidden one — on another virtual desktop — only when nothing shown matches."
  3. Addedv1.12.0
  4. Removedv1.10.4
  5. Addedv1.9.2
  6. Removedv1.8.0
  7. Addedv1.6.0
  8. Removedv1.5.1
  9. Addedv1.5.0
  10. Removedv1.4.3
  11. Addedv1.4.2
  12. Removedv1.4.0
  13. Changed1 schema field changedv1.2.1
    • addedInput schema / properties / include
      Added value: +{
      +  "description": "Optional response-shape opt-in. `['envelope']` returns the self-documenting envelope (`_version` / `data` / `as_of` / `confidence`). `['raw']` forces raw shape (overrides DESKTOP_TOUCH_ENVELOPE=1 server default). Default behaviour is raw shape (compat with existing clients).",
      +  "items": {
      +    "type": "string"
      +  },
      +  "type": "array"
      +}
  14. Addedv1.0.3
  15. Removedv0.15.7
  16. Changed7 schema fields changedv0.10.0
    • removedInput schema / $schema
      Removed value: -"http://json-schema.org/draft-07/schema#"
    • addedInput schema / additionalProperties
      Added value: +false
    • removedInput schema / properties / _stub
      Removed value: -{
      -  "description": "Stub tool — arguments ignored."
      -}
    • addedInput schema / properties / cdpPort
      Added value: +{
      +  "default": 9222,
      +  "description": "CDP port for chromeTabUrlContains (default 9222)",
      +  "maximum": 65535,
      +  "minimum": 1,
      +  "type": "integer"
      +}
    • addedInput schema / properties / chromeTabUrlContains
      Added value: +{
      +  "description": "When set, activate the Chrome/Edge tab whose URL contains this substring before focusing the window. Requires Chrome/Edge running with --remote-debugging-port (default 9222). Use this when the target is a Chrome tab that is not currently active — the active tab title is the only one visible in the window title list.",
      +  "type": "string"
      +}
    • addedInput schema / properties / title
      Added value: +{
      +  "description": "Partial window title to search for (case-insensitive)",
      +  "type": "string"
      +}
    • addedInput schema / required
      Added value: +[
      +  "title"
      +]
  17. First observedv0.6.2

TDQS

A4.8/5.0
Behavior5/5

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

No annotations exist, so the description carries the full burden and does so thoroughly: it discloses silent CDP skipping and where to check (response.hints.warnings), the WindowNotFound error and desktop_discover recovery, focus-stealing caveats, and the Win11 foreground refusal contract (code:'ForegroundRestricted' ok:false instead of silent success).

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

Conciseness4/5

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

Front-loaded with the core verb+resource before any caveats, and nearly every sentence adds operational value. It is dense and long, bordering on caveat overload for a single tool, which keeps it out of the top band.

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

Completeness5/5

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

With no output schema and no annotations, the description still covers error codes, silent-skip semantics, recovery paths, and caveats an agent needs to call this correctly. Nothing material is missing.

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

Parameters4/5

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

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning: chromeTabUrlContains activation semantics and why only the active tab's title is visible, plus forceFocus's auto-escalation behavior on Win11. It slightly exceeds what the schema already documents.

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?

States a specific verb+resource and matching semantics (foreground a window by case-insensitive partial title). Explicitly contrasts with sibling tools: browser_* target by tabId/selector, not windowTitle, and it names desktop_act/click_element as foreground-free alternatives.

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?

Gives explicit when-to-use conditions ('when a tool does not accept a windowTitle param', 'before a sequence of actions') plus a pre-condition for the Chrome tab path. Also names concrete alternatives and their selection criteria (UIA InvokePattern, keyboard BG path for terminals only).

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