MCP SSH Server
镜像
简介
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/ls/test?path=/remote/path" -Method Get
环境变量
SSH_PORT
: 服务器端口 (默认: 8889)SSH_LOG_LEVEL
: 日志级别 (默认: info)
更多信息
查看完整功能列表和详细开发指南,请访问项目仓库。