@pyrokine/mcp-ssh 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -8,21 +8,27 @@ A comprehensive SSH MCP Server for AI assistants (Claude, Cursor, Windsurf, etc.
8
8
  [![Node](https://img.shields.io/badge/node-%3E%3D18-green.svg)](https://nodejs.org/)
9
9
  [![MCP](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.io/)
10
10
 
11
+ ![Linux](https://img.shields.io/badge/Linux-tested-success)
12
+ ![macOS](https://img.shields.io/badge/macOS-untested-yellow)
13
+ ![Windows](https://img.shields.io/badge/Windows-untested-yellow)
14
+
11
15
  ## Features
12
16
 
13
17
  - **Multiple Authentication**: Password, SSH key, SSH agent
18
+ - **SSH Config Support**: Read `~/.ssh/config` with Host aliases, `Host *` inheritance, ProxyJump (`user@host:port`)
14
19
  - **Connection Management**: Connection pooling, keepalive, auto-reconnect
15
20
  - **Session Persistence**: Sessions info saved for reconnection
16
21
  - **Command Execution**:
17
- - Basic exec with timeout
18
- - PTY mode (for interactive commands like `top`, `htop`)
19
- - `sudo` execution
20
- - `su` (switch user) execution - *run commands as different user*
21
- - Batch execution
22
+ - Basic exec with timeout
23
+ - PTY mode (for interactive commands like `top`, `htop`)
24
+ - `sudo` execution
25
+ - `su` (switch user) execution - *run commands as different user*
26
+ - Batch execution
27
+ - Parallel execution on multiple hosts
22
28
  - **Persistent PTY Sessions**: For long-running interactive commands (top, htop, tmux, vim, etc.)
23
- - Output buffering with polling read
24
- - Send keystrokes and commands
25
- - Window resize support
29
+ - Output buffering with polling read
30
+ - Send keystrokes and commands
31
+ - Window resize support
26
32
  - **File Operations**: Upload, download, read, write, list directory (via SFTP)
27
33
  - **Smart Sync**: Directory sync with rsync (auto-fallback to SFTP if rsync unavailable)
28
34
  - **Environment Configuration**: LANG, LC_ALL, custom env vars
@@ -30,21 +36,29 @@ A comprehensive SSH MCP Server for AI assistants (Claude, Cursor, Windsurf, etc.
30
36
 
31
37
  ## Compatible Clients
32
38
 
33
- | Client | Status |
34
- |--------|--------|
35
- | Claude Code | ✅ |
36
- | Claude Desktop | ✅ |
37
- | Cursor | ✅ |
38
- | Windsurf | ✅ |
39
- | Continue.dev | ✅ |
40
- | Cline | ✅ |
41
- | Any MCP-compatible client | ✅ |
39
+ | Client | Status |
40
+ |---------------------------|--------|
41
+ | Claude Code | ✅ |
42
+ | Claude Desktop | ✅ |
43
+ | Cursor | ✅ |
44
+ | Windsurf | ✅ |
45
+ | Continue.dev | ✅ |
46
+ | Cline | ✅ |
47
+ | Any MCP-compatible client | ✅ |
42
48
 
43
49
  ## Installation
44
50
 
51
+ ### npm (Recommended)
52
+
53
+ ```bash
54
+ npm install -g @pyrokine/mcp-ssh
55
+ ```
56
+
57
+ ### From Source
58
+
45
59
  ```bash
46
60
  git clone https://github.com/Pyrokine/claude-mcp-tools.git
47
- cd claude-mcp-tools/ssh
61
+ cd claude-mcp-tools/mcp-ssh
48
62
  npm install
49
63
  npm run build
50
64
  ```
@@ -72,68 +86,135 @@ Add to your MCP settings (e.g., `~/.claude/settings.json` or client-specific con
72
86
  }
73
87
  ```
74
88
 
75
- ## Available Tools (27 tools)
89
+ ## Available Tools (29 tools)
76
90
 
77
91
  ### Connection Management
78
92
 
79
- | Tool | Description |
80
- |------|-------------|
81
- | `ssh_connect` | Establish SSH connection with keepalive |
82
- | `ssh_disconnect` | Close connection |
83
- | `ssh_list_sessions` | List active sessions |
84
- | `ssh_reconnect` | Reconnect a disconnected session |
93
+ | Tool | Description |
94
+ |---------------------|---------------------------------------------------|
95
+ | `ssh_connect` | Establish SSH connection (supports ~/.ssh/config) |
96
+ | `ssh_disconnect` | Close connection |
97
+ | `ssh_list_sessions` | List active sessions |
98
+ | `ssh_reconnect` | Reconnect a disconnected session |
99
+ | `ssh_config_list` | List hosts from ~/.ssh/config |
85
100
 
86
101
  ### Command Execution
87
102
 
88
- | Tool | Description |
89
- |------|-------------|
90
- | `ssh_exec` | Execute command (supports PTY mode) |
91
- | `ssh_exec_as_user` | Execute as different user (via `su`) |
92
- | `ssh_exec_sudo` | Execute with `sudo` |
93
- | `ssh_exec_batch` | Execute multiple commands sequentially |
94
- | `ssh_quick_exec` | One-shot: connect, execute, disconnect |
103
+ | Tool | Description |
104
+ |---------------------|-----------------------------------------------|
105
+ | `ssh_exec` | Execute command (supports PTY mode) |
106
+ | `ssh_exec_as_user` | Execute as different user (via `su`) |
107
+ | `ssh_exec_sudo` | Execute with `sudo` |
108
+ | `ssh_exec_batch` | Execute multiple commands sequentially |
109
+ | `ssh_exec_parallel` | Execute command on multiple hosts in parallel |
110
+ | `ssh_quick_exec` | One-shot: connect, execute, disconnect |
95
111
 
96
112
  ### File Operations
97
113
 
98
- | Tool | Description |
99
- |------|-------------|
100
- | `ssh_upload` | Upload local file to remote server |
101
- | `ssh_download` | Download remote file to local |
102
- | `ssh_read_file` | Read remote file content |
103
- | `ssh_write_file` | Write content to remote file |
104
- | `ssh_list_dir` | List remote directory contents |
105
- | `ssh_file_info` | Get file/directory metadata |
106
- | `ssh_mkdir` | Create remote directory |
107
- | `ssh_sync` | Smart sync with rsync (fallback to SFTP) |
114
+ | Tool | Description |
115
+ |------------------|------------------------------------------|
116
+ | `ssh_upload` | Upload local file to remote server |
117
+ | `ssh_download` | Download remote file to local |
118
+ | `ssh_read_file` | Read remote file content |
119
+ | `ssh_write_file` | Write content to remote file |
120
+ | `ssh_list_dir` | List remote directory contents |
121
+ | `ssh_file_info` | Get file/directory metadata |
122
+ | `ssh_mkdir` | Create remote directory |
123
+ | `ssh_sync` | Smart sync with rsync (fallback to SFTP) |
108
124
 
109
125
  ### PTY Sessions (Persistent Interactive Terminal)
110
126
 
111
- | Tool | Description |
112
- |------|-------------|
113
- | `ssh_pty_start` | Start persistent PTY session (for top, htop, tmux, etc.) |
114
- | `ssh_pty_write` | Send data to PTY (keystrokes, commands) |
115
- | `ssh_pty_read` | Read PTY output (screen mode: current screen, raw mode: ANSI stream) |
116
- | `ssh_pty_resize` | Resize PTY window |
117
- | `ssh_pty_close` | Close PTY session |
118
- | `ssh_pty_list` | List all PTY sessions |
127
+ | Tool | Description |
128
+ |------------------|----------------------------------------------------------------------|
129
+ | `ssh_pty_start` | Start persistent PTY session (for top, htop, tmux, etc.) |
130
+ | `ssh_pty_write` | Send data to PTY (keystrokes, commands) |
131
+ | `ssh_pty_read` | Read PTY output (screen mode: current screen, raw mode: ANSI stream) |
132
+ | `ssh_pty_resize` | Resize PTY window |
133
+ | `ssh_pty_close` | Close PTY session |
134
+ | `ssh_pty_list` | List all PTY sessions |
119
135
 
120
136
  ### Port Forwarding
121
137
 
122
- | Tool | Description |
123
- |------|-------------|
124
- | `ssh_forward_local` | Local port forwarding (ssh -L): access remote services |
138
+ | Tool | Description |
139
+ |----------------------|--------------------------------------------------------|
140
+ | `ssh_forward_local` | Local port forwarding (ssh -L): access remote services |
125
141
  | `ssh_forward_remote` | Remote port forwarding (ssh -R): expose local services |
126
- | `ssh_forward_close` | Close port forwarding |
127
- | `ssh_forward_list` | List all port forwards |
142
+ | `ssh_forward_close` | Close port forwarding |
143
+ | `ssh_forward_list` | List all port forwards |
128
144
 
129
145
  ## Usage Examples
130
146
 
147
+ ### Using SSH Config (Recommended)
148
+
149
+ If you have hosts configured in `~/.ssh/config`:
150
+
151
+ ```
152
+ # List available hosts
153
+ ssh_config_list()
154
+
155
+ # Connect using config host name
156
+ ssh_connect(configHost="myserver")
157
+ ssh_exec(alias="myserver", command="uptime")
158
+
159
+ # Use custom config file path
160
+ ssh_connect(configHost="myserver", configPath="/custom/path/config")
161
+ ```
162
+
163
+ Supported SSH config features:
164
+
165
+ - `Host` with multiple aliases (e.g., `Host a b c`)
166
+ - `Host *` global defaults inheritance (first `Host *` block only)
167
+ - `HostName`, `User`, `Port`, `IdentityFile`
168
+ - `ProxyJump` with `user@host:port` format (first hop only)
169
+ - Explicit parameters override config values (e.g., `ssh_connect(configHost="x", user="override")`)
170
+
171
+ **Not supported** (skipped):
172
+
173
+ - `Include` directive
174
+ - `Match` blocks (entire block skipped until next `Host`)
175
+ - Wildcard patterns (e.g., `Host *.example.com`)
176
+
177
+ **Behavior notes**:
178
+
179
+ - Multiple `Host *` blocks: only first is used
180
+ - Duplicate Host definitions: `ssh_config_list` shows all, `ssh_connect` uses first
181
+ - IPv6 in ProxyJump: use bracket notation `[2001:db8::1]:22`
182
+
183
+ ### Parallel Execution on Multiple Hosts
184
+
185
+ Execute the same command on multiple connected hosts:
186
+
187
+ ```
188
+ 1. ssh_connect(configHost="server1")
189
+ 2. ssh_connect(configHost="server2")
190
+ 3. ssh_connect(configHost="server3")
191
+ 4. ssh_exec_parallel(aliases=["server1", "server2", "server3"], command="uptime")
192
+ ```
193
+
131
194
  ### Basic: Connect and Execute
132
195
 
133
196
  ```
134
- 1. ssh_connect(host="192.168.1.100", user="root", password="xxx", alias="myserver")
135
- 2. ssh_exec(alias="myserver", command="ls -la /home")
136
- 3. ssh_disconnect(alias="myserver")
197
+ ssh_connect(host="192.168.1.100", user="root", keyPath="/home/.ssh/id_rsa", alias="myserver")
198
+ ssh_exec(alias="myserver", command="ls -la /home")
199
+ ssh_disconnect(alias="myserver")
200
+ ```
201
+
202
+ ### Jump Host (Bastion)
203
+
204
+ Connect to internal server via jump host:
205
+
206
+ ```
207
+ ssh_connect(
208
+ host="10.0.0.5",
209
+ user="root",
210
+ keyPath="/home/.ssh/id_rsa",
211
+ alias="internal",
212
+ jumpHost={
213
+ host: "bastion.example.com",
214
+ user: "admin",
215
+ keyPath: "/home/.ssh/bastion_key"
216
+ }
217
+ )
137
218
  ```
138
219
 
139
220
  ### Switch User Execution (su)
@@ -146,6 +227,10 @@ Perfect for scenarios where you SSH as root but need to run commands as another
146
227
  // Output: appuser
147
228
  ```
148
229
 
230
+ By default, shell profile is loaded to ensure environment variables are available (since `su -c` creates a
231
+ non-interactive shell which doesn't execute rc files). Supports bash (`.bashrc`), zsh (`.zshrc`), and other shells (
232
+ `.profile`). Disable with `loadProfile=false` if not needed.
233
+
149
234
  ### Interactive Commands (PTY mode)
150
235
 
151
236
  For commands that need a terminal:
@@ -228,7 +313,8 @@ ssh_sync(..., dryRun=true)
228
313
 
229
314
  If rsync is not available on remote or local, it automatically falls back to SFTP.
230
315
 
231
- **Note**: rsync mode uses SSH key/agent authentication and disables strict host key checking (`StrictHostKeyChecking=no`) for convenience. If you require host key verification, use SFTP mode instead.
316
+ **Note**: rsync mode uses SSH key/agent authentication and disables strict host key checking (
317
+ `StrictHostKeyChecking=no`) for convenience. If you require host key verification, use SFTP mode instead.
232
318
 
233
319
  ### Persistent PTY Sessions (top, tmux, etc.)
234
320
 
@@ -267,6 +353,7 @@ ssh_pty_write(ptyId="pty_1_xxx", data="\x02d")
267
353
  ```
268
354
 
269
355
  Common control sequences:
356
+
270
357
  - Enter: `\r` or `\n`
271
358
  - Ctrl+C: `\x03`
272
359
  - Ctrl+D: `\x04`
@@ -296,25 +383,25 @@ ssh_forward_close(forwardId="fwd_1_xxx")
296
383
 
297
384
  ### Connection Options
298
385
 
299
- | Option | Type | Default | Description |
300
- |--------|------|---------|-------------|
301
- | `host` | string | *required* | Server address |
302
- | `user` | string | *required* | Username |
303
- | `password` | string | - | Password authentication |
304
- | `keyPath` | string | - | Path to SSH private key |
305
- | `port` | number | 22 | SSH port |
306
- | `alias` | string | auto-generated | Connection alias for reference |
307
- | `env` | object | - | Environment variables |
308
- | `keepaliveInterval` | number | 30000 | Keepalive interval in ms |
386
+ | Option | Type | Default | Description |
387
+ |---------------------|--------|----------------|--------------------------------|
388
+ | `host` | string | *required* | Server address |
389
+ | `user` | string | *required* | Username |
390
+ | `password` | string | - | Password authentication |
391
+ | `keyPath` | string | - | Path to SSH private key |
392
+ | `port` | number | 22 | SSH port |
393
+ | `alias` | string | auto-generated | Connection alias for reference |
394
+ | `env` | object | - | Environment variables |
395
+ | `keepaliveInterval` | number | 30000 | Keepalive interval in ms |
309
396
 
310
397
  ### Exec Options
311
398
 
312
- | Option | Type | Default | Description |
313
- |--------|------|---------|-------------|
314
- | `timeout` | number | 30000 | Command timeout in ms |
315
- | `cwd` | string | - | Working directory |
316
- | `env` | object | - | Additional environment variables |
317
- | `pty` | boolean | false | Enable PTY mode for interactive commands |
399
+ | Option | Type | Default | Description |
400
+ |-----------|---------|---------|------------------------------------------|
401
+ | `timeout` | number | 30000 | Command timeout in ms |
402
+ | `cwd` | string | - | Working directory |
403
+ | `env` | object | - | Additional environment variables |
404
+ | `pty` | boolean | false | Enable PTY mode for interactive commands |
318
405
 
319
406
  ## Project Structure
320
407
 
@@ -331,14 +418,6 @@ mcp-ssh/
331
418
  └── README.md
332
419
  ```
333
420
 
334
- ## Roadmap
335
-
336
- - [ ] Dynamic port forwarding (SOCKS proxy)
337
- - [ ] SSH Agent forwarding
338
- - [ ] Command history and audit logging
339
- - [ ] Multi-host parallel execution
340
- - [ ] SSH config file (~/.ssh/config) auto-discovery
341
-
342
421
  ## Contributing
343
422
 
344
423
  Contributions are welcome! Please feel free to submit a Pull Request.
package/README_zh.md CHANGED
@@ -8,21 +8,27 @@
8
8
  [![Node](https://img.shields.io/badge/node-%3E%3D18-green.svg)](https://nodejs.org/)
9
9
  [![MCP](https://img.shields.io/badge/MCP-compatible-purple.svg)](https://modelcontextprotocol.io/)
10
10
 
11
+ ![Linux](https://img.shields.io/badge/Linux-tested-success)
12
+ ![macOS](https://img.shields.io/badge/macOS-untested-yellow)
13
+ ![Windows](https://img.shields.io/badge/Windows-untested-yellow)
14
+
11
15
  ## 功能特性
12
16
 
13
17
  - **多种认证方式**:密码、SSH 密钥、SSH Agent
18
+ - **SSH Config 支持**:读取 `~/.ssh/config`,支持 Host 多别名、`Host *` 继承、ProxyJump(`user@host:port` 格式)
14
19
  - **连接管理**:连接池复用、心跳保持、自动重连
15
20
  - **会话持久化**:会话信息保存,支持重连
16
21
  - **命令执行**:
17
- - 基础执行(带超时)
18
- - PTY 模式(用于 `top`、`htop` 等交互式命令)
19
- - `sudo` 执行
20
- - `su` 切换用户执行
21
- - 批量执行
22
+ - 基础执行(带超时)
23
+ - PTY 模式(用于 `top`、`htop` 等交互式命令)
24
+ - `sudo` 执行
25
+ - `su` 切换用户执行
26
+ - 批量执行
27
+ - 多主机并行执行
22
28
  - **持久化 PTY 会话**:用于长时间运行的交互式命令(top、htop、tmux、vim 等)
23
- - 输出缓冲区,支持轮询读取
24
- - 发送按键和命令
25
- - 窗口大小调整
29
+ - 输出缓冲区,支持轮询读取
30
+ - 发送按键和命令
31
+ - 窗口大小调整
26
32
  - **文件操作**:上传、下载、读取、写入、目录列表(通过 SFTP)
27
33
  - **智能同步**:目录同步,优先使用 rsync(无 rsync 时自动回退到 SFTP)
28
34
  - **环境配置**:LANG、LC_ALL、自定义环境变量
@@ -30,21 +36,29 @@
30
36
 
31
37
  ## 兼容客户端
32
38
 
33
- | 客户端 | 状态 |
34
- |--------|------|
35
- | Claude Code | ✅ |
36
- | Claude Desktop | ✅ |
37
- | Cursor | ✅ |
38
- | Windsurf | ✅ |
39
- | Continue.dev | ✅ |
40
- | Cline | ✅ |
41
- | 其他 MCP 兼容客户端 | ✅ |
39
+ | 客户端 | 状态 |
40
+ |----------------|----|
41
+ | Claude Code | ✅ |
42
+ | Claude Desktop | ✅ |
43
+ | Cursor | ✅ |
44
+ | Windsurf | ✅ |
45
+ | Continue.dev | ✅ |
46
+ | Cline | ✅ |
47
+ | 其他 MCP 兼容客户端 | ✅ |
42
48
 
43
49
  ## 安装
44
50
 
51
+ ### npm(推荐)
52
+
53
+ ```bash
54
+ npm install -g @pyrokine/mcp-ssh
55
+ ```
56
+
57
+ ### 从源码安装
58
+
45
59
  ```bash
46
60
  git clone https://github.com/Pyrokine/claude-mcp-tools.git
47
- cd claude-mcp-tools/ssh
61
+ cd claude-mcp-tools/mcp-ssh
48
62
  npm install
49
63
  npm run build
50
64
  ```
@@ -72,68 +86,135 @@ claude mcp add ssh -- node /path/to/mcp-ssh/dist/index.js
72
86
  }
73
87
  ```
74
88
 
75
- ## 可用工具(27 个)
89
+ ## 可用工具(29 个)
76
90
 
77
91
  ### 连接管理
78
92
 
79
- | 工具 | 描述 |
80
- |------|------|
81
- | `ssh_connect` | 建立 SSH 连接并保持心跳 |
82
- | `ssh_disconnect` | 关闭连接 |
83
- | `ssh_list_sessions` | 列出活跃会话 |
84
- | `ssh_reconnect` | 重新连接断开的会话 |
93
+ | 工具 | 描述 |
94
+ |---------------------|-----------------------------|
95
+ | `ssh_connect` | 建立 SSH 连接(支持 ~/.ssh/config) |
96
+ | `ssh_disconnect` | 关闭连接 |
97
+ | `ssh_list_sessions` | 列出活跃会话 |
98
+ | `ssh_reconnect` | 重新连接断开的会话 |
99
+ | `ssh_config_list` | 列出 ~/.ssh/config 中的 Host |
85
100
 
86
101
  ### 命令执行
87
102
 
88
- | 工具 | 描述 |
89
- |------|------|
90
- | `ssh_exec` | 执行命令(支持 PTY 模式) |
91
- | `ssh_exec_as_user` | 以其他用户身份执行(通过 `su`) |
92
- | `ssh_exec_sudo` | 使用 `sudo` 执行 |
93
- | `ssh_exec_batch` | 批量执行多条命令 |
94
- | `ssh_quick_exec` | 一次性执行:连接、执行、断开 |
103
+ | 工具 | 描述 |
104
+ |---------------------|--------------------|
105
+ | `ssh_exec` | 执行命令(支持 PTY 模式) |
106
+ | `ssh_exec_as_user` | 以其他用户身份执行(通过 `su`) |
107
+ | `ssh_exec_sudo` | 使用 `sudo` 执行 |
108
+ | `ssh_exec_batch` | 批量执行多条命令 |
109
+ | `ssh_exec_parallel` | 在多台主机上并行执行命令 |
110
+ | `ssh_quick_exec` | 一次性执行:连接、执行、断开 |
95
111
 
96
112
  ### 文件操作
97
113
 
98
- | 工具 | 描述 |
99
- |------|------|
100
- | `ssh_upload` | 上传本地文件到远程 |
101
- | `ssh_download` | 从远程下载文件到本地 |
102
- | `ssh_read_file` | 读取远程文件内容 |
103
- | `ssh_write_file` | 写入内容到远程文件 |
104
- | `ssh_list_dir` | 列出远程目录内容 |
105
- | `ssh_file_info` | 获取文件/目录元数据 |
106
- | `ssh_mkdir` | 创建远程目录 |
107
- | `ssh_sync` | 智能同步(优先 rsync,回退 SFTP) |
114
+ | 工具 | 描述 |
115
+ |------------------|------------------------|
116
+ | `ssh_upload` | 上传本地文件到远程 |
117
+ | `ssh_download` | 从远程下载文件到本地 |
118
+ | `ssh_read_file` | 读取远程文件内容 |
119
+ | `ssh_write_file` | 写入内容到远程文件 |
120
+ | `ssh_list_dir` | 列出远程目录内容 |
121
+ | `ssh_file_info` | 获取文件/目录元数据 |
122
+ | `ssh_mkdir` | 创建远程目录 |
123
+ | `ssh_sync` | 智能同步(优先 rsync,回退 SFTP) |
108
124
 
109
125
  ### PTY 会话(持久化交互式终端)
110
126
 
111
- | 工具 | 描述 |
112
- |------|------|
113
- | `ssh_pty_start` | 启动持久化 PTY 会话(用于 top、htop、tmux 等) |
114
- | `ssh_pty_write` | 向 PTY 发送数据(按键、命令) |
115
- | `ssh_pty_read` | 读取 PTY 输出(screen 模式:当前屏幕,raw 模式:ANSI 流) |
116
- | `ssh_pty_resize` | 调整 PTY 窗口大小 |
117
- | `ssh_pty_close` | 关闭 PTY 会话 |
118
- | `ssh_pty_list` | 列出所有 PTY 会话 |
127
+ | 工具 | 描述 |
128
+ |------------------|-----------------------------------------|
129
+ | `ssh_pty_start` | 启动持久化 PTY 会话(用于 top、htop、tmux 等) |
130
+ | `ssh_pty_write` | 向 PTY 发送数据(按键、命令) |
131
+ | `ssh_pty_read` | 读取 PTY 输出(screen 模式:当前屏幕,raw 模式:ANSI 流) |
132
+ | `ssh_pty_resize` | 调整 PTY 窗口大小 |
133
+ | `ssh_pty_close` | 关闭 PTY 会话 |
134
+ | `ssh_pty_list` | 列出所有 PTY 会话 |
119
135
 
120
136
  ### 端口转发
121
137
 
122
- | 工具 | 描述 |
123
- |------|------|
124
- | `ssh_forward_local` | 本地端口转发(ssh -L):访问远程服务 |
138
+ | 工具 | 描述 |
139
+ |----------------------|-----------------------|
140
+ | `ssh_forward_local` | 本地端口转发(ssh -L):访问远程服务 |
125
141
  | `ssh_forward_remote` | 远程端口转发(ssh -R):暴露本地服务 |
126
- | `ssh_forward_close` | 关闭端口转发 |
127
- | `ssh_forward_list` | 列出所有端口转发 |
142
+ | `ssh_forward_close` | 关闭端口转发 |
143
+ | `ssh_forward_list` | 列出所有端口转发 |
128
144
 
129
145
  ## 使用示例
130
146
 
147
+ ### 使用 SSH Config(推荐)
148
+
149
+ 如果已在 `~/.ssh/config` 中配置了主机:
150
+
151
+ ```
152
+ # 列出可用主机
153
+ ssh_config_list()
154
+
155
+ # 使用配置的主机名连接
156
+ ssh_connect(configHost="myserver")
157
+ ssh_exec(alias="myserver", command="uptime")
158
+
159
+ # 使用自定义配置文件路径
160
+ ssh_connect(configHost="myserver", configPath="/custom/path/config")
161
+ ```
162
+
163
+ 支持的 SSH config 特性:
164
+
165
+ - `Host` 多别名(如 `Host a b c`)
166
+ - `Host *` 全局默认继承(仅第一个 `Host *` 块)
167
+ - `HostName`、`User`、`Port`、`IdentityFile`
168
+ - `ProxyJump`,支持 `user@host:port` 格式(仅第一跳)
169
+ - 显式参数优先于 config 值(如 `ssh_connect(configHost="x", user="覆盖值")`)
170
+
171
+ **不支持**(跳过):
172
+
173
+ - `Include` 指令
174
+ - `Match` 块(整个块跳过直到下一个 `Host`)
175
+ - 通配符模式(如 `Host *.example.com`)
176
+
177
+ **行为说明**:
178
+
179
+ - 多个 `Host *` 块:仅使用第一个
180
+ - 重复的 Host 定义:`ssh_config_list` 显示全部,`ssh_connect` 使用第一个
181
+ - ProxyJump 中的 IPv6:使用方括号格式 `[2001:db8::1]:22`
182
+
183
+ ### 多主机并行执行
184
+
185
+ 在多个已连接的主机上并行执行同一命令:
186
+
187
+ ```
188
+ 1. ssh_connect(configHost="server1")
189
+ 2. ssh_connect(configHost="server2")
190
+ 3. ssh_connect(configHost="server3")
191
+ 4. ssh_exec_parallel(aliases=["server1", "server2", "server3"], command="uptime")
192
+ ```
193
+
131
194
  ### 基础:连接和执行
132
195
 
133
196
  ```
134
- 1. ssh_connect(host="192.168.1.100", user="root", password="xxx", alias="myserver")
135
- 2. ssh_exec(alias="myserver", command="ls -la /home")
136
- 3. ssh_disconnect(alias="myserver")
197
+ ssh_connect(host="192.168.1.100", user="root", keyPath="/home/.ssh/id_rsa", alias="myserver")
198
+ ssh_exec(alias="myserver", command="ls -la /home")
199
+ ssh_disconnect(alias="myserver")
200
+ ```
201
+
202
+ ### 跳板机
203
+
204
+ 通过跳板机连接内网服务器:
205
+
206
+ ```
207
+ ssh_connect(
208
+ host="10.0.0.5",
209
+ user="root",
210
+ keyPath="/home/.ssh/id_rsa",
211
+ alias="internal",
212
+ jumpHost={
213
+ host: "bastion.example.com",
214
+ user: "admin",
215
+ keyPath: "/home/.ssh/bastion_key"
216
+ }
217
+ )
137
218
  ```
138
219
 
139
220
  ### 切换用户执行(su)
@@ -146,6 +227,9 @@ claude mcp add ssh -- node /path/to/mcp-ssh/dist/index.js
146
227
  // 输出: appuser
147
228
  ```
148
229
 
230
+ 默认加载 shell 配置以确保环境变量可用(`su -c` 创建非交互式 shell,不会自动执行 rc 文件)。支持 bash(`.bashrc`)、zsh(`.zshrc`
231
+ )及其他 shell(`.profile`)。如不需要可设置 `loadProfile=false`。
232
+
149
233
  ### 交互式命令(PTY 模式)
150
234
 
151
235
  用于需要终端的命令:
@@ -228,7 +312,8 @@ ssh_sync(..., dryRun=true)
228
312
 
229
313
  如果远程或本地没有 rsync,会自动回退到 SFTP。
230
314
 
231
- **注意**:rsync 模式使用 SSH 密钥/代理认证,并禁用严格主机密钥检查(`StrictHostKeyChecking=no`)以方便使用。如需主机密钥验证,请使用 SFTP 模式。
315
+ **注意**:rsync 模式使用 SSH 密钥/代理认证,并禁用严格主机密钥检查(`StrictHostKeyChecking=no`)以方便使用。如需主机密钥验证,请使用
316
+ SFTP 模式。
232
317
 
233
318
  ### 持久化 PTY 会话(top、tmux 等)
234
319
 
@@ -267,6 +352,7 @@ ssh_pty_write(ptyId="pty_1_xxx", data="\x02d")
267
352
  ```
268
353
 
269
354
  常用控制序列:
355
+
270
356
  - 回车: `\r` 或 `\n`
271
357
  - Ctrl+C: `\x03`
272
358
  - Ctrl+D: `\x04`
@@ -296,25 +382,25 @@ ssh_forward_close(forwardId="fwd_1_xxx")
296
382
 
297
383
  ### 连接选项
298
384
 
299
- | 选项 | 类型 | 默认值 | 描述 |
300
- |------|------|--------|------|
301
- | `host` | string | *必需* | 服务器地址 |
302
- | `user` | string | *必需* | 用户名 |
303
- | `password` | string | - | 密码认证 |
304
- | `keyPath` | string | - | SSH 私钥路径 |
305
- | `port` | number | 22 | SSH 端口 |
306
- | `alias` | string | 自动生成 | 连接别名,用于后续引用 |
307
- | `env` | object | - | 环境变量 |
308
- | `keepaliveInterval` | number | 30000 | 心跳间隔(毫秒) |
385
+ | 选项 | 类型 | 默认值 | 描述 |
386
+ |---------------------|--------|-------|-------------|
387
+ | `host` | string | *必需* | 服务器地址 |
388
+ | `user` | string | *必需* | 用户名 |
389
+ | `password` | string | - | 密码认证 |
390
+ | `keyPath` | string | - | SSH 私钥路径 |
391
+ | `port` | number | 22 | SSH 端口 |
392
+ | `alias` | string | 自动生成 | 连接别名,用于后续引用 |
393
+ | `env` | object | - | 环境变量 |
394
+ | `keepaliveInterval` | number | 30000 | 心跳间隔(毫秒) |
309
395
 
310
396
  ### 执行选项
311
397
 
312
- | 选项 | 类型 | 默认值 | 描述 |
313
- |------|------|--------|------|
314
- | `timeout` | number | 30000 | 命令超时(毫秒) |
315
- | `cwd` | string | - | 工作目录 |
316
- | `env` | object | - | 额外环境变量 |
317
- | `pty` | boolean | false | 启用 PTY 模式(用于交互式命令) |
398
+ | 选项 | 类型 | 默认值 | 描述 |
399
+ |-----------|---------|-------|--------------------|
400
+ | `timeout` | number | 30000 | 命令超时(毫秒) |
401
+ | `cwd` | string | - | 工作目录 |
402
+ | `env` | object | - | 额外环境变量 |
403
+ | `pty` | boolean | false | 启用 PTY 模式(用于交互式命令) |
318
404
 
319
405
  ## 项目结构
320
406
 
@@ -331,14 +417,6 @@ mcp-ssh/
331
417
  └── README.md
332
418
  ```
333
419
 
334
- ## 路线图
335
-
336
- - [ ] 动态端口转发(SOCKS 代理)
337
- - [ ] SSH Agent 转发
338
- - [ ] 命令历史和审计日志
339
- - [ ] 多主机并行执行
340
- - [ ] SSH 配置文件(~/.ssh/config)自动发现
341
-
342
420
  ## 贡献
343
421
 
344
422
  欢迎贡献!请随时提交 Pull Request。