Skip to main content
Glama

focus_session

Bring a specific iTerm2 session to the foreground by activating its window and selecting its tab or pane. Provide the session UUID to focus.

Instructions

Bring a session to the foreground.

:param session_id: The session UUID to activate. Its window is raised and its tab/pane is selected.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'focus_session' tool handler. Decorated with @mcp.tool(), it resolves a session by ID and calls async_activate to bring it to the foreground.
    @mcp.tool()
    async def focus_session(session_id: str) -> str:
        """Bring a session to the foreground.
    
        :param session_id: The session UUID to activate. Its window is raised and
            its tab/pane is selected.
        """
        sess = await _session(session_id)
        await sess.async_activate(select_tab=True, order_window_front=True)
        return f"Activated session {session_id}"
  • The _session() helper that resolves a session_id to an iterm2.Session, called by focus_session. Falls back to the currently focused session if session_id is None.
    async def _session(session_id: str | None) -> iterm2.Session:
        """Resolve a session by ID, falling back to the currently active session.
    
        :param session_id: A specific session UUID to target, or ``None`` to use the
            currently focused window/tab/pane.
        """
        app = await _app()
        if session_id:
            sess = app.get_session_by_id(session_id)
            if sess is None:
                raise ValueError(f"No session found with ID {session_id!r}")
            return sess
        win = app.current_terminal_window
        if win is None:
            raise RuntimeError("No active iTerm2 window.")
        tab = win.current_tab
        if tab is None:
            raise RuntimeError("No active tab in the current window.")
        sess = tab.current_session
        if sess is None:
            raise RuntimeError("No active session in the current tab.")
        return sess
  • The FastMCP instance used to register all tools via the @mcp.tool() decorator.
    mcp = FastMCP("iterm2-mcp")
  • The session_id parameter is a plain str (no Pydantic model) – FastMCP derives the schema from the type annotation automatically.
    @mcp.tool()
    async def focus_session(session_id: str) -> str:
Behavior2/5

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

With no annotations provided, the description must fully disclose behavioral traits. It states the outcome (window raised, tab/pane selected) but omits error conditions (e.g., invalid session ID), side effects, or whether it is a no-op if already focused. This is incomplete for a mutation tool.

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 extremely concise: two sentences front-loaded with the action, followed by a parameter docstring. Every sentence serves a purpose with no wasted words.

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 single parameter and the existence of an output schema (not described), the description is adequate but missing key context: it does not mention that the session must exist, error handling, or what the output contains. It also fails to clarify how it relates to siblings like 'get_active_session'.

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 description adds significant meaning beyond the input schema, which has no property descriptions (0% coverage). It explains the session_id parameter is a UUID and specifies the result of calling the tool, compensating well for the schema gap.

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 action ('Bring a session to the foreground') and the effect on the session's window and tab/pane. It distinguishes the tool from siblings like 'close_session' or 'get_active_session' by specifying that it activates an existing session, though it does not explicitly contrast with alternatives.

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 implies when to use (when wanting to bring a session to the foreground) but provides no explicit guidance on when not to use or alternatives. For example, it doesn't mention that the session must already exist or that 'get_active_session' could be used to check which is active.

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/lorencarvalho/iterm2-mcp'

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