mcp-ssh-server-tool
v2.0.1
Published
MCP Server for SSH connections and remote command execution
Maintainers
Readme
SSH MCP Server
一个用于 SSH 连接和远程命令执行的 MCP (Model Context Protocol) 服务器。
功能
- 🔐 密码认证 - 使用用户名和密码连接到 SSH 服务器
- 🔑 公钥认证 - 使用私钥文件连接到 SSH 服务器
- 💻 远程命令执行 - 在连接的服务器上执行命令并获取输出
- 📊 会话管理 - 管理多个 SSH 连接会话
安装
npx -y mcp-ssh-server-toolMCP 工具
ssh_connect
建立 SSH 连接
参数:
host: 服务器地址 (必需)port: 端口号 (默认: 22)username: 用户名 (必需)auth_type: 认证方式 - "password" | "public_key" (必需)password: 密码 (auth_type 为 password 时必需)private_key_path: 私钥路径 (auth_type 为 public_key 时必需)passphrase: 私钥密码 (可选)timeout: 连接超时 (默认: 10秒)
ssh_exec
在 SSH 会话中执行命令
参数:
session_id: SSH 会话 ID (必需)command: 要执行的命令 (必需)
返回:
stdout: 标准输出stderr: 标准错误exitCode: 退出码
ssh_disconnect
断开 SSH 连接
参数:
session_id: SSH 会话 ID (必需)
ssh_list_sessions
列出所有活动的 SSH 会话
使用示例
1. 密码认证连接
{
"host": "192.168.1.100",
"port": 22,
"username": "admin",
"auth_type": "password",
"password": "your_password"
}2. 公钥认证连接
{
"host": "192.168.1.100",
"port": 22,
"username": "admin",
"auth_type": "public_key",
"private_key_path": "/home/user/.ssh/id_rsa"
}3. 执行命令
{
"session_id": "<从 ssh_connect 返回的 session_id>",
"command": "ls -la /home"
}4. 断开连接
{
"session_id": "<session_id>"
}依赖
- Node.js >= 18.0.0
- ssh2 >= 1.15.0
- uuid >= 9.0.0
License
MIT
