mcpField
🖥
🖥️ Shell MCP Server

🖥️ Shell MCP Server

本地服务
github.com/blazickjp开发工具2362 周前更新

关于 🖥️ Shell MCP Server

Shell MCP Server 是面向 Claude AI 的 MCP 服务,用于在指定目录内受控地执行 shell 命令。它适合需要让 AI 运行命令行操作、同时限制执行范围的开发者。项目提供目录隔离、可配置的 shell 和超时控制。

主要功能

  1. 01限定目录内执行命令
  2. 02支持 bash、sh、cmd、powershell
  3. 03可配置命令超时时间
  4. 04跨 Unix 与 Windows 运行
  5. 05工作目录路径校验

适用场景

  1. 01让 AI 在项目目录中查看 git 状态
  2. 02执行文件搜索与内容检索
  3. 03在 Windows 上运行 PowerShell 命令查询系统信息

MCP 相关

该项目是 MCP 服务,向 MCP 客户端暴露 execute_command 形式的 shell 命令执行能力,并限制可用目录与 shell。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

🖥️ Shell MCP Server

PyPI version License: MIT Python Code style: black

🚀 使用 Shell MCP Server 为你的 AI 应用添加安全的 Shell 命令执行能力!专为 Model Context Protocol 打造。

Shell Server MCP server

✨ 功能特性

  • 🔒 安全执行 - 命令仅在指定目录中运行
  • 🐚 支持多种 Shell - 支持 bash、sh、cmd、powershell
  • ⏱️ 超时控制 - 自动终止长时间运行的命令
  • 🌍 跨平台 - 支持 Unix 和 Windows 系统
  • 🛡️ 默认安全 - 内置目录和 Shell 验证

🚀 快速开始

安装
# Using pip
pip install shell-mcp-server

# Using uv (recommended)
uv pip install shell-mcp-server
🔌 Claude Desktop 集成

将以下内容添加到 Claude Desktop 配置中,即可启用 Shell 命令执行:

📝 点击查看配置
{
    "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🐚 Shell 规格(名称和路径)

环境变量:

  • COMMAND_TIMEOUT:⏱️ 最大执行时间,单位为秒(默认值:30)

🛡️ 安全功能

  • 🔐 目录隔离:命令只能在指定目录中执行
  • 🔒 Shell 控制:仅允许使用已配置的 Shell
  • ⏰ 超时保护:所有命令都设有可配置的超时时间
  • 🛑 路径验证:工作目录验证可防止路径遍历攻击
  • 👤 权限隔离:命令以与服务进程相同的权限运行

🛠️ 开发

设置开发环境:

# 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 许可证 - 详情请参阅 LICENSE。


🌟 为你的 AI 增添安全的 Shell 访问能力!🌟

专为 Model Context Protocol 打造 | 由 MCP 社区倾心构建

🎉 在 GitHub 上为我们点亮星标!
如果你觉得这个工具有用,不妨为它点亮星标!这能帮助其他人发现这个项目。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。