Skip to main content
Glama

clear_buffer

Clears both the visible screen and scrollback buffer in iTerm2. Optionally specify a session UUID to target a specific session.

Instructions

Clear both the visible screen and the scrollback buffer.

Uses the iTerm2-proprietary OSC 1337 ; ClearScrollback control sequence (https://iterm2.com/documentation-escape-codes.html).

:param session_id: Target session UUID. Defaults to the active session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
session_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The 'clear_buffer' tool handler function. Decorated with @mcp.tool(), it clears the visible screen and scrollback buffer by sending the iTerm2-proprietary OSC 1337 ; ClearScrollback control sequence to the targeted session.
    @mcp.tool()
    async def clear_buffer(session_id: str | None = None) -> str:
        """Clear both the visible screen and the scrollback buffer.
    
        Uses the iTerm2-proprietary ``OSC 1337 ; ClearScrollback`` control sequence
        (https://iterm2.com/documentation-escape-codes.html).
    
        :param session_id: Target session UUID. Defaults to the active session.
        """
        sess = await _session(session_id)
        await sess.async_send_text("\x1b]1337;ClearScrollback\x07", suppress_broadcast=True)
        return f"Cleared buffer of session {sess.session_id}"
  • The tool is registered via the @mcp.tool() decorator on line 386, which is a FastMCP decorator that registers the function as an MCP tool on the 'mcp' FastMCP instance (defined at line 21).
    @mcp.tool()
  • The '_session' helper function resolves a session ID or falls back to the active session. It is called by clear_buffer on line 395 to obtain 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
Behavior3/5

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

The description mentions it uses an iTerm2-proprietary control sequence, indicating platform-specific behavior. However, it lacks details on side effects (e.g., cursor position, impact on ongoing operations). No annotations exist to compensate.

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 plus a parameter line. Every sentence adds value, with no redundancy or unnecessary text.

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?

For a simple tool with one optional parameter, the description covers the action, mechanism, and parameter. It lacks return value info, but an output schema exists (though not shown). Overall, it is mostly complete.

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 includes a parameter docstring ('Target session UUID. Defaults to the active session.'), which adds meaning beyond the schema (which only provides type and default). This helps the agent understand usage.

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 description clearly states 'Clear both the visible screen and the scrollback buffer,' which is a specific verb+resource. It distinguishes from sibling tools like read_screen or send_control_character by focusing on buffer clearing.

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. It does not mention prerequisites, exclusions, or context about when clearing is appropriate.

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