@yawlabs/ssh-mcp 0.1.0 → 0.4.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 ADDED
@@ -0,0 +1,184 @@
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
+ ## 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
+ ### Auto-diagnostics
77
+
78
+ 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.
79
+
80
+ ### Connection pooling
81
+
82
+ 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.
83
+
84
+ ### SSH config support
85
+
86
+ All connections respect your `~/.ssh/config`. Host aliases, custom ports, usernames, and identity files from your SSH config are used automatically. If you have `Host myserver` configured in your SSH config, just pass `host: "myserver"` — ssh-mcp resolves the real hostname, user, port, and identity file.
87
+
88
+ ## Authentication
89
+
90
+ All remote operations accept connection parameters:
91
+
92
+ | Parameter | Description | Default |
93
+ |-----------|-------------|---------|
94
+ | `host` | SSH hostname or IP (required) | — |
95
+ | `port` | SSH port | From SSH config or `22` |
96
+ | `username` | SSH username | From SSH config or current user |
97
+ | `privateKeyPath` | Path to SSH private key | Auto-detect |
98
+ | `password` | SSH password (prefer keys) | — |
99
+
100
+ **Auth resolution order:** explicit key > explicit password > ssh-agent (`SSH_AUTH_SOCK`) > SSH config identity files > default key paths (`~/.ssh/id_ed25519`, `id_rsa`, `id_ecdsa`).
101
+
102
+ ## Example workflows
103
+
104
+ ### Agent can't git pull
105
+
106
+ ```
107
+ Agent calls ssh_git_check → "Permission denied. Your SSH key is not registered with github.com."
108
+ Agent calls ssh_key_list → finds id_ed25519 exists but is not loaded
109
+ Agent calls ssh_key_load("~/.ssh/id_ed25519") → "Key loaded"
110
+ Agent calls ssh_git_check → "Git SSH authentication to github.com succeeded as username"
111
+ Agent runs git pull → works
112
+ ```
113
+
114
+ ### Host key changed after instance recreation
115
+
116
+ ```
117
+ Agent calls ssh_exec on server → error: "Host key verification failed"
118
+ (auto-diagnostics included in error: "Fix with ssh_known_hosts_fix")
119
+ Agent calls ssh_known_hosts_fix("my-server") → "Host key refreshed"
120
+ Agent calls ssh_exec → works
121
+ ```
122
+
123
+ ### First-time connection to a new server
124
+
125
+ ```
126
+ Agent calls ssh_test("new-server") → "Connection refused at new-server:22"
127
+ Agent calls ssh_diagnose("new-server") → full report showing agent running, keys loaded, but host unreachable
128
+ Agent reports: "SSH server isn't running on new-server or port 22 is blocked"
129
+ ```
130
+
131
+ ## Programmatic usage
132
+
133
+ ```typescript
134
+ import { connect, exec, diagnose, ensureAgent, listSshKeys, checkGitSsh, ConnectionPool } from '@yawlabs/ssh-mcp';
135
+
136
+ // Fix SSH environment
137
+ const agent = ensureAgent();
138
+ console.log(agent.message);
139
+
140
+ // Check git access
141
+ const git = checkGitSsh('github.com');
142
+ console.log(git.message);
143
+
144
+ // List available keys
145
+ const keys = listSshKeys();
146
+ for (const key of keys) {
147
+ console.log(`${key.name} (${key.type}) - ${key.loadedInAgent ? 'loaded' : 'not loaded'}`);
148
+ }
149
+
150
+ // Run a remote command (one-off)
151
+ const client = await connect({ host: 'my-server', username: 'deploy' });
152
+ const result = await exec(client, 'uptime');
153
+ console.log(result.stdout);
154
+ client.end();
155
+
156
+ // Run multiple commands with connection pooling
157
+ const pool = new ConnectionPool();
158
+ await pool.withConnection({ host: 'my-server' }, async (client) => {
159
+ const r1 = await exec(client, 'uptime');
160
+ console.log(r1.stdout);
161
+ });
162
+ // Connection stays open for 60s — next call reuses it
163
+ await pool.withConnection({ host: 'my-server' }, async (client) => {
164
+ const r2 = await exec(client, 'df -h');
165
+ console.log(r2.stdout);
166
+ });
167
+ pool.drain(); // close all connections when done
168
+
169
+ // Diagnose issues
170
+ const report = diagnose('my-server');
171
+ console.log(report.overall); // "ok" | "warning" | "error"
172
+ for (const check of report.checks) {
173
+ console.log(`[${check.status}] ${check.name}: ${check.message}`);
174
+ }
175
+ ```
176
+
177
+ ## Requirements
178
+
179
+ - Node.js 18+
180
+ - SSH client installed (for diagnostics and environment management)
181
+
182
+ ## License
183
+
184
+ MIT