MCP Shell Server

MCP Shell Server

镜像

简介

MCP Shell 服务器是一个安全的 shell 命令执行服务器,实现了 Model Context 协议 (MCP)。它允许远程执行白名单中的 shell 命令,并提供完整的输出控制。

主要特性

  • 仅允许执行白名单中的命令
  • 支持标准输入传递
  • 返回完整执行结果(标准输出、错误输出、状态码和执行时间)
  • Shell 操作符安全验证
  • 命令执行超时控制

安装

pip install mcp-shell-server

快速配置

在 Claude.app 中配置 MCP 客户端

编辑配置文件:

code ~/Library/Application\ Support/Claude/claude_desktop_config.json

发布版本配置

{
  "mcpServers": {
    "shell": {
      "command": "uvx",
      "args": ["mcp-shell-server"],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    }
  }
}

本地开发版本配置

{
  "mcpServers": {
    "shell": {
      "command": "uv",
      "args": ["--directory", ".", "run", "mcp-shell-server"],
      "env": {
        "ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
      }
    }
  }
}

基本使用

启动服务器

ALLOW_COMMANDS="ls,cat,echo" uvx mcp-shell-server

也可以使用别名 ALLOWED_COMMANDS

请求示例

基本命令执行:

{
    "command": ["ls", "-l", "/tmp"]
}

带标准输入的命令:

{
    "command": ["cat"],
    "stdin": "Hello, World!"
}

带超时和工作目录的命令:

{
    "command": ["grep", "-r", "pattern"],
    "directory": "/path/to/search",
    "timeout": 60
}

响应格式

成功响应:

{
    "stdout": "命令输出",
    "stderr": "",
    "status": 0,
    "execution_time": 0.123
}

错误响应:

{
    "error": "不允许的命令: rm",
    "status": 1,
    "stdout": "",
    "stderr": "不允许的命令: rm",
    "execution_time": 0
}

系统要求

  • Python 3.11 或更高版本
  • mcp >= 1.1.0

更多信息

完整文档可访问:GitHub 仓库