🚀 Shell MCP 服务器专为 Model Context Protocol 构建,能为 AI 应用程序添加安全的 Shell 命令执行功能,让您的 AI 应用更加安全、高效!
# 使用 pip
pip install shell-mcp-server
# 使用 uv(推荐)
uv pip install shell-mcp-server
将此内容添加到您的 Claude Desktop 配置中以启用 Shell 命令执行:
{
"mcpServers": {
"shell-mcp-server": {
"command": "uv",
"args": [
"--venv",
".venv",
"python",
"-m",
"shell_mcp_server.server",
"--port",
"23456"
]
}
}
}
# 启动服务器
uv python -m shell_mcp_server.server --port 23456
# 发送命令
curl http://localhost:23456/shell -X POST -d "echo Hello World!"
from shell_mcp_server import ShellMCPClient
client = ShellMCPClient("http://localhost:23456")
# 执行命令并获取输出
result = client.run_command("ls -a")
print(result.stdout) # 输出结果
通过以下方式配置服务器:
# 启动时指定配置文件
uv python -m shell_mcp_server.server --config config.json
config.json 示例:
{
"port": 23456,
"allowed_commands": ["ls", "echo"],
"super_users": ["user1", "user2"]
}
设置开发环境:
# 创建并激活虚拟环境
uv venv
source .venv/bin/activate
# 安装开发依赖
uv pip install -e ".[test]"
# 运行测试
python -m pytest
# 带覆盖率运行测试
python -m pytest --cov=shell_mcp_server
欢迎贡献!请随意:
MIT 许可证 - 详见 LICENSE 了解详细信息。