@yawlabs/ssh-mcp 0.8.0 → 0.9.0
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.
- package/README.md +219 -219
- package/dist/index.js +523 -492
- package/dist/server.d.ts +39 -39
- package/dist/server.js +32 -10
- package/package.json +61 -61
package/README.md
CHANGED
|
@@ -1,219 +1,219 @@
|
|
|
1
|
-
# @yawlabs/ssh-mcp
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/@yawlabs/ssh-mcp)
|
|
4
|
-
[](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
|
-
## The problem
|
|
11
|
-
|
|
12
|
-
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.
|
|
13
|
-
|
|
14
|
-
This happens across every situation that needs SSH keys:
|
|
15
|
-
|
|
16
|
-
- **Git** — clone, pull, push, fetch, submodules, LFS
|
|
17
|
-
- **Package managers** — `npm install`, `pip install`, `go get`, `cargo`, `composer` from private repos
|
|
18
|
-
- **Server access** — SSH, SCP, SFTP, rsync
|
|
19
|
-
- **Tunneling** — port forwarding to databases, SOCKS proxies
|
|
20
|
-
- **Deployment** — Ansible, Terraform, Capistrano, deploy scripts
|
|
21
|
-
- **Cloud** — AWS EC2, GCP, Azure, DigitalOcean, any VPS
|
|
22
|
-
|
|
23
|
-
**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.
|
|
24
|
-
|
|
25
|
-
## Quick start
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
npm install -g @yawlabs/ssh-mcp
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
Add to your MCP client config:
|
|
32
|
-
|
|
33
|
-
```json
|
|
34
|
-
{
|
|
35
|
-
"mcpServers": {
|
|
36
|
-
"ssh": {
|
|
37
|
-
"command": "ssh-mcp"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## Tools
|
|
44
|
-
|
|
45
|
-
### SSH environment management
|
|
46
|
-
|
|
47
|
-
Tools that fix your local SSH setup so everything else — git, deploys, tunnels — stops breaking.
|
|
48
|
-
|
|
49
|
-
| Tool | Description |
|
|
50
|
-
|------|-------------|
|
|
51
|
-
| `ssh_agent_ensure` | Ensure ssh-agent is running. Starts one if needed and sets env vars for the session. |
|
|
52
|
-
| `ssh_key_list` | List all SSH keys in ~/.ssh/ with type, fingerprint, and agent status. |
|
|
53
|
-
| `ssh_key_load` | Load a key into the running agent. Ensures the agent is started first. |
|
|
54
|
-
| `ssh_config_lookup` | Resolve the effective SSH config for a host (hostname, user, port, proxy, identity files). |
|
|
55
|
-
| `ssh_known_hosts_fix` | Remove a stale host key and re-scan. Fixes "host key verification failed" errors. |
|
|
56
|
-
| `ssh_git_check` | Test Git-over-SSH auth to GitHub, GitLab, Bitbucket, etc. |
|
|
57
|
-
| `ssh_test` | Quick connectivity test with timing and actionable error details. |
|
|
58
|
-
|
|
59
|
-
### Diagnostics
|
|
60
|
-
|
|
61
|
-
| Tool | Description |
|
|
62
|
-
|------|-------------|
|
|
63
|
-
| `ssh_diagnose` | Full SSH environment diagnostic. Checks agent, keys, config, known_hosts, and connectivity. Returns exact fix commands for every failure. |
|
|
64
|
-
|
|
65
|
-
### Remote operations
|
|
66
|
-
|
|
67
|
-
| Tool | Description |
|
|
68
|
-
|------|-------------|
|
|
69
|
-
| `ssh_exec` | Execute a command on a remote host. Returns stdout, stderr, and exit code. |
|
|
70
|
-
| `ssh_read_file` | Read a file from a remote host via SFTP. |
|
|
71
|
-
| `ssh_write_file` | Write content to a file on a remote host via SFTP. |
|
|
72
|
-
| `ssh_upload` | Upload a local file to a remote host via SFTP. |
|
|
73
|
-
| `ssh_download` | Download a file from a remote host to local filesystem. |
|
|
74
|
-
| `ssh_ls` | List files in a directory on a remote host. |
|
|
75
|
-
|
|
76
|
-
### Higher-level operations
|
|
77
|
-
|
|
78
|
-
Tools that wrap common patterns agents build with ssh_exec — faster and less error-prone.
|
|
79
|
-
|
|
80
|
-
| Tool | Description |
|
|
81
|
-
|------|-------------|
|
|
82
|
-
| `ssh_multi_exec` | Run a command on multiple hosts in parallel. Returns results per host. |
|
|
83
|
-
| `ssh_find` | Search for files remotely with structured parameters (name, type, size, depth). |
|
|
84
|
-
| `ssh_tail` | Read the last N lines of a file, optionally filtered by a grep pattern. |
|
|
85
|
-
| `ssh_service_status` | Check systemd service status (active, PID, uptime, description). |
|
|
86
|
-
|
|
87
|
-
### Auto-diagnostics
|
|
88
|
-
|
|
89
|
-
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.
|
|
90
|
-
|
|
91
|
-
### Connection pooling
|
|
92
|
-
|
|
93
|
-
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.
|
|
94
|
-
|
|
95
|
-
### SSH config support
|
|
96
|
-
|
|
97
|
-
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.
|
|
98
|
-
|
|
99
|
-
**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.
|
|
100
|
-
|
|
101
|
-
### Host key verification
|
|
102
|
-
|
|
103
|
-
All remote operations verify the server's host key against `~/.ssh/known_hosts`:
|
|
104
|
-
|
|
105
|
-
- **Known host, key matches** — accept.
|
|
106
|
-
- **Known host, key changed** — reject (MITM protection).
|
|
107
|
-
- **Unknown host** — accept on first connection (TOFU). Use `ssh_known_hosts_fix` to pin the key for future mismatch detection.
|
|
108
|
-
|
|
109
|
-
For stricter environments, set `SSH_MCP_STRICT_HOST_KEY=1` to reject unknown hosts. Add them explicitly with `ssh_known_hosts_fix` first.
|
|
110
|
-
|
|
111
|
-
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`.
|
|
112
|
-
|
|
113
|
-
### Windows support
|
|
114
|
-
|
|
115
|
-
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.
|
|
116
|
-
|
|
117
|
-
## Authentication
|
|
118
|
-
|
|
119
|
-
All remote operations accept connection parameters:
|
|
120
|
-
|
|
121
|
-
| Parameter | Description | Default |
|
|
122
|
-
|-----------|-------------|---------|
|
|
123
|
-
| `host` | SSH hostname or IP (required) | — |
|
|
124
|
-
| `port` | SSH port | From SSH config or `22` |
|
|
125
|
-
| `username` | SSH username | From SSH config or current user |
|
|
126
|
-
| `privateKeyPath` | Path to SSH private key | Auto-detect |
|
|
127
|
-
| `password` | SSH password (prefer keys) | — |
|
|
128
|
-
|
|
129
|
-
**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.
|
|
130
|
-
|
|
131
|
-
1. Explicit `privateKeyPath`
|
|
132
|
-
2. Explicit `password`
|
|
133
|
-
3. ssh-agent (`SSH_AUTH_SOCK` on Unix, `\\.\pipe\openssh-ssh-agent` on Windows)
|
|
134
|
-
4. Identity files from `~/.ssh/config` for the host
|
|
135
|
-
5. Default key paths (`~/.ssh/id_ed25519`, `id_rsa`, `id_ecdsa`)
|
|
136
|
-
|
|
137
|
-
## Example workflows
|
|
138
|
-
|
|
139
|
-
### Agent can't git pull
|
|
140
|
-
|
|
141
|
-
```
|
|
142
|
-
Agent calls ssh_git_check → "Permission denied. Your SSH key is not registered with github.com."
|
|
143
|
-
Agent calls ssh_key_list → finds id_ed25519 exists but is not loaded
|
|
144
|
-
Agent calls ssh_key_load("~/.ssh/id_ed25519") → "Key loaded"
|
|
145
|
-
Agent calls ssh_git_check → "Git SSH authentication to github.com succeeded as username"
|
|
146
|
-
Agent runs git pull → works
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Host key changed after instance recreation
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
Agent calls ssh_exec on server → error: "Host key verification failed"
|
|
153
|
-
(auto-diagnostics included in error: "Fix with ssh_known_hosts_fix")
|
|
154
|
-
Agent calls ssh_known_hosts_fix("my-server") → "Host key refreshed"
|
|
155
|
-
Agent calls ssh_exec → works
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### First-time connection to a new server
|
|
159
|
-
|
|
160
|
-
```
|
|
161
|
-
Agent calls ssh_test("new-server") → "Connection refused at new-server:22"
|
|
162
|
-
Agent calls ssh_diagnose("new-server") → full report showing agent running, keys loaded, but host unreachable
|
|
163
|
-
Agent reports: "SSH server isn't running on new-server or port 22 is blocked"
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## Programmatic usage
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
import { connect, exec, diagnose, ensureAgent, listSshKeys, checkGitSsh, ConnectionPool } from '@yawlabs/ssh-mcp';
|
|
170
|
-
|
|
171
|
-
// Fix SSH environment
|
|
172
|
-
const agent = ensureAgent();
|
|
173
|
-
console.log(agent.message);
|
|
174
|
-
|
|
175
|
-
// Check git access
|
|
176
|
-
const git = checkGitSsh('github.com');
|
|
177
|
-
console.log(git.message);
|
|
178
|
-
|
|
179
|
-
// List available keys
|
|
180
|
-
const keys = listSshKeys();
|
|
181
|
-
for (const key of keys) {
|
|
182
|
-
console.log(`${key.name} (${key.type}) - ${key.loadedInAgent ? 'loaded' : 'not loaded'}`);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Run a remote command (one-off)
|
|
186
|
-
const client = await connect({ host: 'my-server', username: 'deploy' });
|
|
187
|
-
const result = await exec(client, 'uptime');
|
|
188
|
-
console.log(result.stdout);
|
|
189
|
-
client.end();
|
|
190
|
-
|
|
191
|
-
// Run multiple commands with connection pooling
|
|
192
|
-
const pool = new ConnectionPool();
|
|
193
|
-
await pool.withConnection({ host: 'my-server' }, async (client) => {
|
|
194
|
-
const r1 = await exec(client, 'uptime');
|
|
195
|
-
console.log(r1.stdout);
|
|
196
|
-
});
|
|
197
|
-
// Connection stays open for 60s — next call reuses it
|
|
198
|
-
await pool.withConnection({ host: 'my-server' }, async (client) => {
|
|
199
|
-
const r2 = await exec(client, 'df -h');
|
|
200
|
-
console.log(r2.stdout);
|
|
201
|
-
});
|
|
202
|
-
pool.drain(); // close all connections when done
|
|
203
|
-
|
|
204
|
-
// Diagnose issues
|
|
205
|
-
const report = diagnose('my-server');
|
|
206
|
-
console.log(report.overall); // "ok" | "warning" | "error"
|
|
207
|
-
for (const check of report.checks) {
|
|
208
|
-
console.log(`[${check.status}] ${check.name}: ${check.message}`);
|
|
209
|
-
}
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
## Requirements
|
|
213
|
-
|
|
214
|
-
- Node.js 18+
|
|
215
|
-
- SSH client installed (for diagnostics and environment management)
|
|
216
|
-
|
|
217
|
-
## License
|
|
218
|
-
|
|
219
|
-
MIT
|
|
1
|
+
# @yawlabs/ssh-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@yawlabs/ssh-mcp)
|
|
4
|
+
[](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
|
+
## The problem
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
|
|
14
|
+
This happens across every situation that needs SSH keys:
|
|
15
|
+
|
|
16
|
+
- **Git** — clone, pull, push, fetch, submodules, LFS
|
|
17
|
+
- **Package managers** — `npm install`, `pip install`, `go get`, `cargo`, `composer` from private repos
|
|
18
|
+
- **Server access** — SSH, SCP, SFTP, rsync
|
|
19
|
+
- **Tunneling** — port forwarding to databases, SOCKS proxies
|
|
20
|
+
- **Deployment** — Ansible, Terraform, Capistrano, deploy scripts
|
|
21
|
+
- **Cloud** — AWS EC2, GCP, Azure, DigitalOcean, any VPS
|
|
22
|
+
|
|
23
|
+
**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.
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm install -g @yawlabs/ssh-mcp
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Add to your MCP client config:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"mcpServers": {
|
|
36
|
+
"ssh": {
|
|
37
|
+
"command": "ssh-mcp"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Tools
|
|
44
|
+
|
|
45
|
+
### SSH environment management
|
|
46
|
+
|
|
47
|
+
Tools that fix your local SSH setup so everything else — git, deploys, tunnels — stops breaking.
|
|
48
|
+
|
|
49
|
+
| Tool | Description |
|
|
50
|
+
|------|-------------|
|
|
51
|
+
| `ssh_agent_ensure` | Ensure ssh-agent is running. Starts one if needed and sets env vars for the session. |
|
|
52
|
+
| `ssh_key_list` | List all SSH keys in ~/.ssh/ with type, fingerprint, and agent status. |
|
|
53
|
+
| `ssh_key_load` | Load a key into the running agent. Ensures the agent is started first. |
|
|
54
|
+
| `ssh_config_lookup` | Resolve the effective SSH config for a host (hostname, user, port, proxy, identity files). |
|
|
55
|
+
| `ssh_known_hosts_fix` | Remove a stale host key and re-scan. Fixes "host key verification failed" errors. |
|
|
56
|
+
| `ssh_git_check` | Test Git-over-SSH auth to GitHub, GitLab, Bitbucket, etc. |
|
|
57
|
+
| `ssh_test` | Quick connectivity test with timing and actionable error details. |
|
|
58
|
+
|
|
59
|
+
### Diagnostics
|
|
60
|
+
|
|
61
|
+
| Tool | Description |
|
|
62
|
+
|------|-------------|
|
|
63
|
+
| `ssh_diagnose` | Full SSH environment diagnostic. Checks agent, keys, config, known_hosts, and connectivity. Returns exact fix commands for every failure. |
|
|
64
|
+
|
|
65
|
+
### Remote operations
|
|
66
|
+
|
|
67
|
+
| Tool | Description |
|
|
68
|
+
|------|-------------|
|
|
69
|
+
| `ssh_exec` | Execute a command on a remote host. Returns stdout, stderr, and exit code. |
|
|
70
|
+
| `ssh_read_file` | Read a file from a remote host via SFTP. |
|
|
71
|
+
| `ssh_write_file` | Write content to a file on a remote host via SFTP. |
|
|
72
|
+
| `ssh_upload` | Upload a local file to a remote host via SFTP. |
|
|
73
|
+
| `ssh_download` | Download a file from a remote host to local filesystem. |
|
|
74
|
+
| `ssh_ls` | List files in a directory on a remote host. |
|
|
75
|
+
|
|
76
|
+
### Higher-level operations
|
|
77
|
+
|
|
78
|
+
Tools that wrap common patterns agents build with ssh_exec — faster and less error-prone.
|
|
79
|
+
|
|
80
|
+
| Tool | Description |
|
|
81
|
+
|------|-------------|
|
|
82
|
+
| `ssh_multi_exec` | Run a command on multiple hosts in parallel. Returns results per host. |
|
|
83
|
+
| `ssh_find` | Search for files remotely with structured parameters (name, type, size, depth). |
|
|
84
|
+
| `ssh_tail` | Read the last N lines of a file, optionally filtered by a grep pattern. |
|
|
85
|
+
| `ssh_service_status` | Check systemd service status (active, PID, uptime, description). |
|
|
86
|
+
|
|
87
|
+
### Auto-diagnostics
|
|
88
|
+
|
|
89
|
+
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.
|
|
90
|
+
|
|
91
|
+
### Connection pooling
|
|
92
|
+
|
|
93
|
+
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.
|
|
94
|
+
|
|
95
|
+
### SSH config support
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
**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.
|
|
100
|
+
|
|
101
|
+
### Host key verification
|
|
102
|
+
|
|
103
|
+
All remote operations verify the server's host key against `~/.ssh/known_hosts`:
|
|
104
|
+
|
|
105
|
+
- **Known host, key matches** — accept.
|
|
106
|
+
- **Known host, key changed** — reject (MITM protection).
|
|
107
|
+
- **Unknown host** — accept on first connection (TOFU). Use `ssh_known_hosts_fix` to pin the key for future mismatch detection.
|
|
108
|
+
|
|
109
|
+
For stricter environments, set `SSH_MCP_STRICT_HOST_KEY=1` to reject unknown hosts. Add them explicitly with `ssh_known_hosts_fix` first.
|
|
110
|
+
|
|
111
|
+
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`.
|
|
112
|
+
|
|
113
|
+
### Windows support
|
|
114
|
+
|
|
115
|
+
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.
|
|
116
|
+
|
|
117
|
+
## Authentication
|
|
118
|
+
|
|
119
|
+
All remote operations accept connection parameters:
|
|
120
|
+
|
|
121
|
+
| Parameter | Description | Default |
|
|
122
|
+
|-----------|-------------|---------|
|
|
123
|
+
| `host` | SSH hostname or IP (required) | — |
|
|
124
|
+
| `port` | SSH port | From SSH config or `22` |
|
|
125
|
+
| `username` | SSH username | From SSH config or current user |
|
|
126
|
+
| `privateKeyPath` | Path to SSH private key | Auto-detect |
|
|
127
|
+
| `password` | SSH password (prefer keys) | — |
|
|
128
|
+
|
|
129
|
+
**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.
|
|
130
|
+
|
|
131
|
+
1. Explicit `privateKeyPath`
|
|
132
|
+
2. Explicit `password`
|
|
133
|
+
3. ssh-agent (`SSH_AUTH_SOCK` on Unix, `\\.\pipe\openssh-ssh-agent` on Windows)
|
|
134
|
+
4. Identity files from `~/.ssh/config` for the host
|
|
135
|
+
5. Default key paths (`~/.ssh/id_ed25519`, `id_rsa`, `id_ecdsa`)
|
|
136
|
+
|
|
137
|
+
## Example workflows
|
|
138
|
+
|
|
139
|
+
### Agent can't git pull
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
Agent calls ssh_git_check → "Permission denied. Your SSH key is not registered with github.com."
|
|
143
|
+
Agent calls ssh_key_list → finds id_ed25519 exists but is not loaded
|
|
144
|
+
Agent calls ssh_key_load("~/.ssh/id_ed25519") → "Key loaded"
|
|
145
|
+
Agent calls ssh_git_check → "Git SSH authentication to github.com succeeded as username"
|
|
146
|
+
Agent runs git pull → works
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Host key changed after instance recreation
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
Agent calls ssh_exec on server → error: "Host key verification failed"
|
|
153
|
+
(auto-diagnostics included in error: "Fix with ssh_known_hosts_fix")
|
|
154
|
+
Agent calls ssh_known_hosts_fix("my-server") → "Host key refreshed"
|
|
155
|
+
Agent calls ssh_exec → works
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### First-time connection to a new server
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
Agent calls ssh_test("new-server") → "Connection refused at new-server:22"
|
|
162
|
+
Agent calls ssh_diagnose("new-server") → full report showing agent running, keys loaded, but host unreachable
|
|
163
|
+
Agent reports: "SSH server isn't running on new-server or port 22 is blocked"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Programmatic usage
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { connect, exec, diagnose, ensureAgent, listSshKeys, checkGitSsh, ConnectionPool } from '@yawlabs/ssh-mcp';
|
|
170
|
+
|
|
171
|
+
// Fix SSH environment
|
|
172
|
+
const agent = ensureAgent();
|
|
173
|
+
console.log(agent.message);
|
|
174
|
+
|
|
175
|
+
// Check git access
|
|
176
|
+
const git = checkGitSsh('github.com');
|
|
177
|
+
console.log(git.message);
|
|
178
|
+
|
|
179
|
+
// List available keys
|
|
180
|
+
const keys = listSshKeys();
|
|
181
|
+
for (const key of keys) {
|
|
182
|
+
console.log(`${key.name} (${key.type}) - ${key.loadedInAgent ? 'loaded' : 'not loaded'}`);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Run a remote command (one-off)
|
|
186
|
+
const client = await connect({ host: 'my-server', username: 'deploy' });
|
|
187
|
+
const result = await exec(client, 'uptime');
|
|
188
|
+
console.log(result.stdout);
|
|
189
|
+
client.end();
|
|
190
|
+
|
|
191
|
+
// Run multiple commands with connection pooling
|
|
192
|
+
const pool = new ConnectionPool();
|
|
193
|
+
await pool.withConnection({ host: 'my-server' }, async (client) => {
|
|
194
|
+
const r1 = await exec(client, 'uptime');
|
|
195
|
+
console.log(r1.stdout);
|
|
196
|
+
});
|
|
197
|
+
// Connection stays open for 60s — next call reuses it
|
|
198
|
+
await pool.withConnection({ host: 'my-server' }, async (client) => {
|
|
199
|
+
const r2 = await exec(client, 'df -h');
|
|
200
|
+
console.log(r2.stdout);
|
|
201
|
+
});
|
|
202
|
+
pool.drain(); // close all connections when done
|
|
203
|
+
|
|
204
|
+
// Diagnose issues
|
|
205
|
+
const report = diagnose('my-server');
|
|
206
|
+
console.log(report.overall); // "ok" | "warning" | "error"
|
|
207
|
+
for (const check of report.checks) {
|
|
208
|
+
console.log(`[${check.status}] ${check.name}: ${check.message}`);
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Requirements
|
|
213
|
+
|
|
214
|
+
- Node.js 18+
|
|
215
|
+
- SSH client installed (for diagnostics and environment management)
|
|
216
|
+
|
|
217
|
+
## License
|
|
218
|
+
|
|
219
|
+
MIT
|