Skip to main content
Glama

write_to_terminal

Send text to an iTerm2 session. Optionally execute commands by appending a newline, or submit text without executing for interactive prompts.

Instructions

Send text to an iTerm2 session.

:param text: The characters to send. :param session_id: Target session UUID. Defaults to the active session. :param add_newline: If True (the default), appends \n so commands execute. Set to False to type without submitting, e.g. when filling an interactive prompt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes
session_idNo
add_newlineNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The write_to_terminal tool handler: sends text to an iTerm2 session. Decorated with @mcp.tool() which also serves as registration. Accepts `text`, optional `session_id`, and `add_newline` parameters.
    @mcp.tool()
    async def write_to_terminal(
        text: str,
        session_id: str | None = None,
        add_newline: bool = True,
    ) -> str:
        """Send text to an iTerm2 session.
    
        :param text: The characters to send.
        :param session_id: Target session UUID. Defaults to the active session.
        :param add_newline: If True (the default), appends ``\\n`` so commands
            execute. Set to False to type without submitting, e.g. when filling an
            interactive prompt.
        """
        sess = await _session(session_id)
        payload = text + "\n" if add_newline else text
        await sess.async_send_text(payload, suppress_broadcast=True)
        return f"Sent {len(payload)} characters to session {sess.session_id}"
  • Registration via the @mcp.tool() decorator on line 123, which registers `write_to_terminal` as an MCP tool with the FastMCP instance.
    @mcp.tool()
  • The function signature serves as the schema: `text: str` (required), `session_id: str | None = None` (optional), `add_newline: bool = True` (optional, default True).
    async def write_to_terminal(
        text: str,
        session_id: str | None = None,
        add_newline: bool = True,
    ) -> str:
  • The `_session` helper function used by write_to_terminal to resolve session_id to an iTerm2 Session object, falling back to the currently active 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?

With no annotations, the description bears full behavioral burden. It discloses that adding a newline causes command execution and defaults session to active, but omits details on side effects (e.g., error handling if session is invalid) or synchronous behavior.

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?

The description is structured as a docstring with clear parameter breakdown. It is efficient without extraneous content, though slightly verbose due to reStructuredText formatting.

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 there is an output schema but no return value description, and parameter explanations are basic, the description leaves gaps (e.g., character encoding, error cases). It is adequate but not thorough.

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 coverage is 0%, so description must compensate. It explains all three parameters: 'text' as characters, 'session_id' with default behavior, and 'add_newline' with example usage. This adds meaningful context beyond the bare schema.

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 states 'Send text to an iTerm2 session' which is a specific verb-resource combination. It distinguishes itself from siblings like 'run_command' and 'send_control_character' by focusing on raw text input.

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 provides context for using 'add_newline' (e.g., set False for interactive prompts) but does not explicitly clarify when to use this tool versus alternatives like 'run_command' for sending commands or 'send_control_character' for control keys.

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