Linux系统命令服务器

一个安全的Linux MCP服务器,允许AI(如Claude和Cursor)读取系统信息并通过PolicyKit执行命令。

  • by marcos2872
  • Rust
  • 本地部署
  • 5 星标
  • 更新于
在 GitHub 查看 marcos2872/linux-mcp

使用说明

Linux MCP服务器🚀

用于Linux的安全MCP服务器,允许IAs(如Claude和Cursor)通过PolicyKit读取系统信息并执行命令。


⚡ 快速安装

  1. 克隆和编译:
git clone https://github.com/marcos2872/os-mcp.git
cd os-mcp
cargo build --release

二进制将在: target/release/linux-mcp


⚙️ 配置(JSON)

添加到您的配置文件( 替换) /CAMINHO/PARA 真正的道路):

克劳德桌面版

~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "linux-mcp": {
      "command": "/CAMINHO/PARA/os-mcp/target/release/linux-mcp",
      "args": [],
      "env": {}
    }
  }
}

光标IDE/VS代码

.cursor/mcp_config.json 或 .vscode/mcp.json 工程根 :

{
  "mcpServers": {
    "linux-mcp": {
      "command": "/CAMINHO/PARA/os-mcp/target/release/linux-mcp",
      "args": [],
      "env": {}
    }
  }
}

检查员(目视测试)

直接在浏览器中测试服务器 :

npx @modelcontextprotocol/inspector ./target/release/linux-mcp

🛠️ 高级设置

服务器将自动创建配置文件 ~/.config/linux-mcp/:

  1. config.toml (动态允许列表):

    • 允许的命令列表。
    • 您可以编辑此文件以添加/删除命令而无需重新编译。
    • 编辑后重新启动服务器 。
  2. audit.log (审计追踪):

    • 所有已执行命令的完整日志 。
    • 显示日期、时间、命令、状态(允许/阻止)和详细信息。

📚 使用范例

1. 查看系统信息

{
  "name": "get_system_info",
  "arguments": { "info_type": "all" }
}

2. 执行命令 (安全)

允许的命令(Allowlist)可以用或不用root运行。

普通命令 :

{
  "name": "execute_command",
  "arguments": { "command": "ls -la" }
}

root 命令( 打开密码窗口) :

{
  "name": "execute_command",
  "arguments": { 
    "command": "apt update",
    "use_polkit": true 
  }
}

🛡️ 安全

此服务器在 安全模式:

  1. 允许名单只允许命令( 例如 : ls, grep, git, apt)可以执行。
  2. 无RM: 命令 rm 锁定,临时文件夹除外(/tmp)和轻。
  3. 政策工具包管理命令需要通过系统本机窗口输入您的密码。

📄 完整文档: