Skip to main content
Glama

iterm2-mcp

An MCP server that provides full control over iTerm2.

Prerequisites

  1. iTerm2 running on macOS.

  2. Preferences > General > Magic > "Enable Python API" must be checked.

  3. Install iTerm2 shell integration in your shell. run_command and session variables like path/jobName depend on it. Without it, run_command falls back to its timeout.

The first time the server connects, iTerm2 will prompt you to approve the binary. Approve once; subsequent launches are automatic.

Related MCP server: iTerm MCP Server

Install

uv tool install iterm2-mcp

Or from source:

git clone https://github.com/lorencarvalho/iterm2-mcp.git
cd iterm2-mcp
uv sync

Register with Claude

Claude Code:

claude mcp add iterm2 -- uvx iterm2-mcp

Claude Desktop — add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "iterm2": {
      "command": "uvx",
      "args": ["iterm2-mcp"]
    }
  }
}

Security

This server can type into terminals, run commands, and close sessions — anything you can do in iTerm2. Only connect it to MCP clients you trust. It has no sandboxing beyond what iTerm2 itself provides.

Tools

Most tools accept an optional session_id — omit it to target the currently active session.

Tool

Purpose

list_sessions

Tree of windows/tabs/sessions with IDs

get_active_session

ID and name of the focused session

focus_session

Bring a session to the foreground

write_to_terminal

Send text (optionally with newline)

send_control_character

Send Ctrl-C, Ctrl-D, Ctrl-Z, ESC, etc.

send_escape_sequence

Send a raw ANSI escape (e.g. \x1b[2J)

read_screen

Read the visible screen as plain text

get_cursor_position

Current cursor (x, y)

run_command

Send a command and wait for COMMAND_END

create_window

Open a new iTerm2 window

create_tab

Open a new tab

split_pane

Split a pane horizontally or vertically

close_session

Close a specific session

set_session_name

Rename a session

set_badge

Set the iTerm2 badge text

clear_buffer

Clear screen and scrollback

list_profiles

Enumerate iTerm2 profiles

get_variable

Read an iTerm2 session variable

Development

uv sync
uv run ruff check
uv run ruff format
uv run ty check

License

MIT

Available Tools

18 tools
clear_bufferA

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.

Inputs: session_id. Returns: result

close_sessionB

Close a specific session.

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

Inputs: session_id (required), force. Returns: result

create_tabB

Create a new tab in a window.

:param window_id: Target window ID. Defaults to the current window. :param command: Optional shell command to run in the new tab's session. :param profile: Name of the iTerm2 profile to use.

Inputs: command, profile, window_id. Returns: result

create_windowA

Create a new iTerm2 window.

:param command: Optional shell command to run in the new session. :param profile: Name of the iTerm2 profile to use. Defaults to the default profile.

Inputs: command, profile. Returns: result

focus_sessionB

Bring a session to the foreground.

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

Inputs: session_id (required). Returns: result

get_active_sessionA

Return the ID and name of the currently focused iTerm2 session.

Inputs: no named parameters. Returns: result

get_cursor_positionA

Return the cursor coordinates x, y within the visible screen.

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

Inputs: session_id. Returns: result

get_variableA

Read an iTerm2 session variable.

Commonly useful names: jobName, jobPid, path (requires shell integration), username, hostname, rows, columns, autoName. Prefix with user. for variables set via iTerm2 custom control sequences.

:param name: The variable name to read. :param session_id: Target session UUID. Defaults to the active session.

Inputs: name (required), session_id. Returns: result

list_profilesA

List all iTerm2 profiles with their names and GUIDs.

Inputs: no named parameters. Returns: result

list_sessionsA

List all iTerm2 windows, tabs, and sessions.

Returns a tree with session IDs that can be passed to other tools. The * marker shows the currently focused window, tab, and session.

Inputs: no named parameters. Returns: result

read_screenA

Read the visible contents of an iTerm2 session as plain text.

ANSI escape codes are stripped. Trailing blank lines are trimmed.

:param session_id: Target session UUID. Defaults to the active session. :param max_lines: If set, return only the last N lines.

Inputs: max_lines, session_id. Returns: result

run_commandA

Run a command and wait for it to finish, returning the resulting screen.

Completion is detected via iTerm2's PromptMonitor COMMAND_END notification, which requires iTerm2 shell integration to be installed in the target shell. If the prompt-end event does not arrive within timeout_seconds, the current screen is returned with a [timeout] marker.

:param command: The command line to run. :param session_id: Target session UUID. Defaults to the active session. :param timeout_seconds: How long to wait for COMMAND_END before giving up.

Inputs: command (required), session_id, timeout_seconds. Returns: result

send_control_characterA

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.

Inputs: letter (required), session_id. Returns: result

send_escape_sequenceA

Send a raw escape sequence to an iTerm2 session.

Python string escapes in sequence are interpreted before sending, so values like \x1b[2J (clear screen) or \x1b[H (cursor home) work as expected.

:param sequence: The escape sequence string. :param session_id: Target session UUID. Defaults to the active session.

Inputs: sequence (required), session_id. Returns: result

set_badgeA

Set the iTerm2 session badge (translucent overlay text).

The profile's Badge field must reference \(user.badge) for the value to show up; this is the default in stock profiles.

:param badge: Text to display as the badge. :param session_id: Target session UUID. Defaults to the active session.

Inputs: badge (required), session_id. Returns: result

set_session_nameB

Set the title/name of an iTerm2 session.

:param name: The new session name. :param session_id: Target session UUID. Defaults to the active session.

Inputs: name (required), session_id. Returns: result

split_paneA

Split an iTerm2 pane horizontally or vertically.

:param session_id: Session UUID to split. Defaults to the active session. :param vertical: If True, split left/right; if False, split top/bottom. :param profile: Name of the iTerm2 profile to use for the new pane. :param command: Optional command to run in the new pane after the split.

Inputs: command, profile, vertical, session_id. Returns: result

write_to_terminalA

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.

Inputs: text (required), session_id, add_newline. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 18 tools

    Disambiguation5/5

    Each tool targets a distinct action (e.g., clear, close, create, focus, get, list, read, run, send, set, split, write). Even closely related tools like write_to_terminal and send_control_character have clear differentiation through descriptions.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern in snake_case (e.g., clear_buffer, create_tab, get_variable, set_badge). No mixing of conventions or ambiguous prefixes.

    Tool Count4/5

    18 tools is slightly above the typical 5-15 range, but each tool has a well-defined purpose covering window, tab, session, and terminal operations. No obvious bloat.

    Completeness4/5

    Covers core CRUD and lifecycle operations for sessions/tabs/windows, plus screen reading, command execution, variable access, and profile listing. Minor gaps like missing pane resizing or session info retrieval, but nothing critical for automation.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      This MCP server enables users to execute shell commands in the current iTerm2 session through integration with Claude Desktop, facilitating seamless command execution via the Model Context Protocol.
      3
      178 npm
      572
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A Model Context Protocol server that enables AI assistants to interact with iTerm2 terminals, allowing creation and management of terminal sessions, command execution, and reading terminal output.
      5
      78 npm
      14
      ISC
    • A
      license
      A
      quality
      D
      maintenance
      An MCP server that enables AI assistants to control iTerm2 sessions, windows, tabs, and profiles using the official iTerm2 Python API. It includes a security model with session tagging and tiered permissions to ensure safe and controlled terminal interactions.
      40
      2
      MIT