# ssh-mcp **Repository Path**: freedom_steven/ssh-mcp ## Basic Information - **Project Name**: ssh-mcp - **Description**: 远程连接ssh的mcp工具 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-02-04 - **Last Updated**: 2026-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SSH MCP Tools 独立的SSH远程控制MCP工具包,基于Model Context Protocol标准实现。 ## 功能特性 - ✅ 统一的SSH连接管理 - ✅ 支持密码和私钥认证 - ✅ 命令执行(支持sudo) - ✅ 批量命令执行 - ✅ 预定义部署任务 - ✅ 连接状态管理 - ✅ X11转发支持(用于图形界面应用) ## 安装依赖 ```bash npm install # 或 yarn install ``` ## 启动服务 ```bash # 生产模式 npm start # 开发模式(自动重启) npm run dev ``` ## 使用示例 ### 1. 建立SSH连接 ```javascript { operationType: "connect", host: "10.56.23.14", username: "steven", password: "your_password" } ``` ### 2. 执行命令 ```javascript { operationType: "execute", connectionId: "steven@10.56.23.14:22", command: "ls -la" } ``` ### 3. 启用X11转发连接(用于图形界面应用) ```javascript { operationType: "connect", host: "10.56.23.14", username: "steven", password: "your_password", x11: true, // 启用X11转发 x11Authentication: "MIT-MAGIC-COOKIE-1" // X11认证类型 } ``` ### 4. 在X11转发连接上执行图形界面应用 ```javascript { operationType: "execute", connectionId: "steven@10.56.23.14:22", command: "export DISPLAY=:0 && xclock", // 运行图形界面应用 useSudo: false } ``` ### 5. 执行sudo命令 ```javascript { operationType: "execute", connectionId: "steven@10.56.23.14:22", command: "lspci -vv -s 02:00.0", useSudo: true, sudoPassword: "your_sudo_password" } ``` ### 6. 批量执行命令 ```javascript { operationType: "batch_execute", connectionId: "steven@10.56.23.14:22", commands: [ "pwd", "ls -la", "date" ] } ``` ### 7. 部署任务 ```javascript { operationType: "deploy", connectionId: "steven@10.56.23.14:22", task: "git_pull" // git_pull, npm_install, docker_build, service_restart } ``` ### 8. 断开连接 ```javascript { operationType: "disconnect", connectionId: "steven@10.56.23.14:22" } ``` ### 9. 列出连接 ```javascript { operationType: "list_connections" } ``` ### 10. 检查并连接设备 ```javascript { operationType: "check_and_connect", host: "10.56.23.14", username: "steven", password: "your_password" } ``` ## 工具参数说明 ### ssh_remote_control 工具参数 - `operationType`: 操作类型 (connect, execute, batch_execute, deploy, disconnect, list_connections, check_and_connect) - `host`: 目标主机地址 (connect操作必需) - `port`: SSH端口号,默认22 - `username`: 用户名 (connect操作必需) - `password`: 密码 (connect操作可选) - `privateKeyPath`: 私钥文件路径 (可选) - `command`: 要执行的命令 (execute操作必需) - `commands`: 要批量执行的命令数组 (batch_execute操作必需) - `connectionId`: 连接ID (execute, batch_execute, deploy, disconnect操作必需) - `useSudo`: 是否使用sudo执行命令,默认false - `sudoPassword`: sudo密码 (如果useSudo为true则需要) - `x11`: 是否启用X11转发,用于图形界面应用支持,默认false - `x11Authentication`: X11认证类型 ('MIT-MAGIC-COOKIE-1' 或 'XDM-AUTHORIZATION-1'),默认'MIT-MAGIC-COOKIE-1' ## 错误处理 - 错误码 -32601: 未知方法 - 错误码 -32603: 内部错误 - 错误码 -32700: JSON解析错误 ## 许可证 MIT License