Logo Terminal MCP

Terminal MCP

Cộng đồng
elleryfamilia

A terminal emulator exposed via MCP for AI assistants

Nhà phát hànhelleryfamilia
Kho mãterminal-mcp
Ngôn ngữTypeScript
Bản fork
15
Sao
139
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépMIT
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    Terminal MCP cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    139 sao và 15 bản fork từ kho mã được liên kết.

Install

bash
npm install -g @ellery/terminal-mcp

Or via install script:

bash
curl -fsSL https://raw.githubusercontent.com/elleryfamilia/terminal-mcp/main/install.sh | bash

Configure your AI tools

Wire terminal-mcp into the MCP config of every AI tool installed on your machine in one shot:

bash
terminal-mcp setup                      # detect & install for all detected tools
terminal-mcp setup --dry-run            # preview without writing
terminal-mcp setup --client claude-code,gemini   # specific tools only
terminal-mcp setup --uninstall          # remove the entry from each tool

Supported clients (each gets the right schema for its config format):

ClientConfig fileFormat
OpenAI Codex CLI~/.codex/config.tomlTOML
GitHub Copilot CLI~/.copilot/mcp-config.jsonJSON
Gemini CLI~/.gemini/settings.jsonJSON
OpenCode~/.config/opencode/opencode.jsonJSON
Claude Code~/.claude.jsonJSON
Claude Desktop~/Library/Application Support/Claude/claude_desktop_config.json (macOS) / %APPDATA%\Claude\claude_desktop_config.json (Windows)JSON

A .bak of any pre-existing config is written next to the original on first install. The terminal-mcp entry is added without disturbing other servers or unrelated keys; running setup again is a no-op.

Upgrading

bash
npm install -g @ellery/terminal-mcp@latest

Interactive mode will print a banner on next launch when a newer release is available — terminal-mcp checks the npm registry once per day and caches the result. Headless and MCP-client modes never check or print anything (so MCP stdio stays clean). To opt out entirely, set NO_UPDATE_NOTIFIER=1 or pass --no-update-notifier.

Features

  • Full Terminal Emulation: Uses xterm.js headless for accurate VT100/ANSI emulation
  • Cross-Platform PTY: Native pseudo-terminal support via node-pty (macOS, Linux, Windows)
  • MCP Protocol: Implements Model Context Protocol for AI assistant integration
  • Session Recording: Record terminal sessions to asciicast format for playback with asciinema
  • Simple API: Nine tools covering input, observation, recording, and session lifecycle
  • Headless Mode: Run as a standalone MCP server without a TTY — ideal for CI, containers, and non-interactive environments
  • Multi-Session: Run multiple isolated terminal sessions in one process, addressed by sessionId
  • Sandbox Mode: Optional security restrictions for filesystem and network access

Building from Source

bash
npm install
npm run build

Usage

MCP Configuration

Add to your MCP client settings:

json
{
  "mcpServers": {
    "terminal": {
      "command": "terminal-mcp"
    }
  }
}

With custom options:

json
{
  "mcpServers": {
    "terminal": {
      "command": "terminal-mcp",
      "args": ["--cols", "100", "--rows", "30", "--shell", "/bin/zsh"]
    }
  }
}

Command-Line Options

terminal-mcp [OPTIONS]

Options:
  --cols <number>        Terminal width in columns (default: 120)
  --rows <number>        Terminal height in rows (default: 40)
  --shell <path>         Shell to use (default: $SHELL or bash)
  --headless             Run in headless mode (embedded PTY + MCP over stdio, no TTY needed)
  --sandbox              Enable sandbox mode (restricts filesystem/network)
  --sandbox-config <path> Load sandbox config from JSON file
  --version, -v          Show version number
  --help, -h             Show help message

Recording Options:
  --record [mode]     Enable recording (default mode: always)
                      Modes: always, on-failure, off
  --record-dir <dir>  Recording output directory
                      (default: ~/.local/state/terminal-mcp/recordings)
  --idle-time-limit <sec>   Max idle time between events (default: 2s)
  --max-duration <sec>      Max recording duration (default: 3600s)
  --inactivity-timeout <sec>  Stop after no output (default: 600s)

Multi-Session Options:
  --max-sessions <n>           Max concurrent sessions (default: 5)
  --session-idle-timeout <sec> Idle non-default sessions are auto-destroyed
                               after this period (default: 600s)

Headless Mode

By default, Terminal MCP uses a dual-process architecture: you run terminal-mcp in an interactive terminal (which creates a Unix socket), then your MCP client spawns a second instance that connects to that socket. This requires a TTY.

Headless mode (--headless) eliminates this requirement by spawning an embedded PTY internally and serving MCP directly over stdio in a single process. No interactive terminal session, 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 to run alongside
  • Remote/cloud environments — MCP servers spawned by automation
  • Simplified setup — single process, no socket coordination needed

Configuration

json
{
  "mcpServers": {
    "terminal": {
      "command": "terminal-mcp",
      "args": ["--headless", "--cols", "120", "--rows", "40"]
    }
  }
}

How it works

MCP Client (Claude Code, etc.)
    │ STDIO (JSON-RPC)
    ▼
terminal-mcp --headless
    ├── MCP Server (stdio transport)
    ├── Terminal Emulator (@xterm/headless)
    └── Embedded PTY (node-pty)
            │
            ▼
        Shell Process (bash, zsh, etc.)

In headless mode, the terminal session is initialized eagerly at startup, so all tools (type, sendKey, getContent, takeScreenshot, startRecording, stopRecording, createSession, listSessions, destroySession) are available immediately.

MCP Tools

All input/output tools (type, sendKey, getContent, takeScreenshot) accept an optional sessionId argument. Omit it to target the default session; pass the ID returned by createSession to drive a specific session.

type

Send text input to the terminal.

json
{
  "name": "type",
  "arguments": {
    "text": "echo hello"
  }
}

sendKey

Send special keys or key combinations.

json
{
  "name": "sendKey",
  "arguments": {
    "key": "Enter"
  }
}

Supported keys:

  • Basic: Enter, Tab, Escape, Backspace, Delete
  • Arrow: ArrowUp, ArrowDown, ArrowLeft, ArrowRight
  • Navigation: Home, End, PageUp, PageDown, Insert
  • Function: F1 through F12
  • Control: Ctrl+A through Ctrl+Z, Ctrl+C, Ctrl+D, etc.

getContent

Get the terminal buffer as plain text.

json
{
  "name": "getContent",
  "arguments": {
    "visibleOnly": false
  }
}

takeScreenshot

Capture the terminal state. Supports three output formats:

FormatDescription
text (default)JSON with plain text content, cursor position, and dimensions
ansiJSON with ANSI color escape codes preserved in the content field
pngColor screenshot as a PNG image (requires @resvg/resvg-js)
json
{
  "name": "takeScreenshot",
  "arguments": { "format": "text" }
}

The ansi format reconstructs SGR escape sequences from the terminal's cell buffer, preserving 16-color, 256-color, and 24-bit truecolor attributes along with bold, dim, italic, and underline styles.

The png format returns an MCP image content block with base64-encoded PNG data, rendered with the One Dark color theme and macOS-style window chrome.

startRecording

Start recording terminal output to an asciicast v2 file.

json
{
  "name": "startRecording",
  "arguments": {
    "mode": "always",
    "idleTimeLimit": 2,
    "maxDuration": 3600
  }
}

Options:

  • mode: always (save all) or on-failure (save only on non-zero exit)
  • outputDir: Custom output directory
  • idleTimeLimit: Max seconds between events (caps pauses in playback)
  • maxDuration: Auto-stop after N seconds
  • inactivityTimeout: Auto-stop after N seconds of no output

stopRecording

Stop a recording and finalize the asciicast file.

json
{
  "name": "stopRecording",
  "arguments": {
    "recordingId": "abc123"
  }
}

createSession

Create a new terminal session and return its metadata. Use the returned sessionId to target this session in subsequent tool calls.

json
{
  "name": "createSession",
  "arguments": {
    "shell": "/bin/zsh",
    "cols": 100,
    "rows": 30
  }
}

All arguments are optional. Returns:

json
{
  "sessionId": "3029d",
  "shell": "/bin/zsh",
  "cols": 100,
  "rows": 30,
  "createdAt": "2026-04-25T12:58:01.072Z",
  "lastActivityAt": "2026-04-25T12:58:01.072Z",
  "isDefault": false
}

listSessions

List all active sessions including the default. Reports configured limits.

json
{ "name": "listSessions", "arguments": {} }

destroySession

Destroy a session by ID. The default session cannot be destroyed.

json
{
  "name": "destroySession",
  "arguments": { "sessionId": "3029d" }
}

Multi-Session

By default, every tool call without a sessionId targets a single auto-created default session — the same behavior the project has always had. Pass sessionId to drive multiple isolated PTYs from one process.

  • The default session is created on first use and cannot be destroyed.
  • Additional sessions are created by createSession and tracked until they're destroyed or idle-evicted (--session-idle-timeout, default 600s).
  • Concurrent sessions are capped at --max-sessions (default 5).
  • An active recording captures output from all sessions in the process.

Typical use case: an AI agent driving a long-running build in one session while running diagnostics in another, without command interleaving.

Sandbox Mode

Run the terminal with restricted filesystem and network access:

bash
# Interactive permission configuration
terminal-mcp --sandbox

# With a config file
terminal-mcp --sandbox --sandbox-config ~/.terminal-mcp-sandbox.json

The interactive mode shows a TUI dialog to configure permissions:

Example config file:

json
{
  "filesystem": {
    "readWrite": [".", "/tmp", "~/.cache"],
    "readOnly": ["~"],
    "blocked": ["~/.ssh", "~/.aws", "~/.gnupg"]
  },
  "network": {
    "mode": "all"
  }
}

Platform support:

  • macOS: Full support via sandbox-exec (Seatbelt)
  • Linux: Full support via bubblewrap (requires bwrap installed)
  • Windows: Graceful fallback (runs without sandbox)

See Sandbox Documentation for detailed configuration options.

Recording

Terminal MCP can record sessions to asciicast v2 format, compatible with asciinema for playback.

Quick Start

bash
# Start with recording enabled
terminal-mcp --record

# Run your commands, then exit
exit

# Output shows the saved file path:
# Recordings saved:
#   ~/.local/state/terminal-mcp/recordings/20240115_143022.cast
#
# Play with: asciinema play <file>

Playback

Install asciinema to play back recordings:

bash
# macOS
brew install asciinema

# Linux/pip
pip install asciinema

# Play a recording
asciinema play ~/.local/state/terminal-mcp/recordings/20240115_143022.cast

# Play at 2x speed
asciinema play -s 2 recording.cast

Recording Modes

  • always (default): Save every recording
  • on-failure: Only save if the session exits with a non-zero code (useful for debugging failed CI runs)
bash
# Only save recordings when something fails
terminal-mcp --record=on-failure

MCP Tool Recording

AI assistants can also control recording programmatically via MCP tools:

  1. Call startRecording to begin capturing
  2. Perform terminal operations
  3. Call stopRecording to finalize and save

This enables AI-driven workflows like "record this debugging session" or "capture this demo".

Architecture

Terminal MCP has three operating modes:

ModeFlagStdinDescription
Interactive(default)TTYUser gets a shell; AI connects via Unix socket
Client(default)non-TTYConnects to an interactive session's socket, serves MCP over stdio
Headless--headlessanySelf-contained: embedded PTY + MCP server over stdio

Headless mode (recommended for MCP configs)

MCP Client (Claude Code, etc.)
    │ STDIO (JSON-RPC)
    ▼
terminal-mcp --headless
    ├── MCP SDK (@modelcontextprotocol/sdk)
    ├── Terminal Emulator (@xterm/headless)
    └── Embedded PTY (node-pty)
            │
            ▼
        Shell Process (bash, zsh, etc.)

Interactive + Client mode (two-process)

terminal-mcp (interactive, in your terminal)
    ├── User shell (stdin/stdout)
    └── Unix socket server (/tmp/terminal-mcp.sock)
            ▲
            │ JSON-RPC over socket
            ▼
terminal-mcp (client, spawned by MCP client)
    └── MCP server (stdio transport)

Example Session

bash
# Type a command
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"type","arguments":{"text":"ls -la"}}}

# Send Enter key
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"sendKey","arguments":{"key":"Enter"}}}

# Get the output
{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"getContent","arguments":{}}}

Development

bash
npm run build    # Compile TypeScript
npm run dev      # Run with tsx (development)

Documentation

See the docs folder for detailed documentation:

Requirements

  • Node.js 18.0.0 or later
  • Windows 10 version 1809 or later (for ConPTY support)

License

MIT

Dùng MCP Terminal MCP với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối Terminal MCP, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm Terminal MCP làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của Terminal MCP.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "terminal-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của Terminal MCP, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của Terminal MCP.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng Terminal MCP giúp tôi làm việc này không?
Terminal MCP
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng Terminal MCP.

Câu hỏi thường gặp

Máy chủ MCP Terminal MCP dùng để làm gì?

Terminal MCP là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP Terminal MCP với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng Terminal MCP với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP Terminal MCP với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối Terminal MCP, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP Terminal MCP với TypingMind?

Terminal MCP hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP Terminal MCP cung cấp những công cụ nào trong TypingMind?

Terminal MCP cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP Terminal MCP không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu Terminal MCP yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇