Skip to main content
Glama
README.md
# mcp-ssh

[![CI](https://github.com/jiwonchang/mcp-ssh/actions/workflows/ci.yml/badge.svg)](https://github.com/jiwonchang/mcp-ssh/actions/workflows/ci.yml)

An [MCP](https://modelcontextprotocol.io) server that gives AI agents SSH access to remote hosts.

An agent with a shell can already run `ssh host "command"`. This server adds what that lacks:

- **Pooled connections.** One connection per host stays open between tool calls, so a call costs milliseconds instead of a new handshake. Dropped connections re-open on the next call.
- **Bounded output.** Command output is capped, keeping the start and end and dropping the middle, so a large log cannot flood the model's context.
- **Credential isolation.** The model refers to hosts by name. Keys, passwords and passphrases never appear in tool input or output, and cannot be placed in the config file.
- **Strict host key checking.** A host must match a pinned fingerprint or your `known_hosts`. The model has no way to accept a new key.
- **File operations over SFTP.** Reading and writing files does not depend on shell quoting, and writes are atomic.

> **Status: early development (`0.1.0-dev`).** The tools below work and are tested. See [Roadmap](#roadmap) for what is not built yet.

## Tools

| Tool | What it does |
|---|---|
| `ssh_list_hosts` | Lists configured hosts and whether each is connected. |
| `ssh_exec` | Runs a non-interactive command. Returns exit code, stdout and stderr. Takes `cwd`, `timeoutSec` and `maxOutputBytes`. |
| `ssh_read_file` | Reads a file, or a byte range of one. |
| `ssh_write_file` | Creates or replaces a file atomically, keeping an existing file's permissions. |
| `ssh_list_dir` | Lists a directory with type, size and modification time. |

## Setup

Requires Node.js 20 or later.

```sh
git clone https://github.com/jiwonchang/mcp-ssh.git
cd mcp-ssh
npm install
npm run build
```

### 1. Describe your hosts

Create `~/.mcp-ssh/hosts.json` (or point the `MCP_SSH_CONFIG` environment variable at another path). See [examples/hosts.example.json](examples/hosts.example.json).

```json
{
  "hosts": {
    "web1": {
      "host": "192.0.2.10",
      "username": "deploy",
      "description": "Production web server"
    }
  }
}
```

| Field | Default | Meaning |
|---|---|---|
| `host` | required | Hostname or IP address. |
| `username` | required | Login user. |
| `port` | `22` | SSH port. |
| `auth` | `{ "type": "agent" }` | How to authenticate (below). |
| `hostKeyFingerprint` | none | Pins the host key, e.g. `SHA256:...` as printed by `ssh-keygen -lf`. |
| `description` | none | Shown to the model by `ssh_list_hosts`. |

Authentication methods:

- `{ "type": "agent" }` uses your SSH agent (`SSH_AUTH_SOCK`, or the OpenSSH agent service on Windows).
- `{ "type": "key", "path": "~/.ssh/id_ed25519", "passphraseEnv": "VAR" }` reads a private key file. `passphraseEnv` is optional and names an environment variable.
- `{ "type": "password", "env": "VAR" }` reads the password from an environment variable.

### 2. Trust each host key

The server connects only when the host key is trusted. Either:

- connect once yourself with `ssh user@host` so the key is recorded in `~/.ssh/known_hosts`, or
- set `hostKeyFingerprint` for the host.

Plain and hashed `known_hosts` entries are supported. Wildcard patterns and `@cert-authority` lines are not.

### 3. Register the server with your MCP client

The server speaks MCP over stdio: the client starts it on demand, so there is nothing to host or keep running.

Claude Code:

```sh
claude mcp add ssh -- node /absolute/path/to/mcp-ssh/dist/index.js
```

Other clients (Claude Desktop and similar) take an entry like this in their MCP configuration:

```json
{
  "mcpServers": {
    "ssh": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-ssh/dist/index.js"],
      "env": { "LAB_PASSWORD": "..." }
    }
  }
}
```

## Security model

This server lets a model run commands on your machines. Treat it accordingly.

- The model can run **any command the configured user can run**. There is no command filtering yet. Use a least-privilege account on each host.
- Only hosts in the config file are reachable. The model cannot supply an address, user or credential.
- Secrets are read from the SSH agent, key files or environment variables. The config schema rejects unknown fields, so a password cannot be stored in it by mistake.
- Host keys are always verified. An unknown or changed key refuses the connection and tells the model to ask you.
- Keep your MCP client's per-call approval on for `ssh_exec` and `ssh_write_file` unless you fully trust the task.

## Roadmap

- Background jobs: start, poll, tail and stop long-running commands that survive a disconnect.
- Interactive sessions (PTY) for prompts and REPLs.
- Per-host policy: read-only mode, command allow and deny lists.
- Audit log of every command and file change.
- Jump hosts and port forwarding.
- Line-based file reads and in-place string edits.
- Reading hosts from `~/.ssh/config`.
- Streamable HTTP transport for remote clients.

## Development

```sh
npm run typecheck   # type-check src and test
npm test            # build, then run all tests
```

Tests start a real SSH server in-process (using `ssh2`) and drive the built MCP server over stdio with the official MCP client, so no external host is needed. The test server has no SFTP subsystem, so the three file tools are not covered by automated tests yet.

See [CLAUDE.md](CLAUDE.md) for the code layout, [Docs/Changelog.md](Docs/Changelog.md) for changes, and [Docs/Conventions](Docs/Conventions) for versioning and workflow.

## License

[MIT](LICENSE)

TDQS

A4/5.0

Scored across 5 tools

Disambiguation4/5

Each tool has a clear primary purpose: host listing, command execution, file read, file write, and directory listing. The only overlap is that ssh_exec can perform many of the same file and directory operations as the SFTP tools, but the descriptions make the intended boundaries reasonably clear.

Naming Consistency5/5

All tools use the same ssh_ prefix and snake_case verb-based naming. The pattern is predictable across list, exec, read, write, and list operations.

Tool Count5/5

Five tools is well-scoped for an SSH/SFTP server and each tool earns its place. There is no redundant or obviously unnecessary tool.

Completeness4/5

The surface covers host discovery, command execution, file read/write, and directory listing, which supports most core workflows. It lacks explicit SFTP operations such as delete, rename, or mkdir, though ssh_exec can work around those gaps.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues