Purpose
Terminal MCP lets AI (LLM) see and interact with your terminal sessions. It is suitable for two types of scenarios: real-time debugging of CLI and TUI applications, or letting AI autonomously drive terminal-based tools.
Main Capabilities
- Full terminal emulation: precise VT100/ANSI emulation using xterm.js headless.
- Cross-platform PTY: native pseudo-terminal support via node-pty (macOS, Linux, Windows).
- MCP protocol: implements the Model Context Protocol for AI assistant integration.
- Session recording: record sessions in asciicast format, playable with asciinema.
- Simple API: nine tools covering input, observation, recording, and session lifecycle.
- Headless mode: can run as a standalone MCP server without a TTY, suitable for CI, containers, and non-interactive environments.
- Multi-session: run multiple isolated terminal sessions within one process, addressed via sessionId.
- Sandbox mode: optional security restrictions on filesystem and network access.
Usage
Configure AI Tools
terminal-mcp can be connected in one go to the MCP configuration of every AI tool installed on the machine. Supported clients each receive a schema suited to their configuration format. On first installation, a .bak backup is written next to the original file for any existing configuration. Adding the terminal-mcp entry does not interfere with other servers or keys; running setup again is a no-op.
Interactive mode prints a banner on the next launch if an updated version is available—terminal-mcp checks the npm registry once a day and caches the result. Headless and MCP client modes never check or print anything (to keep MCP stdio clean). To opt out entirely, set NO_UPDATE_NOTIFIER=1 or pass --no-update-notifier.
Build from Source
(No specific build commands were provided in the material)
MCP Configuration
Add to your MCP client settings: (No complete configuration example was provided in the material)
Using custom options: (No complete configuration example was provided in the material)
Command-Line Options
(No specificbody option list)
Run Modes
By default, Terminal MCP uses a two-process architecture: you run terminal-mcp in an interactive terminal (creating a Unix socket), and then the MCP client starts a second instance to connect to that socket. This requires a TTY.
Headless mode (--headless) eliminates that requirement by internally starting an embedded PTY and serving MCP directly over stdio in a single process. No interactive terminal session is needed, no socket—just a self-contained MCP server with a built-in terminal.
When to use headless mode:
- CI/CD pipelines—no TTY available
- Docker containers—no interactive shell available to run in parallel
- Remote/cloud environments—MCP servers started by automation
- Simplified setup—single process, no socket coordination
In headless mode, the terminal session is initialized at startup, so all tools (type, sendKey, getContent, takeScreenshot, startRecording, stopRecording, createSession, listSessions, destroySession) are immediately available.
Three run modes:
- Headless mode (recommended for MCP configuration)
- Interactive + client mode (two-process)
- (The material lists three but only clearly describes the first two)
Tools and API
All input/output tools (type, sendKey, getContent, takeScreenshot) accept an optional sessionId parameter. Omitting it targets the default session; passing the ID returned by createSession can drive a specific session.
- type: sends text input to the terminal.
- sendKey: sends special keys or key combinations. Supports:
- Basic keys: Enter, Tab, Escape, Backspace, Delete
- Arrow keys: ArrowUp, ArrowDown, ArrowLeft, ArrowRight
- Navigation keys: Home, End, PageUp, PageDown, Insert
- Function keys: F1 to F12
- Control keys: Ctrl+A to Ctrl+Z, Ctrl+C, Ctrl+D, etc.
- getContent: gets the terminal buffer as plain text.
- takeScreenshot: captures the terminal state, supporting three output formats.
- The ansi format reconstructs SGR escape sequences from the terminal cell buffer, preserving 16-color, 256-color, and 24-bit true color attributes as well as bold, dim, italic, and underline styles.
- The png format returns an MCP image content block with base64-encoded PNG data, rendered using the One Dark color theme and macOS-style window chrome.
- startRecording: starts recording terminal output to an asciicast v2 file. Parameters include mode (always saves everything / on-failure saves only on non-zero exit), outputDir (custom output directory), idleTimeLimit (maximum seconds between events, limiting pauses in playback), maxDuration (automatically stops after N seconds), inactivityTimeout (automatically stops after N seconds with no output).
- stopRecording: stops recording and finalizes the asciicast file.
- createSession: creates a new terminal session and returns its metadata. Use the returned sessionId to target this session in subsequent tool calls. All parameters are optional.
- listSessions: lists all active sessions (including the default session), reporting the configured limits.
- destroySession: destroys a session by ID. The default session cannot be destroyed.
Multiple Sessions
By default, every tool call without a sessionId targets a single automatically created default session—this is the project's consistent behavior. Passing a sessionId allows driving multiple isolated PTYs from a single process.
- The default session is created on first use and cannot be destroyed.
- Additional sessions are created by createSession and tracked until destroyed or evicted when idle (--session-idle-timeout, default 600 seconds).
- The upper limit for concurrent sessions is --max-sessions (default 5).
- Active recording captures the output of all sessions in the process.
- Typical use case: one AI agent in one sessionDrive long-running builds while running diagnostics in another session, without command interleaving.
Sandbox Mode
Run the terminal with restricted filesystem and network access: (complete command examples not provided in the material)
Interactive mode displays a TUI dialog to configure permissions.
Platform support:
- macOS: fully supported via sandbox-exec (Seatbelt)
- Linux: fully supported via bubblewrap (requires bwrap to be installed)
- Windows: graceful degradation (runs without sandbox)
See the Sandbox Documentation for detailed configuration options.
Session Recording
Terminal MCP can record sessions in asciicast v2 format, compatible with asciinema playback. Install asciinema to play back recordings.
Recording modes:
- always (default): save every recording
- on-failure: save only when the session exits with a non-zero code (useful for debugging failed CI runs)
MCP tool recording: AI assistants can also control recording programmatically via MCP tools: call startRecording to begin capture, perform terminal operations, and call stopRecording to finalize and save. This supports AI-driven workflows such as "record this debugging session" or "capture this demo."
Use Cases and Limitations
Use cases: real-time debugging of CLI/TUI, letting AI autonomously operate terminal tools, CI/CD and container environments (headless mode), multi-session parallel tasks.
Known prerequisites: Node.js 18.0.0 or higher; Windows 10 version 1809 or higher (for ConPTY support).
Limitations and notes: the default dual-process mode requires a TTY; on Windows, sandbox mode degrades to running without a sandbox; the default session cannot be destroyed; the default maximum number of concurrent sessions is 5.
Examples and Sessions
(the material mentions Example Session and the docs folder, but does not provide specific content)