ssh-client-mcp-server

v1.6.3
io.github.sapientsai/ssh-client-mcp-server Checked 14 hours ago Published 2 days ago

MCP server for executing shell commands on remote hosts via SSH.

Built on somamcp — a functional MCP framework on the MCP TypeScript SDK 2.x, with telemetry and introspection. These live in sapientsai/mcp-servers, a pnpm workspace of MCP servers, as three folders: For the fleet server, start with its README: first run, fleet_setup, audit log, policy, CA mode, and running on several machines (where to register it, installing on a hub, per-hub keys versus CA mode, macOS hosts).

Summary extracted from the README.

SSH Client MCP Server

License: MIT NPM Version CI

SSH Client MCP Server is a local Model Context Protocol (MCP) server that lets LLMs and other MCP clients execute shell commands on remote hosts over SSH. It runs from Linux, macOS, or Windows and targets any reachable SSH server (Linux, macOS, Windows with OpenSSH, etc.).

Built on somamcp — a functional MCP framework on the MCP TypeScript SDK 2.x, with telemetry and introspection.

Contents

Monorepo

These live in sapientsai/mcp-servers, a pnpm workspace of MCP servers, as three folders:

Folder npm name Role
servers/ssh-core @ssh-mcp/core (private) Shared SSH pool, tmux command builders, and auth resolution. Bundled into the other packages; not published separately.
servers/ssh-client (this folder) ssh-client-mcp-server Single-host MCP server (the original package). exec + tmux_* tools for one configured SSH host.
servers/ssh-fleet ssh-fleet-mcp-server Multi-host fleet MCP server. Host-routed exec + tmux_* tools driven by a TOML fleet config.

For the fleet server, start with its README: first run, fleet_setup, audit log, policy, CA mode, and running on several machines (where to register it, installing on a hub, per-hub keys versus CA mode, macOS hosts).

Run every server's checks from the repo root:

pnpm validate

Quick Start

  1. Configure your MCP client (Claude Desktop, Cursor, Cline, etc.) to launch this server via npx — see Client Setup.
  2. Ask your LLM to run shell commands on the target host.

No global install required — npx fetches and runs the latest published version.

Features

  • Single exec tool — runs a shell command on the remote host. A non-zero exit is the failure; a command that exits 0 succeeds even if it wrote to stderr, and its stderr follows stdout under a [stderr] marker. A failure reads exit <code>: then stderr, then stdout under [stdout]; a command a signal ended reads exit 137 (signal KILL).
  • Four auth modes — password, key file, key from environment variable (e.g. injected by envpkt, Vault, Doppler), or SSH_AUTH_SOCK (system ssh-agent, 1Password, Bitwarden Desktop, KeePassXC).
  • Smart path expansion — --key supports ~, $VAR, ${VAR}, and relative paths via functype-os. Unresolved variables fail fast with a typed error.
  • OS-user fallback — --user defaults to the current OS username when omitted.
  • Fail-fast auth — the SSH key is loaded and validated at server startup, not on the first exec call.
  • Introspection out-of-the-box — an info tool, auto-registered by somamcp, reports the server's name, version, runtime, and tool counts.
  • Cross-platform — runs on Linux, macOS, Windows (anywhere Node 22+ runs).

Tools

Tool Description
exec Execute a shell command on the remote SSH server and return its output.
info Server name, version, runtime, and registered tool counts.

Persistent sessions (tmux)

For driving long-running interactive processes (e.g. a remote coding agent) across calls, the server exposes tmux-backed tools. tmux must be installed on the remote host.

  • tmux_list — list live tmux sessions.
  • tmux_send({ session?, input, submit? }) — type input into session (created if absent); presses Enter unless submit: false.
  • tmux_read({ session?, lines? }) — return the recent pane transcript (lines default 200, max 2000).
  • tmux_keys({ session?, keys }) — send control/special keys, e.g. { keys: ["C-c"] }.

The tmux tools find tmux on the host's PATH, then in /opt/homebrew/bin and /usr/local/bin. That covers Homebrew on macOS, where a command sent over SSH gets only /usr/bin:/bin:/usr/sbin:/sbin. exec gets no such help: to run other Homebrew tools through it, load Homebrew's PATH in the host's ~/.zshenv.

They need a POSIX login shell, such as sh, bash or zsh, for the SSH account: sshd runs each command with it, and csh, tcsh and fish can't parse the commands. On such an account the tools fail and say so; exec is unaffected.

session defaults to --tmux-session (default agent). Tip: run agents in a line-oriented mode (not a full-screen TUI) so tmux_read returns a clean transcript.

Installation

No install step — your MCP client launches it on demand. See Client Setup.

Global install

npm install -g ssh-client-mcp-server
# then:
ssh-client-mcp-server --host=1.2.3.4 --user=root --password=pass

From source (for contributors)

git clone https://github.com/sapientsai/mcp-servers.git
cd mcp-servers
pnpm install
cd servers/ssh-client
pnpm build

Configuration

The server reads SSH connection info from CLI flags:

Flag Required Default Description
--host yes — Hostname or IP of the remote SSH server.
--user no OS username SSH username. Falls back to the local OS user (whoami) when omitted.
--port no 22 SSH port.
--password no* — SSH password.
--key no* — Path to a private SSH key. Supports ~, $VAR, ${VAR}, and relative paths.
--key-env no* — Name of an env var holding the private key PEM (e.g. injected by envpkt, Vault, Doppler).
--agent no* — Set to true to use SSH_AUTH_SOCK (system ssh-agent, 1Password, Bitwarden Desktop, KeePassXC).

*Auth precedence is --password → --key → --key-env → --agent. If none are set the server starts but ssh2 will fail to authenticate on first exec.

A config the startup check rejects doesn't stop the server either. The check catches a missing --host, no --user when the OS user can't be found, a non-numeric --port, an invalid --tmux-session, and auth that can't be set up: a --key that can't be read, a --key-env variable that isn't set, or --agent with no SSH_AUTH_SOCK. The server prints a warning on stderr, starts, and lists its tools. Until the flags are fixed, exec and the tmux_* tools fail with the reason, ahead of a bad session name or key; info still works. A call that doesn't match the tool's input schema, such as exec with no command, still gets that error first. The check doesn't cover everything: an out-of-range --port fails only when a tool connects, and an unknown flag is ignored. So the client shows the problem, and a registry that starts the server with no flags can still list its tools.

Pulling keys from a password manager (Bitwarden / 1Password / KeePassXC)

Each of these can expose your SSH keys via SSH_AUTH_SOCK. Unlock the vault, confirm the agent is enabled, then run with --agent=true — the server never sees the private key.

# verify the agent is reachable
ssh-add -l

# launch the MCP server through it
ssh-client-mcp-server --host=1.2.3.4 --user=root --agent=true

For Bitwarden Desktop ≥ 2024.12: enable Settings → SSH agent, then on macOS confirm launchctl getenv SSH_AUTH_SOCK points at Bitwarden's socket.

Pulling keys from envpkt (or any tool that injects env vars)

Store the PEM as a sealed value in envpkt.toml, then launch via envpkt exec:

envpkt exec -- ssh-client-mcp-server --host=1.2.3.4 --user=root --key-env=MY_SSH_KEY

Same pattern works for HashiCorp Vault, Doppler, Infisical, AWS Secrets Manager, or any wrapper that lands the key in process.env.

Client Setup

Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "ssh-client-mcp-server": {
      "command": "npx",
      "args": ["-y", "ssh-client-mcp-server", "--host=1.2.3.4", "--user=root", "--key=~/.ssh/id_ed25519"]
    }
  }
}

Password auth

Replace the --key arg with --password=hunter2. Avoid checking this into version control.

Using the current OS user

Omit --user entirely — the server defaults to your local username.

Other MCP clients

Any client that speaks the stdio MCP transport works. Same command / args shape.

Testing

Against a published build

npx @modelcontextprotocol/inspector npx ssh-client-mcp-server --host=1.2.3.4 --user=root --key=~/.ssh/id_ed25519

Against a local build (after pnpm build)

pnpm inspect

This builds and launches the MCP Inspector pointed at dist/index.js.

Development

All tooling is delegated to ts-builds:

pnpm validate      # format → lint → typecheck → test → build
pnpm run ci        # validate's checks without fixing, as CI runs them (type `run`: `pnpm ci` is a clean install)
pnpm test          # vitest run
pnpm test:watch    # vitest watch mode
pnpm build         # production build to dist/
pnpm dev           # tsdown watch mode to lib/
pnpm inspect       # build + launch MCP Inspector

Pure helpers (parseArgv, validateConfig, resolveAuth, effectiveUser) live in src/config.ts and are covered by test/config.spec.ts (18 cases, including tempfile-backed key reads and env-var expansion).

Disclaimer

Provided under the MIT License. Use at your own risk. Not affiliated with or endorsed by any SSH vendor or MCP provider. Be careful granting LLMs shell access — audit commands, restrict target-account privileges, and consider a jump box.

Contributing

Issues and PRs welcome at sapientsai/mcp-servers. Please run pnpm validate before submitting.


Maintained by Jordan Burke · Affiliated with SapientsAI