ssh-mcp-dynamic
The ssh-mcp-dynamic server enables secure, key-based SSH command execution on remote hosts, with support for both regular and sudo commands, configurable per-call parameters, and environment-variable-based defaults.
Execute shell commands: Run arbitrary shell commands on remote servers via SSH using the
ssh_exectool.Execute privileged commands: Run commands with
sudoprivileges using thessh_sudo_exectool, which automatically prependssudo.Connect to multiple machines: Host, user, port, and key are all specified per call — not hardcoded — so a single server instance can target many machines.
Key-based authentication: Authenticate using PEM private keys via direct file paths (with
~expansion) or pre-configured named shortcuts (e.g.prod,staging) defined inSSH_MCP_KEYS. No passwords are handled or stored.Configurable defaults: Set default values for SSH key, username (default:
root), port (default:22), and timeout (default:60000ms) via environment variables to reduce repetition.MCP client integration: Designed for use with MCP clients like Claude Desktop and Claude Code, allowing natural language prompts to invoke its tools.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@ssh-mcp-dynamicrun 'uptime' on prod-web1"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
ssh-mcp-dynamic
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 |
| Run a shell command on a remote host. |
| Run a shell command with |
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-dynamicWith 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-dynamicScopes (-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.jsonWindows:
%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 putsudoin the command yourself.
Configuration
Everything host-specific is supplied through environment variables — nothing is hardcoded in the source.
Variable | Default | Purpose |
|
| JSON object mapping key shortcuts to private-key paths. A leading |
| (none) | Shortcut or path used when a call omits |
|
| Default SSH username. |
|
| Default SSH port. |
|
| Default command/connection timeout in milliseconds. |
| (any) | Comma-separated allowlist of hostnames / IPs. |
|
|
|
|
| known_hosts file consulted for host key verification. |
| (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 unlessSSH_MCP_DEFAULT_KEYis set.user— SSH username (defaults toSSH_MCP_DEFAULT_USER).port— SSH port (defaults toSSH_MCP_DEFAULT_PORT).timeout— timeout in ms (defaults toSSH_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 |
| refused | refused |
| recorded in the file, then accepted | refused |
| 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:
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.
This server.
SSH_MCP_ALLOWED_HOSTSbounds which hosts the model can reach. Host key verification (strictby 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.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_keysoptions (from=,command=,restrict), a dedicated low-privilege user, andsudoersrules that limit whatssh_sudo_execcan run.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=offand leavingSSH_MCP_ALLOWED_HOSTSunset 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 buildThis 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 testTests 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
Bump
versioninpackage.jsonon a branch and merge it through a pull request (mainrequires green CI).Tag the merge commit
vX.Y.Zand publish a GitHub Release for that tag.The
Publish to npmworkflow (.github/workflows/publish.yml) runs the tests, checks the tag matchespackage.json, and runsnpm 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
Available Tools
2 toolsssh_execC
Execute a shell command on a remote host via SSH.
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Provide a configured key shortcut or a full path to the private key file (supports a leading ~ for the home directory). | |
| host | Yes | IP address or hostname of the remote server. | |
| port | No | SSH port (default: 22) | |
| user | No | SSH username (default: root) | root |
| command | Yes | Shell command to execute on the remote server | |
| timeout | No | Timeout in milliseconds (default: 60000) |
TDQS
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.
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.
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.
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.
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.
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.
| Name | Required | Description | Default |
|---|---|---|---|
| key | No | Provide a configured key shortcut or a full path to the private key file (supports a leading ~ for the home directory). | |
| host | Yes | IP address or hostname of the remote server. | |
| port | No | SSH port (default: 22) | |
| user | No | SSH username (default: root) | root |
| command | Yes | Shell command to execute with sudo (do not include 'sudo' prefix) | |
| timeout | No | Timeout in milliseconds (default: 60000) |
TDQS
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.
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.
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.
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.
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.
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.
2 tool updates
v1.1.2- Changed
ssh_exec1 field changed- changed
Input schema / properties / host / descriptionPrevious value: -"IP address or hostname of the remote server"New value: +"IP address or hostname of the remote server."
- Changed
ssh_sudo_exec1 field changed- changed
Input schema / properties / host / descriptionPrevious value: -"IP address or hostname of the remote server"New value: +"IP address or hostname of the remote server."
2 tool updates
v1.0.0- First observed
ssh_exec - First observed
ssh_sudo_exec
TDQS
Scored across 2 tools
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.
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.
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.
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
Related MCP Connectors
Run commands and read/write files on your servers over Termalin's keyless tunnels (hosted MCP).
Remote MCP server for supportsheep: run AI interviews and manage support content for your blog.
Zero-install remote MCP server for proof-of-existence file attestation.
Related MCP Servers
- AlicenseBqualityDmaintenanceA server that enables remote command execution over SSH through the Model Context Protocol (MCP), supporting both password and private key authentication.16 npm2MIT
- AlicenseAqualityDmaintenanceZero-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.178 npm2MIT
- AlicenseNot gradedqualityAmaintenanceA local MCP server that enables LLMs to execute shell commands on remote hosts over SSH with multiple authentication methods.35 npm3MIT
- AlicenseNot gradedqualityDmaintenanceA minimal MCP server that executes commands on remote hosts by delegating to the local ssh binary, supporting batch-mode execution and optional timeout.MIT