Skip to main content
Glama

Command-Line MCP Server

by andresthor

命令行 MCP 服务器

安全的模型控制协议 (MCP) 服务器,允许 AI 助手以受控的目录访问和命令权限执行终端命令。

概述

命令行 MCP 在 AI 助手和终端之间提供了一个安全层。它实现了双重安全模型:

  1. 命令权限:命令分为读取(安全)、写入(更改数据)或系统(影响系统状态),具有不同的批准要求
  2. 目录权限:命令只能访问明确列入白名单的目录或会话期间批准的目录

AI 助手使用标准化 MCP 工具与此服务器交互,从而实现安全的终端命令执行,同时阻止访问敏感文件或执行危险操作。您可以根据需要将安全级别从严格限制配置为更宽松。

主要特点

安全可用性一体化
目录白名单命令分类(读/写/系统)Claude 桌面兼容性
命令过滤持久会话权限标准MCP协议
模式匹配命令链(管道等)自动批准选项
危险的命令阻塞直观的审批工作流程多种配置方法

支持的命令(开箱即用)

读取命令

  • lspwdcatlessheadtailgrepfindwhichdudffilesort等。

写入命令

  • cpmvrmmkdirrmdirtouchchmodchown等。

系统命令

  • pstophtopwhonetstatifconfigping等。

安全架构

该系统实施多层安全方法:

┌───────────────────────────────────────────────────────────────┐ │ COMMAND-LINE MCP SERVER │ ├──────────────────┬────────────────────────┬───────────────────┤ │ COMMAND SECURITY │ DIRECTORY SECURITY │ SESSION SECURITY │ ├──────────────────┼────────────────────────┼───────────────────┤ │ ✓ Read commands │ ✓ Directory whitelist │ ✓ Session IDs │ │ ✓ Write commands │ ✓ Runtime approvals │ ✓ Persistent │ │ ✓ System commands│ ✓ Path validation │ permissions │ │ ✓ Blocked list │ ✓ Home dir expansion │ ✓ Auto timeouts │ │ ✓ Pattern filters│ ✓ Subdirectory check │ ✓ Desktop mode │ └──────────────────┴────────────────────────┴───────────────────┘

所有安全功能都可以根据您的威胁模型和便利性要求从限制性配置为许可性。

快速入门

# Install git clone https://github.com/yourusername/cmd-line-mcp.git cd cmd-line-mcp python -m venv venv source venv/bin/activate pip install -e . cp config.json.example config.json # Run cmd-line-mcp # With default config cmd-line-mcp --config config.json # With specific config

配置选项

服务器支持四种配置方法,按优先顺序排列:

  1. 内置默认配置(default_config.json)
  2. JSON配置文件(建议定制)
    cmd-line-mcp --config config.json
  3. 环境变量(用于特定覆盖)
    export CMD_LINE_MCP_SECURITY_WHITELISTED_DIRECTORIES="~,/tmp"
  4. .env 文件(用于特定环境的设置)
    cmd-line-mcp --config config.json --env .env

默认配置存储在default_config.json中,并包含在软件包中。您可以复制此文件来创建自己的自定义配置。

核心配置设置
{ "security": { "whitelisted_directories": ["/home", "/tmp", "~"], "auto_approve_directories_in_desktop_mode": false, "require_session_id": false, "allow_command_separators": true }, "commands": { "read": ["ls", "cat", "grep"], "write": ["touch", "mkdir", "rm"], "system": ["ps", "ping"] } }
环境变量格式

环境变量使用可预测的命名模式:

CMD_LINE_MCP_<SECTION>_<SETTING>

例子:

# Security settings export CMD_LINE_MCP_SECURITY_WHITELISTED_DIRECTORIES="/projects,/var/data" export CMD_LINE_MCP_SECURITY_AUTO_APPROVE_DIRECTORIES_IN_DESKTOP_MODE=true # Command additions (these merge with defaults) export CMD_LINE_MCP_COMMANDS_READ="awk,jq,wc"

Claude 桌面集成

设置
  1. 安装Claude 桌面版
  2. ~/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", "CMD_LINE_MCP_SECURITY_AUTO_APPROVE_DIRECTORIES_IN_DESKTOP_MODE": "true" } } } }
推荐的 Claude 桌面设置

为了获得最佳体验,请配置:

  • require_session_id: false - 防止审批循环
  • auto_approve_directories_in_desktop_mode: true - 可选,方便访问
  • 将常用目录添加到白名单中

配置完成后,重新启动Claude for Desktop。

AI助手工具

该服务器为AI助手提供了以下MCP工具:

工具目的需要批准
execute_command运行任意命令类型是的,用于写入/系统命令
execute_read_command运行只读命令仅目录批准
approve_directory授予目录访问权限N/A - 这是一个审批工具
approve_command_type授予命令类别的权限N/A - 这是一个审批工具
list_directories显示授权目录
list_available_commands显示命令类别
get_command_help获取命令使用指南
get_configuration查看当前设置

工具示例

目录管理
# Check available directories dirs = await list_directories(session_id="session123") whitelisted = dirs["whitelisted_directories"] approved = dirs["session_approved_directories"] # Request permission for a directory if "/projects/my-data" not in whitelisted and "/projects/my-data" not in approved: result = await approve_directory( directory="/projects/my-data", session_id="session123" )
命令执行
# Read commands (read permissions enforced) result = await execute_read_command("ls -la ~/Documents") # Any command type (may require command type approval) result = await execute_command( command="mkdir -p ~/Projects/new-folder", session_id="session123" )
获取配置
# Check current settings config = await get_configuration() whitelist = config["directory_whitelisting"]["whitelisted_directories"]

目录安全系统

服务器将命令执行限制在特定目录中,从而防止访问敏感文件。

目录安全模式

系统支持三种安全模式:

模式描述最适合配置
严格的仅允许列入白名单的目录最高安全级别auto_approve_directories_in_desktop_mode: false
赞同非白名单目录需要明确批准交互式使用标准客户端的默认行为
自动批准自动批准 Claude Desktop 的目录方便auto_approve_directories_in_desktop_mode: true

白名单目录配置

"security": { "whitelisted_directories": [ "/home", // System directories "/tmp", "~", // User's home "~/Documents" // Common user directories ], "auto_approve_directories_in_desktop_mode": false // Set to true for convenience }

目录审批流程

  1. 在目录中请求命令
  2. 系统检查:
    • 该目录是否在全局白名单中?→允许
    • 目录是否已在此会话中被批准?→允许
    • 都不是?→请求批准
  3. 批准后,目录将在整个会话期间保持批准状态

路径格式支持

  • 绝对路径: /home/user/documents
  • 主目录: ~ (扩展至用户主目录)
  • 用户子目录: ~/Downloads

Claude 桌面集成

服务器为 Claude Desktop 维护一个持久会话,确保目录批准在请求之间持续存在并防止批准循环。

命令自定义

系统使用命令分类来控制访问:

类别描述示例命令需要批准
安全操作ls,cat,find
数据修改mkdir、rm、touch是的
系统系统操作ps、ping、ifconfig是的
已阻止危险命令sudo、bash、eval总是被拒绝

定制方法

// In config.json { "commands": { "read": ["ls", "cat", "grep", "awk", "jq"], "write": ["mkdir", "touch", "rm"], "system": ["ping", "ifconfig", "kubectl"], "blocked": ["sudo", "bash", "eval"] } }

环境变量方法:

# Add to existing lists, not replace (comma-separated) export CMD_LINE_MCP_COMMANDS_READ="awk,jq" export CMD_LINE_MCP_COMMANDS_BLOCKED="npm,pip"

MCP 服务器将这些附加功能与现有命令合并,让您无需重新创建完整的命令列表即可扩展功能。

命令链

服务器支持三种命令链接方法:

方法象征例子配置设置
管道```lsgrep txt`allow_command_separators: true
顺序;mkdir dir; cd dirallow_command_separators: true
背景&find . -name "*.log" &allow_command_separators: true

链中的所有命令都必须来自受支持的命令列表。安全检查适用于整个链。

快速配置:

"security": { "allow_command_separators": true // Set to false to disable all chaining }

要禁用特定的分隔符,请将它们添加到dangerous_patterns列表中。

执照

麻省理工学院

-
security - not tested
A
license - permissive license
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

允许AI助手通过具有全面安全功能的受控界面安全地执行常见的Unix / macOS终端命令。

  1. 概述
    1. 主要特点
      1. 支持的命令(开箱即用)
        1. 读取命令
        2. 写入命令
        3. 系统命令
      2. 安全架构
        1. 快速入门
          1. 配置选项
          2. Claude 桌面集成
        2. AI助手工具
          1. 工具示例
        3. 目录安全系统
          1. 目录安全模式
          2. 白名单目录配置
          3. 目录审批流程
          4. 路径格式支持
          5. Claude 桌面集成
        4. 命令自定义
          1. 定制方法
          2. 命令链
        5. 执照

          Related MCP Servers

          • A
            security
            A
            license
            A
            quality
            Command line interface with secure execution and customizable security policies
            Last updated -
            2
            134
            Python
            MIT License
            • Apple
          • -
            security
            A
            license
            -
            quality
            A secure server that enables AI applications to execute shell commands in specified directories, supporting multiple shell types (bash, sh, cmd, powershell) with built-in security features like directory isolation and timeout control.
            Last updated -
            10
            Python
            Apache 2.0
            • Linux
            • Apple
          • -
            security
            A
            license
            -
            quality
            An enhanced MCP server that grants AI assistants the ability to execute terminal commands on a user's system with improved security controls, designed for use in controlled environments.
            Last updated -
            Python
            MIT License
            • Apple
          • -
            security
            F
            license
            -
            quality
            Enables AI assistants to securely execute shell commands on local machines through an SSH interface with session management, command execution, and sudo support.
            Last updated -
            Python
            • Linux

          View all related MCP servers

          MCP directory API

          We provide all the information about MCP servers via our MCP API.

          curl -X GET 'https://glama.ai/api/mcp/v1/servers/andresthor/cmd-line-mcp'

          If you have feedback or need assistance with the MCP directory API, please join our Discord server