MCP Hub
Back to servers

SSH MCP Server

A toolset for executing commands and transferring files or directories on remote servers via SSH. It supports both direct connection parameters and pre-configured server profiles for seamless remote infrastructure management.

Updated
Feb 6, 2026

SSH MCP Server

基于 Model Context Protocol (MCP) 的 SSH 服务器工具集,支持在远程服务器上执行命令和传输文件。

两种使用方式

本工具支持两种连接 SSH 服务器的方式

方式一:直接参数(临时连接)

直接在工具调用中指定服务器信息,适合临时操作:

{
  "tool": "ssh_execute_command",
  "arguments": {
    "host": "192.168.1.100",
    "port": 22,
    "username": "root",
    "password": "your_password",
    "command": "docker ps"
  }
}

方式二:配置文件(推荐)

预先配置服务器信息,通过名称调用,适合频繁使用的服务器:

  1. 创建 ssh-mcp.config.json 配置文件
  2. 使用 server 参数指定服务器名称
{
  "tool": "ssh_execute_command",
  "arguments": {
    "server": "production",
    "command": "docker ps"
  }
}

优势:

  • 无需每次输入密码
  • 支持多服务器配置
  • 通过 ssh_list_servers 工具查询可用服务器
  • Agent 可自主发现并使用服务器

安装

npm install
npm run build

MCP 客户端配置

OpenCode

配置文件位置:C:\Users\<用户名>\.config\opencode\opencode.jsonc

{
  "mcp": {
    "ssh-mcp": {
      "type": "local",
      "command": ["node", "path/to/ssh-mcp/dist/index.js"],
      "enabled": true
    }
  }
}

Claude Code

配置文件位置:C:\Users\<用户名>\.claude\CLAUDE.json

{
  "mcpServers": {
    "ssh-mcp": {
      "command": "node",
      "args": ["/path/to/ssh-mcp/dist/index.js"],
      "disabled": false
    }
  }
}

Claude Desktop

配置文件位置:

  • Windows: %APPDATA%/Claude/claude_desktop_config.json
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "ssh-mcp": {
      "command": "node",
      "args": ["/path/to/ssh-mcp/dist/index.js"],
      "disabled": false
    }
  }
}

SSH 配置文件

创建配置文件

{
  "servers": {
    "production": {
      "host": "192.168.1.100",
      "port": 22,
      "username": "root",
      "password": "your_password",
      "timeout": 60000
    },
    "development": {
      "host": "192.168.1.50",
      "port": 2222,
      "username": "admin",
      "password": "dev_password"
    }
  },
  "defaultServer": "development"
}

配置文件位置(按优先级)

  1. SSH_MCP_CONFIG 环境变量指定路径
  2. 当前项目目录 ssh-mcp.config.json
  3. 当前项目目录 .ssh-mcp-config.json
  4. 用户主目录 .ssh-mcp-config.json

配置文件参数说明

参数必填默认值说明
host-SSH 服务器地址
port22SSH 端口
username-用户名
password-密码
timeout30000超时时间(毫秒)

使用示例

列出所有已配置的服务器

{
  "tool": "ssh_list_servers"
}

ssh_execute_command - 执行命令

使用配置文件中的服务器:

{
  "tool": "ssh_execute_command",
  "arguments": {
    "server": "production",
    "command": "docker ps -a"
  }
}

直接指定参数:

{
  "tool": "ssh_execute_command",
  "arguments": {
    "host": "192.168.1.100",
    "port": 22,
    "username": "root",
    "password": "123",
    "command": "df -h",
    "response_format": "markdown"
  }
}

指定工作目录:

{
  "tool": "ssh_execute_command",
  "arguments": {
    "server": "production",
    "working_dir": "/var/www/app",
    "command": "npm run build"
  }
}

ssh_upload_file - 上传文件

使用配置文件:

{
  "tool": "ssh_upload_file",
  "arguments": {
    "server": "production",
    "local_path": "./config/app.yml",
    "remote_path": "/etc/myapp/config.yml"
  }
}

直接指定参数:

{
  "tool": "ssh_upload_file",
  "arguments": {
    "host": "192.168.1.100",
    "port": 22,
    "username": "root",
    "password": "123",
    "local_path": "./deploy.sh",
    "remote_path": "/opt/deploy/deploy.sh"
  }
}

ssh_download_file - 下载文件

从服务器下载日志文件:

{
  "tool": "ssh_download_file",
  "arguments": {
    "server": "production",
    "remote_path": "/var/log/app/error.log",
    "local_path": "./logs/error.log"
  }
}

指定输出格式:

{
  "tool": "ssh_download_file",
  "arguments": {
    "server": "development",
    "remote_path": "/etc/nginx/nginx.conf",
    "local_path": "./config/nginx.conf",
    "response_format": "json"
  }
}

ssh_upload_directory - 上传目录

部署应用到服务器:

{
  "tool": "ssh_upload_directory",
  "arguments": {
    "server": "production",
    "local_path": "./dist",
    "remote_path": "/var/www/myapp"
  }
}

同步配置目录:

{
  "tool": "ssh_upload_directory",
  "arguments": {
    "server": "development",
    "local_path": "./config",
    "remote_path": "/etc/myapp/config"
  }
}

ssh_download_directory - 下载目录

下载服务器日志目录:

{
  "tool": "ssh_download_directory",
  "arguments": {
    "server": "production",
    "remote_path": "/var/log/myapp",
    "local_path": "./logs"
  }
}

备份项目目录:

{
  "tool": "ssh_download_directory",
  "arguments": {
    "server": "production",
    "remote_path": "/opt/project",
    "local_path": "./backup/project"
  }
}

工具列表

工具说明
ssh_list_servers列出所有已配置的服务器
ssh_execute_command执行命令
ssh_upload_file上传文件
ssh_download_file下载文件
ssh_upload_directory上传目录
ssh_download_directory下载目录

ssh_execute_command 参数

参数类型必填说明
serverstring服务器名称(配置文件)
hoststringSSH 服务器地址
portnumberSSH 端口,默认 22
usernamestring用户名
passwordstring密码
timeoutnumber超时时间(毫秒)
commandstring要执行的命令
working_dirstring工作目录
response_formatstring输出格式(markdown/json)

ssh_upload_file 参数

参数类型必填说明
serverstring服务器名称(配置文件)
hoststringSSH 服务器地址
portnumberSSH 端口,默认 22
usernamestring用户名
passwordstring密码
timeoutnumber超时时间(毫秒)
local_pathstring本地文件路径
remote_pathstring远程目标路径
response_formatstring输出格式(markdown/json)

ssh_download_file 参数

参数类型必填说明
serverstring服务器名称(配置文件)
hoststringSSH 服务器地址
portnumberSSH 端口,默认 22
usernamestring用户名
passwordstring密码
timeoutnumber超时时间(毫秒)
remote_pathstring远程文件路径
local_pathstring本地目标路径
response_formatstring输出格式(markdown/json)

ssh_upload_directory 参数

参数类型必填说明
serverstring服务器名称(配置文件)
hoststringSSH 服务器地址
portnumberSSH 端口,默认 22
usernamestring用户名
passwordstring密码
timeoutnumber超时时间(毫秒)
local_pathstring本地目录路径
remote_pathstring远程目标目录
response_formatstring输出格式(markdown/json)

ssh_download_directory 参数

参数类型必填说明
serverstring服务器名称(配置文件)
hoststringSSH 服务器地址
portnumberSSH 端口,默认 22
usernamestring用户名
passwordstring密码
timeoutnumber超时时间(毫秒)
remote_pathstring远程目录路径
local_pathstring本地目标目录
response_formatstring输出格式(markdown/json)

Reviews

No reviews yet

Sign in to write a review