iterm2-mcp
English | 简体中文
An iTerm2 MCP server built around visible execution: every command is injected into a terminal session as typed text (send text) — exactly as if the user typed it — so everything stays on screen and under your supervision. There is no exec / silent-execution tool of any kind.
Inspired by electerm's MCP integration and ferrislucas/iterm-mcp, customized for multi-server profile management.
Features
- Connect via saved iTerm2 profiles: open a new tab by profile name (or GUID); duplicate profile names raise an error listing all GUIDs — it never silently connects to the wrong machine
- Visible execution:
send_commandis equivalent to typing a command and pressing Enter;send_textfeeds input step by step for REPLs / interactive programs. There is no execution channel that bypasses the terminal screen - Address sessions by name: after a tab is created, its session is automatically registered under the profile name; the agent can rename it at any time, and all other tools address sessions by name
- Auto-login: when a profile auto-types its password, the server detects the password prompt and sends the confirming Enter for you
- File transfer:
upload_file/download_filedrivescpfrom a local shell session (Mac-initiated outbound connection — works with public-internet servers);distribute_keysends your Mac's public key into an already-logged-in server session (no password needed), after which transfers run fully automatically;check_transferverifies md5 on both ends - Multi-session management: list / focus (switch tab) / close
Tools
| Tool | Description |
|---|---|
list_profiles |
List all iTerm2 profile names (duplicates flagged) |
list_sessions |
List all window/tab/session entries (id, name, MCP name) |
create_session |
Open a new tab by profile name; session auto-named after the profile |
create_session_by_guid |
Open a tab by profile GUID (for disambiguating duplicate names) |
focus_session |
Focus the iTerm2 window on a session (select its tab and bring to front) |
close_session |
Close a session (by name or id) |
rename_session |
Rename a session |
send_command |
Send one line of command to a session (auto \n, visible as typed) |
send_text |
Send raw text/keystrokes to a session (for REPLs; no trailing newline) |
read_screen |
Read a session's current screen contents (line by line) |
interrupt |
Send Ctrl+C to a session |
create_local_session |
Open a local shell tab registered as local-shell (used by transfer tools) |
upload_file |
Upload a local file to a server via scp (Mac-initiated) |
download_file |
Download a server file to local via scp (Mac-initiated) |
distribute_key |
Send Mac's public key into a logged-in server session + pre-scan host key (one-time, passwordless afterwards) |
check_transfer |
Verify transfer integrity by comparing remote/local md5 |
Every tool that accepts a name also accepts a session id — the name_or_id parameter auto-detects.
Requirements
- macOS + iTerm2 ≥ 3.5, with Settings → General → Magic → Enable Python API turned on
- Python 3.12+
Install & Register
Prerequisite: pipx or uv (pick one, if not installed yet)
Method 1 / Method 2 depend on the pipx / uvx commands. Install one first (via Homebrew on macOS):
brew install pipx # https://pipx.pypa.io
# or
brew install uv # https://docs.astral.sh/uv/ (provides uvx)
On machines without Homebrew, use the official installers at the links above — or skip ahead to Method 3.
Method 1: pipx (recommended, isolated environment)
pipx install iterm2-mcp-zanlan
Then register (Claude Desktop / .mcp.json JSON config):
{
"mcpServers": {
"iterm2": {
"command": "iterm2-mcp"
}
}
}
One-liner for Claude Code:
claude mcp add iterm2 -- iterm2-mcp
Method 2: uvx, zero install
{
"mcpServers": {
"iterm2": {
"command": "uvx",
"args": ["iterm2-mcp-zanlan"]
}
}
}
Method 3: from source
git clone https://github.com/Zane-lan/iterm2-mcp.git
cd iterm2-mcp
pip install iterm2 "mcp[cli]>=1,<2" # homebrew Python: add --user --break-system-packages
{
"mcpServers": {
"iterm2": {
"command": "/path/to/python3.12",
"args": ["/path/to/iterm2-mcp/src/iterm2_mcp/server.py"]
}
}
}
Design decisions
- Duplicate-profile protection: opening a tab by name that matches multiple profiles raises an error listing every GUID — the user picks one (or deletes the duplicates in iTerm2); a GUID-based tool is provided as the escape hatch
- Auto-naming on creation: a tab opened via a profile is registered under the profile name, so later tools can address it by name
- Name addressing uses an MCP-maintained registry (
~/.config/iterm2-mcp/registry.json) — in practice, shell integration resets the session title back to an automatic name (e.g.~ (-zsh)) after every command via OSC escape sequences, sosession.nameis unreliable;set_nameis still attempted for a readable tab title, but addressing never depends on it; a livesession.nameprefix match serves as fallback when the registry misses - Send-only, no exec: no tool in the set bypasses the terminal screen
Verification
The end-to-end integration test runs against a real iTerm2 (opens tabs, sends commands, Ctrl+C, closes tabs):
python3.12 test_e2e.py
Implementation notes (pitfalls found the hard way)
- iTerm2 3.6.x no longer listens on TCP 1912; the Python API moved to a Unix Domain Socket (
~/Library/Application Support/iTerm2/private/socket), which the officialiterm2package auto-detects - When driving the iterm2 package from a custom event loop, you must also start the
Connection._async_dispatch_foreverdispatch loop — otherwise every RPC hangs forever iterm22.30: entry point isiterm2.run_until_complete(coro);ScreenContentsuses theline(i)method;App.current_sessionis gone- FastMCP's lifespan must be passed to the
FastMCP(...)constructor; settingsettings.lifespanafterwards has no effect
License
MIT
Metadata
Release files for iterm2-mcp-zanlan 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| iterm2_mcp_zanlan-0.2.2.tar.gz | 16.8 kB | Without provenance | Details for iterm2_mcp_zanlan-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iterm2_mcp_zanlan-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for iterm2_mcp_zanlan-0.2.2-py3-none-any.whl |
Total release size: 30.3 kB
Release files / iterm2_mcp_zanlan-0.2.2.tar.gz
| Download URL | iterm2_mcp_zanlan-0.2.2.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49181d985013d3cce76344be6197cb46e7f938b908a0c824884b0205f2d24e59
|
|
BLAKE2b-256 checksum How to use checksums |
af2e131132f37ea59b1c4d8114f9386d42bd24f4865920689f31c23845cae067
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / iterm2_mcp_zanlan-0.2.2-py3-none-any.whl
| Download URL | iterm2_mcp_zanlan-0.2.2-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2b9401ab9c16ba9ac268fab68312c35ee30301b68c437a47370a06ad4c37880e
|
|
BLAKE2b-256 checksum How to use checksums |
0efdfdacb771de8c1db72a1ba6b271fe558fedf57f5b1b87b416d87db59c9c42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for iterm2-mcp-zanlan 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.