@regele/ssh-mcp-server 0.0.0-stage → 0.2.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +252 -3
  3. package/dist/index.js +41044 -0
  4. package/package.json +49 -6
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ssh-mcp-server contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,252 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ <div align="center">
2
+
3
+ # ssh-mcp-server
4
+
5
+ **SSH access for AI agents through the Model Context Protocol**
6
+
7
+ [![npm](https://img.shields.io/npm/v/@regele/ssh-mcp-server?style=flat-square)](https://www.npmjs.com/package/@regele/ssh-mcp-server)
8
+ [![license](https://img.shields.io/github/license/k6w/ssh-mcp-server?style=flat-square)](LICENSE)
9
+ [![node](https://img.shields.io/node/v/@regele/ssh-mcp-server?style=flat-square)](package.json)
10
+
11
+ [Installation](#installation) · [Configuration](#configuration) · [Tools](#tools) · [Security](#security)
12
+
13
+ </div>
14
+
15
+ ---
16
+
17
+ An MCP server that lets AI agents connect to remote hosts over SSH. Run commands, manage files, control services and containers, and monitor server health through a persistent connection.
18
+
19
+ ## Features
20
+
21
+ - Persistent sessions: connect once, run many commands without reconnecting
22
+ - State preservation: shell environment and working directory persist between calls
23
+ - Policy enforcement: commands are classified by risk, destructive operations require confirmation
24
+ - Audit logging: operations logged to stderr as JSON
25
+
26
+ ## Installation
27
+
28
+ ### npm (recommended)
29
+
30
+ ```sh
31
+ npx @regele/ssh-mcp-server
32
+ ```
33
+
34
+ Or install globally:
35
+
36
+ ```sh
37
+ npm install -g @regele/ssh-mcp-server
38
+ ssh-mcp-server
39
+ ```
40
+
41
+ ### From source
42
+
43
+ Requires [Bun](https://bun.sh) for building.
44
+
45
+ ```sh
46
+ git clone https://github.com/k6w/ssh-mcp-server.git
47
+ cd ssh-mcp-server
48
+ bun install
49
+ bun run build
50
+ node dist/index.js
51
+ ```
52
+
53
+ ## Configuration
54
+
55
+ ### Claude Code
56
+
57
+ ```sh
58
+ claude mcp add ssh -- npx @regele/ssh-mcp-server
59
+ ```
60
+
61
+ Or with a local build:
62
+
63
+ ```sh
64
+ claude mcp add ssh -- node /path/to/ssh-mcp-server/dist/index.js
65
+ ```
66
+
67
+ ### MCP config file
68
+
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "ssh": {
73
+ "command": "npx",
74
+ "args": ["@regele/ssh-mcp-server"]
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ### SSH agent
81
+
82
+ Without a password or key, the server uses your SSH agent (`SSH_AUTH_SOCK` or Pageant on Windows). Pass the socket explicitly if needed:
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "ssh": {
88
+ "command": "npx",
89
+ "args": ["@regele/ssh-mcp-server"],
90
+ "env": { "SSH_AUTH_SOCK": "/path/to/agent.sock" }
91
+ }
92
+ }
93
+ }
94
+ ```
95
+
96
+ ## Architecture
97
+
98
+ ```mermaid
99
+ flowchart LR
100
+ subgraph Client
101
+ A[MCP Client]
102
+ end
103
+
104
+ subgraph Server[ssh-mcp-server]
105
+ direction TB
106
+ T[Tools]
107
+ T --> P[policy.ts]
108
+ T --> AU[audit.ts]
109
+ T --> V[validation.ts]
110
+ T --> SM[session-manager.ts]
111
+ SM --> SS[shell-session.ts]
112
+ SM --> JM[job-manager.ts]
113
+ SM --> SF[sftp-manager.ts]
114
+ end
115
+
116
+ subgraph Remote
117
+ H[Remote Hosts]
118
+ end
119
+
120
+ A <-->|stdio| T
121
+ SM <-->|SSH| H
122
+ ```
123
+
124
+ ## Tools
125
+
126
+ 32 tools across 7 categories.
127
+
128
+ ### Connection
129
+
130
+ | Tool | Description |
131
+ |------|-------------|
132
+ | `ssh_connect` | Open session with password, key, or agent auth |
133
+ | `ssh_disconnect` | Close session |
134
+ | `ssh_list_sessions` | List active sessions |
135
+
136
+ ### Execution
137
+
138
+ | Tool | Description |
139
+ |------|-------------|
140
+ | `ssh_exec` | Run command, return stdout/stderr/exitCode |
141
+ | `ssh_shell_start` | Open interactive PTY shell |
142
+ | `ssh_shell_send` | Send input to shell |
143
+ | `ssh_shell_read` | Read shell output |
144
+ | `ssh_shell_close` | Close shell |
145
+
146
+ ### Background Jobs
147
+
148
+ | Tool | Description |
149
+ |------|-------------|
150
+ | `ssh_job_start` | Start long-running command |
151
+ | `ssh_job_status` | Check job state |
152
+ | `ssh_job_output` | Read job output |
153
+ | `ssh_job_kill` | Kill running job |
154
+ | `ssh_job_list` | List jobs |
155
+
156
+ ### Files (SFTP)
157
+
158
+ | Tool | Description |
159
+ |------|-------------|
160
+ | `ssh_file_read` | Read file contents |
161
+ | `ssh_file_write` | Write file with auto-backup |
162
+ | `ssh_file_list` | List directory |
163
+ | `ssh_file_stat` | Get file metadata |
164
+ | `ssh_file_delete` | Delete file |
165
+ | `ssh_mkdir` | Create directory |
166
+
167
+ ### Status
168
+
169
+ | Tool | Description |
170
+ |------|-------------|
171
+ | `ssh_server_status` | System snapshot: OS, load, memory, disk, services, containers |
172
+
173
+ ### Services (systemd)
174
+
175
+ | Tool | Risk | Description |
176
+ |------|------|-------------|
177
+ | `ssh_service_status` | safe | Show unit state |
178
+ | `ssh_service_start` | mutating | Start unit |
179
+ | `ssh_service_restart` | mutating | Restart with verification |
180
+ | `ssh_service_stop` | dangerous | Stop unit (requires `allowDangerous`) |
181
+ | `ssh_service_logs` | safe | Read journal entries |
182
+
183
+ ### Docker
184
+
185
+ | Tool | Risk | Description |
186
+ |------|------|-------------|
187
+ | `ssh_docker_ps` | safe | List containers |
188
+ | `ssh_docker_logs` | safe | Container logs |
189
+ | `ssh_docker_start` | mutating | Start container |
190
+ | `ssh_docker_restart` | mutating | Restart container |
191
+ | `ssh_docker_stop` | dangerous | Stop container (requires `allowDangerous`) |
192
+ | `ssh_docker_compose_up` | mutating | Start compose stack |
193
+ | `ssh_docker_compose_down` | dangerous | Stop compose stack (requires `allowDangerous`) |
194
+
195
+ ## Security
196
+
197
+ ### Risk tiers
198
+
199
+ Commands are classified before execution:
200
+
201
+ | Tier | Behavior | Examples |
202
+ |------|----------|----------|
203
+ | `safe` | Runs | `ls`, `cat`, `docker ps`, `systemctl status` |
204
+ | `mutating` | Runs | `mv`, `cp`, `docker start`, `systemctl restart` |
205
+ | `dangerous` | Requires `allowDangerous: true` | `rm -rf`, `kill -9`, `docker stop` |
206
+ | `blocked` | Always refused | `shutdown`, `reboot`, `rm -rf /`, `mkfs` |
207
+
208
+ ### Policy coverage
209
+
210
+ | Tools | Policy | Audit |
211
+ |-------|--------|-------|
212
+ | `ssh_service_*`, `ssh_docker_*` | Yes | Yes |
213
+ | `ssh_server_status` | Yes | No |
214
+ | `ssh_exec`, `ssh_shell_*`, `ssh_job_*` | No | No |
215
+ | `ssh_file_*` | No | No |
216
+
217
+ > [!NOTE]
218
+ > `ssh_exec` and shell tools pass commands directly. Use a restricted account.
219
+
220
+ ### Audit format
221
+
222
+ ```json
223
+ {"timestamp":"...","sessionId":"...","command":"systemctl restart nginx","tier":"mutating","allowed":true,"exitCode":0,"durationMs":412}
224
+ ```
225
+
226
+ ### Limitations
227
+
228
+ - No host key verification: accepts any server key
229
+ - Credentials in memory: passwords/keys kept for session lifetime
230
+ - Timeouts do not cancel remote commands: use jobs for long work
231
+ - Sessions lost on restart
232
+
233
+ ### Recommendations
234
+
235
+ 1. Use a dedicated non-root account with limited sudo
236
+ 2. Enable confirmation prompts in your MCP client
237
+ 3. Prefer key authentication with passphrase
238
+ 4. Keep `allowDangerous` off unless necessary
239
+ 5. Review audit logs after agent sessions
240
+
241
+ ## Development
242
+
243
+ ```sh
244
+ bun install # install dependencies
245
+ bun run build # bundle to dist/index.js
246
+ bun run typecheck # type-check with tsc
247
+ bun run start # run server
248
+ ```
249
+
250
+ ## License
251
+
252
+ [MIT](LICENSE)