SSH MCP Server

SSH MCP Server

An MCP server that lets an AI assistant run commands and transfer files over SSH without exposing connection details.

Category
访问服务器

README

SSH MCP Server

An MCP server that lets an AI assistant (Claude Code, Claude Desktop, etc.) run commands and transfer files over SSH — without ever seeing your real connection details. The assistant only works with aliases like prod or server1; hostnames, usernames, keys, and passwords stay on your machine.

Built on the official @modelcontextprotocol/sdk and ssh2, with an optional passthrough mode that shells out to your system ssh/scp and reads ~/.ssh/config.

Why

  • Credentials never reach the model. Real host/user/IP live in your local config (or ~/.ssh/config) and are scrubbed from all output before the assistant sees it.
  • Alias-only surface. The assistant calls ssh_exec("prod", "..."); it has no idea what prod resolves to.
  • Real scp/rsync/ProxyJump support via passthrough mode when you want it.

Tools

Tool Description
ssh_exec Run a command on a server. Returns stdout/stderr/exit code.
ssh_upload Upload a file, a glob (logs/*.gz), or a whole directory (recursive=true). preserve=true keeps mode+timestamps (scp -p).
ssh_download Download a file, a glob, or a whole directory (recursive=true). Same preserve option.
ssh_list List a remote directory.
ssh_list_servers List configured aliases and their descriptions. Never exposes hosts.

Install

git clone <this-repo> sshmcp
cd sshmcp
npm install

Requires Node 18+. Passthrough mode additionally needs the OpenSSH client (ssh/scp) on your PATH — built into Windows 10/11, macOS, and Linux.

Configure your servers

Create ~/.claude/ssh-servers.json (or anywhere, and point SSH_CONFIG_PATH at it). Each entry is an alias. Pick one auth method per server.

A. SSH key (recommended)

{
  "server1": {
    "description": "Main deploy box",
    "host": "10.0.0.5",
    "port": 22,
    "username": "deploy",
    "privateKeyPath": "~/.ssh/id_ed25519"
  }
}

B. Password from an environment variable

{
  "box": {
    "host": "10.0.0.6",
    "username": "admin",
    "passwordEnv": "BOX_PASS"
  }
}

Then export BOX_PASS before the server starts.

C. Direct password (local/testing only)

{
  "box": { "host": "10.0.0.6", "username": "admin", "password": "secret" }
}

D. SSH-config passthrough (most secure, full scp/rsync)

{
  "prod": { "description": "Main prod", "sshConfigHost": "prod" }
}

When an entry has sshConfigHost, the tools shell out to the system ssh/scp using that Host alias from ~/.ssh/config. HostName, User, IdentityFile, ProxyJump, etc. all come from there and never appear in this file — no credentials live in ssh-servers.json at all. Real hostnames/users/IPs are scrubbed from output.

  • "sshConfigHost": true reuses the JSON alias as the Host name.
  • "sshConfigHost": "prod" maps to a differently-named Host in ~/.ssh/config.
  • Requires key/agent auth (ssh config holds no passwords).

Methods can be mixed freely across servers in one file. See ssh-servers.example.json.

Register with Claude Code

claude mcp add ssh --scope user -- node /absolute/path/to/sshmcp/ssh-server.js

MCP servers are not configured in settings.json — use claude mcp add (writes ~/.claude.json) or a project .mcp.json.

Set a custom config path with the SSH_CONFIG_PATH env var if you don't use ~/.claude/ssh-servers.json.

After adding (or editing the server), fully restart Claude Code — MCP tools load at session startup, so a running session won't pick up changes.

Usage examples

# run a command
ssh_exec(serverAlias="prod", command="systemctl status nginx")

# upload a build, preserving permissions and timestamps
ssh_upload(serverAlias="prod", localPath="./dist", remotePath="/var/www/app", recursive=true, preserve=true)

# pull all logs matching a glob
ssh_download(serverAlias="prod", remotePath="/var/log/*.log", localPath="./logs")

Security model

  • The config file holds credentials and is .gitignored. chmod 600 ~/.claude/ssh-servers.json.
  • Connection errors are sanitized — host/IP/username are replaced with the alias before returning.
  • Passthrough mode resolves the real host/user via ssh -G server-side only to scrub them from output; that data never enters the assistant's context.
  • Prefer keys or passwordEnv over inline passwords.

Notes & limitations

  • Windows + preserve: timestamps are preserved reliably in both directions; Unix permission bits are limited by what Windows (NTFS) can represent — Windows has no execute bit, so a 755 source becomes 666 when Windows is one end. Linux↔Linux (server-to-server style) is unaffected.
  • Glob matches a single directory level; use recursive=true for whole trees.
  • Symlinks are skipped during recursive directory walks to avoid cycles.
  • Passwords are not supported in passthrough mode (ssh config holds none); give those hosts a key to use mode D.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选