Shell命令执行服务

Go语言实现的Shell命令执行服务器,支持安全配置允许的命令集,适用于需要安全执行Shell命令的开发场景。

  • by gamunu
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 gamunu/mcp-unix-shell

使用说明

Shell命令MCP服务器

Go服务器实现模型上下文协议(MCP)以执行shell命令。

特性

  • 使用bash或zsh执行shell命令
  • 列出以前执行的命令
  • 限制允许命令的安全功能
  • 配置允许的安全命令集

备注:服务器将只允许执行通过allowedCommands参数指定的命令,或者如果配置了“*”,则允许执行所有命令。

API

工具

  • execute_命令

    • 执行shell命令
    • 输入:
      • command (string):要执行的命令
      • shell (string,可选):要使用的shell(bash或zsh,默认为bash)
    • 输出:
      • 同时具有stdout和stderr的命令输出
      • 退出代码
      • 执行时间
  • list_recent_命令

    • 列出最近执行的命令
    • 输入:
      • limit (整数,可选):要返回的命令数(默认为10)
    • 输出:
      • 最近执行的命令列表,包括时间戳和状态
  • list_allowed_命令

    • 列出允许服务器执行的所有命令
    • 无需输入
    • 退货:
      • 允许的命令列表,如果允许所有命令,则使用“*”

使用Claude Desktop

安装服务器

go install github.com/gamunu/mcp-unix-shell

将此添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "shell": {
      "command": "mcp-unix-shell",
      "args": [
        "--allowed-commands=ls,cat,echo,find"
      ]
    }
  }
}

要允许所有命令(谨慎使用):

{
  "mcpServers": {
    "shell": {
      "command": "mcp-unix-shell",
      "args": [
        "--allowed-commands=*"
      ]
    }
  }
}

安全考虑

使用此MCP服务器时,请考虑:

  1. 只允许您信任的命令-建议使用限制性满列表
  2. 避免允许可能修改系统设置或访问敏感数据的命令
  3. 服务器在运行Claude Desktop的用户的权限下运行
  4. 命令输出被发送回LLM,因此请注意敏感信息

许可证

此MCP服务器根据Apache许可证2.0获得许可。