🖥️ シェル MCP サーバー
🚀 Shell MCP サーバーを使用して、AI アプリケーションに安全なシェル コマンド実行機能を追加します。モデル コンテキスト プロトコル用に構築されています。
✨ 特徴
- 🔒セキュア実行- コマンドは指定されたディレクトリ内でのみ実行されます
- 🐚複数のシェル- bash、sh、cmd、powershell をサポート
- ⏱️タイムアウト制御- 長時間実行されるコマンドの自動終了
- 🌍クロスプラットフォーム- Unix と Windows の両方のシステムで動作します
- 🛡️デフォルトで安全- ディレクトリとシェルの検証が組み込まれています
🚀 クイックスタート
インストール
# Using pip
pip install shell-mcp-server
# Using uv (recommended)
uv pip install shell-mcp-server
🔌 クロード デスクトップ統合
シェル コマンドの実行を有効にするには、Claude Desktop 構成にこれを追加します。
{
"mcpServers": {
"shell-mcp-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/shell-mcp-server",
"run",
"shell-mcp-server",
"/path/to/allowed/dir1",
"/path/to/allowed/dir2",
"--shell", "bash", "/bin/bash",
"--shell", "zsh", "/bin/zsh"
]
}
}
}
🎮 使用例
基本的なファイル操作
# List directory contents
result = execute_command(
command="ls -la",
shell="bash",
cwd="/path/to/project"
)
# Find files by pattern
result = execute_command(
command="find . -name '*.py'",
shell="bash",
cwd="/path/to/project"
)
プロジェクト管理
# Git operations
result = execute_command(
command="git status && git diff",
shell="bash",
cwd="/path/to/repo"
)
# Package management
result = execute_command(
command="pip list --outdated",
shell="bash",
cwd="/path/to/python/project"
)
システム情報
# Resource usage
result = execute_command(
command="df -h && free -h",
shell="bash",
cwd="/path/to/dir"
)
# Process monitoring
result = execute_command(
command="ps aux | grep python",
shell="bash",
cwd="/path/to/dir"
)
ファイル処理
# Search file content
result = execute_command(
command="grep -r 'TODO' .",
shell="bash",
cwd="/path/to/project"
)
# File manipulation
result = execute_command(
command="awk '{print $1}' data.csv | sort | uniq -c",
shell="bash",
cwd="/path/to/data"
)
Windows固有の例
# List processes
result = execute_command(
command="Get-Process | Where-Object {$_.CPU -gt 10}",
shell="powershell",
cwd="C:\\path\\to\\dir"
)
# System information
result = execute_command(
command="systeminfo | findstr /B /C:'OS'",
shell="cmd",
cwd="C:\\path\\to\\dir"
)
⚙️ 構成
コマンドライン引数を使用して動作を構成します。
口論 | 説明 |
---|
directories | 📁 許可されたディレクトリのリスト |
--shell name path | 🐚 シェルの仕様(名前とパス) |
環境変数:
COMMAND_TIMEOUT
: ⏱️ 最大実行時間(秒)(デフォルト: 30)
🛡️ セキュリティ機能
- 🔐ディレクトリ分離: コマンドは指定されたディレクトリ内でのみ実行できます
- 🔒シェル制御: 設定されたシェルのみが許可されます
- ⏰タイムアウト保護: すべてのコマンドには設定可能なタイムアウトがあります
- 🛑パス検証: 作業ディレクトリの検証によりトラバーサル攻撃を防止
- 👤権限分離: コマンドはサーバープロセスと同じ権限で実行されます
🛠️ 開発
開発環境をセットアップします。
# Create and activate virtual environment
uv venv
source .venv/bin/activate
# Install development dependencies
uv pip install -e ".[test]"
# Run tests
python -m pytest
# Run tests with coverage
python -m pytest --cov=shell_mcp_server
🤝 貢献する
貢献大歓迎!お気軽にどうぞ:
- 🐛 バグを報告する
- 💡 機能を提案する
- 🔧 プルリクエストを送信する
- 📚 ドキュメントの改善
📜 ライセンス
MIT ライセンス - 詳細についてはライセンスを参照してください。
🌟 セキュア シェル アクセスで AI を強化しましょう! 🌟
モデルコンテキストプロトコル向けに構築 | MCPコミュニティによって愛を込めて作成