AC

andresthor/cmd-line-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

10 stars 4 forks 质量 80 趋势 16MIT

一个允许AI助手安全运行终端命令的MCP服务器. 命令被分类(读取/写取/系统),目录被白列,危险模式被自动被屏蔽.

概览

一个允许AI助手安全运行终端命令的MCP服务器. 命令被分类(读取/写取/系统),目录被白列,危险模式被自动被屏蔽. 添加到~/图书馆/应用程序支持/Claude/claude desktop config.json: 需要 session id:假是克洛德桌面的默认并阻止批准循环,但它是自动批准书写和系统命令;设置允许 user 确认:假是需要明确批准代替. 该模型可以通过批准 command type自行请求批准,所以您的客户端的工具确认是真正的门. auto approve directories in desktop mode:完全关闭目录封装。 见文件/SECURITY.md。 命令执行前要经过验证程序: 1. 拒绝已配置的危险模式( 写入系统路径、 tar -- to- command等) 2. ——命令由严格的Lexer解析;不支持的 shell语法被否定 3.

概述(AI 翻译)

一个允许AI助手安全运行终端命令的MCP服务器. 命令被分类(读取/写取/系统),目录被白列,危险模式被自动被屏蔽.

– – . . .

□ 快开始

运行服务器 :

– – . . .

□ Claude 桌面设置

添加到 [[T0] :

保存后重新启动 Claude 桌面 。

[呻

require_session_id: false是克洛德桌面中的默认并阻止批准循环,但它是自动批准书写和系统命令的;设置[T2],需要明确批准取而代之. 模型本身可以通过approve_command_type请求批准,所以你的客户端的工具确认是真正的门. [[T4] 完全关闭目录封装. 见文件/SECURITY.md。

– – . . .

如何运作

命令执行前要经过验证程序:

  1. ** 方法匹配** — 拒绝所配置的危险模式(写入系统路径,[[T5]等)
  2. Parsing — 命令由严格的语法解析; 不支持的 shell语法被拒绝 3个.

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

Command-Line MCP Server

An MCP server that lets AI assistants run terminal commands safely. Commands are categorized (read/write/system), directories are whitelisted, and dangerous patterns are blocked automatically.


Quick Start

pip install cmd-line-mcp

# Or from source
git clone https://github.com/andresthor/cmd-line-mcp.git
cd cmd-line-mcp
pip install -e .

Run the server:

cmd-line-mcp                        # default config
cmd-line-mcp --config config.json   # custom config

Claude Desktop Setup

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "cmd-line": {
      "command": "/path/to/venv/bin/cmd-line-mcp",
      "args": ["--config", "/path/to/config.json"],
      "env": {
        "CMD_LINE_MCP_SECURITY_REQUIRE_SESSION_ID": "false"
      }
    }
  }
}

Restart Claude Desktop after saving.

[!WARNING] require_session_id: false is the default and prevents approval loops in Claude Desktop, but it auto-approves write and system commands; set allow_user_confirmation: false to require explicit approval instead. The model can request that approval itself through approve_command_type, so your client’s tool confirmation is the real gate. auto_approve_directories_in_desktop_mode: true turns off directory confinement entirely. See docs/SECURITY.md.


How It Works

Commands go through a validation pipeline before execution:

  1. Pattern matching — rejects configured dangerous patterns (writes to system paths, tar --to-command, etc.)
  2. Parsing — the command is parsed by a strict lexer; unsupported shell syntax is rejected
  3. Command classification — each command must be in the read, write or system list, and not blocked
  4. Path check — every path, glob match and redirect target in every command must be whitelisted or session-approved
  5. Approval check — write/system commands require approval

Pipes, ;, && and || are supported, and each command is validated independently. Background &, variables ($NAME), command substitution and subshells are rejected. The server runs its own fully quoted rendering of the validated command, never the raw input.

What’s Allowed

Category Commands Approval
Read ls, cat, grep, head, tail, wc, du, … Auto
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →

配置

{ "mcpServers": { "cmd-line": { "command": "/path/to/venv/bin/cmd-line-mcp", "args": ["--config", "/path/to/config.json"], "env": { "CMD_LINE_MCP_SECURITY_REQUIRE_SESSION_ID": "false" } } } }