Mac Shell MCP Server

Integrations

  • Allows execution of macOS terminal commands with built-in security mechanisms including command whitelisting and approval workflows

  • Enables execution of commands through the ZSH shell with security controls for running terminal commands on macOS

Mac Shell MCP 服务器

一个 MCP(模型上下文协议)服务器,用于使用 ZSH shell 执行 macOS 终端命令。该服务器通过内置的白名单和审批机制,提供了一种安全执行 shell 命令的方法。

特征

  • 通过 MCP 执行 macOS 终端命令
  • 具有安全级别的命令白名单:
    • 安全:无需批准即可执行的命令
    • 需要批准:执行前需要明确批准的命令
    • 禁止:明确阻止的命令
  • 预先配置白名单,包含常用安全命令
  • 潜在危险命令的审批工作流程
  • 全面的命令管理工具

安装

# Clone the repository git clone https://github.com/cfdude/mac-shell-mcp.git cd mac-shell-mcp # Install dependencies npm install # Build the project npm run build

用法

启动服务器

npm start

或者直接:

node build/index.js

在 Roo Code 和 Claude Desktop 中配置

Roo Code 和 Claude Desktop 的 MCP 服务器配置格式类似。以下是设置 Mac Shell MCP 服务器的方法:

使用本地安装
Roo 代码配置

将以下内容添加到您的 Roo Code MCP 设置配置文件(位于~/Library/Application Support/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_mcp_settings.json ):

"mac-shell": { "command": "node", "args": [ "/path/to/mac-shell-mcp/build/index.js" ], "alwaysAllow": [], "disabled": false }
Claude桌面配置

将以下内容添加到您的 Claude Desktop 配置文件(位于~/Library/Application Support/Claude/claude_desktop_config.json ):

"mac-shell": { "command": "node", "args": [ "/path/to/mac-shell-mcp/build/index.js" ], "alwaysAllow": false, "disabled": false }

/path/to/mac-shell-mcp替换为您克隆存储库的实际路径。

使用 NPX(推荐)

为了更方便的设置,不需要保持终端窗口打开,您可以将包发布到 npm 并与 npx 一起使用:

发布到 npm
  1. 使用您的详细信息更新 package.json
  2. 发布到 npm:
    npm publish
Roo 代码配置
"mac-shell": { "command": "npx", "args": [ "-y", "mac-shell-mcp" ], "alwaysAllow": [], "disabled": false }
Claude桌面配置
"mac-shell": { "command": "npx", "args": [ "-y", "mac-shell-mcp" ], "alwaysAllow": false, "disabled": false }

这种方法允许 MCP 客户端自动启动 MCP 服务器,而无需单独的终端窗口或手动干预。

笔记

  • 对于 Roo 代码:出于安全考虑,建议将alwaysAllow设置为空数组[] ,因为它会在执行任何命令之前提示您批准。如果您想允许特定命令而不提示,可以将这些命令的名称添加到数组中,例如: "alwaysAllow": ["execute_command", "get_whitelist"]
  • 对于 Claude Desktop:出于安全考虑,建议alwaysAllow设置为false Desktop 使用布尔值而不是数组,其中false表示所有命令都需要批准, true表示所有命令均允许,无需提示。

重要提示alwaysAllow参数由 MCP 客户端(Roo Code 或 Claude Desktop)处理,而非由 Mac Shell MCP 服务器本身处理。服务器无论使用哪种格式都能正常工作,因为客户端会在向服务器发送请求之前处理审批流程。

可用工具

该服务器公开以下 MCP 工具:

execute_command

在 macOS 上执行 shell 命令。

{ "command": "ls", "args": ["-la"] }
get_whitelist

获取白名单命令列表。

{}
add_to_whitelist

将命令添加到白名单。

{ "command": "python3", "securityLevel": "safe", "description": "Run Python 3 scripts" }
update_security_level

更新白名单命令的安全级别。

{ "command": "python3", "securityLevel": "requires_approval" }
remove_from_whitelist

从白名单中删除命令。

{ "command": "python3" }
get_pending_commands

获取待批准的命令列表。

{}
approve_command

批准待处理的命令。

{ "commandId": "command-uuid-here" }
deny_command

拒绝待处理的命令。

{ "commandId": "command-uuid-here", "reason": "This command is potentially dangerous" }

默认白名单命令

安全命令(无需批准)

  • ls列出目录内容
  • pwd打印工作目录
  • echo将文本打印到标准输出
  • cat连接并打印文件
  • grep在文件中搜索模式
  • find在目录层次结构中查找文件
  • cd更改目录
  • head输出文件的第一部分
  • tail输出文件的最后部分
  • wc打印换行符、字数和字节数

需要批准的命令

  • mv移动(重命名)文件
  • cp复制文件和目录
  • mkdir创建目录
  • touch更改文件时间戳或创建空文件
  • chmod更改文件模式位
  • chown更改文件所有者和组

禁止的命令

  • rm删除文件或目录
  • sudo以另一个用户身份执行命令

安全注意事项

  • 所有命令均以运行 MCP 服务器的用户权限执行
  • 需要批准的命令将被保留在队列中,直到明确批准
  • 禁止的命令永远不会执行
  • 服务器使用 Node.js 的execFile而不是exec来防止 shell 注入
  • 指定时,根据允许的模式验证参数

扩展白名单

您可以使用add_to_whitelist工具扩展白名单。例如:

{ "command": "npm", "securityLevel": "requires_approval", "description": "Node.js package manager" }

用作 npm 包

要将 Mac Shell MCP 服务器与npx一起使用,类似于 Brave Search 等其他 MCP 服务器,您可以将其发布到 npm 或直接从 GitHub 使用它。

使用 npx 配置

将以下内容添加到您的 MCP 设置配置中:

罗奥代码
"mac-shell": { "command": "npx", "args": [ "-y", "github:cfdude/mac-shell-mcp" ], "alwaysAllow": [], "disabled": false }
克劳德桌面
"mac-shell": { "command": "npx", "args": [ "-y", "github:cfdude/mac-shell-mcp" ], "alwaysAllow": false, "disabled": false }

这将自动下载并运行服务器,而无需手动克隆和构建过程。

发布到 npm

如果你想将自己的版本发布到 npm:

  1. 使用您的详细信息更新 package.json
  2. 在 package.json 中添加“bin”字段:
    "bin": { "mac-shell-mcp": "./build/index.js" }
  3. 发布到 npm:
    npm publish

然后您可以在 MCP 配置中使用它:

罗奥代码
"mac-shell": { "command": "npx", "args": [ "-y", "mac-shell-mcp" ], "alwaysAllow": [], "disabled": false }
克劳德桌面
"mac-shell": { "command": "npx", "args": [ "-y", "mac-shell-mcp" ], "alwaysAllow": false, "disabled": false }

执照

此 MCP 服务器采用 MIT 许可证。这意味着您可以自由使用、修改和分发该软件,但须遵守 MIT 许可证的条款和条件。更多详情,请参阅项目仓库中的 LICENSE 文件。

-
security - not tested
F
license - not found
-
quality - not tested

local-only server

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

MCP 服务器允许通过 Claude 或 Roo Code 安全执行 macOS 终端命令,并具有内置的安全白名单和批准机制。

  1. 特征
    1. 安装
      1. 用法
        1. 启动服务器
        2. 在 Roo Code 和 Claude Desktop 中配置
        3. 可用工具
      2. 默认白名单命令
        1. 安全命令(无需批准)
        2. 需要批准的命令
        3. 禁止的命令
      3. 安全注意事项
        1. 扩展白名单
          1. 用作 npm 包
            1. 使用 npx 配置
            2. 发布到 npm
          2. 执照

            Related MCP Servers

            • A
              security
              A
              license
              A
              quality
              A secure shell command execution server implementing the Model Context Protocol (MCP). This server allows remote execution of whitelisted shell commands with support for stdin input.
              Last updated -
              1
              74
              Python
              MIT License
              • Apple
            • A
              security
              A
              license
              A
              quality
              A secure MCP server for executing whitelisted shell commands with resource and timeout controls, designed for integration with Claude and other MCP-compatible LLMs.
              Last updated -
              20
              143
              2
              TypeScript
              MIT License
            • A
              security
              A
              license
              A
              quality
              An MCP server that enables secure terminal command execution, directory navigation, and file system operations through a standardized interface for LLMs.
              Last updated -
              10
              23
              Python
              MIT License
              • Apple
            • A
              security
              A
              license
              A
              quality
              A secure terminal execution server that enables controlled command execution with security features and resource limits via the Model Context Protocol (MCP).
              Last updated -
              1
              12
              1
              JavaScript
              MIT License
              • Apple

            View all related MCP servers

            ID: ykvehzxj93