ssh-mcp-dynamic

ssh-mcp-dynamic

A minimal MCP server that lets an MCP client run shell commands on remote hosts over SSH, with host, key, user, and port chosen per call.

Category
访问服务器

README

ssh-mcp-dynamic

A minimal Model Context Protocol (MCP) server that lets an MCP client (e.g. Claude Desktop) run shell commands on remote hosts over SSH. The host, private key, user and port are chosen per call, so a single server instance can reach many machines.

It exposes two tools:

Tool Description
ssh_exec Run a shell command on a remote host.
ssh_sudo_exec Run a shell command with sudo (don't include the sudo prefix yourself).

Authentication is key-based only (PEM private keys). No passwords are handled or stored.

Requirements

  • Node.js 18+
  • SSH access to the target hosts with a private key

Install & build

npm install
npm run build

This compiles src/index.ts to dist/index.js.

Configuration

Everything host-specific is supplied through environment variables — nothing is hardcoded in the source.

Variable Default Purpose
SSH_MCP_KEYS {} JSON object mapping key shortcuts to private-key paths. A leading ~ expands to the home directory.
SSH_MCP_DEFAULT_KEY (none) Shortcut or path used when a call omits key. If unset, key is required per call.
SSH_MCP_DEFAULT_USER root Default SSH username.
SSH_MCP_DEFAULT_PORT 22 Default SSH port.
SSH_MCP_TIMEOUT_MS 60000 Default command/connection timeout in milliseconds.

Example SSH_MCP_KEYS:

{
  "prod": "~/keys/prod.pem",
  "staging": "~/keys/staging.pem"
}

With that set, a call can pass "key": "prod" instead of a full path. You can also pass a full path directly at call time without configuring any shortcut.

Tool parameters

Both tools accept:

  • host (required) — IP or hostname.
  • command (required) — the shell command.
  • key — a configured shortcut or a path to the PEM file. Required unless SSH_MCP_DEFAULT_KEY is set.
  • user — SSH username (defaults to SSH_MCP_DEFAULT_USER).
  • port — SSH port (defaults to SSH_MCP_DEFAULT_PORT).
  • timeout — timeout in ms (defaults to SSH_MCP_TIMEOUT_MS).

Use with Claude Code (CLI)

The quickest way — no clone, no manual build. Claude Code runs it on demand via npx straight from GitHub.

Minimal — no environment config at all. You provide the host, command and a full key path on every call:

claude mcp add ssh-mcp -- npx -y github:Calevi-Consulting/ssh-mcp-dynamic

With shortcuts and defaults — preconfigure your keys once so calls can use a short name (e.g. prod) and omit the user/port:

claude mcp add ssh-mcp -s user \
  -e SSH_MCP_KEYS='{"prod":"~/keys/prod.pem"}' \
  -e SSH_MCP_DEFAULT_KEY=prod \
  -e SSH_MCP_DEFAULT_USER=ubuntu \
  -- npx -y github:Calevi-Consulting/ssh-mcp-dynamic

npx clones the repo, builds it (via the prepare script) and launches the server. Once published to npm you can drop the github: prefix and use npx -y ssh-mcp-dynamic.

Prefer a local checkout? Build it once and point Claude Code at the compiled file:

git clone https://github.com/Calevi-Consulting/ssh-mcp-dynamic.git
cd ssh-mcp-dynamic && npm install && npm run build

claude mcp add ssh-mcp -s user \
  -e SSH_MCP_KEYS='{"prod":"~/keys/prod.pem"}' \
  -e SSH_MCP_DEFAULT_KEY=prod \
  -- node "$(pwd)/dist/index.js"

Scopes (-s): local (default, current project only), user (all your projects), project (saved to a versioned .mcp.json to share with your team).

Verify with claude mcp list, or /mcp inside a session. Remove with claude mcp remove ssh-mcp.

Use with Claude Desktop

Add the server to your claude_desktop_config.json:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "ssh-mcp": {
      "command": "node",
      "args": ["/absolute/path/to/ssh-mcp-dynamic/dist/index.js"],
      "env": {
        "SSH_MCP_KEYS": "{\"prod\":\"~/keys/prod.pem\",\"staging\":\"~/keys/staging.pem\"}",
        "SSH_MCP_DEFAULT_KEY": "prod",
        "SSH_MCP_DEFAULT_USER": "ubuntu"
      }
    }
  }
}

Restart Claude Desktop after editing the config.

Usage

Once the server is registered, you don't call the tools directly — you ask your MCP client (Claude Code / Claude Desktop) in plain language and it invokes ssh_exec / ssh_sudo_exec for you. Some example prompts:

Using ssh-mcp, run `hostname && uptime` on 10.0.0.5 with the prod key.

Check the free disk space on staging.example.com (df -h) via ssh-mcp.

On 10.0.0.5, tail the last 50 lines of /var/log/syslog with sudo.

Restart nginx on web-01.example.com with sudo, then show `systemctl status nginx`.

Run `docker ps` on 203.0.113.10 as user ubuntu on port 2222 using ~/keys/prod.pem.

How those map to a tool call (the client fills this in for you):

// "run hostname on 10.0.0.5 with the prod key"
{
  "tool": "ssh_exec",
  "host": "10.0.0.5",
  "command": "hostname",
  "key": "prod"          // a configured shortcut, or a full path like ~/keys/prod.pem
}

// "tail syslog with sudo on 10.0.0.5"
{
  "tool": "ssh_sudo_exec",
  "host": "10.0.0.5",
  "command": "tail -n 50 /var/log/syslog"   // no 'sudo' prefix — the tool adds it
}

Tips:

  • Mention the host, the command, and which key/user/port when they aren't the configured defaults.
  • Naming the server ("using ssh-mcp…") helps the client pick the right tool when you have several MCP servers registered.
  • For privileged commands ask for "with sudo" so the client uses ssh_sudo_exec — and don't put sudo in the command yourself.

Security notes

  • This server executes arbitrary shell commands on remote hosts, including with sudo via ssh_sudo_exec. Only connect it to hosts and keys you control, and only run it with an MCP client you trust.
  • Private keys are read from disk at call time. Never commit private keys*.pem, *.key, and common key filenames are already in .gitignore.
  • Prefer keys that are passphrase-protected or scoped to specific hosts.
  • The server communicates over stdio with the local MCP client; it does not open any network listener of its own.

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选