Shell MCP Server

Shell MCP Server

Enables safe shell command execution with configurable directory and command restrictions, allowing Claude Desktop to run shell commands securely.

Category
访问服务器

README

Shell MCP Server

A Model Context Protocol (MCP) server for safe shell command execution. This server allows Claude Desktop to execute shell commands with configurable safety restrictions.

Features

  • 🔒 Safe Command Execution: Configurable directory and command restrictions
  • ⏱️ Timeout Protection: Prevents long-running commands from hanging
  • 📝 Detailed Logging: Comprehensive execution logs and error reporting
  • ⚙️ Configurable: Customizable allowed directories and blocked commands
  • 🐍 Easy Installation: Standard Python package distribution

Installation

Option 1: Install from PyPI (Recommended)

pip install shell-mcp-server

Option 2: Install from Source

git clone https://github.com/jeffwikstrom/shell-mcp-server.git
cd shell-mcp-server
pip install .

Option 3: Development Install

git clone https://github.com/jeffwikstrom/shell-mcp-server.git
cd shell-mcp-server
pip install -e .

Configuration

Claude Desktop Setup

After installation, add the following to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Linux/Windows: ~/.config/claude/claude_desktop_config.json

{
  "mcpServers": {
    "shell-executor": {
      "command": "shell-mcp-server",
      "env": {
        "SHELL_MCP_CONFIG": "/path/to/your/shell_mcp_config.json"
      }
    }
  }
}

Server Configuration (Optional)

Create a configuration file to customize the server behavior:

# Create config file
cp shell_mcp_config.template.json ~/.config/shell_mcp_config.json

Edit the configuration file:

{
  "allowed_directories": [
    "/Users/username",
    "/Users/username/Projects",
    "/Users/username/Documents",
    "/tmp"
  ],
  "blocked_commands": [
    "rm -rf /",
    "sudo rm",
    "sudo shutdown",
    "format",
    "mkfs"
  ],
  "timeout": 30
}

Alternative Configurations

Using Virtual Environment

If you prefer using a virtual environment:

# Create virtual environment
python3 -m venv ~/.local/share/shell-mcp-server
source ~/.local/share/shell-mcp-server/bin/activate
pip install shell-mcp-server

Claude Desktop config:

{
  "mcpServers": {
    "shell-executor": {
      "command": "/Users/username/.local/share/shell-mcp-server/bin/shell-mcp-server"
    }
  }
}

Using pipx (Isolated Installation)

# Install with pipx
pipx install shell-mcp-server

Claude Desktop config:

{
  "mcpServers": {
    "shell-executor": {
      "command": "shell-mcp-server"
    }
  }
}

Using Conda

# Create conda environment
conda create -n shell-mcp python=3.11
conda activate shell-mcp
pip install shell-mcp-server

Claude Desktop config:

{
  "mcpServers": {
    "shell-executor": {
      "command": "/path/to/conda/envs/shell-mcp/bin/shell-mcp-server"
    }
  }
}

Usage

Once configured, you can ask Claude to execute shell commands:

Can you list the files in my Documents directory?
Can you create a new directory called "test-project"?
Can you check the current git status?
Can you run the tests in my project?

Safety Features

Directory Restrictions

By default, commands can only be executed in:

  • User home directory and subdirectories
  • /tmp and /var/tmp

Command Filtering

The following command patterns are blocked by default:

  • rm -rf / (recursive deletion of root)
  • sudo rm (privileged deletion)
  • sudo shutdown/reboot/halt (system control)
  • format, fdisk, mkfs (disk formatting)
  • chmod 777 (overly permissive permissions)
  • curl | sh, wget | sh (piped execution)

Timeout Protection

Commands are automatically terminated after 30 seconds (configurable).

Configuration Reference

Environment Variables

  • SHELL_MCP_CONFIG: Path to configuration file

Configuration File Options

Option Type Default Description
allowed_directories Array See defaults Directories where commands can be executed
blocked_commands Array See defaults Command patterns to block
timeout Number 30 Command timeout in seconds

Default Allowed Directories

  • $HOME (user home directory)
  • $HOME/Documents
  • $HOME/Downloads
  • $HOME/Desktop
  • $HOME/Projects
  • $HOME/Development
  • /tmp
  • /var/tmp
  • /~ (fallback for tilde expansion edge cases)

Troubleshooting

Common Issues

  1. "Command not found: shell-mcp-server"

    • Ensure the package is installed: pip list | grep shell-mcp-server
    • Check if the installation directory is in your PATH
    • Use full path to executable in Claude config
  2. "Directory not allowed" errors

    • Check your allowed_directories configuration
    • Ensure the directory exists and is accessible
  3. Commands timing out

    • Increase the timeout value in configuration
    • Check if the command is actually long-running
  4. Server not connecting

    • Restart Claude Desktop completely
    • Check the MCP server logs in Claude Desktop
    • Verify JSON syntax in configuration files

Debugging

Enable debug logging by setting the environment variable:

export SHELL_MCP_LOG_LEVEL=DEBUG

Getting Help

  1. Check the Issues page
  2. Create a new issue with:
    • Your configuration file
    • Error messages from Claude Desktop
    • Steps to reproduce the problem

Development

Local Development

git clone https://github.com/jeffwikstrom/shell-mcp-server.git
cd shell-mcp-server
python3 -m venv venv
source venv/bin/activate
pip install -e .

Running Tests

pip install pytest pytest-asyncio
pytest

Building Distribution

pip install build
python -m build

Security Considerations

  • Always review the allowed directories and blocked commands
  • Consider running in a sandboxed environment for additional security
  • Monitor command execution logs
  • Keep the package updated

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

Changelog

v1.0.0

  • Initial release
  • Basic shell command execution
  • Safety restrictions
  • Configurable settings

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选