iTerm2 MCP Server
Enables AI assistants to read, write, and control iTerm2 terminal panes, including listing panes, reading contents, sending commands, and splitting panes.
README
iTerm2 MCP Server
An MCP (Model Context Protocol) server that allows AI assistants like Claude to read the contents of iTerm2 terminal panes. This enables AI assistants to see what's happening in your other terminal windows and tabs.
Features
- List all panes: See all open iTerm2 windows, tabs, and panes with their working directories and running jobs
- Read pane contents: Get the screen buffer text from any pane
- Current pane detection: Automatically detects which pane the server is running in
- Status checking: Verify that iTerm2 Python API is properly configured
Prerequisites
- macOS with iTerm2 installed
- Node.js >= 18.0.0
- Python 3 with the
iterm2package:pip install iterm2 - iTerm2 Python API enabled:
- Open iTerm2 > Settings (Cmd+,)
- Go to General > Magic
- Check Enable Python API
- Restart iTerm2
Installation
Using npx (recommended)
npx iterm2-mcp-server
Global installation
npm install -g iterm2-mcp-server
iterm2-mcp-server
Configuration
Claude Desktop
Add to your Claude Desktop configuration file (~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"iterm2": {
"command": "npx",
"args": ["iterm2-mcp-server"]
}
}
}
Claude Code
Add the MCP server using the CLI:
claude mcp add --scope user iterm2 -- npx github:sumchattering/iterm2-mcp-server
This installs it globally so it's available in all your projects. You can verify it's working:
claude mcp list
You should see: iterm2: npx github:sumchattering/iterm2-mcp-server - ✓ Connected
Available Tools
iterm2_list_panes
List all iTerm2 windows, tabs, and panes with their shorthand IDs, names, working directories, and running jobs.
iterm2_read_pane
Read the screen buffer contents of a specific pane.
Parameters:
session_id(required): The pane ID using shorthand liket3p1(tab 3, pane 1) orw1t3p1
iterm2_send_text
Send text or commands to an iTerm2 pane as if typed by the user.
Parameters:
session_id(required): The pane ID (e.g.,t3p1)text(required): The text or command to sendnewline(optional, default: true): Whether to press Enter after the text
iterm2_send_control_character
Send control characters like Ctrl+C, Ctrl+D, Ctrl+Z, or Ctrl+L to an iTerm2 pane.
Parameters:
session_id(required): The pane ID (e.g.,t3p1)control(required):c(Ctrl+C),d(Ctrl+D),z(Ctrl+Z),l(Ctrl+L)
iterm2_split_pane
Split an iTerm2 pane horizontally or vertically, creating a new pane.
Parameters:
session_id(required): The pane ID to split (e.g.,t3p1)vertical(optional, default: false): If true, split vertically (side by side)
iterm2_current_pane
Get information about the current iTerm2 pane where Claude Code is running.
iterm2_status
Check if iTerm2 Python API is properly configured and ready to use.
iterm2_enable_api
Enable the iTerm2 Python API in preferences. Note: iTerm2 must be restarted after enabling.
Pane IDs
Panes are identified using shorthand IDs that match iTerm2's UI (1-based indexing):
t3p1- Tab 3, Pane 1 (assumes Window 1)t3p2- Tab 3, Pane 2w1t3p1- Window 1, Tab 3, Pane 1 (explicit window)w2t1p1- Window 2, Tab 1, Pane 1
Use iterm2_list_panes to see all available panes and their IDs.
Using with Claude Code
Once installed, Claude Code can see and interact with your terminal panes. Here are effective ways to use it:
Asking about panes
- "What's in tab 3?" - Claude will read the contents of tab 3
- "What's running in the pane next to you?" - Claude can identify adjacent panes
- "Show me all my terminal tabs" - Lists all panes with their shorthand IDs
- "What's the output of my server?" - Claude can find and read server output
Running commands in other panes
- "Run
npm testin t3p1" - Sends command to specific pane - "Stop the process in tab 4" - Sends Ctrl+C to interrupt
- "Clear the terminal in t2p1" - Sends Ctrl+L
Working with multiple panes
- "Split my terminal and run the dev server in the new pane"
- "What errors are showing in my other terminals?"
- "Compare the output in tab 2 and tab 3"
Tips for effective queries
- Be specific about location: "tab 3" or "t3p1" is clearer than "the other terminal"
- Reference the pane list: Ask Claude to list panes first if you're unsure of the layout
- Use relative references: "the pane next to you" or "the tab on the left" work too
Troubleshooting
"Connection failed" error
- Make sure iTerm2 is running
- Verify Python API is enabled: iTerm2 > Settings > General > Magic > Enable Python API
- Restart iTerm2 after enabling the API (Cmd+Q, then reopen)
"iterm2 module not installed"
Install the Python package:
pip install iterm2
"Not running in an iTerm2 session"
The MCP server needs to be started from within an iTerm2 terminal for current pane detection to work.
How It Works
This MCP server uses the iTerm2 Python API to communicate with iTerm2 via a WebSocket connection. The server:
- Receives tool calls from the AI assistant via MCP
- Executes Python scripts that use the
iterm2library - Returns formatted results back to the assistant
Development
# Clone the repository
git clone https://github.com/sumchattering/iterm2-mcp-server.git
cd iterm2-mcp-server
# Install dependencies
npm install
# Build
npm run build
# Run locally
npm start
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Future Improvements
The following features are being considered for future releases. Feedback welcome!
- Create tab/window:
iterm2_create_tabanditerm2_create_windowtools - Close pane:
iterm2_close_panetool to close panes programmatically - Focus pane:
iterm2_focus_paneto bring a specific pane to the foreground - Wait for prompt:
iterm2_wait_for_promptto wait until a command finishes executing - Set pane title: Ability to set custom titles for panes
- Performance optimization: Persistent Python process instead of spawning per request
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。