shell-mcp
shell-mcp
ローカルLLMクライアントでシェルコマンドを安全に実行するための、非常にセキュアなMCP(Model Context Protocol)サーバーです。
セキュリティモデル
コマンドは8つの独立したセキュリティレイヤーを通過します。すべてを通過する必要があります:
レイヤー | 内容 |
1 | Zodスキーマ検証 — 処理前の厳格な型チェック |
2 | シェルなしのspawn — |
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のみ |
|
| off |
| ファイルの上書きを許可 | off |
| すべての書き込みを無効化( | off |
| curl、wget、nc のブロックを解除 | off |
| 子プロセスに環境変数をそのまま渡す | off(サニタイズされます) |
LLMに公開されるツール
run_command
明示的な引数配列を使用してコマンドを実行します。シェルは使用しません — パイプやリダイレクトは機能しません。
{
"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