Skip to main content
Glama

close_session

Close a specific iTerm2 session by providing its session ID. Optionally force close without confirmation.

Instructions

Close a specific session.

:param session_id: The session UUID to close. :param force: If True, skip iTerm2's "running process" confirmation prompt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idYes
forceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `close_session` tool handler. Decorated with @mcp.tool(), it accepts a session_id (str) and optional force (bool) parameter. Resolves the session via _session() helper, calls sess.async_close(force=force), and returns a confirmation string.
    @mcp.tool()
    async def close_session(session_id: str, force: bool = False) -> str:
        """Close a specific session.
    
        :param session_id: The session UUID to close.
        :param force: If True, skip iTerm2's "running process" confirmation prompt.
        """
        sess = await _session(session_id)
        await sess.async_close(force=force)
        return f"Closed session {session_id}"
  • The `@mcp.tool()` decorator registers `close_session` as an MCP tool on the FastMCP server instance.
    @mcp.tool()
  • The `_session()` helper function resolves a session_id string to an iterm2.Session object, used by close_session to find the target session.
    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
Behavior2/5

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

With no annotations, the description must fully disclose behavior. It states the tool closes a session and describes the force parameter for skipping confirmation, but fails to mention destructive nature, impact on running processes, or error handling. Important behavioral traits are omitted.

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, comprising one line for the purpose and two lines for parameters. It is front-loaded with the action, and every sentence serves a purpose with no redundancy.

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?

For a simple close operation with an output schema, the description covers purpose and parameters. However, it lacks guidance on usage context and behavioral transparency. Given the absence of annotations, more details about side effects or prerequisites would improve completeness.

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?

Despite 0% schema description coverage, the description provides meaningful parameter explanations: session_id is 'The session UUID to close' and force effect is detailed. This adds value beyond the schema's type/title, though no further details like valid formats or constraints are given.

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 'Close a specific session,' specifying the verb and resource. This distinguishes it from sibling tools like focus_session or get_active_session. The purpose is immediately clear, but the description is minimal and does not elaborate beyond the action.

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?

No guidance is provided on when to use this tool versus alternatives such as focus_session or split_pane. The description only explains the force parameter's effect, but offers no context for selecting close_session over other session manipulation tools.

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