Back to MCP directory
publicPublicdnsLocal runtime

shell-mcp-server

Shell MCP Server是一个为AI应用提供安全Shell命令执行能力的服务,支持多平台和多Shell环境。

article

README

🚀 🖥️ Shell MCP 服务器

Shell MCP 服务器专为模型上下文协议构建,能够为您的 AI 应用程序添加安全的 Shell 命令执行功能,让您的应用在不同系统上安全、稳定地运行。

🚀 快速开始

安装

# 使用 pip
pip install shell-mcp-server

# 使用 uv(推荐)
uv pip install shell-mcp-server

🔌 Claude 桌面集成

将此内容添加到您的 Claude 桌面配置中以启用 Shell 命令执行:

📝 点击查看配置
{
    "mcp": {
        "servers": [
            {
                "name": "shell_mcp",
                "class_name": "ShellMCPClient",
                "args": {}
            }
        ]
    }
}

将上述配置添加到 claudia.toml 文件中:

echo '[mcp]\n  servers = [{{name=\"shell_mcp\", class_name=\"ShellMCPClient\", args={}}}]' >> claudia.toml

✨ 主要特性

  • 🔒 安全执行 - 命令仅在指定目录中运行
  • 🐚 多壳支持 - 支持 bash、sh、cmd、powershell
  • ⏱️ 超时控制 - 自动终止长时间运行的命令
  • 🌍 跨平台 - 在 Unix 和 Windows 系统上均适用
  • 🛡️ 默认安全 - 内置目录和壳程序验证

💻 使用示例

基础用法

在您的代码中导入并使用 ShellMCPClient:

from shell_mcp_server import ShellMCPClient

# 创建一个 ShellMCP 客户端实例
client = ShellMCPClient()

# 执行命令
response = client.execute("echo Hello, World!")
print(response)  # 输出: "Hello, World!\n"

# 设置超时时间(可选)
client.timeout = 10  # 设置为 10 秒

# 带有参数的命令
response = client.execute("ls -l", working_dir="/path/to/dir")
print(response)

高级用法

您可以自定义以下设置:

  • timeout: 指定超时时间(默认:无限制)
  • shell_path: 自定义 Shell 解释器路径(默认:/bin/sh)
  • env: 自定义环境变量
  • working_dir: 设置工作目录

🛠️ 开发

设置您的开发环境:

# 创建并激活虚拟环境
uv venv
source .venv/bin/activate

# 安装开发依赖项
uv pip install -e ".[test]"

# 运行测试
python -m pytest

# 带覆盖率的测试
python -m pytest --cov=shell_mcp_server

🤝 贡献

欢迎贡献!请随意:

  • 🐛 报告错误
  • 💡 提供建议功能
  • 🔧 提交拉取请求
  • 📚 改进文档

📄 许可证

MIT 许可证 - 详情见 LICENSE


🌟 使用安全 Shell 接入增强您的 AI! 🌟

模型上下文协议 构建 | 热心于 MCP 社区的开发者制作

🎉 在 GitHub 上为该项目点星星!
如果您觉得此工具有用,请考虑给它点个星!这有助于更多人发现此项目。
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client