SSH连接管理工具

SSH MCP Server是一个提供SSH访问的Model Context Protocol服务器,支持远程连接、命令执行、文件传输和交互式会话管理。

  • by kpanuragh
  • TypeScript
  • 本地部署
  • 5 星标
  • 更新于
在 GitHub 查看 kpanuragh/ssh-mcp

使用说明

SSH MCP服务器

一个MCP(模型上下文协议)服务器,提供具有Warp式终端体验的SSH访问。连接到远程服务器、执行命令、传输文件和管理交互式shell会话。

安装

npm install -g @kpanuragh/ssh-mcp

或者直接使用npx运行:

npx @kpanuragh/ssh-mcp

特性

  • SSH连接管理 -具有会话持久性的多个并发连接
  • 命令执行 -使用stdout/stderr捕获和退出代码运行命令
  • SFTP操作 -上传、下载和列出远程服务器上的文件
  • 交互式外壳 -基于PTY的交互式命令shell会话
  • 认证 -支持密码和SSH密钥身份验证

MCP工具

工具 说明
ssh_connect 建立与远程服务器的SSH连接
ssh_exec 在连接的服务器上执行命令
ssh_disconnect 关闭SSH会话
ssh_list_sessions 列出所有活动的SSH会话
sftp_upload 将文件上传到远程服务器
sftp_download 从远程服务器下载文件
sftp_list 列出远程目录中的文件
ssh_shell_start 启动交互式shell会话
ssh_shell_send 将输入发送到交互式shell
ssh_shell_read 从交互式shell读取输出
ssh_shell_close 关闭交互式shell会话

使用Claude Desktop

添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "ssh": {
      "command": "npx",
      "args": ["@kpanuragh/ssh-mcp"]
    }
  }
}

工作流示例

1.连接到服务器

{
  "tool": "ssh_connect",
  "arguments": {
    "host": "example.com",
    "username": "user",
    "password": "password"
  }
}

或者使用SSH密钥:

{
  "tool": "ssh_connect",
  "arguments": {
    "host": "example.com",
    "username": "user",
    "privateKeyPath": "/home/user/.ssh/id_rsa"
  }
}

2.执行命令

{
  "tool": "ssh_exec",
  "arguments": {
    "sessionId": "uuid-from-connect",
    "command": "ls -la"
  }
}

3.传输文件

{
  "tool": "sftp_upload",
  "arguments": {
    "sessionId": "uuid-from-connect",
    "localPath": "/local/file.txt",
    "remotePath": "/remote/file.txt"
  }
}

4.交互式外壳

{
  "tool": "ssh_shell_start",
  "arguments": {
    "sessionId": "uuid-from-connect"
  }
}
{
  "tool": "ssh_shell_send",
  "arguments": {
    "sessionId": "uuid-from-connect",
    "shellId": "shell-uuid",
    "input": "cd /var/log\n"
  }
}

5.断开连接

{
  "tool": "ssh_disconnect",
  "arguments": {
    "sessionId": "uuid-from-connect"
  }
}

许可证

麻省理工学院