Skip to main content
Glama

java_focus_window

Destructive

Brings an attached Java window to the foreground and confirms whether it actually has keyboard focus before sending shortcuts, so keystrokes do not land in another window.

Instructions

Bring an attached window to the front, and report whether it actually came forward.

Use it before java_send_keys, whose chord goes to whichever window has the keyboard focus: attaching a window does not give it focus (measured in pyjab#180), so a shortcut can otherwise land somewhere else entirely.

The reply is the point, not the action. "I asked for focus" and "the window is now in front" are two different facts, and this tool answers with the second one. It does so by reading back the state pyjab left behind, because Windows' SetForegroundWindow has no useful return of its own. So there are three answers, not two:

  • the window is the foreground window now;

  • it is not — a normal answer rather than a failure, because Windows refuses foreground activation from a non-interactive session (a service, a scheduled task) and no amount of retrying changes that. An error would be wrong here: nothing failed, and the caller has a fact it can act on;

  • pyjab answered something that is neither True nor False, so this server cannot say — reported as such rather than filed under "did not come forward", because "I could not tell" is not a measurement.

It is not free: when the window is not already in front, pyjab sends a space keystroke first, which is what Windows' foreground-activation rules require of a process that wants the foreground — and that keystroke goes to whatever currently has the focus. A caller that cannot tolerate a stray keystroke elsewhere should not call this.

This needs pyjab 1.11.0, which released JABDriver.focus(). The call is probed rather than assumed, like every pyjab capability here: an install below the pin is told which release has it instead of raising an AttributeError.

Args: session_id: From java_attach_window.

Returns: Whether the window is now the foreground window, said plainly, with the next step.

Errors: is_error only for an unknown session, or a pyjab below the pin — which names the release that has the API. "It did not come forward" is a result, not an error.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "session_id": "<session_id>"
    },
    "name": "java_focus_window"
  }
}

Input Schema

NameRequiredDescriptionDefault
session_idYes

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A4.8/5.0
Behavior5/5

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

Annotations declare destructiveHint=true and openWorldHint=true; the description earns credit by explaining *why* — the undocumented space keystroke sent to whatever currently has focus when the window is not already in front. It further discloses the three-way outcome model (came forward / refused by Windows / cannot tell) and the exact is_error conditions, none of which is in the structured fields.

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 purpose and the reply-over-action framing, then organized into outcome bullets, cost warning, version requirement, and args/returns/errors. It is long for a one-parameter tool and carries some flourish (the pyjab#180 citation, repeated restatement of the three answers), but nearly every sentence conveys behavior the agent could otherwise get wrong.

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?

Complete for a focus tool with a real side effect and a non-binary result: side effects, error semantics, version gating, and the meaning of each of the three outcomes are all covered. The output schema exists, so the description's explanation of the reply is a bonus rather than a gap-filler.

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 description coverage is 0% for the single session_id parameter, so the description must compensate; it does so by naming the provenance ("From java_attach_window"). It does not describe the identifier's format or lifetime, but for one parameter the added meaning is adequate.

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 first sentence states a specific verb and resource ("Bring an attached window to the front, and report whether it actually came forward") and immediately frames the tool's core distinction — the reported result matters more than the request. It also distinguishes itself from java_send_keys by explaining that attaching a window does not grant it focus.

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?

States exactly when to call it ("Use it before `java_send_keys`, whose chord goes to whichever window has the keyboard focus") and an explicit when-not-to ("A caller that cannot tolerate a stray keystroke elsewhere should not call this"). It also pins prerequisites (pyjab 1.11.0 with JABDriver.focus) so the agent knows the failure mode before calling.

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