一个安全的模型上下文协议(MCP)服务器,提供在Linux上的Claude桌面执行Linux shell命令的能力。
git clone https://github.com/Frost26/mcp-linux-shell-server.git
cd mcp-linux-shell-server
python3 -m venv mcpEnv
source mcpEnv/bin/activate
# 安装核心依赖
pip install -r requirements.txt
# 安装开发依赖(可选)
pip install -r requirements-dev.txt
# 运行测试以确保一切正常
python -m pytest tests/ -v --cov=linux_shell_server
配置文件通常位于:
~/.config/claude/claude_desktop_config.json
在你的Claude桌面配置文件中添加以下内容:
{
"mcpServers": {
"linux-shell": {
"command": "/path/to/your/mcp-linux-shell-server/mcpEnv/bin/python",
"args": [
"-m",
"linux_shell_server.main"
],
"env": {
"PYTHONPATH": "/path/to/your/mcp-linux-shell-server"
}
}
}
}
将/path/to/your/mcp-linux-shell-server替换为你实际的项目目录路径。
此项目的示例:
{
"mcpServers": {
"linux-shell": {
"command": "/home/AI/Documents/CodeProjects/mcp-linux-shell-server/mcpEnv/bin/python",
"args": [
"-m",
"linux_shell_server.main"
],
"env": {
"PYTHONPATH": "/home/AI/Documents/CodeProjects/mcp-linux-shell-server"
}
}
}
}
更新配置后,重启Claude桌面以加载MCP服务器。
MCP服务器提供了三个主要工具:
| 工具 | 描述 | 参数 |
|---|---|---|
execute_command | 执行shell命令 | command (字符串) |
change_directory | 更改工作目录 | path (字符串) |
get_current_directory | 获取当前工作目录 | 无 |
# 运行所有测试
python -m pytest tests/
# 带有覆盖率运行
python -m pytest tests/ --cov=linux_shell_server --cov-report=html
# 运行特定测试文件
python -m pytest tests/test_main.py -v
# 使用Black格式化代码
black linux_shell_server/ tests/
# 使用Ruff检查代码风格
ruff check linux_shell_server/ tests/
# 使用isort排序导入
isort linux_shell_server/ tests/
mypy linux_shell_server/
1. Claude桌面无法连接到MCP服务器
2. 执行命令时出现权限错误
3. 模块未找到错误
PYTHONPATH设置是否正确要以调试模式运行服务器进行故障排除:
# 激活虚拟环境
source yourEnv/bin/activate
# 直接运行服务器
python -m linux_shell_server.main
本项目根据MIT许可证发布