Terminal MCP Server

Terminal MCP Server

Enables Claude Desktop or other MCP clients to execute shell commands, read/write files, and list directories on the local machine. Includes basic safety guardrails to block obviously destructive operations.

Category
访问服务器

README

Terminal MCP Server

Gives Claude Desktop (or any MCP client) the ability to run shell commands, read/write files, and list directories on your machine.

⚠️ Read this first

This connects Claude to a real terminal on your computer. Claude will be able to run whatever commands it decides to run, within the safety limits below. Only install this if you're comfortable with that level of access — treat it like handing someone a terminal, not like a sandboxed toy. See SECURITY.md for the full threat model.

Built-in guardrails (not a full security boundary, just a basic net):

  • Refuses a short list of obviously destructive commands (rm -rf /, fork bombs, mkfs, etc.)
  • Anything at or under BASE_DIR (defaults to your home directory) always works with no friction
  • Any path outside BASE_DIR needs a one-time permission grant before it's touched — see Directory permissions below
  • 30-second default timeout per command (configurable per call)

Project structure

terminal-mcp/
├── server.py               # the MCP server (tools: run_command, list_directory, read_file,
│                            #   write_file, get_cwd, grant/revoke/list_directory_permission(s))
├── tests/
│   └── test_server.py       # pytest suite (risky-command regex, path resolution, permissions, tool behavior)
├── pyproject.toml           # deps (mcp[cli]) + dev extras (pytest, ruff) + packaging metadata + ruff config
├── install.sh               # one-shot installer (uv + venv + deps + Claude Desktop config, cross-platform)
├── uninstall.sh             # removes the "terminal" entry from Claude Desktop's config
├── .github/workflows/ci.yml # runs ruff + pytest on push/PR
├── .gitignore
├── LICENSE                  # MIT
├── SECURITY.md              # threat model & guardrail limitations
├── 00_change.md             # AI-assisted change log (what changed, why, by whom)
└── README.md

Quick install (recommended)

From inside this folder:

cd terminal-mcp
./install.sh

The script will:

  1. Detect your OS (macOS / Linux / Windows-git-bash)
  2. Make sure uv is installed (offering to install it for you if it isn't), then create a venv/ here (if it doesn't exist yet) and install dependencies from pyproject.toml
  3. Ask you for the base directory the terminal tool should be scoped to (defaults to your home directory — press Enter to accept)
  4. Auto-detect this folder's absolute path and write the correct command and args into your Claude Desktop config
  5. Back up your existing claude_desktop_config.json before touching it, and merge in the terminal entry (other MCP servers you already have configured are left untouched)

Then just restart Claude Desktop.

To remove it later:

./uninstall.sh

This removes only the terminal entry from the config (backing it up first) — it doesn't touch this repo or the venv.

Manual install

If you'd rather do it by hand:

1. Install dependencies

Requires uv (curl -LsSf https://astral.sh/uv/install.sh | sh):

cd terminal-mcp
uv venv venv
uv pip install --python venv/bin/python .        # Windows: venv\Scripts\python.exe

2. Test it locally (optional but recommended)

The mcp package ships a dev inspector so you can try tools before wiring it into Claude Desktop:

mcp dev server.py

This opens a local web UI where you can call run_command, list_directory, etc. and see the results.

3. Connect it to Claude Desktop

Find your Claude Desktop config file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

Add (or merge in) this entry, using the absolute path to your server.py and to the Python interpreter inside the venv you just created:

{
  "mcpServers": {
    "terminal": {
      "command": "/absolute/path/to/terminal-mcp/venv/bin/python",
      "args": ["/absolute/path/to/terminal-mcp/server.py"],
      "env": {
        "TERMINAL_MCP_BASE_DIR": "/absolute/path/to/wherever/you/want/it/scoped"
      }
    }
  }
}

On Windows, command would point at ...\\terminal-mcp\\venv\\Scripts\\python.exe.

4. Restart Claude Desktop

You should see a 🔌 / tools icon indicating the terminal server is connected, with tools: run_command, list_directory, read_file, write_file, get_cwd, grant_directory_permission, revoke_directory_permission, list_directory_permissions.

Directory permissions

Anything at or under BASE_DIR always works with no friction, same as before. Any path outside BASE_DIR — say you're scoped to a project folder but ask Claude to look at ~/Downloads — now needs a one-time permission grant before the server will touch it. Once granted, it's remembered across restarts (stored in ~/.terminal-mcp/permissions.json by default, or wherever TERMINAL_MCP_PERMISSIONS_FILE points) and never asked again.

When Claude hits a path with no standing permission, it'll ask you to pick a scope:

  • This directory only — just that directory, plus files directly inside it. Subdirectories still need their own grant. Example: allowing /Users/dha/Downloads this way does not also allow /Users/dha/Downloads/dwe.
  • This directory and all subdirectories — the directory plus everything nested beneath it, at any depth. Example: allowing /Users/dha/Downloads this way also allows /Users/dha/Downloads/dwe, /Users/dha/Downloads/dwe/test, etc.

Ask Claude things like:

  • "List what directories are allowed" / "terminal list allowed" → shows every granted path and its scope
  • "Revoke access to ~/Downloads" → removes that entry; the next request there will prompt again

Try it

Ask Claude something like:

  • "List the files in my current project folder"
  • "Run git status in ~/projects/my-app"
  • "Read the contents of config.yaml and summarize it"
  • "Create a file called notes.txt with today's todo list"
  • "Always allow ~/Downloads and its subdirectories"

Development

uv pip install --python venv/bin/python ".[dev]"
ruff check .        # lint
pytest -v           # run tests

CI (.github/workflows/ci.yml) runs both on every push/PR to main across Python 3.10–3.12.

Customizing

  • Scope it tighter: set TERMINAL_MCP_BASE_DIR to a specific project folder instead of your home directory, so everything else requires an explicit permission grant (see Directory permissions).
  • Move the permissions store: set TERMINAL_MCP_PERMISSIONS_FILE to change where granted permissions are persisted (default ~/.terminal-mcp/permissions.json).
  • Add more guardrails: extend RISKY_PATTERNS in server.py for any other commands you never want run automatically.
  • Add more tools: the pattern is @mcp.tool() decorating a function with a docstring — Claude reads the docstring to know when/how to call it. You could add things like git_diff, run_tests, curl, etc. as dedicated tools with tighter guardrails than raw run_command.

Using with Claude Code instead

If you're using Claude Code rather than Claude Desktop, you likely don't need this at all — Claude Code already has built-in terminal access. This server is most useful for Claude Desktop or other MCP clients that don't have a terminal tool of their own.

Change log

See 00_change.md for a running log of AI-assisted changes to this repo — what changed, why, and by which assistant.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选