Skip to main content
Glama

app_get_focus

Retrieve details about the currently active window, tab, and session in iTerm2 to monitor or control terminal interactions.

Instructions

Get information about the currently focused window, tab, and session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main handler function for app_get_focus tool. Decorated with @mcp.tool(), this async function retrieves information about the currently focused iTerm2 window, tab, and session. It uses an inner _impl function that accesses app.current_terminal_window and traverses the hierarchy to collect window_id, tab_id, session_id, and session_name, returning them as JSON.
    @mcp.tool()
    async def app_get_focus() -> str:
        """Get information about the currently focused window, tab, and session."""
    
        async def _impl(connection: iterm2.Connection, app: iterm2.App) -> str:
            result: dict[str, Any] = {}
            window = app.current_terminal_window
            if window:
                result["window_id"] = window.window_id
                tab = window.current_tab
                if tab:
                    result["tab_id"] = tab.tab_id
                    session = tab.current_session
                    if session:
                        result["session_id"] = session.session_id
                        name = await session.async_get_variable("session.name")
                        if name:
                            result["session_name"] = name
            return json.dumps(result, indent=2)
    
        return await _run(_impl)
  • Helper function _run that creates a connection to iTerm2 and executes the tool implementation. It creates an iterm2.Connection, retrieves the app instance, and calls the provided function with connection and app parameters.
    async def _run(func: Callable[..., Awaitable[T]], **kwargs: Any) -> T:
        """Create a connection to iTerm2, run *func*, and return its result."""
        connection = await iterm2.Connection.async_create()
        app = await iterm2.async_get_app(connection)
        return await func(connection=connection, app=app, **kwargs)
  • Security tier configuration defining app_get_focus as a Tier.READ tool. This places the tool in the 'read' permission tier, indicating it performs read-only operations that don't modify state.
    TOOL_TIERS: dict[str, Tier] = {
        # read
        "session_list": Tier.READ,
        "session_read": Tier.READ,
        "session_get_variable": Tier.READ,
        "tab_list": Tier.READ,
        "window_list": Tier.READ,
        "app_get_focus": Tier.READ,
        "profile_list": Tier.READ,
        "profile_show": Tier.READ,
        "app_version": Tier.READ,
        "app_theme": Tier.READ,
        "window_arrange_list": Tier.READ,
  • FastMCP instance creation that serves as the tool registry. The @mcp.tool() decorator used on app_get_focus registers it with this MCP server instance named 'it2mcp'.
    mcp = FastMCP(
        "it2mcp",
        instructions="Control iTerm2 from MCP — manage sessions, windows, tabs, profiles, and more.",
    )
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses that the tool retrieves information (a read operation), which is useful, but it does not add behavioral details such as permissions needed, rate limits, or what specific data is returned (though an output schema exists). The description is accurate but lacks rich context beyond the basic action.

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, efficient sentence that directly states the tool's function without any wasted words. It is front-loaded with the core action and resource, making it highly concise and well-structured for quick understanding.

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 low complexity (0 parameters, no annotations) and the presence of an output schema, the description is complete enough for a read-only information retrieval tool. It clearly states what information is retrieved, though it could benefit from mentioning the output schema's role in detailing return values, but this is not required.

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?

The tool has 0 parameters, and the input schema has 100% coverage, so no parameter information is needed. The description does not mention parameters, which is appropriate, earning a baseline score of 4 as it avoids redundancy and focuses on the tool's purpose.

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

Purpose4/5

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

The description clearly states the verb 'Get' and the resource 'information about the currently focused window, tab, and session', making the purpose specific and actionable. However, it does not explicitly differentiate from sibling tools like 'window_focus' or 'session_focus', which focus on changing focus rather than retrieving information, so it falls short of a perfect score.

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

Usage Guidelines3/5

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

The description implies usage when information about the current focus is needed, but it does not provide explicit guidance on when to use this tool versus alternatives like 'window_list' or 'session_list' for broader information. No exclusions or prerequisites are mentioned, leaving usage context somewhat vague.

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/urjitbhatia/it2mcp'

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