MCP SSH Server

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
} | 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)

更多资源

详细文档和源代码请访问: https://github.com/shaike1/mcp-server-ssh