MCP SSH 服务器
一个功能强大的 SSH 服务器实现,适用于模型上下文协议 (MCP)。此服务器通过 SSH 协议启用安全的远程命令执行和文件操作,支持密码和基于密钥的身份验证。
功能
- ✨ 安全的 SSH 连接管理
- 🔑 密码和基于密钥的身份验证
- 💻 远程命令执行
- 📁 文件操作(上传/下载)
- 📊 传输进度跟踪
- 🔐 权限管理
- 📂 目录操作
- 🚀 批量文件传输
- 📝 详细日志记录
安装
- 安装包:
npm install mcp-ssh
- 将以下内容添加到您的 Claude 桌面配置 (
claude_desktop_config.json
) 中:
{
"mcpServers": {
"ssh": {
"command": "node",
"args": ["%APPDATA%/npm/node_modules/mcp-ssh/dist/server.js"],
"env": {
"SSH_PORT": "8889",
"SSH_LOG_LEVEL": "info"
}
}
}
}
使用方法
密码认证
$body = @{
id = "test"
host = "example.com"
port = 22
username = "user"
password = "pass123"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:8889/connect" -Method Post -Body $body -ContentType "application/json"
密钥认证
$body = @{
id = "test"
host = "example.com"
port = 22
username = "user"
privateKey = Get-Content ~/.ssh/id_rsa | Out-String
passphrase = "optional-key-passphrase"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:8889/connect" -Method Post -Body $body -ContentType "application/json"
执行命令
$execBody = @{
id = "test"
command = "ls -la"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:8889/exec" -Method Post -Body $execBody -ContentType "application/json"
文件操作
$uploadForm = @{
file = Get-Item -Path "localfile.txt"
remotePath = "/remote/path/file.txt"
}
Invoke-RestMethod -Uri "http://localhost:8889/upload/test" -Method Post -Form $uploadForm
Invoke-RestMethod -Uri "http://localhost:8889/download/test?remotePath=/remote/path/file.txt" -Method Get -OutFile "downloaded.txt"
目录操作
Invoke-RestMethod -Uri "http://localhost:8889/dir/list" -Method Get
Invoke-RestMethod -Uri "http://localhost:8889/dir/create?path=/remote/path/newdir" -Method Post
Invoke-RestMethod -Uri "http://localhost:8889/dir/delete?path=/remote/path/existdir" -Method Delete
开发
- 克隆仓库:
git clone [仓库地址]
cd mcp-ssh
- 安装依赖项:
npm install
- 构建项目:
npm run build
- 启动服务器:
npm start
环境变量
SSH_PORT
:SSH 服务端口,默认值为 8889
SSH_LOG_LEVEL
:日志级别,可选值为 debug
, info
, warning
, error
, 默认值为 info
贡献指南
- Fork 本仓库
- 创建功能分支
- 提交更改
- 推送到您的分支
- 创建 Pull Request
许可证
本项目采用 MIT 许可证。