{"_id":"@calevi/ssh-mcp-dynamic","_rev":"2-eab26785061b0ecbb9c22cc1535a24eb","name":"@calevi/ssh-mcp-dynamic","dist-tags":{"latest":"1.1.2"},"versions":{"1.1.1":{"name":"@calevi/ssh-mcp-dynamic","version":"1.1.1","keywords":["mcp","model-context-protocol","ssh","claude","remote-exec"],"license":"MIT","_id":"@calevi/ssh-mcp-dynamic@1.1.1","maintainers":[{"name":"mhereu","email":"mhereu@gmail.com"}],"homepage":"https://github.com/Calevi-Consulting/ssh-mcp-dynamic#readme","bugs":{"url":"https://github.com/Calevi-Consulting/ssh-mcp-dynamic/issues"},"bin":{"ssh-mcp-dynamic":"dist/index.js"},"dist":{"shasum":"2a10b682dd461da89789d1a6ec39ffc7db394de5","tarball":"https://registry.npmjs.org/@calevi/ssh-mcp-dynamic/-/ssh-mcp-dynamic-1.1.1.tgz","fileCount":10,"integrity":"sha512-06LciQgq5/woJuBIFTMdrKaQsScAR1L+13JC706nUWcb1aFujNIoMer/IHUOCoFYE9g5fb0jhJkQmqF8alctdA==","signatures":[{"sig":"MEUCIQDkkpKnsLSjEmfPb7AAbVSkfU8Z/BjP5tS1bAesgEmQoQIgA5dFJ8LBL07khnhIUz3f9FtMXNgs8Pb71M7WWo/FWko=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":45690},"main":"dist/index.js","engines":{"node":">=18"},"gitHead":"dae8813b601b7544db04e3284942f35150dcd39c","scripts":{"test":"npm run build:test && node scripts/run-tests.js","build":"tsc","start":"node dist/index.js","prepare":"npm run build","build:test":"tsc -p tsconfig.test.json"},"_npmUser":{"name":"mhereu","email":"mhereu@gmail.com"},"repository":{"url":"git+https://github.com/Calevi-Consulting/ssh-mcp-dynamic.git","type":"git"},"_npmVersion":"10.9.8","description":"Dynamic SSH MCP server — host and key per call","directories":{},"_nodeVersion":"22.23.2","dependencies":{"ssh2":"^1.16.0","@modelcontextprotocol/sdk":"^1.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.0.0","@types/node":"^20.0.0","@types/ssh2":"^1.15.0"},"_npmOperationalInternal":{"tmp":"tmp/ssh-mcp-dynamic_1.1.1_1788723139289_0.5603508595956443","host":"s3://npm-registry-packages-npm-production"}},"1.1.2":{"name":"@calevi/ssh-mcp-dynamic","version":"1.1.2","description":"Dynamic SSH MCP server — host and key per call","main":"dist/index.js","bin":{"ssh-mcp-dynamic":"dist/index.js"},"engines":{"node":">=18"},"keywords":["mcp","model-context-protocol","ssh","claude","remote-exec"],"license":"MIT","repository":{"type":"git","url":"git+https://github.com/Calevi-Consulting/ssh-mcp-dynamic.git"},"homepage":"https://github.com/Calevi-Consulting/ssh-mcp-dynamic#readme","bugs":{"url":"https://github.com/Calevi-Consulting/ssh-mcp-dynamic/issues"},"publishConfig":{"access":"public"},"scripts":{"build":"tsc","prepare":"npm run build","start":"node dist/index.js","build:test":"tsc -p tsconfig.test.json","test":"npm run build:test && node scripts/run-tests.js"},"dependencies":{"@modelcontextprotocol/sdk":"^1.0.0","ssh2":"^1.16.0"},"devDependencies":{"@types/node":"^20.0.0","@types/ssh2":"^1.15.0","typescript":"^5.0.0"},"_id":"@calevi/ssh-mcp-dynamic@1.1.2","gitHead":"45e158b242c7677a7831fa30c92c9152e23e48b1","_nodeVersion":"22.23.2","_npmVersion":"10.9.8","dist":{"integrity":"sha512-8VmA5spTW+UwWQD+QQ1Us/LC2ftieOWpqzLdG5RIt7vsF049xgsPf+QbtiE5Tat7XCb7Y0poPrPImZOilym6ug==","shasum":"cdab473af468529ae657a25fc41a0a068675d381","tarball":"https://registry.npmjs.org/@calevi/ssh-mcp-dynamic/-/ssh-mcp-dynamic-1.1.2.tgz","fileCount":10,"unpackedSize":46180,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIERGtDYH4rD3GiH/cPB53jckM0uL0y1+83rBW18E7ydrAiBy4c7FdaCDR1LtE+Hc2XegWu7OjRq3xl1TFHf9qES6YA=="}]},"_npmUser":{"name":"mhereu","email":"mhereu@gmail.com"},"directories":{},"maintainers":[{"name":"mhereu","email":"mhereu@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ssh-mcp-dynamic_1.1.2_1788725368040_0.9537305826712883"},"_hasShrinkwrap":false}},"time":{"created":"2026-09-06T19:32:19.080Z","modified":"2026-09-06T20:09:28.448Z","1.1.1":"2026-09-06T19:32:19.416Z","1.1.2":"2026-09-06T20:09:28.176Z"},"bugs":{"url":"https://github.com/Calevi-Consulting/ssh-mcp-dynamic/issues"},"license":"MIT","homepage":"https://github.com/Calevi-Consulting/ssh-mcp-dynamic#readme","keywords":["mcp","model-context-protocol","ssh","claude","remote-exec"],"repository":{"type":"git","url":"git+https://github.com/Calevi-Consulting/ssh-mcp-dynamic.git"},"description":"Dynamic SSH MCP server — host and key per call","maintainers":[{"name":"mhereu","email":"mhereu@gmail.com"}],"readme":"# ssh-mcp-dynamic\n\n[![CI](https://github.com/Calevi-Consulting/ssh-mcp-dynamic/actions/workflows/ci.yml/badge.svg)](https://github.com/Calevi-Consulting/ssh-mcp-dynamic/actions/workflows/ci.yml) [![npm](https://img.shields.io/npm/v/%40calevi%2Fssh-mcp-dynamic)](https://www.npmjs.com/package/@calevi/ssh-mcp-dynamic)\n\nA minimal [Model Context Protocol](https://modelcontextprotocol.io) (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.\n\nIt exposes two tools:\n\n| Tool | Description |\n|------|-------------|\n| `ssh_exec` | Run a shell command on a remote host. |\n| `ssh_sudo_exec` | Run a shell command with `sudo` (don't include the `sudo` prefix yourself). |\n\nAuthentication is key-based only (PEM private keys). No passwords are handled or stored.\n\n**Contents**: [Quick start](#quick-start) · [Usage](#usage) · [Configuration](#configuration) · [Security model](#security-model) · [Development](#development) · [License](#license)\n\n## Quick start\n\nYou 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`](https://www.npmjs.com/package/@calevi/ssh-mcp-dynamic); `npx` downloads and runs it on demand, so there is nothing to clone or build.\n\n### Claude Code (CLI)\n\n**Minimal** — no environment config at all. You provide the host, command and a full key path on every call:\n\n```bash\nclaude mcp add ssh-mcp -- npx -y @calevi/ssh-mcp-dynamic\n```\n\n**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:\n\n```bash\nclaude mcp add ssh-mcp -s user \\\n  -e SSH_MCP_KEYS='{\"prod\":\"~/keys/prod.pem\"}' \\\n  -e SSH_MCP_DEFAULT_KEY=prod \\\n  -e SSH_MCP_DEFAULT_USER=ubuntu \\\n  -e SSH_MCP_ALLOWED_HOSTS='10.0.0.*,*.internal.example.com' \\\n  -e SSH_MCP_AUDIT_LOG=~/.ssh-mcp/audit.log \\\n  -- npx -y @calevi/ssh-mcp-dynamic\n```\n\n**Scopes** (`-s`): `local` (default, current project only), `user` (all your projects), `project` (saved to a versioned `.mcp.json` to share with your team).\n\nVerify with `claude mcp list`, or `/mcp` inside a session. Remove with `claude mcp remove ssh-mcp`.\n\nTo 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](#development).\n\n### Claude Desktop\n\nAdd the server to your `claude_desktop_config.json`:\n\n- macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`\n- Windows: `%APPDATA%\\Claude\\claude_desktop_config.json`\n\n```json\n{\n  \"mcpServers\": {\n    \"ssh-mcp\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@calevi/ssh-mcp-dynamic\"],\n      \"env\": {\n        \"SSH_MCP_KEYS\": \"{\\\"prod\\\":\\\"~/keys/prod.pem\\\",\\\"staging\\\":\\\"~/keys/staging.pem\\\"}\",\n        \"SSH_MCP_DEFAULT_KEY\": \"prod\",\n        \"SSH_MCP_DEFAULT_USER\": \"ubuntu\",\n        \"SSH_MCP_ALLOWED_HOSTS\": \"10.0.0.*,*.internal.example.com\",\n        \"SSH_MCP_AUDIT_LOG\": \"~/.ssh-mcp/audit.log\"\n      }\n    }\n  }\n}\n```\n\nRestart Claude Desktop after editing the config.\n\n## Usage\n\nOnce 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:\n\n```text\nUsing ssh-mcp, run `hostname && uptime` on 10.0.0.5 with the prod key.\n\nCheck the free disk space on staging.example.com (df -h) via ssh-mcp.\n\nOn 10.0.0.5, tail the last 50 lines of /var/log/syslog with sudo.\n\nRestart nginx on web-01.example.com with sudo, then show `systemctl status nginx`.\n\nRun `docker ps` on 203.0.113.10 as user ubuntu on port 2222 using ~/keys/prod.pem.\n```\n\nHow those map to a tool call (the client fills this in for you):\n\n```jsonc\n// \"run hostname on 10.0.0.5 with the prod key\"\n{\n  \"tool\": \"ssh_exec\",\n  \"host\": \"10.0.0.5\",\n  \"command\": \"hostname\",\n  \"key\": \"prod\"          // a configured shortcut, or a full path like ~/keys/prod.pem\n}\n\n// \"tail syslog with sudo on 10.0.0.5\"\n{\n  \"tool\": \"ssh_sudo_exec\",\n  \"host\": \"10.0.0.5\",\n  \"command\": \"tail -n 50 /var/log/syslog\"   // no 'sudo' prefix — the tool adds it\n}\n```\n\nTips:\n- Mention the host, the command, and which key/user/port when they aren't the configured defaults.\n- Naming the server (\"using ssh-mcp…\") helps the client pick the right tool when you have several MCP servers registered.\n- For privileged commands ask for \"with sudo\" so the client uses `ssh_sudo_exec` — and don't put `sudo` in the command yourself.\n\n## Configuration\n\nEverything host-specific is supplied through environment variables — nothing is hardcoded in the source.\n\n| Variable | Default | Purpose |\n|----------|---------|---------|\n| `SSH_MCP_KEYS` | `{}` | JSON object mapping **key shortcuts** to private-key paths. A leading `~` expands to the home directory. |\n| `SSH_MCP_DEFAULT_KEY` | *(none)* | Shortcut or path used when a call omits `key`. If unset, `key` is required per call. |\n| `SSH_MCP_DEFAULT_USER` | `root` | Default SSH username. |\n| `SSH_MCP_DEFAULT_PORT` | `22` | Default SSH port. |\n| `SSH_MCP_TIMEOUT_MS` | `60000` | Default command/connection timeout in milliseconds. |\n| `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. |\n| `SSH_MCP_HOST_KEY_CHECKING` | `strict` | `strict`, `accept-new` or `off`. See [Host key verification](#host-key-verification). |\n| `SSH_MCP_KNOWN_HOSTS` | `~/.ssh/known_hosts` | known_hosts file consulted for host key verification. |\n| `SSH_MCP_AUDIT_LOG` | *(none)* | File that receives one JSON line per call. Records are always written to stderr as well. See [Audit log](#audit-log). |\n\nExample `SSH_MCP_KEYS`:\n\n```json\n{\n  \"prod\": \"~/keys/prod.pem\",\n  \"staging\": \"~/keys/staging.pem\"\n}\n```\n\nWith 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.\n\n### Tool parameters\n\nBoth tools accept:\n\n- `host` (required) — IP or hostname.\n- `command` (required) — the shell command.\n- `key` — a configured shortcut or a path to the PEM file. Required unless `SSH_MCP_DEFAULT_KEY` is set.\n- `user` — SSH username (defaults to `SSH_MCP_DEFAULT_USER`).\n- `port` — SSH port (defaults to `SSH_MCP_DEFAULT_PORT`).\n- `timeout` — timeout in ms (defaults to `SSH_MCP_TIMEOUT_MS`).\n\n### Host allowlist\n\nSet `SSH_MCP_ALLOWED_HOSTS` to bound which machines the model can reach, regardless of what it puts in `host`:\n\n```bash\nSSH_MCP_ALLOWED_HOSTS='10.0.0.*,*.internal.example.com,web-01'\n```\n\nA 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.\n\n### Host key verification\n\nThe 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`:\n\n| Value | Unknown host | Key changed |\n|-------|--------------|-------------|\n| `strict` (default) | refused | refused |\n| `accept-new` | recorded in the file, then accepted | refused |\n| `off` | accepted | accepted |\n\nA 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.\n\n### Audit log\n\nEvery 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`):\n\n```json\n{\"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}\n{\"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.*')\"}\n```\n\n`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.\n\n## Security model\n\n**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:\n\n1. **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.\n2. **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.\n3. **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.\n4. **Transport.** The server talks to the MCP client over stdio and opens no network listener of its own.\n\nWhat 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).\n\nPractical notes:\n\n- Only connect it to hosts and keys you control, and only run it with an MCP client you trust.\n- **Never commit private keys.** `*.pem`, `*.key`, and common key filenames are already in `.gitignore`.\n- Prefer passphrase-protected keys or keys scoped to specific hosts.\n- Setting `SSH_MCP_HOST_KEY_CHECKING=off` and leaving `SSH_MCP_ALLOWED_HOSTS` unset restores the 1.0.x behaviour.\n\n## Development\n\n### Local checkout\n\n```bash\ngit clone https://github.com/Calevi-Consulting/ssh-mcp-dynamic.git\ncd ssh-mcp-dynamic\nnpm install\nnpm run build\n```\n\nThis compiles `src/index.ts` to `dist/index.js`. Point your MCP client at the compiled file instead of the npm package:\n\n```bash\nclaude mcp add ssh-mcp -s user \\\n  -e SSH_MCP_KEYS='{\"prod\":\"~/keys/prod.pem\"}' \\\n  -e SSH_MCP_DEFAULT_KEY=prod \\\n  -- node \"$(pwd)/dist/index.js\"\n```\n\nFor Claude Desktop, use `\"command\": \"node\"` with `\"args\": [\"/absolute/path/to/ssh-mcp-dynamic/dist/index.js\"]`.\n\n### Tests\n\n```bash\nnpm test\n```\n\nTests 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`.\n\n### Releasing\n\n1. Bump `version` in `package.json` on a branch and merge it through a pull request (`main` requires green CI).\n2. Tag the merge commit `vX.Y.Z` and publish a GitHub Release for that tag.\n3. 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.\n\n## License\n\n[MIT](./LICENSE)\n","readmeFilename":"README.md"}