terminal-mcp
問題点
すべての AI コーディングツールが同じ壁にぶつかります。本物のターミナルにアクセスできないのです。
Claude Code の Bash ツール、GitHub Copilot、Codex はすべて、隔離されたサブプロセスでコマンドを実行します。コマンドごとに新しく起動され、状態は引き継がれません。つまり、次のようなことができません。
SSH セッション — リモートサーバーに接続して複数のコマンドを実行できない
REPL — Python、Node、Ruby のインタプリタを対話的に使えない
データベース CLI — psql、mysql、redis-cli の接続を維持できない
TUI アプリ — htop、vim、fzf を矢印キーで操作できない
長時間実行プロセス — ビルドの監視、ログのウォッチ、開発サーバーの実行ができない
Related MCP server: Interactive Terminal MCP Server
解決策
terminal-mcp は AI エージェントに本物のターミナルを提供します。永続的な PTY セッションがツール呼び出しをまたいで維持されます。コマンド送信、出力読み取り、キー入力、TUI の操作 — まるで人間がターミナルを使っているかのように。
uvx terminal-mcp1 つのコマンド。Claude Code、Claude Desktop、VS Code、Cursor、Windsurf で動作します。
クイックスタート
1. インストール(30秒)
# No install needed - run directly
uvx terminal-mcp
# Or install globally
pip install terminal-mcp2. AI クライアントに接続
~/.claude.json またはプロジェクトの .mcp.json に追加:
{
"mcpServers": {
"terminal": {
"command": "uvx",
"args": ["terminal-mcp"]
}
}
}claude_desktop_config.json に追加:
{
"mcpServers": {
"terminal": {
"command": "uvx",
"args": ["terminal-mcp"]
}
}
}上のワンクリックインストールバッジをクリックするか、.vscode/mcp.json に追加:
{
"servers": {
"terminal-mcp": {
"command": "uvx",
"args": ["terminal-mcp"]
}
}
}~/.codeium/windsurf/mcp_config.json に追加:
{
"mcpServers": {
"terminal": {
"command": "uvx",
"args": ["terminal-mcp"]
}
}
}3. 確認
session_exec exec="echo hello from terminal-mcp"これで何ができるのか?
リモートサーバーに SSH 接続
session_create command="ssh user@prod-server.com" label="prod"
session_interact session_id="a1b2c3d4" input="df -h" wait_for="\$"
session_interact session_id="a1b2c3d4" input="docker ps" wait_for="\$"
session_close session_id="a1b2c3d4"対話型 REPL の実行
session_create command="python3" label="python"
session_interact session_id="e5f6g7h8" input="import pandas as pd" wait_for=">>>"
session_interact session_id="e5f6g7h8" input="df = pd.read_csv('data.csv')" wait_for=">>>"
session_interact session_id="e5f6g7h8" input="df.describe()" wait_for=">>>"
session_close session_id="e5f6g7h8"データベースのクエリ
session_create command="psql -U admin mydb" label="db"
session_interact session_id="x1y2z3w4" input="SELECT count(*) FROM users;" wait_for="row"
session_interact session_id="x1y2z3w4" input="\dt" wait_for="#"
session_close session_id="x1y2z3w4"TUI アプリの操作
session_create command="htop" label="monitor"
session_read session_id="a1b2c3d4"
# Auto-detects TUI, returns screen snapshot
session_send session_id="a1b2c3d4" key="F6"
session_read session_id="a1b2c3d4" mode="diff"
# Returns only changed lines - saves tokens
session_send session_id="a1b2c3d4" key="F10"
session_close session_id="a1b2c3d4"長時間実行ビルドの監視
session_create command="bash" label="build"
session_send session_id="a1b2c3d4" input="npm run build"
session_wait_for session_id="a1b2c3d4" pattern="Build complete|ERROR" timeout=120単発コマンドの実行
session_exec exec="git log --oneline -10"
session_exec exec="docker compose ps" timeout=10機能一覧
機能 | 説明 |
永続セッション | ツール呼び出しをまたいで維持される本物の PTY セッション |
送信+読み取りを 1 回の呼び出しで |
|
パターンベースの読み取り |
|
自動 TUI 検出 | htop、vim などを検出し、自動で画面スナップショットモードに切り替え |
出力差分モード | 変更された画面行のみを返し、トークンを最小化 |
特殊キー | 矢印キー、Tab、F1-F12、Home/End、Page Up/Down |
制御文字 | Ctrl-C、Ctrl-D、Ctrl-Z、Ctrl-L、telnet エスケープ |
危険コマンドゲート |
|
OSC 133 シェル統合 | コマンド境界と終了コードを自動検出 |
スマート切り詰め | 4 つの戦略でコンテキストオーバーフローを防止 |
秘密入力 | パスワードをログに残さず送信 |
動的リサイズ | SIGWINCH でターミナルをその場でリサイズ |
アイドルクリーンアップ | アイドルセッションを自動で閉じる |
クロスプラットフォーム | Linux、macOS、Windows をサポート |
ツールリファレンス
terminal-mcp は 9 個の MCP ツール を公開しています。詳細は docs/tools.md を参照。
ツール | 目的 |
永続ターミナルセッションを起動 | |
テキスト、キー、制御文字を送信 | |
出力を読み取り(ストリーム、スナップショット、自動、差分モード) | |
送信+読み取りを 1 回の呼び出しで | |
出力に正規表現パターンが現れるのを待つ | |
単発コマンドの実行 | |
セッションを正常に閉じる | |
ターミナルの大きさを変更 | |
アクティブなセッションを一覧表示 |
アーキテクチャ
flowchart LR
Client[AI Client] -->|MCP JSON-RPC| Server[terminal-mcp]
Server --> SM[Session Manager]
SM --> S1[PTY 1: bash]
SM --> S2[PTY 2: python3]
SM --> S3[PTY 3: ssh user@host]
S1 & S2 & S3 -.->|PTY output| Reader[Reader Thread]
Reader -.->|buffer| Server各セッションは pexpect.spawn(Windows では PopenSpawn)を介した本物の PTY によってバックアップされています。アーキテクチャの詳細は docs/architecture.md を参照。
設定
すべての設定は TERMINAL_MCP_* 環境変数で設定可能。完全なリファレンスは docs/configuration.md を参照。
設定 | 環境変数 | デフォルト |
最大セッション数 |
|
|
アイドルタイムアウト |
|
|
セーフティゲート |
|
|
バッファ上限 |
|
|
切り詰め方法 |
|
|
カスタム設定の例:
{
"mcpServers": {
"terminal": {
"command": "uvx",
"args": ["terminal-mcp"],
"env": {
"TERMINAL_MCP_MAX_SESSIONS": "20",
"TERMINAL_MCP_IDLE_TIMEOUT": "3600",
"TERMINAL_MCP_TRUNCATION_MODE": "head_tail"
}
}
}
}ドキュメント
ドキュメント | 説明 |
9 個の MCP ツールの完全な API | |
terminal-mcp の内部動作 | |
すべての設定と環境変数 | |
危険コマンドの検出とセーフティゲート | |
実用的なレシピとパターン | |
バージョン履歴とリリースノート | |
コントリビューション方法 |
サポート対象クライアント
クライアント | 状態 | インストール方法 |
Claude Code (CLI) | 対応済み |
|
Claude Desktop | 対応済み | |
VS Code (Copilot Chat) | 対応済み | ワンクリックインストール または |
Cursor | 対応済み | ワンクリックインストール または設定 |
Windsurf | 対応済み |
|
テストの実行
pip install -e ".[dev]"
pytest tests/ -vコントリビュート
コントリビューション歓迎!ガイドラインは docs/contributing.md を参照。
ライセンス
Available Tools
9 toolssession_closeA
Terminate a session gracefully. Sends EOF, then SIGHUP, then SIGKILL.
Inputs: session_id (required).
session_createA
Spawn a persistent PTY terminal session. Returns a session_id used by all other session_* tools. Supports interactive shells, SSH, REPLs, and database CLIs. Snapshot mode is always available.
Inputs: command (required), cols, rows, label, +3 more.
session_execB
Execute a command in a temporary session and return the output. The session is automatically cleaned up after execution.
Inputs: exec (required), cols, rows, command, +2 more.
session_interactA
Send input and read output in a single call. Combines session_send + session_read to halve round trips. Optionally waits for a regex pattern in the output.
Inputs: session_id (required), key, input, timeout, +8 more.
session_listA
List all active terminal sessions with their status and idle time.
Inputs: no named parameters.
session_readA
Read output from a session. Mode 'auto' (default) auto-detects TUI applications and switches between stream and snapshot. 'diff' returns only changed screen lines.
Inputs: session_id (required), mode, timeout, scrollback, +2 more.
session_resizeA
Resize the terminal window of an active session. Sends SIGWINCH to the process.
Inputs: cols (required), rows (required), session_id (required).
session_sendA
Send input text, a control character, or a special key to an active session. Use control_char for signals (e.g. 'c' for Ctrl-C). Use key for special keys (e.g. 'up', 'tab', 'f1').
Inputs: session_id (required), key, input, password, +3 more.
session_wait_forA
Read output from a session until a regex pattern matches or timeout expires. Use this instead of session_read when you know what output to expect.
Inputs: pattern (required), session_id (required), timeout, strip_ansi, +1 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 9 tools
Each tool has a clear, distinct purpose: create/list/resize/send/read/wait/interact/exec/close. Overlaps like session_read vs session_wait_for are well-differentiated by their descriptions (reading vs waiting for a pattern). No two tools could be easily confused.
All tools follow a consistent 'session_verb' pattern using snake_case. Verbs are descriptive (create, list, resize, send, read, wait_for, interact, exec, close). No mixing of styles or vague names.
Nine tools is an ideal size for a terminal session manager. Each tool serves a necessary operation without being too few or too many, covering creation, manipulation, reading, and destruction of sessions.
The tool set provides a full lifecycle for interactive terminal sessions: creation (session_create), querying (session_list), resizing, input sending (session_send), output reading (session_read, session_wait_for), combined interaction (session_interact), one-shot execution (session_exec), and cleanup (session_close). No obvious gaps.
Maintenance
Related MCP Connectors
Persistent cloud workspaces for AI agents: run commands, edit files, use git and a browser.
Persistent Linux computers for AI agents: desktop, signed-in browser, vault, apps and shell.
Cloud desktops for AI agents: create a Linux computer, see its screen, click, type and run tasks.
Operate Linux, macOS and Windows from your LLM. Every action runs through an auditable allowlist.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides stateful, interactive terminal access for LLMs to spawn and maintain persistent processes like SSH sessions, debuggers, and REPLs with continuous input/output interaction across commands.8-
- AlicenseNot gradedqualityDmaintenanceProvides AI agents with fully interactive terminal sessions, including TUI support, keyboard control, and screen capture across Windows, Linux, and Mac.MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to have persistent, fully interactive SSH sessions into remote hosts, behaving like a local terminal.9 npm2MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to securely execute terminal commands with persistent sessions, async jobs, and mission control, while providing a live dashboard for human oversight.4Apache 2.0