Skip to main content
Glama
Calevi-Consulting

ssh-mcp-dynamic

ssh-mcp-dynamic

CI npm

A minimal Model Context Protocol (MCP) server that lets an MCP client (Claude Code, 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.

Contents: Quick start · Usage · Configuration · Security model · Development · License

Quick start

You need Node.js 18+ on the machine that runs your MCP client, and SSH access to the target hosts with a private key. The server is published on npm as @calevi/ssh-mcp-dynamic; npx downloads and runs it on demand, so there is nothing to clone or build.

Claude Code (CLI)

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 @calevi/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, bound the reachable hosts, and keep an audit log:

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 \
  -e SSH_MCP_ALLOWED_HOSTS='10.0.0.*,*.internal.example.com' \
  -e SSH_MCP_AUDIT_LOG=~/.ssh-mcp/audit.log \
  -- npx -y @calevi/ssh-mcp-dynamic

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.

To pin an exact version use npx -y @calevi/ssh-mcp-dynamic@1.1.2. To run straight from GitHub instead (a tagged release, or main without the #tag), use npx -y github:Calevi-Consulting/ssh-mcp-dynamic#v1.1.2; npx then clones and builds it via the prepare script. For a local checkout see Development.

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": "npx",
      "args": ["-y", "@calevi/ssh-mcp-dynamic"],
      "env": {
        "SSH_MCP_KEYS": "{\"prod\":\"~/keys/prod.pem\",\"staging\":\"~/keys/staging.pem\"}",
        "SSH_MCP_DEFAULT_KEY": "prod",
        "SSH_MCP_DEFAULT_USER": "ubuntu",
        "SSH_MCP_ALLOWED_HOSTS": "10.0.0.*,*.internal.example.com",
        "SSH_MCP_AUDIT_LOG": "~/.ssh-mcp/audit.log"
      }
    }
  }
}

Restart Claude Desktop after editing the config.

Related MCP server: ssh-chat-mcp

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.

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.

SSH_MCP_ALLOWED_HOSTS

(any)

Comma-separated allowlist of hostnames / IPs. * and ? wildcards, case-insensitive. Calls to any other host are refused before a connection is attempted.

SSH_MCP_HOST_KEY_CHECKING

strict

strict, accept-new or off. See Host key verification.

SSH_MCP_KNOWN_HOSTS

~/.ssh/known_hosts

known_hosts file consulted for host key verification.

SSH_MCP_AUDIT_LOG

(none)

File that receives one JSON line per call. Records are always written to stderr as well. See Audit log.

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).

Host allowlist

Set SSH_MCP_ALLOWED_HOSTS to bound which machines the model can reach, regardless of what it puts in host:

SSH_MCP_ALLOWED_HOSTS='10.0.0.*,*.internal.example.com,web-01'

A call to a host outside the list returns an error and is recorded in the audit log with "outcome":"denied". No SSH connection is opened. The configured list is also included in the tool description so the model knows the boundary up front. When the variable is unset, any host is allowed.

Host key verification

The server verifies the remote host key against SSH_MCP_KNOWN_HOSTS (default ~/.ssh/known_hosts), the same file OpenSSH uses. Plain, hashed (|1|...), [host]:port, wildcard and @revoked entries are understood. SSH_MCP_HOST_KEY_CHECKING selects the policy, mirroring OpenSSH StrictHostKeyChecking:

Value

Unknown host

Key changed

strict (default)

refused

refused

accept-new

recorded in the file, then accepted

refused

off

accepted

accepted

A refused call returns an error explaining why and is audited as denied. If you hit Host key verification failed for a host you trust, either connect to it once with ssh from the same machine (so OpenSSH records the key), or run with SSH_MCP_HOST_KEY_CHECKING=accept-new. A HOST KEY MISMATCH means the key on record differs from the one the server presented: treat it as OpenSSH would, and only remove the old entry if you know the host was rebuilt.

Audit log

Every call produces one JSON line on stderr (Claude Code and Claude Desktop keep MCP server stderr in their logs). Set SSH_MCP_AUDIT_LOG to also append it to a file (created with mode 0600):

{"ts":"2026-09-06T14:02:11.482Z","tool":"ssh_sudo_exec","host":"10.0.0.5","port":22,"user":"ubuntu","key":"prod","command":"sudo systemctl restart nginx","duration_ms":812,"outcome":"ok","exit_code":0}
{"ts":"2026-09-06T14:02:40.107Z","tool":"ssh_exec","host":"203.0.113.9","port":22,"user":"ubuntu","key":"prod","command":"id","duration_ms":1,"outcome":"denied","error":"Host '203.0.113.9' is not in SSH_MCP_ALLOWED_HOSTS ('10.0.0.*')"}

outcome is ok (exit code 0), error (non-zero exit or connection failure) or denied (blocked by the allowlist or host key policy). key is the shortcut or path as supplied by the caller. Command output and key material are never logged.

Security model

This server executes arbitrary shell commands on remote hosts, including with sudo via ssh_sudo_exec. It is deliberately thin and does not try to be a policy engine. The controls are layered, and the server only owns some of them:

  1. The MCP client. Claude Code and Claude Desktop show the exact host and command and ask for approval before each call. Nothing runs unattended unless you allowlist the tool in the client.

  2. This server. SSH_MCP_ALLOWED_HOSTS bounds which hosts the model can reach. Host key verification (strict by default) refuses unknown or changed hosts. Every call, including refused ones, is written to the audit log. Authentication is key-based only; no passwords are handled or stored, and keys are read from disk at call time.

  3. The keys and the hosts. A call can only reach hosts where the configured key is authorized, so keep one key per environment. On the host, scope what that identity can do with authorized_keys options (from=, command=, restrict), a dedicated low-privilege user, and sudoers rules that limit what ssh_sudo_exec can run.

  4. Transport. The server talks to the MCP client over stdio and opens no network listener of its own.

What it does not do: there is no command allow/deny list (express that in sudoers and authorized_keys, where it is enforced regardless of the client), no support for SSH certificates (@cert-authority entries are ignored), and the audit log is advisory (a failure to write it is reported on stderr but does not block the call).

Practical notes:

  • Only connect it to hosts and keys you control, and only run it with an MCP client you trust.

  • Never commit private keys. *.pem, *.key, and common key filenames are already in .gitignore.

  • Prefer passphrase-protected keys or keys scoped to specific hosts.

  • Setting SSH_MCP_HOST_KEY_CHECKING=off and leaving SSH_MCP_ALLOWED_HOSTS unset restores the 1.0.x behaviour.

Development

Local checkout

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

This compiles src/index.ts to dist/index.js. Point your MCP client at the compiled file instead of the npm package:

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"

For Claude Desktop, use "command": "node" with "args": ["/absolute/path/to/ssh-mcp-dynamic/dist/index.js"].

Tests

npm test

Tests use Node's built-in test runner and an in-process SSH server from the ssh2 package with generated ed25519 keys, so the host key, allowlist and audit paths are exercised over a real SSH handshake with no external dependencies. The same suite runs in CI on Node 18, 20, 22 and 24 for every pull request, together with a stdio smoke test of the built server and npm audit.

Releasing

  1. Bump version in package.json on a branch and merge it through a pull request (main requires green CI).

  2. Tag the merge commit vX.Y.Z and publish a GitHub Release for that tag.

  3. The Publish to npm workflow (.github/workflows/publish.yml) runs the tests, checks the tag matches package.json, and runs npm publish --provenance. It authenticates with npm trusted publishing (OIDC), so no npm token lives in the repository; the trusted publisher is configured once on npmjs.com under the package's settings. If that version is already on npm the publish step is skipped, so re-publishing a release is safe.

License

MIT

Available Tools

2 tools
ssh_execC

Execute a shell command on a remote host via SSH.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyNoProvide a configured key shortcut or a full path to the private key file (supports a leading ~ for the home directory).
hostYesIP address or hostname of the remote server.
portNoSSH port (default: 22)
userNoSSH username (default: root)root
commandYesShell command to execute on the remote server
timeoutNoTimeout in milliseconds (default: 60000)

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are present, so the description carries the full burden of behavioral disclosure. It only says 'Execute a shell command', without noting that arbitrary remote commands may be destructive, that a key or authentication setup is typically required, or how output and errors are returned. This is a significant transparency gap for an SSH execution tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise, front-loaded sentence that directly states the core action. It earns its place, though it could have used additional structure to add usage guidance without losing brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given that this is a powerful command-execution tool with no annotations, no output schema, and a closely related sibling, the description is too thin. It omits return behavior, side-effect expectations, key/authentication prerequisites, and the relationship to ssh_sudo_exec, leaving important operational context unspecified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the input schema already documents all six parameters well. The tool description adds no additional parameter-level meaning, but because the schema carries the burden, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states a specific verb ('Execute'), a well-defined resource ('a shell command on a remote host'), and the transport mechanism ('via SSH'). It is clear and unambiguous, but it does not explicitly distinguish itself from the sibling tool ssh_sudo_exec, so it stops short of a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

There is no guidance about when to use ssh_exec versus ssh_sudo_exec, nor any mention of when elevated privileges would be required. The existence of the sibling tool makes this omission noticeable; an agent is left to infer the distinction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

ssh_sudo_execA

Execute a shell command with sudo on a remote host via SSH.

ParametersJSON Schema
NameRequiredDescriptionDefault
keyNoProvide a configured key shortcut or a full path to the private key file (supports a leading ~ for the home directory).
hostYesIP address or hostname of the remote server.
portNoSSH port (default: 22)
userNoSSH username (default: root)root
commandYesShell command to execute with sudo (do not include 'sudo' prefix)
timeoutNoTimeout in milliseconds (default: 60000)

TDQS

A3.9/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the behavioral burden, and it states the key fact that the command will run with sudo over SSH, implying remote, elevated execution. However, it does not mention authentication expectations, whether sudo prompts are supported, or what happens to the output/exit code, leaving meaningful behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single focused sentence with no filler, and it front-loads the key facts: execute, command, sudo, remote host, SSH. Every word contributes to the tool's identity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The schema is complete and self-explanatory for parameters, and the description identifies the elevated, remote nature of execution. But with no output schema and no annotation protection, the agent still lacks explicit information about return values, sudo/authentication behavior, and side effects, so the description is only moderately complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with all six parameters documented in the input schema itself. The tool description adds no parameter-level detail, so the baseline of 3 applies; the schema carries the semantic load.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific action (execute), a target (shell command on remote host), and a distinguishing method (via SSH with sudo). It clearly differentiates from the sibling ssh_exec by the sudo elevation requirement, so an agent can identify this tool's purpose without opening the schema.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The phrase 'with sudo' provides clear context for when this tool should be selected over the sibling ssh_exec: when a command needs elevated privileges. It does not explicitly state exclusions or name the alternative, but the context is clear enough to guide routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

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

  1. 2 tool updatesv1.1.2
    • Changedssh_exec1 field changed
      • changedInput schema / properties / host / description
        Previous value: -"IP address or hostname of the remote server"New value: +"IP address or hostname of the remote server."
    • Changedssh_sudo_exec1 field changed
      • changedInput schema / properties / host / description
        Previous value: -"IP address or hostname of the remote server"New value: +"IP address or hostname of the remote server."
  2. 2 tool updatesv1.0.0
    • First observedssh_exec
    • First observedssh_sudo_exec

TDQS

B3.4/5.0

Scored across 2 tools

Disambiguation4/5

The two tools are very similar—both execute shell commands via SSH—but they are clearly differentiated by the sudo privilege level. An agent could mistake one for the other if not reading carefully, but the descriptions make the distinction explicit.

Naming Consistency5/5

Both tool names follow a consistent pattern: the ssh_ prefix followed by the action, with an optional sudo modifier. ssh_exec and ssh_sudo_exec are predictable and clearly related.

Tool Count3/5

With only two tools, the server feels thin, even for a focused SSH execution purpose. The count is borderline—functional but minimal—and does not include complementary operations like file transfer or session management.

Completeness3/5

The tool set covers command execution with and without sudo, which handles a basic SSH execution workflow. However, the server name suggests a broader SSH scope, and missing operations like file upload/download, connection status, or environment inspection create notable gaps.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    D
    maintenance
    A server that enables remote command execution over SSH through the Model Context Protocol (MCP), supporting both password and private key authentication.
    1
    6 npm
    2
    MIT
  • A
    license
    A
    quality
    D
    maintenance
    Zero-config SSH/SFTP MCP server that lets an LLM client open temporary SSH/SFTP sessions to remote hosts, run commands, and upload/download files without holding any pre-baked credentials.
    17
    8 npm
    2
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal MCP server that executes commands on remote hosts by delegating to the local ssh binary, supporting batch-mode execution and optional timeout.
    MIT