Skip to main content
Glama

send_control_character

Send keyboard control characters to iTerm2 sessions, such as Ctrl-C to interrupt processes. Specify a letter (A-Z, ESC, or ]) to emulate the corresponding control key.

Instructions

Send a control character to an iTerm2 session.

Supported values: any single letter A-Z (Ctrl-A through Ctrl-Z), ESC/ESCAPE for Escape (0x1B), and ] for the telnet escape (0x1D).

:param letter: The control key name; see above for accepted forms. :param session_id: Target session UUID. Defaults to the active session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
letterYes
session_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The tool handler function 'send_control_character' that implements the logic. It maps a letter (A-Z) to its Ctrl equivalent, handles special keys ESC/ESCAPE (0x1B) and ] (0x1D), and sends the resulting control character to the target iTerm2 session.
    @mcp.tool()
    async def send_control_character(
        letter: str,
        session_id: str | None = None,
    ) -> str:
        """Send a control character to an iTerm2 session.
    
        Supported values: any single letter ``A``-``Z`` (Ctrl-A through Ctrl-Z),
        ``ESC``/``ESCAPE`` for Escape (0x1B), and ``]`` for the telnet escape
        (0x1D).
    
        :param letter: The control key name; see above for accepted forms.
        :param session_id: Target session UUID. Defaults to the active session.
        """
        _SPECIAL_KEYS = {"ESC": 0x1B, "ESCAPE": 0x1B, "]": 0x1D}
        key = letter.strip().upper()
        if key in _SPECIAL_KEYS:
            code = _SPECIAL_KEYS[key]
        elif len(key) == 1 and "A" <= key <= "Z":
            code = ord(key) - ord("A") + 1
        else:
            raise ValueError(f"Unrecognized control key {letter!r}")
        sess = await _session(session_id)
        await sess.async_send_text(chr(code), suppress_broadcast=True)
        return f"Sent Ctrl-{key} to session {sess.session_id}"
  • The @mcp.tool() decorator registers 'send_control_character' as an MCP tool with the FastMCP server instance.
    @mcp.tool()
  • Input schema for the tool: 'letter' (str) - the control key name (A-Z, ESC, ESCAPE, or ]), and optional 'session_id' (str | None). The docstring/type annotations serve as the schema definition for FastMCP.
    async def send_control_character(
        letter: str,
        session_id: str | None = None,
    ) -> str:
  • The '_session' helper function is used by send_control_character to resolve the target session (by explicit session_id or the currently focused 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?

No annotations provided, and description does not disclose side effects, permission requirements, or error behavior. However, the action is simple and low-risk.

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?

Description is brief, well-structured, with param documentation inline, no wasted words.

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?

Output schema exists, reducing need for return value explanation. Description covers input details but lacks error handling or result info.

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 has 0% description coverage, but description adds valuable context: accepted formats for letter (A-Z, ESC, ESCAPE, ]) and session_id defaults.

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?

Description clearly states the tool sends a control character to an iTerm2 session and lists supported values, distinguishing it from siblings like send_escape_sequence.

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?

Description explains supported values and default session but does not explicitly state when to use this tool over alternatives like send_escape_sequence.

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