Skip to main content
Glama

mcp-ssh

CI

An MCP 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 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.

Related MCP server: SSH MCP Server

Setup

Requires Node.js 20 or later.

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.

{
  "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:

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:

{
  "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

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 for the code layout, Docs/Changelog.md for changes, and Docs/Conventions for versioning and workflow.

License

MIT

Available Tools

5 tools
ssh_execRun a remote commandA
Destructive

Runs a shell command on a host and returns its exit code, stdout and stderr. The command gets no stdin and no terminal, so it must be non-interactive. Each call starts a fresh shell: use cwd, or chain with &&, instead of relying on an earlier cd. Large output is truncated in the middle; narrow it with grep, head or tail.

Inputs: host (required), command (required), cwd, timeoutSec, +1 more.

ssh_list_dirList a remote directoryA
Read-only

Lists the entries of a directory on a host over SFTP, with type, size and modification time.

Inputs: host (required), path (required).

ssh_list_hostsList SSH hostsA
Read-only

Lists the hosts this server can connect to. Other tools take one of these names.

Inputs: no named parameters.

ssh_read_fileRead a remote fileA
Read-only

Reads a text file from a host over SFTP. Returns at most maxBytes starting at byte offset; the first line of the result says how much of the file was returned.

Inputs: host (required), path (required), offset, maxBytes.

ssh_write_fileWrite a remote fileA
DestructiveIdempotent

Creates or replaces a text file on a host over SFTP. The whole file is replaced with content. An existing file keeps its permission bits. The parent directory must exist.

Inputs: host (required), path (required), content (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    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

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Enables AI assistants to securely execute remote SSH commands, perform file transfers, and monitor system status through a standardized interface. It features robust security controls including command whitelisting, blacklisting, and credential isolation to prevent unauthorized operations.
      10
      20 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to securely execute commands, transfer files, and manage port forwarding on remote servers via SSH.
      114 npm
      38
      Apache 2.0
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to securely execute commands on remote hosts via SSH and SFTP, with persistent shells, file transfers, screenshots, and an audit log.
      5
      MIT