Bash命令服务器

一个强大的模型上下文协议(MCP)服务器,使Claude桌面应用能够在Windows的WSL2 Linux发行版中执行bash命令和脚本。

  • by gunjanjp
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 gunjanjp/linuxshell-mcp

使用说明

Linux Bash MCP服务器

一个强大的模型上下文协议(MCP)服务器,使Claude Desktop能够在Windows上的任何WSL2 Linux发行版中执行bash命令和脚本。具有通用Linux兼容性、智能分布检测和全面的安全措施。

🚀 快速开始

# 1. Clone the repository
git clone https://github.com/yourusername/linux-bash-mcp-server.git
cd linux-bash-mcp-server

# 2. Run automated setup
npm run fix

# 3. Restart Claude Desktop
# 4. Start using Linux commands in Claude!

✨ 特性

  • 🐧 通用Linux支持 -适用于Ubuntu、Debian、Fedora、openSUSE、Alpine等
  • 🔍 智能配电检测 -自动检测和配置可用的WSL发行版
  • 🛡️ 安全配置合并 -设置时保留现有的MCP服务器
  • 🔧 综合诊断 -内置故障排除和自动修复工具
  • ⚡ 高性能 -通过可配置的超时优化命令执行
  • 📊 详细日志记录 -故障排除和监控的调试模式
  • 🔄 易于管理 -用于设置、测试和维护的简单脚本

🛠️ 可用工具

工具 说明 示例使用
execute_bash_command 运行单个bash命令 ps aux | grep nginx
execute_bash_script 使用args执行bash脚本 运行监控脚本
create_bash_script 创建新的bash脚本 生成自动化脚本
list_directory 列出目录内容 浏览文件系统
get_system_info 全面的系统信息 检查操作系统、内存、磁盘使用情况
check_wsl_status WSL和分发状态 验证连接

📋 先决条件

  • 安装了WSL2的Windows
  • WSL2中的任何Linux发行版 (Ubuntu、Debian等)
  • Node.js 18+
  • 克劳德桌面应用程序

🎯 安装和设置

选项1:自动设置(推荐)

git clone https://github.com/yourusername/linux-bash-mcp-server.git
cd linux-bash-mcp-server
npm run fix

选项2:手动设置

# Install dependencies
npm install

# Run interactive setup
npm run setup

# Test functionality
npm test

选项3:快速诊断

# Check for issues
npm run debug

# Verify configuration
npm run check-config

⚙️ 配置

服务器会自动检测您的WSL发行版并进行自我配置。手动配置可在 config.json:

{
  "wslDistribution": "auto-detect",
  "defaultTimeout": 30000,
  "scriptTimeout": 60000,
  "maxBufferSize": 10485760,
  "debugMode": false
}

🔧 可用脚本

命令 描述
npm run fix 自动修复常见问题和设置
npm run setup 交互式配置向导
npm run debug 全面诊断
npm run test 测试所有功能
npm run check-config 验证配置
npm start 启动MCP服务器

🐧 支持的Linux发行版

  • 乌班图 (最常见)
  • Debian
  • 菲多拉
  • openSUSE
  • Alpine Linux
  • Kali Linux
  • Oracle Linux
  • 还有更多。..

💡 使用示例

配置后,在Claude Desktop中使用以下命令:

系统管理

  • “显示我的Linux环境的全面系统信息”
  • “检查磁盘使用情况和可用空间”
  • “按CPU使用率排序的运行进程列表”

文件操作

  • “列出/var/log中的所有文件及其详细信息”
  • “查找过去24小时内修改的文件”
  • “在/home中显示目录大小”

开发任务

  • “检查Docker是否正在运行”
  • “显示我主目录中存储库的git状态”
  • “列出已安装的Python包”

自动化

  • “为我的文档创建备份脚本”
  • “生成系统监控脚本”
  • “创建日志轮换脚本”

🛡️ 安全功能

  • 配置保存 -从不覆盖现有的MCP服务器
  • 自动备份 -创建损坏配置的备份
  • 输入验证 -验证所有命令和参数
  • 超时保护 -防止挂起命令
  • 错误处理 -全面的错误报告和恢复

🔍 故障排除

快速修复

npm run fix        # Auto-resolve common issues
npm run debug      # Detailed diagnostics

常见问题

WSL未找到

wsl --install
wsl --install -d Ubuntu

缺少依赖关系

npm install

配置问题

npm run check-config
npm run setup

服务器未启动

npm run debug

看 故障排除.md 详细的解决方案。

🤝 与其他MCP服务器集成

此服务器与以下服务器无缝协作:

  • PowerShell MCP服务器(Windows命令)
  • 内存MCP服务器(持久注释)
  • 文件MCP服务器(文件操作)
  • Git MCP服务器(版本控制)
  • 任何其他MCP服务器

📚 项目结构

linux-bash-mcp-server/
├── src/
│   └── index.js              # Main MCP server
├── test/
│   └── test.js               # Comprehensive tests
├── examples/
│   ├── system_info.sh        # Example monitoring script
│   └── file_operations.sh    # Example file operations
├── config.json               # Server configuration
├── setup.js                  # Interactive setup
├── debug.js                  # Diagnostic tool
├── quick-fix.js             # Auto-fix utility
├── check-config.js          # Configuration checker
└── README.md                # This file

🔄 版本历史记录

v1.0.0(当前)

  • ✅ 通用Linux发行版支持
  • ✅ 智能WSL分布检测
  • ✅ 安全配置合并
  • ✅ 全面的诊断工具
  • ✅ 自动修复实用程序
  • ✅ 增强的错误处理
  • ✅ 调试模式支持

🤝 贡献

欢迎投稿!拜托:

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 如果适用,添加测试
  5. 更新文档
  6. 提交拉取请求

📄 许可证

此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。

🆘 支持

🙏 致谢

  • Anthropic 对于模型上下文协议
  • 微软 WSL2技术
  • 开源社区 Linux发行版和工具

由以下材料制成❤️ 克劳德桌面和Linux社区

⭐ 如果你觉得这个存储库有用,请为其加星!