shell-mcp
shell-mcp
一个超安全的 MCP (Model Context Protocol) 服务器,用于与本地 LLM 客户端安全地运行 Shell 命令。
安全模型
命令通过 8 个独立的安全层 —— 每一层都必须通过:
层级 | 功能 |
1 | Zod 模式验证 — 在任何处理前进行严格的类型检查 |
2 | 禁止 Shell 生成 — 使用 |
3 | 硬编码黑名单 — |
4 | 参数检查 — 拒绝元字符、空字节、可疑模式以及特定命令的危险标志 |
5 | 目录白名单 — 每个路径必须位于 |
6 | 符号链接解析 — 在路径检查前解析符号链接(防止通过符号链接逃逸) |
7 | 资源限制 — 超时、输出大小上限、并发限制 |
8 | 环境清理 — 剥离 |
Related MCP server: MCP Shell Server
快速开始
# Clone and build
git clone https://github.com/your-username/shell-mcp.git
cd shell-mcp
npm install
npm run build
# Run (must specify at least one --allow-dir)
node dist/index.js --allow-dir ~/projects --allow-dir ~/dataLLM 客户端配置
{
"shell-mcp": {
"command": "node",
"args": [
"/path/to/shell-mcp/dist/index.js",
"--allow-dir", "/home/user/projects",
"--allow-dir", "/home/user/data",
"--allow-cmd", "ls",
"--allow-cmd", "cat",
"--allow-cmd", "grep",
"--allow-cmd", "find",
"--allow-cmd", "python3",
"--timeout", "30",
"--log-file", "/home/user/.shell-mcp/audit.log"
]
}
}标志
标志 | 描述 | 默认值 |
| 允许的目录(必需,可重复) | 无 — 服务器无法启动 |
| 指定允许的命令白名单(可重复) | 所有非黑名单命令 |
| 额外禁止的命令 | — |
| 最大执行时间 (1–300) | 30 |
| 最大输出大小 | 1048576 (1MB) |
| 最大并行命令数 (1–10) | 3 |
| 审计日志文件路径 | 仅 stderr |
| 启用 | 关闭 |
| 允许覆盖文件 | 关闭 |
| 禁用所有写入(覆盖 | 关闭 |
| 解锁 curl, wget, nc | 关闭 |
| 将完整环境变量转发给子进程 | 关闭(已清理) |
暴露给 LLM 的工具
run_command
使用显式参数数组运行命令。无 Shell — 管道和重定向将无法工作。
{
"command": "grep",
"args": ["-r", "TODO", "/home/user/projects/myapp"],
"cwd": "/home/user/projects/myapp",
"timeout": 10
}read_file
读取文件内容。支持行范围和二进制 (base64) 输出。
{
"path": "/home/user/projects/myapp/src/main.py",
"startLine": 1,
"endLine": 50
}list_directory
以树状视图、大小和权限列出目录。
{
"path": "/home/user/projects/myapp",
"recursive": true
}write_file (需要 --enable-write)
写入文件。没有 --allow-overwrite 时不会覆盖。
{
"path": "/home/user/projects/myapp/notes.txt",
"content": "Hello world"
}get_server_info
返回当前服务器配置和限制。有助于 LLM 在操作前了解其沙箱环境。
永久禁止的命令
这些命令无法通过任何标志启用:
rm, rmdir, shred, dd, mkfs, fdisk, diskutil, sudo, su, doas,
osascript, defaults, open, launchctl, crontab,
curl, wget, nc, ssh, scp, rsync,
brew, npm, yarn, pip, gem, cargo, docker,
gcc, clang, kill, killall, shutdown, reboot,
gpg, security (macOS keychain), ...and more审计日志
每个命令尝试(无论允许或拒绝)都会以 JSON 格式记录:
{"timestamp":"2024-01-01T12:00:00.000Z","sessionId":"A3F9B2C1","event":"COMMAND_DENY","command":"rm","args":["-rf","/"],"denyLayer":3,"denyReason":"Command \"rm\" is on the hardcoded blocklist"}
{"timestamp":"2024-01-01T12:00:01.000Z","sessionId":"A3F9B2C1","event":"COMMAND_ALLOW","command":"ls","args":["-la"],"cwd":"/home/user/projects","exitCode":0,"durationMs":12,"outputBytes":1024}使用 MCP Inspector 检查
npx @modelcontextprotocol/inspector node dist/index.js --allow-dir /tmp/testThis server cannot be deployed
Maintenance
Related MCP Connectors
- gatewayOAuthai.sealgate
MCP gateway with runtime security policy, tool-call-level control, and audit of agent actions.
Paid remote MCP for LLM security scans, jailbreak checks, analytics, checkout, and readiness.
Security & DLP proxy for MCP: tool-poisoning scans, PII redaction on tool args/results. Beta.
Remote MCP for Android CLI agent build gate, structured receipts, audit logs, and reviewer-ready evi
Related MCP Servers
- AlicenseAqualityFmaintenanceAn MCP server that enables secure execution of shell commands across Windows, macOS, and Linux with built-in whitelisting and approval mechanisms for enhanced security.971 npm21MIT
- AlicenseBqualityDmaintenanceEnables secure execution of whitelisted shell commands through MCP, with support for stdin input, timeout control, and comprehensive output including stdout, stderr, and execution time.1MIT

terminal-toolkit-mcpofficial
AlicenseNot gradedqualityCmaintenanceEnables LLM clients to execute shell commands safely through the MCP protocol, with features like session management, safe mode, and process control.1Apache 2.0- AlicenseNot gradedqualityDmaintenanceEnables executing shell commands on the host system via an MCP tool, with JWT/OAuth authentication and audit logging for secure remote access.1MIT