@yawlabs/ssh-mcp 0.11.1 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +291 -274
  2. package/dist/index.js +0 -0
  3. package/package.json +62 -62
package/README.md CHANGED
@@ -1,274 +1,291 @@
1
- # @yawlabs/ssh-mcp
2
-
3
- [![npm version](https://img.shields.io/npm/v/@yawlabs/ssh-mcp)](https://www.npmjs.com/package/@yawlabs/ssh-mcp)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
-
6
- **Make SSH work for AI tools.** MCP server that manages your SSH environment, diagnoses what's broken, fixes it, and gives your agent remote access to anything.
7
-
8
- Built and maintained by [Yaw Labs](https://yaw.sh).
9
-
10
- [![Add to mcp.hosting](https://mcp.hosting/install-button.svg)](https://mcp.hosting/install?name=SSH&command=npx&args=-y%2C%40yawlabs%2Fssh-mcp&description=Run%20commands%20on%20remote%20hosts%2C%20transfer%20files%2C%20manage%20SSH%20tunnels%20and%20keys&source=https%3A%2F%2Fgithub.com%2FYawLabs%2Fssh-mcp)
11
-
12
- One click adds this to your [mcp.hosting](https://mcp.hosting) account so it syncs to every MCP client you use. Or install manually below.
13
-
14
- ## The problem
15
-
16
- AI CLI tools run in subprocesses where SSH is constantly broken. The agent tries to `git pull` and gets `Permission denied (publickey)`. It tries to SSH into a server and the agent socket is stale. It tries to deploy and the host key changed because the instance was recreated. Every time, the AI has no idea what's wrong and spirals.
17
-
18
- This happens across every situation that needs SSH keys:
19
-
20
- - **Git** — clone, pull, push, fetch, submodules, LFS
21
- - **Package managers** — `npm install`, `pip install`, `go get`, `cargo`, `composer` from private repos
22
- - **Server access** — SSH, SCP, SFTP, rsync
23
- - **Tunneling** — port forwarding to databases, SOCKS proxies
24
- - **Deployment** — Ansible, Terraform, Capistrano, deploy scripts
25
- - **Cloud** — AWS EC2, GCP, Azure, DigitalOcean, any VPS
26
-
27
- **ssh-mcp** fixes this. It manages the SSH agent, loads keys, diagnoses failures with actionable fix commands, and provides remote operations — all as MCP tools your AI agent can call.
28
-
29
- ## Quick start
30
-
31
- ```bash
32
- npm install -g @yawlabs/ssh-mcp
33
- ```
34
-
35
- Add to your MCP client config:
36
-
37
- ```json
38
- {
39
- "mcpServers": {
40
- "ssh": {
41
- "command": "ssh-mcp"
42
- }
43
- }
44
- }
45
- ```
46
-
47
- ## Tools
48
-
49
- ### SSH environment management
50
-
51
- Tools that fix your local SSH setup so everything else — git, deploys, tunnels — stops breaking.
52
-
53
- | Tool | Description |
54
- |------|-------------|
55
- | `ssh_agent_ensure` | Ensure ssh-agent is running. Starts one if needed and sets env vars for the session. |
56
- | `ssh_key_list` | List all SSH keys in ~/.ssh/ with type, fingerprint, and agent status. |
57
- | `ssh_key_load` | Load a key into the running agent. Ensures the agent is started first. |
58
- | `ssh_config_lookup` | Resolve the effective SSH config for a host (hostname, user, port, proxy, identity files). |
59
- | `ssh_known_hosts_fix` | Remove a stale host key and re-scan. Fixes "host key verification failed" errors. |
60
- | `ssh_git_check` | Test Git-over-SSH auth to GitHub, GitLab, Bitbucket, etc. |
61
- | `ssh_test` | Quick connectivity test with timing and actionable error details. |
62
-
63
- ### Diagnostics
64
-
65
- | Tool | Description |
66
- |------|-------------|
67
- | `ssh_diagnose` | Full SSH environment diagnostic. Checks agent, keys, config, known_hosts, and connectivity. Returns exact fix commands for every failure. |
68
-
69
- ### Remote operations
70
-
71
- | Tool | Description |
72
- |------|-------------|
73
- | `ssh_exec` | Execute a command on a remote host. Returns stdout, stderr, and exit code (or `[signal: NAME]` and `code: -1` when the channel closed signal-only). Optional `env` param sets per-call environment variables (POSIX-safe prefix, works regardless of sshd's `AcceptEnv`). Subject to [command policy](#command-policy) if configured. |
74
- | `ssh_read_file` | Read a file from a remote host via SFTP. |
75
- | `ssh_write_file` | Write content to a file on a remote host via SFTP. |
76
- | `ssh_upload` | Upload a local file to a remote host via SFTP. |
77
- | `ssh_download` | Download a file from a remote host to local filesystem. |
78
- | `ssh_ls` | List files in a directory on a remote host. |
79
- | `ssh_stat` | Get metadata for a file or directory (size, mode in octal, uid/gid, mtime/atime, isFile/isDirectory/isSymbolicLink). Use instead of parsing `ls -la`. |
80
- | `ssh_mkdir` | Create a directory via SFTP. Set `recursive: true` for `mkdir -p` behavior. |
81
- | `ssh_delete` | Delete a file or empty directory via SFTP. Auto-dispatches unlink vs rmdir based on the path's type. Recursive directory delete is intentionally NOT supported -- use `ssh_exec rm -rf` if you need it. |
82
-
83
- ### Higher-level operations
84
-
85
- Tools that wrap common patterns agents build with ssh_exec — faster and less error-prone.
86
-
87
- | Tool | Description |
88
- |------|-------------|
89
- | `ssh_multi_exec` | Run a command on multiple hosts in parallel. Returns results per host. Subject to [command policy](#command-policy) if configured (policy is checked once before fan-out). |
90
- | `ssh_find` | Search for files remotely with structured parameters (`name`, `type`, `size`, `depth`, `newer` match files modified more recently than a reference path). |
91
- | `ssh_tail` | Read the last N lines of a file, optionally filtered by a grep pattern. |
92
- | `ssh_service_status` | Check systemd service status (active, PID, uptime, description). Flags `isError` only when the unit could not be found / queried, not when an existing unit is intentionally stopped. |
93
-
94
- ### Auto-diagnostics
95
-
96
- When any remote operation fails, ssh-mcp automatically runs diagnostics and includes the results in the error response. Your agent doesn't need to call `ssh_diagnose` separately — it gets told what's wrong and how to fix it right in the error message.
97
-
98
- ### Connection pooling
99
-
100
- Remote operations reuse SSH connections automatically. When your agent makes multiple calls to the same host, the first call opens a connection and subsequent calls reuse it. Connections are kept alive for 60 seconds after the last use, then closed automatically.
101
-
102
- The pool caps at 100 active connections by default. Set `SSH_MCP_MAX_POOL_SIZE=<n>` to raise it for fan-out workloads against many distinct hosts (e.g. `ssh_multi_exec` across a large fleet). When the cap is reached, the pool evicts an idle entry to make room; if every entry is in use it rejects with `Connection pool is full`.
103
-
104
- ### SSH config support
105
-
106
- All connections respect your `~/.ssh/config`. Host aliases, custom ports, usernames, identity files, and ProxyJump settings are used automatically. If you have `Host myserver` configured in your SSH config, just pass `host: "myserver"` — ssh-mcp resolves everything.
107
-
108
- **ProxyJump / bastion hosts** are supported automatically. If your SSH config has `ProxyJump bastion` for a host, ssh-mcp connects through the bastion transparently. Chained proxies work too.
109
-
110
- ### Host key verification
111
-
112
- All remote operations verify the server's host key against `~/.ssh/known_hosts`:
113
-
114
- - **Known host, key matches** — accept.
115
- - **Known host, key changed** — reject (MITM protection).
116
- - **Unknown host** — accept on first connection (TOFU). Use `ssh_known_hosts_fix` to pin the key for future mismatch detection.
117
-
118
- For stricter environments, set `SSH_MCP_STRICT_HOST_KEY=1` to reject unknown hosts. Add them explicitly with `ssh_known_hosts_fix` first.
119
-
120
- The diagnostic tools (`ssh_test`, `ssh_diagnose`) use `StrictHostKeyChecking=no` for their probe commands. Those probes only run `echo SSH_OK` — no credentials or data pass through — so the relaxed setting is safe for connectivity testing. Real operations always go through the `hostVerifier`.
121
-
122
- ### Command policy
123
-
124
- `ssh_exec` and `ssh_multi_exec` accept free-form shell commands from the agent. For security-conscious deployments, you can restrict which commands run via two env vars, each accepting a comma-separated list of regex patterns:
125
-
126
- - `SSH_MCP_COMMAND_WHITELIST` — if set, the command **must** match at least one pattern, else it's blocked.
127
- - `SSH_MCP_COMMAND_BLACKLIST` if set, the command **must not** match any pattern, else it's blocked.
128
-
129
- When both are set, the command must pass both checks (whitelist first, then blacklist). When neither is set (the default), all commands are allowed.
130
-
131
- Patterns are JavaScript regexes. Use `^` and `$` for anchored matches; otherwise patterns are treated as substring matches. Commas are the delimiter, so a literal comma in a pattern needs to be expressed as `\x2c` or via a character class.
132
-
133
- ```bash
134
- # Read-only allowlist: only ls / df / cat / find / tail
135
- SSH_MCP_COMMAND_WHITELIST="^ls( .*)?,^df( .*)?,^cat ,^find ,^tail "
136
-
137
- # Block destructive ops even if your agent goes off-script
138
- SSH_MCP_COMMAND_BLACKLIST="^rm ,^shutdown,^reboot,^mkfs,^dd if=,>\s*/dev/"
139
- ```
140
-
141
- Blocked commands surface as a clear error mentioning which pattern (or which env var) rejected the call, so the agent can adapt rather than guess. Policy is enforced before the SSH connection opens no remote process is started for a blocked command.
142
-
143
- The structured higher-level tools (`ssh_find`, `ssh_tail`, `ssh_service_status`, SFTP ops) are exempt from policy. They build commands from typed parameters, so a tight `^ls` whitelist would otherwise force you to allow `^find `, `^tail `, `^systemctl ` just to keep those tools working — defeating the point of a tight whitelist.
144
-
145
- #### Policy interaction with `ssh_exec`'s `env` parameter
146
-
147
- When `ssh_exec` is called with `env: { KEY: "value" }`, the values are injected as a `KEY='value' ...` shell prefix before the command (see the `ssh_exec` description). **Policy is checked against the full prefixed command**, not the bare `command` argument. That's the safer ordering at the protocol layer — but it means whitelist patterns need to anticipate the prefix and must be **anchored**, not substring matches:
148
-
149
- ```bash
150
- # WRONG -- blocks any ssh_exec call that uses `env`, because the final command
151
- # starts with `KEY='value' ` and never matches `^ls`.
152
- SSH_MCP_COMMAND_WHITELIST="^ls "
153
-
154
- # RIGHT -- allow zero or more `KEY='value' ` prefixes before the real command.
155
- SSH_MCP_COMMAND_WHITELIST="^([A-Za-z_][A-Za-z0-9_]*='[^']*' )*ls( |$)"
156
- ```
157
-
158
- **Avoid substring-match patterns** like ` ls ` if you're worried about a hostile agent. An agent could pass `env: { ATTACK: " ls " }` to make the final command `ATTACK=' ls ' rm -rf /`, which matches a substring ` ls ` and bypasses the whitelist. Anchored patterns of the form above don't have this weakness because they require the real command name to follow the env-prefix block, not appear inside a quoted env value.
159
-
160
- Blacklists need the same care. `^rm ` blocks a bare `rm` call, but doesn't block `FOO='bar' rm`. Use the same env-prefix-tolerant anchor:
161
-
162
- ```bash
163
- SSH_MCP_COMMAND_BLACKLIST="^([A-Za-z_][A-Za-z0-9_]*='[^']*' )*rm( |$)"
164
- ```
165
-
166
- If you don't trust the agent's `env` values at all, the simplest mitigation is to leave `env` unused in your client config and pass everything through the `command` string yourself.
167
-
168
- ### Windows support
169
-
170
- On Windows, ssh-mcp detects the OpenSSH Authentication Agent service automatically (via the `\\.\pipe\openssh-ssh-agent` named pipe). No `SSH_AUTH_SOCK` needed — just make sure the OpenSSH agent service is running.
171
-
172
- ## Authentication
173
-
174
- All remote operations accept connection parameters:
175
-
176
- | Parameter | Description | Default |
177
- |-----------|-------------|---------|
178
- | `host` | SSH hostname or IP (required) | — |
179
- | `port` | SSH port | From SSH config or `22` |
180
- | `username` | SSH username | From SSH config or current user |
181
- | `privateKeyPath` | Path to SSH private key | Auto-detect |
182
- | `password` | SSH password (prefer keys) | — |
183
-
184
- **Auth resolution order:** ssh-mcp picks the first match from this list and does not fall through to later entries — this makes the auth method deterministic and predictable.
185
-
186
- 1. Explicit `privateKeyPath`
187
- 2. Explicit `password`
188
- 3. ssh-agent (`SSH_AUTH_SOCK` on Unix, `\\.\pipe\openssh-ssh-agent` on Windows)
189
- 4. Identity files from `~/.ssh/config` for the host
190
- 5. Default key paths (`~/.ssh/id_ed25519`, `id_rsa`, `id_ecdsa`)
191
-
192
- ## Example workflows
193
-
194
- ### Agent can't git pull
195
-
196
- ```
197
- Agent calls ssh_git_check "Permission denied. Your SSH key is not registered with github.com."
198
- Agent calls ssh_key_list finds id_ed25519 exists but is not loaded
199
- Agent calls ssh_key_load("~/.ssh/id_ed25519") "Key loaded"
200
- Agent calls ssh_git_check → "Git SSH authentication to github.com succeeded as username"
201
- Agent runs git pull works
202
- ```
203
-
204
- ### Host key changed after instance recreation
205
-
206
- ```
207
- Agent calls ssh_exec on server error: "Host key verification failed"
208
- (auto-diagnostics included in error: "Fix with ssh_known_hosts_fix")
209
- Agent calls ssh_known_hosts_fix("my-server") → "Host key refreshed"
210
- Agent calls ssh_exec → works
211
- ```
212
-
213
- ### First-time connection to a new server
214
-
215
- ```
216
- Agent calls ssh_test("new-server") → "Connection refused at new-server:22"
217
- Agent calls ssh_diagnose("new-server")full report showing agent running, keys loaded, but host unreachable
218
- Agent reports: "SSH server isn't running on new-server or port 22 is blocked"
219
- ```
220
-
221
- ## Programmatic usage
222
-
223
- ```typescript
224
- import { connect, exec, diagnose, ensureAgent, listSshKeys, checkGitSsh, ConnectionPool } from '@yawlabs/ssh-mcp';
225
-
226
- // Fix SSH environment
227
- const agent = ensureAgent();
228
- console.log(agent.message);
229
-
230
- // Check git access
231
- const git = checkGitSsh('github.com');
232
- console.log(git.message);
233
-
234
- // List available keys
235
- const keys = listSshKeys();
236
- for (const key of keys) {
237
- console.log(`${key.name} (${key.type}) - ${key.loadedInAgent ? 'loaded' : 'not loaded'}`);
238
- }
239
-
240
- // Run a remote command (one-off)
241
- const client = await connect({ host: 'my-server', username: 'deploy' });
242
- const result = await exec(client, 'uptime');
243
- console.log(result.stdout);
244
- client.end();
245
-
246
- // Run multiple commands with connection pooling
247
- const pool = new ConnectionPool();
248
- await pool.withConnection({ host: 'my-server' }, async (client) => {
249
- const r1 = await exec(client, 'uptime');
250
- console.log(r1.stdout);
251
- });
252
- // Connection stays open for 60s — next call reuses it
253
- await pool.withConnection({ host: 'my-server' }, async (client) => {
254
- const r2 = await exec(client, 'df -h');
255
- console.log(r2.stdout);
256
- });
257
- pool.drain(); // close all connections when done
258
-
259
- // Diagnose issues
260
- const report = diagnose('my-server');
261
- console.log(report.overall); // "ok" | "warning" | "error"
262
- for (const check of report.checks) {
263
- console.log(`[${check.status}] ${check.name}: ${check.message}`);
264
- }
265
- ```
266
-
267
- ## Requirements
268
-
269
- - Node.js 18+
270
- - SSH client installed (for diagnostics and environment management)
271
-
272
- ## License
273
-
274
- MIT
1
+ # @yawlabs/ssh-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@yawlabs/ssh-mcp)](https://www.npmjs.com/package/@yawlabs/ssh-mcp)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ **Make SSH work for AI tools.** MCP server that manages your SSH environment, diagnoses what's broken, fixes it, and gives your agent remote access to anything.
7
+
8
+ Built and maintained by [Yaw Labs](https://yaw.sh).
9
+
10
+ [![Add to Yaw MCP](https://yaw.sh/yaw-mcp-button.svg)](yaw://install?name=SSH&command=npx&args=-y%2C%40yawlabs%2Fssh-mcp&description=Run%20commands%20on%20remote%20hosts%2C%20transfer%20files%2C%20manage%20SSH%20tunnels%20and%20keys&source=https%3A%2F%2Fgithub.com%2FYawLabs%2Fssh-mcp)
11
+
12
+ One click adds this to your local Yaw MCP config so it's available in every Yaw Terminal session. Or install manually below.
13
+
14
+ ## The problem
15
+
16
+ AI CLI tools run in subprocesses where SSH is constantly broken. The agent tries to `git pull` and gets `Permission denied (publickey)`. It tries to SSH into a server and the agent socket is stale. It tries to deploy and the host key changed because the instance was recreated. Every time, the AI has no idea what's wrong and spirals.
17
+
18
+ This happens across every situation that needs SSH keys:
19
+
20
+ - **Git** — clone, pull, push, fetch, submodules, LFS
21
+ - **Package managers** — `npm install`, `pip install`, `go get`, `cargo`, `composer` from private repos
22
+ - **Server access** — SSH, SCP, SFTP, rsync
23
+ - **Tunneling** — port forwarding to databases, SOCKS proxies
24
+ - **Deployment** — Ansible, Terraform, Capistrano, deploy scripts
25
+ - **Cloud** — AWS EC2, GCP, Azure, DigitalOcean, any VPS
26
+
27
+ **ssh-mcp** fixes this. It manages the SSH agent, loads keys, diagnoses failures with actionable fix commands, and provides remote operations — all as MCP tools your AI agent can call.
28
+
29
+ ## Quick start
30
+
31
+ Add to your MCP client config:
32
+
33
+ ```json
34
+ {
35
+ "mcpServers": {
36
+ "ssh": {
37
+ "command": "npx",
38
+ "args": ["-y", "@yawlabs/ssh-mcp@latest"]
39
+ }
40
+ }
41
+ }
42
+ ```
43
+
44
+ On Windows wrap with `cmd /c` since Node 20+ can't spawn `.cmd` files directly:
45
+
46
+ ```json
47
+ {
48
+ "mcpServers": {
49
+ "ssh": {
50
+ "command": "cmd",
51
+ "args": ["/c", "npx", "-y", "@yawlabs/ssh-mcp@latest"]
52
+ }
53
+ }
54
+ }
55
+ ```
56
+
57
+ The `@latest` tag makes `npx` re-resolve against the registry on every spawn, so each MCP session uses the newest published version. Or install globally if you'd rather pin (no auto-update):
58
+
59
+ ```bash
60
+ npm install -g @yawlabs/ssh-mcp
61
+ # then in client config: "command": "ssh-mcp"
62
+ ```
63
+
64
+ ## Tools
65
+
66
+ ### SSH environment management
67
+
68
+ Tools that fix your local SSH setup so everything else — git, deploys, tunnels — stops breaking.
69
+
70
+ | Tool | Description |
71
+ |------|-------------|
72
+ | `ssh_agent_ensure` | Ensure ssh-agent is running. Starts one if needed and sets env vars for the session. |
73
+ | `ssh_key_list` | List all SSH keys in ~/.ssh/ with type, fingerprint, and agent status. |
74
+ | `ssh_key_load` | Load a key into the running agent. Ensures the agent is started first. |
75
+ | `ssh_config_lookup` | Resolve the effective SSH config for a host (hostname, user, port, proxy, identity files). |
76
+ | `ssh_known_hosts_fix` | Remove a stale host key and re-scan. Fixes "host key verification failed" errors. |
77
+ | `ssh_git_check` | Test Git-over-SSH auth to GitHub, GitLab, Bitbucket, etc. |
78
+ | `ssh_test` | Quick connectivity test with timing and actionable error details. |
79
+
80
+ ### Diagnostics
81
+
82
+ | Tool | Description |
83
+ |------|-------------|
84
+ | `ssh_diagnose` | Full SSH environment diagnostic. Checks agent, keys, config, known_hosts, and connectivity. Returns exact fix commands for every failure. |
85
+
86
+ ### Remote operations
87
+
88
+ | Tool | Description |
89
+ |------|-------------|
90
+ | `ssh_exec` | Execute a command on a remote host. Returns stdout, stderr, and exit code (or `[signal: NAME]` and `code: -1` when the channel closed signal-only). Optional `env` param sets per-call environment variables (POSIX-safe prefix, works regardless of sshd's `AcceptEnv`). Subject to [command policy](#command-policy) if configured. |
91
+ | `ssh_read_file` | Read a file from a remote host via SFTP. |
92
+ | `ssh_write_file` | Write content to a file on a remote host via SFTP. |
93
+ | `ssh_upload` | Upload a local file to a remote host via SFTP. |
94
+ | `ssh_download` | Download a file from a remote host to local filesystem. |
95
+ | `ssh_ls` | List files in a directory on a remote host. |
96
+ | `ssh_stat` | Get metadata for a file or directory (size, mode in octal, uid/gid, mtime/atime, isFile/isDirectory/isSymbolicLink). Use instead of parsing `ls -la`. |
97
+ | `ssh_mkdir` | Create a directory via SFTP. Set `recursive: true` for `mkdir -p` behavior. |
98
+ | `ssh_delete` | Delete a file or empty directory via SFTP. Auto-dispatches unlink vs rmdir based on the path's type. Recursive directory delete is intentionally NOT supported -- use `ssh_exec rm -rf` if you need it. |
99
+
100
+ ### Higher-level operations
101
+
102
+ Tools that wrap common patterns agents build with ssh_exec faster and less error-prone.
103
+
104
+ | Tool | Description |
105
+ |------|-------------|
106
+ | `ssh_multi_exec` | Run a command on multiple hosts in parallel. Returns results per host. Subject to [command policy](#command-policy) if configured (policy is checked once before fan-out). |
107
+ | `ssh_find` | Search for files remotely with structured parameters (`name`, `type`, `size`, `depth`, `newer` — match files modified more recently than a reference path). |
108
+ | `ssh_tail` | Read the last N lines of a file, optionally filtered by a grep pattern. |
109
+ | `ssh_service_status` | Check systemd service status (active, PID, uptime, description). Flags `isError` only when the unit could not be found / queried, not when an existing unit is intentionally stopped. |
110
+
111
+ ### Auto-diagnostics
112
+
113
+ When any remote operation fails, ssh-mcp automatically runs diagnostics and includes the results in the error response. Your agent doesn't need to call `ssh_diagnose` separately — it gets told what's wrong and how to fix it right in the error message.
114
+
115
+ ### Connection pooling
116
+
117
+ Remote operations reuse SSH connections automatically. When your agent makes multiple calls to the same host, the first call opens a connection and subsequent calls reuse it. Connections are kept alive for 60 seconds after the last use, then closed automatically.
118
+
119
+ The pool caps at 100 active connections by default. Set `SSH_MCP_MAX_POOL_SIZE=<n>` to raise it for fan-out workloads against many distinct hosts (e.g. `ssh_multi_exec` across a large fleet). When the cap is reached, the pool evicts an idle entry to make room; if every entry is in use it rejects with `Connection pool is full`.
120
+
121
+ ### SSH config support
122
+
123
+ All connections respect your `~/.ssh/config`. Host aliases, custom ports, usernames, identity files, and ProxyJump settings are used automatically. If you have `Host myserver` configured in your SSH config, just pass `host: "myserver"` — ssh-mcp resolves everything.
124
+
125
+ **ProxyJump / bastion hosts** are supported automatically. If your SSH config has `ProxyJump bastion` for a host, ssh-mcp connects through the bastion transparently. Chained proxies work too.
126
+
127
+ ### Host key verification
128
+
129
+ All remote operations verify the server's host key against `~/.ssh/known_hosts`:
130
+
131
+ - **Known host, key matches** accept.
132
+ - **Known host, key changed** — reject (MITM protection).
133
+ - **Unknown host** — accept on first connection (TOFU). Use `ssh_known_hosts_fix` to pin the key for future mismatch detection.
134
+
135
+ For stricter environments, set `SSH_MCP_STRICT_HOST_KEY=1` to reject unknown hosts. Add them explicitly with `ssh_known_hosts_fix` first.
136
+
137
+ The diagnostic tools (`ssh_test`, `ssh_diagnose`) use `StrictHostKeyChecking=no` for their probe commands. Those probes only run `echo SSH_OK` — no credentials or data pass through — so the relaxed setting is safe for connectivity testing. Real operations always go through the `hostVerifier`.
138
+
139
+ ### Command policy
140
+
141
+ `ssh_exec` and `ssh_multi_exec` accept free-form shell commands from the agent. For security-conscious deployments, you can restrict which commands run via two env vars, each accepting a comma-separated list of regex patterns:
142
+
143
+ - `SSH_MCP_COMMAND_WHITELIST` if set, the command **must** match at least one pattern, else it's blocked.
144
+ - `SSH_MCP_COMMAND_BLACKLIST` — if set, the command **must not** match any pattern, else it's blocked.
145
+
146
+ When both are set, the command must pass both checks (whitelist first, then blacklist). When neither is set (the default), all commands are allowed.
147
+
148
+ Patterns are JavaScript regexes. Use `^` and `$` for anchored matches; otherwise patterns are treated as substring matches. Commas are the delimiter, so a literal comma in a pattern needs to be expressed as `\x2c` or via a character class.
149
+
150
+ ```bash
151
+ # Read-only allowlist: only ls / df / cat / find / tail
152
+ SSH_MCP_COMMAND_WHITELIST="^ls( .*)?,^df( .*)?,^cat ,^find ,^tail "
153
+
154
+ # Block destructive ops even if your agent goes off-script
155
+ SSH_MCP_COMMAND_BLACKLIST="^rm ,^shutdown,^reboot,^mkfs,^dd if=,>\s*/dev/"
156
+ ```
157
+
158
+ Blocked commands surface as a clear error mentioning which pattern (or which env var) rejected the call, so the agent can adapt rather than guess. Policy is enforced before the SSH connection opens no remote process is started for a blocked command.
159
+
160
+ The structured higher-level tools (`ssh_find`, `ssh_tail`, `ssh_service_status`, SFTP ops) are exempt from policy. They build commands from typed parameters, so a tight `^ls` whitelist would otherwise force you to allow `^find `, `^tail `, `^systemctl ` just to keep those tools working — defeating the point of a tight whitelist.
161
+
162
+ #### Policy interaction with `ssh_exec`'s `env` parameter
163
+
164
+ When `ssh_exec` is called with `env: { KEY: "value" }`, the values are injected as a `KEY='value' ...` shell prefix before the command (see the `ssh_exec` description). **Policy is checked against the full prefixed command**, not the bare `command` argument. That's the safer ordering at the protocol layer — but it means whitelist patterns need to anticipate the prefix and must be **anchored**, not substring matches:
165
+
166
+ ```bash
167
+ # WRONG -- blocks any ssh_exec call that uses `env`, because the final command
168
+ # starts with `KEY='value' ` and never matches `^ls`.
169
+ SSH_MCP_COMMAND_WHITELIST="^ls "
170
+
171
+ # RIGHT -- allow zero or more `KEY='value' ` prefixes before the real command.
172
+ SSH_MCP_COMMAND_WHITELIST="^([A-Za-z_][A-Za-z0-9_]*='[^']*' )*ls( |$)"
173
+ ```
174
+
175
+ **Avoid substring-match patterns** like ` ls ` if you're worried about a hostile agent. An agent could pass `env: { ATTACK: " ls " }` to make the final command `ATTACK=' ls ' rm -rf /`, which matches a substring ` ls ` and bypasses the whitelist. Anchored patterns of the form above don't have this weakness because they require the real command name to follow the env-prefix block, not appear inside a quoted env value.
176
+
177
+ Blacklists need the same care. `^rm ` blocks a bare `rm` call, but doesn't block `FOO='bar' rm`. Use the same env-prefix-tolerant anchor:
178
+
179
+ ```bash
180
+ SSH_MCP_COMMAND_BLACKLIST="^([A-Za-z_][A-Za-z0-9_]*='[^']*' )*rm( |$)"
181
+ ```
182
+
183
+ If you don't trust the agent's `env` values at all, the simplest mitigation is to leave `env` unused in your client config and pass everything through the `command` string yourself.
184
+
185
+ ### Windows support
186
+
187
+ On Windows, ssh-mcp detects the OpenSSH Authentication Agent service automatically (via the `\\.\pipe\openssh-ssh-agent` named pipe). No `SSH_AUTH_SOCK` needed — just make sure the OpenSSH agent service is running.
188
+
189
+ ## Authentication
190
+
191
+ All remote operations accept connection parameters:
192
+
193
+ | Parameter | Description | Default |
194
+ |-----------|-------------|---------|
195
+ | `host` | SSH hostname or IP (required) | — |
196
+ | `port` | SSH port | From SSH config or `22` |
197
+ | `username` | SSH username | From SSH config or current user |
198
+ | `privateKeyPath` | Path to SSH private key | Auto-detect |
199
+ | `password` | SSH password (prefer keys) | |
200
+
201
+ **Auth resolution order:** ssh-mcp picks the first match from this list and does not fall through to later entries — this makes the auth method deterministic and predictable.
202
+
203
+ 1. Explicit `privateKeyPath`
204
+ 2. Explicit `password`
205
+ 3. ssh-agent (`SSH_AUTH_SOCK` on Unix, `\\.\pipe\openssh-ssh-agent` on Windows)
206
+ 4. Identity files from `~/.ssh/config` for the host
207
+ 5. Default key paths (`~/.ssh/id_ed25519`, `id_rsa`, `id_ecdsa`)
208
+
209
+ ## Example workflows
210
+
211
+ ### Agent can't git pull
212
+
213
+ ```
214
+ Agent calls ssh_git_check → "Permission denied. Your SSH key is not registered with github.com."
215
+ Agent calls ssh_key_list → finds id_ed25519 exists but is not loaded
216
+ Agent calls ssh_key_load("~/.ssh/id_ed25519") → "Key loaded"
217
+ Agent calls ssh_git_check"Git SSH authentication to github.com succeeded as username"
218
+ Agent runs git pull works
219
+ ```
220
+
221
+ ### Host key changed after instance recreation
222
+
223
+ ```
224
+ Agent calls ssh_exec on server error: "Host key verification failed"
225
+ (auto-diagnostics included in error: "Fix with ssh_known_hosts_fix")
226
+ Agent calls ssh_known_hosts_fix("my-server") → "Host key refreshed"
227
+ Agent calls ssh_exec → works
228
+ ```
229
+
230
+ ### First-time connection to a new server
231
+
232
+ ```
233
+ Agent calls ssh_test("new-server") → "Connection refused at new-server:22"
234
+ Agent calls ssh_diagnose("new-server") → full report showing agent running, keys loaded, but host unreachable
235
+ Agent reports: "SSH server isn't running on new-server or port 22 is blocked"
236
+ ```
237
+
238
+ ## Programmatic usage
239
+
240
+ ```typescript
241
+ import { connect, exec, diagnose, ensureAgent, listSshKeys, checkGitSsh, ConnectionPool } from '@yawlabs/ssh-mcp';
242
+
243
+ // Fix SSH environment
244
+ const agent = ensureAgent();
245
+ console.log(agent.message);
246
+
247
+ // Check git access
248
+ const git = checkGitSsh('github.com');
249
+ console.log(git.message);
250
+
251
+ // List available keys
252
+ const keys = listSshKeys();
253
+ for (const key of keys) {
254
+ console.log(`${key.name} (${key.type}) - ${key.loadedInAgent ? 'loaded' : 'not loaded'}`);
255
+ }
256
+
257
+ // Run a remote command (one-off)
258
+ const client = await connect({ host: 'my-server', username: 'deploy' });
259
+ const result = await exec(client, 'uptime');
260
+ console.log(result.stdout);
261
+ client.end();
262
+
263
+ // Run multiple commands with connection pooling
264
+ const pool = new ConnectionPool();
265
+ await pool.withConnection({ host: 'my-server' }, async (client) => {
266
+ const r1 = await exec(client, 'uptime');
267
+ console.log(r1.stdout);
268
+ });
269
+ // Connection stays open for 60s — next call reuses it
270
+ await pool.withConnection({ host: 'my-server' }, async (client) => {
271
+ const r2 = await exec(client, 'df -h');
272
+ console.log(r2.stdout);
273
+ });
274
+ pool.drain(); // close all connections when done
275
+
276
+ // Diagnose issues
277
+ const report = diagnose('my-server');
278
+ console.log(report.overall); // "ok" | "warning" | "error"
279
+ for (const check of report.checks) {
280
+ console.log(`[${check.status}] ${check.name}: ${check.message}`);
281
+ }
282
+ ```
283
+
284
+ ## Requirements
285
+
286
+ - Node.js 18+
287
+ - SSH client installed (for diagnostics and environment management)
288
+
289
+ ## License
290
+
291
+ MIT
package/dist/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "@yawlabs/ssh-mcp",
3
- "version": "0.11.1",
4
- "mcpName": "io.github.YawLabs/ssh-mcp",
5
- "description": "MCP server for SSH operations with built-in diagnostics",
6
- "type": "module",
7
- "bin": {
8
- "ssh-mcp": "dist/index.js"
9
- },
10
- "exports": {
11
- ".": {
12
- "import": "./dist/server.js",
13
- "types": "./dist/server.d.ts"
14
- }
15
- },
16
- "files": [
17
- "dist",
18
- "LICENSE",
19
- "README.md"
20
- ],
21
- "scripts": {
22
- "build": "tsup",
23
- "dev": "tsup --watch",
24
- "lint": "biome check src/",
25
- "lint:fix": "biome check --write src/",
26
- "typecheck": "tsc --noEmit",
27
- "test": "vitest run",
28
- "test:integration": "docker compose -f test/docker/docker-compose.yml up -d --build --wait && SSH_MCP_INTEGRATION=1 vitest run src/tests/integration.test.ts; docker compose -f test/docker/docker-compose.yml down",
29
- "test:ci": "npm run build && npm test",
30
- "prepublishOnly": "npm run build"
31
- },
32
- "keywords": [
33
- "mcp",
34
- "ssh",
35
- "remote",
36
- "model-context-protocol",
37
- "ai",
38
- "devops"
39
- ],
40
- "author": "Yaw Labs <contact@yaw.sh>",
41
- "license": "MIT",
42
- "repository": {
43
- "type": "git",
44
- "url": "git+https://github.com/YawLabs/ssh-mcp.git"
45
- },
46
- "engines": {
47
- "node": ">=18"
48
- },
49
- "dependencies": {
50
- "@modelcontextprotocol/sdk": "^1.29.0",
51
- "ssh2": "^1.17.0",
52
- "zod": "^4.4.3"
53
- },
54
- "devDependencies": {
55
- "@biomejs/biome": "^2.4.15",
56
- "@types/node": "^25.7.0",
57
- "@types/ssh2": "^1.15.5",
58
- "tsup": "^8.5.1",
59
- "typescript": "^6.0.3",
60
- "vitest": "^4.1.6"
61
- }
62
- }
1
+ {
2
+ "name": "@yawlabs/ssh-mcp",
3
+ "version": "0.11.2",
4
+ "mcpName": "io.github.YawLabs/ssh-mcp",
5
+ "description": "MCP server for SSH operations with built-in diagnostics",
6
+ "type": "module",
7
+ "bin": {
8
+ "ssh-mcp": "dist/index.js"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/server.js",
13
+ "types": "./dist/server.d.ts"
14
+ }
15
+ },
16
+ "files": [
17
+ "dist",
18
+ "LICENSE",
19
+ "README.md"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsup",
23
+ "dev": "tsup --watch",
24
+ "lint": "biome check src/",
25
+ "lint:fix": "biome check --write src/",
26
+ "typecheck": "tsc --noEmit",
27
+ "test": "vitest run",
28
+ "test:integration": "docker compose -f test/docker/docker-compose.yml up -d --build --wait && SSH_MCP_INTEGRATION=1 vitest run src/tests/integration.test.ts; docker compose -f test/docker/docker-compose.yml down",
29
+ "test:ci": "npm run build && npm test",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+ "keywords": [
33
+ "mcp",
34
+ "ssh",
35
+ "remote",
36
+ "model-context-protocol",
37
+ "ai",
38
+ "devops"
39
+ ],
40
+ "author": "Yaw Labs <contact@yaw.sh>",
41
+ "license": "MIT",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/YawLabs/ssh-mcp.git"
45
+ },
46
+ "engines": {
47
+ "node": ">=18"
48
+ },
49
+ "dependencies": {
50
+ "@modelcontextprotocol/sdk": "^1.29.0",
51
+ "ssh2": "^1.17.0",
52
+ "zod": "^4.4.3"
53
+ },
54
+ "devDependencies": {
55
+ "@biomejs/biome": "^2.4.15",
56
+ "@types/node": "^25.7.0",
57
+ "@types/ssh2": "^1.15.5",
58
+ "tsup": "^8.5.1",
59
+ "typescript": "^6.0.3",
60
+ "vitest": "^4.1.6"
61
+ }
62
+ }