一个实现模型上下文协议(MCP)的安全外壳命令执行服务器。此服务器允许远程执行白名单中的外壳命令,并支持标准输入。
<a href="https://glama.ai/mcp/servers/rt2d4pbn22"><img width="380" height="200" src="https://gips1.baidu.com/it/u=4056089610,762172656&fm=3081&app=3081&f=PNG?w=760&h=400" alt="mcp-shell-server MCP 服务器" /></a>
<a href="https://glama.ai/mcp/servers/rt2d4pbn22"><img width="380" height="200" src="https://gips1.baidu.com/it/u=4056089610,762172656&fm=3081&app=3081&f=PNG?w=760&h=400" alt="mcp-shell-server MCP 服务器" /></a>
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"
}
},
}
}
code ~/Library/Application\ Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"shell": {
"command": "uv",
"args": [
"--directory",
".",
"run",
"mcp-shell-server"
],
"env": {
"ALLOW_COMMANDS": "ls,cat,pwd,grep,wc,touch,find"
}
},
}
}
要通过 Smithery 自动安装 Shell Server 到 Claude Desktop:
npx -y @smithery/cli install mcp-shell-server --client claude
pip install mcp-shell-server
要通过 Smithery 自动安装 Shell Server 到 Claude Desktop:
npx -y @smithery/cli install mcp-shell-server --client claude
ALLOW_COMMANDS="ls,cat,echo" uvx mcp-shell-server
# 或使用别名
ALLOWED_COMMANDS="ls,cat,echo" uvx mcp-shell-server
环境变量 ALLOW_COMMANDS(或其别名 ALLOWED_COMMANDS)指定了哪些命令是允许执行的。命令之间可以用逗号分隔,可选地在逗号周围添加空格。
ALLOW_COMMANDS 或 ALLOWED_COMMANDS 的有效格式:
ALLOW_COMMANDS="ls,cat,echo" # 基本格式
ALLOWED_COMMANDS="ls ,echo, cat" # 带有空格(使用别名)
ALLOW_COMMANDS="ls, cat , echo" # 多个空格
# 基本命令执行
{
"command": ["ls", "-l", "/tmp"]
}
# 带有标准输入的命令
{
"command": ["cat"],
"stdin": "Hello, World!"
}
# 带有超时的命令
{
"command": ["long-running-process"],
"timeout": 30 # 最大执行时间(秒)
}
# 带有工作目录和超时的命令
{
"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
}
服务器实现了多种安全措施:
git clone https://github.com/yourusername/mcp-shell-server.git
cd mcp-shell-server
pip install -e ".[test]"
pytest
| 字段 | 类型 | 必需 | 描述 |
|---|---|---|---|
| command | string[] | 是 | 命令及其参数作为数组元素 |
| stdin | string | 否 | 要传递给命令的输入 |
| directory | string | 否 | 命令执行的工作目录 |
| timeout | integer | 否 | 命令的最大执行时间(秒) |
| 字段 | 类型 | 描述 |
|---|---|---|
| stdout | string | 命令的标准输出 |
| stderr | string | 命令的标准错误输出 |
| status | integer | 退出状态码 |
| execution_time | float | 执行所用时间(秒) |
| error | string | 错误信息(仅在失败时存在) |
MIT 许可证 - 查看 LICENSE 文件以获取详细信息