mcp-hydrocoder-ssh 0.1.2 → 0.1.3
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/CONFIG-GUIDE.md +148 -0
- package/CONFIG-GUIDE_EN.md +148 -0
- package/README_CN.md +325 -0
- package/package.json +4 -1
package/CONFIG-GUIDE.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# 配置指南
|
|
2
|
+
|
|
3
|
+
[README 中文](README_CN.md) | [README English](README.md) | **中文** | [English](CONFIG-GUIDE_EN.md)
|
|
4
|
+
|
|
5
|
+
## 配置文件位置
|
|
6
|
+
|
|
7
|
+
配置文件位于用户目录:
|
|
8
|
+
```
|
|
9
|
+
~/.claude/ssh-mcp-config.json
|
|
10
|
+
```
|
|
11
|
+
**适用场景**:个人常用服务器,所有项目共享
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 配置示例
|
|
16
|
+
|
|
17
|
+
### 使用 SSH Agent(推荐)
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"servers": [
|
|
21
|
+
{
|
|
22
|
+
"id": "prod-server",
|
|
23
|
+
"name": "Production Server",
|
|
24
|
+
"host": "example.com",
|
|
25
|
+
"port": 22,
|
|
26
|
+
"username": "deploy",
|
|
27
|
+
"authMethod": "agent"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### 使用私钥文件
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"servers": [
|
|
37
|
+
{
|
|
38
|
+
"id": "my-server",
|
|
39
|
+
"name": "My Server",
|
|
40
|
+
"host": "8.140.225.161",
|
|
41
|
+
"port": 22,
|
|
42
|
+
"username": "root",
|
|
43
|
+
"authMethod": "key",
|
|
44
|
+
"privateKeyPath": "D:\\Data\\aliyun-ecs\\docslim.pem"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 使用密码(不推荐)
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"servers": [
|
|
54
|
+
{
|
|
55
|
+
"id": "test-server",
|
|
56
|
+
"name": "Test Server",
|
|
57
|
+
"host": "test.example.com",
|
|
58
|
+
"port": 22,
|
|
59
|
+
"username": "ubuntu",
|
|
60
|
+
"authMethod": "password",
|
|
61
|
+
"password": "your-password"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 完整配置
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"servers": [
|
|
74
|
+
{
|
|
75
|
+
"id": "prod-server",
|
|
76
|
+
"name": "Production Server",
|
|
77
|
+
"host": "prod.example.com",
|
|
78
|
+
"port": 22,
|
|
79
|
+
"username": "deploy",
|
|
80
|
+
"authMethod": "agent",
|
|
81
|
+
"connectTimeout": 30000
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "test-server",
|
|
85
|
+
"name": "Test Server",
|
|
86
|
+
"host": "test.example.com",
|
|
87
|
+
"port": 2222,
|
|
88
|
+
"username": "ubuntu",
|
|
89
|
+
"authMethod": "key",
|
|
90
|
+
"privateKeyPath": "~/.ssh/id_rsa",
|
|
91
|
+
"connectTimeout": 15000
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"settings": {
|
|
95
|
+
"defaultConnectTimeout": 30000,
|
|
96
|
+
"defaultKeepaliveInterval": 60000,
|
|
97
|
+
"commandTimeout": 60000,
|
|
98
|
+
"maxConnections": 5,
|
|
99
|
+
"autoReconnect": false,
|
|
100
|
+
"logCommands": true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 字段说明
|
|
108
|
+
|
|
109
|
+
### 服务器配置
|
|
110
|
+
| 字段 | 必填 | 说明 |
|
|
111
|
+
|------|------|------|
|
|
112
|
+
| `id` | ✅ | 服务器唯一标识,用于连接命令 |
|
|
113
|
+
| `name` | ✅ | 服务器名称,方便识别 |
|
|
114
|
+
| `host` | ✅ | 服务器地址(IP 或域名) |
|
|
115
|
+
| `port` | ❌ | SSH 端口,默认 22 |
|
|
116
|
+
| `username` | ✅ | SSH 用户名 |
|
|
117
|
+
| `authMethod` | ❌ | 认证方式:`agent` / `key` / `password`,默认 `agent` |
|
|
118
|
+
| `privateKeyPath` | ❌ | 私钥路径(`authMethod=key` 时需要) |
|
|
119
|
+
| `password` | ❌ | 密码(`authMethod=password` 时需要) |
|
|
120
|
+
| `connectTimeout` | ❌ | 连接超时(毫秒),默认 30000 |
|
|
121
|
+
|
|
122
|
+
### 全局设置
|
|
123
|
+
| 字段 | 说明 | 默认值 |
|
|
124
|
+
|------|------|--------|
|
|
125
|
+
| `defaultConnectTimeout` | 默认连接超时 | 30000 |
|
|
126
|
+
| `defaultKeepaliveInterval` | 默认心跳间隔(毫秒) | 60000 |
|
|
127
|
+
| `commandTimeout` | 命令执行超时 | 60000 |
|
|
128
|
+
| `maxConnections` | 最大连接数 | 5 |
|
|
129
|
+
| `autoReconnect` | 自动重连 | false |
|
|
130
|
+
| `logCommands` | 记录命令日志 | true |
|
|
131
|
+
|
|
132
|
+
**心跳配置说明:** `defaultKeepaliveInterval` 用于设置 SSH 连接的心跳间隔,保持长连接活跃,防止因超时而断开。
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 常见问题
|
|
137
|
+
|
|
138
|
+
### SSH Agent 未运行
|
|
139
|
+
```bash
|
|
140
|
+
# Windows:确保 "OpenSSH Authentication Agent" 服务正在运行
|
|
141
|
+
# 或使用密钥文件认证方式
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### 私钥权限问题
|
|
145
|
+
确保私钥文件只有当前用户可读取。
|
|
146
|
+
|
|
147
|
+
### 配置文件格式错误
|
|
148
|
+
使用 JSON 验证工具检查语法。
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# Configuration Guide
|
|
2
|
+
|
|
3
|
+
[README 中文](README_CN.md) | [README English](README.md) | [中文](CONFIG-GUIDE.md) | **English**
|
|
4
|
+
|
|
5
|
+
## Configuration File Location
|
|
6
|
+
|
|
7
|
+
The configuration file is located in the user directory:
|
|
8
|
+
```
|
|
9
|
+
~/.claude/ssh-mcp-config.json
|
|
10
|
+
```
|
|
11
|
+
**Use case**: Personal frequently-used servers, shared across all projects
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Configuration Examples
|
|
16
|
+
|
|
17
|
+
### Using SSH Agent (Recommended)
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"servers": [
|
|
21
|
+
{
|
|
22
|
+
"id": "prod-server",
|
|
23
|
+
"name": "Production Server",
|
|
24
|
+
"host": "example.com",
|
|
25
|
+
"port": 22,
|
|
26
|
+
"username": "deploy",
|
|
27
|
+
"authMethod": "agent"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Using Private Key File
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"servers": [
|
|
37
|
+
{
|
|
38
|
+
"id": "my-server",
|
|
39
|
+
"name": "My Server",
|
|
40
|
+
"host": "8.140.225.161",
|
|
41
|
+
"port": 22,
|
|
42
|
+
"username": "root",
|
|
43
|
+
"authMethod": "key",
|
|
44
|
+
"privateKeyPath": "D:\\Data\\aliyun-ecs\\docslim.pem"
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Using Password (Not Recommended)
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"servers": [
|
|
54
|
+
{
|
|
55
|
+
"id": "test-server",
|
|
56
|
+
"name": "Test Server",
|
|
57
|
+
"host": "test.example.com",
|
|
58
|
+
"port": 22,
|
|
59
|
+
"username": "ubuntu",
|
|
60
|
+
"authMethod": "password",
|
|
61
|
+
"password": "your-password"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Complete Configuration
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"servers": [
|
|
74
|
+
{
|
|
75
|
+
"id": "prod-server",
|
|
76
|
+
"name": "Production Server",
|
|
77
|
+
"host": "prod.example.com",
|
|
78
|
+
"port": 22,
|
|
79
|
+
"username": "deploy",
|
|
80
|
+
"authMethod": "agent",
|
|
81
|
+
"connectTimeout": 30000
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"id": "test-server",
|
|
85
|
+
"name": "Test Server",
|
|
86
|
+
"host": "test.example.com",
|
|
87
|
+
"port": 2222,
|
|
88
|
+
"username": "ubuntu",
|
|
89
|
+
"authMethod": "key",
|
|
90
|
+
"privateKeyPath": "~/.ssh/id_rsa",
|
|
91
|
+
"connectTimeout": 15000
|
|
92
|
+
}
|
|
93
|
+
],
|
|
94
|
+
"settings": {
|
|
95
|
+
"defaultConnectTimeout": 30000,
|
|
96
|
+
"defaultKeepaliveInterval": 60000,
|
|
97
|
+
"commandTimeout": 60000,
|
|
98
|
+
"maxConnections": 5,
|
|
99
|
+
"autoReconnect": false,
|
|
100
|
+
"logCommands": true
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## Field Descriptions
|
|
108
|
+
|
|
109
|
+
### Server Configuration
|
|
110
|
+
| Field | Required | Description |
|
|
111
|
+
|-------|----------|-------------|
|
|
112
|
+
| `id` | ✅ | Unique server identifier, used for connect command |
|
|
113
|
+
| `name` | ✅ | Server name for easy identification |
|
|
114
|
+
| `host` | ✅ | Server address (IP or domain) |
|
|
115
|
+
| `port` | ❌ | SSH port, default 22 |
|
|
116
|
+
| `username` | ✅ | SSH username |
|
|
117
|
+
| `authMethod` | ❌ | Authentication method: `agent` / `key` / `password`, default `agent` |
|
|
118
|
+
| `privateKeyPath` | ❌ | Private key path (required when `authMethod=key`) |
|
|
119
|
+
| `password` | ❌ | Password (required when `authMethod=password`) |
|
|
120
|
+
| `connectTimeout` | ❌ | Connection timeout (milliseconds), default 30000 |
|
|
121
|
+
|
|
122
|
+
### Global Settings
|
|
123
|
+
| Field | Description | Default |
|
|
124
|
+
|-------|-------------|---------|
|
|
125
|
+
| `defaultConnectTimeout` | Default connection timeout | 30000 |
|
|
126
|
+
| `defaultKeepaliveInterval` | Default keepalive interval (milliseconds) | 60000 |
|
|
127
|
+
| `commandTimeout` | Command execution timeout | 60000 |
|
|
128
|
+
| `maxConnections` | Maximum connections | 5 |
|
|
129
|
+
| `autoReconnect` | Auto reconnect | false |
|
|
130
|
+
| `logCommands` | Log commands | true |
|
|
131
|
+
|
|
132
|
+
**Keepalive Configuration:** `defaultKeepaliveInterval` sets the SSH connection keepalive interval to keep persistent connections active and prevent timeout disconnections.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## Troubleshooting
|
|
137
|
+
|
|
138
|
+
### SSH Agent Not Running
|
|
139
|
+
```bash
|
|
140
|
+
# Windows: Ensure "OpenSSH Authentication Agent" service is running
|
|
141
|
+
# Or use key file authentication method
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Private Key Permissions
|
|
145
|
+
Ensure the private key file is readable only by the current user.
|
|
146
|
+
|
|
147
|
+
### Configuration File Format Error
|
|
148
|
+
Use a JSON validation tool to check syntax.
|
package/README_CN.md
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# mcp-hydrocoder-ssh
|
|
2
|
+
|
|
3
|
+
**中文** | [English](README.md) | [Configuration Guide](CONFIG-GUIDE_EN.md) | [配置指南](CONFIG-GUIDE.md)
|
|
4
|
+
|
|
5
|
+
为 Claude Code 提供 SSH 远程连接能力的 MCP 服务器。连接远程服务器、执行命令、自动化部署,无需单独打开 SSH 工具窗口。
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/mcp-hydrocoder-ssh)
|
|
8
|
+
[](https://opensource.org/licenses/MIT)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 第一部分:功能介绍
|
|
13
|
+
|
|
14
|
+
### 这是什么?
|
|
15
|
+
|
|
16
|
+
`mcp-hydrocoder-ssh` 是一个 MCP (Model Context Protocol) 服务器,让 Claude Code 能够:
|
|
17
|
+
- 🔌 直接连接远程 SSH 服务器(后台长连接)
|
|
18
|
+
- ⚡ 执行命令并获取完整输出
|
|
19
|
+
- 🔄 保持连接状态,支持多步连续操作
|
|
20
|
+
- 🚀 运行部署脚本(git pull、npm install、systemctl restart 等)
|
|
21
|
+
|
|
22
|
+
### 主要好处
|
|
23
|
+
|
|
24
|
+
| 好处 | 说明 |
|
|
25
|
+
|------|------|
|
|
26
|
+
| **无需切换窗口** | 在 Claude Code 对话中完成所有远程操作 |
|
|
27
|
+
| **智能部署** | Claude 可根据命令输出自动判断下一步操作 |
|
|
28
|
+
| **多服务器管理** | 同时管理多个服务器配置,快速切换 |
|
|
29
|
+
| **安全认证** | 支持 SSH agent、密钥文件 |
|
|
30
|
+
| **连接池管理** | 保持长连接,避免重复认证和连接开销 |
|
|
31
|
+
|
|
32
|
+
### 可用工具
|
|
33
|
+
|
|
34
|
+
**SSH 连接工具 (5 个):**
|
|
35
|
+
- `ssh_list_servers` - 列出所有配置的服务器
|
|
36
|
+
- `ssh_connect` - 连接到指定服务器
|
|
37
|
+
- `ssh_exec` - 执行命令(支持指定工作目录)
|
|
38
|
+
- `ssh_get_status` - 获取连接状态
|
|
39
|
+
- `ssh_disconnect` - 断开连接
|
|
40
|
+
|
|
41
|
+
**配置管理工具 (5 个):**
|
|
42
|
+
- `ssh_add_server` - 添加新服务器配置
|
|
43
|
+
- `ssh_remove_server` - 删除服务器配置
|
|
44
|
+
- `ssh_update_server` - 更新服务器配置
|
|
45
|
+
- `ssh_view_config` - 查看配置(过滤敏感信息)
|
|
46
|
+
- `ssh_help` - 显示帮助信息
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 第二部分:快速安装(推荐)
|
|
51
|
+
|
|
52
|
+
### 步骤 1:选择安装方式
|
|
53
|
+
|
|
54
|
+
**方式 A:全局安装(推荐)**
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install -g mcp-hydrocoder-ssh
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**方式 B:使用 npx(无需安装)**
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
# 无需执行任何命令,直接在配置中使用 npx
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
### 步骤 2:配置 Claude Code
|
|
69
|
+
|
|
70
|
+
编辑用户目录的 `~/.claude.json` 文件:
|
|
71
|
+
|
|
72
|
+
**Windows 路径:** `C:\Users\<你的用户名>\.claude.json`
|
|
73
|
+
**macOS/Linux 路径:** `~/.claude.json`
|
|
74
|
+
|
|
75
|
+
**方式 A(全局安装)的配置:**
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"hydrossh": {
|
|
80
|
+
"command": "mcp-hydrocoder-ssh"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
**方式 B(npx)的配置:**
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"mcpServers": {
|
|
90
|
+
"hydrossh": {
|
|
91
|
+
"command": "npx",
|
|
92
|
+
"args": ["-y", "mcp-hydrocoder-ssh"]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
> **注意:**
|
|
99
|
+
> - `hydrossh` 是服务器名称标识,可以改为任意你喜欢的名字。
|
|
100
|
+
> - `-y` 标志让 npx 自动确认安装,避免交互提示卡住。
|
|
101
|
+
|
|
102
|
+
### 步骤 3:重启 Claude Code
|
|
103
|
+
|
|
104
|
+
关闭并重新打开 Claude Code,配置将自动加载。
|
|
105
|
+
|
|
106
|
+
### 步骤 4:验证安装
|
|
107
|
+
|
|
108
|
+
在 Claude Code 中输入:
|
|
109
|
+
```
|
|
110
|
+
列出可用的 SSH 服务器
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
如果看到服务器列表(空列表表示尚未配置),说明安装成功。你可以通过自然语言让 Claude 帮你添加配置、修改配置或连接服务器,连接后可以执行各种操作。
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 第三部分:源码使用(开发方式)
|
|
118
|
+
|
|
119
|
+
### 1. 下载源码
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
git clone https://github.com/hydroCoderClaud/mcpHydroSSH.git
|
|
123
|
+
cd mcpHydroSSH
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 2. 安装依赖
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
npm install
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 3. 编译构建
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
npm run build
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
编译输出到 `dist/` 目录,主要文件:
|
|
139
|
+
- `dist/index.js` - MCP 服务器入口
|
|
140
|
+
- `dist/ssh-manager.js` - SSH 连接管理
|
|
141
|
+
- `dist/config.js` - 配置管理
|
|
142
|
+
|
|
143
|
+
### 4. 配置 Claude Code
|
|
144
|
+
|
|
145
|
+
编辑用户目录的 `~/.claude.json` 文件:
|
|
146
|
+
|
|
147
|
+
**Windows 路径:** `C:\Users\<你的用户名>\.claude.json`
|
|
148
|
+
**macOS/Linux 路径:** `~/.claude.json`
|
|
149
|
+
|
|
150
|
+
```json
|
|
151
|
+
{
|
|
152
|
+
"mcpServers": {
|
|
153
|
+
"hydrossh": {
|
|
154
|
+
"command": "node",
|
|
155
|
+
"args": ["<项目绝对路径>/dist/index.js"]
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
> **注意:** 将 `<项目绝对路径>` 替换为你实际的源码目录绝对路径。
|
|
162
|
+
> - Windows 示例:`C:\\workspace\\develop\\ccExtensions\\mcpHydroSSH`
|
|
163
|
+
> - macOS/Linux 示例:`/home/user/projects/mcpHydroSSH`
|
|
164
|
+
|
|
165
|
+
### 5. 重启 Claude Code
|
|
166
|
+
|
|
167
|
+
关闭并重新打开 Claude Code,配置将自动加载。
|
|
168
|
+
|
|
169
|
+
### 6. 开发模式(可选)
|
|
170
|
+
|
|
171
|
+
如需热重载开发:
|
|
172
|
+
```bash
|
|
173
|
+
npm run dev
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
此时 Claude Code 配置改为:
|
|
177
|
+
|
|
178
|
+
```json
|
|
179
|
+
{
|
|
180
|
+
"mcpServers": {
|
|
181
|
+
"hydrossh": {
|
|
182
|
+
"command": "npx",
|
|
183
|
+
"args": ["tsx", "<项目绝对路径>/src/index.ts"]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
> **注意:** 将 `<项目绝对路径>` 替换为你实际的源码目录绝对路径。
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 附录 A:配置 SSH 服务器
|
|
194
|
+
|
|
195
|
+
首次运行时,服务器会自动创建配置文件 `~/.hydrossh/config.json`。
|
|
196
|
+
|
|
197
|
+
### 配置示例
|
|
198
|
+
|
|
199
|
+
```json
|
|
200
|
+
{
|
|
201
|
+
"servers": [
|
|
202
|
+
{
|
|
203
|
+
"id": "prod-server",
|
|
204
|
+
"name": "生产服务器",
|
|
205
|
+
"host": "example.com",
|
|
206
|
+
"port": 22,
|
|
207
|
+
"username": "deploy",
|
|
208
|
+
"authMethod": "agent"
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
"id": "test-server",
|
|
212
|
+
"name": "测试服务器",
|
|
213
|
+
"host": "test.example.com",
|
|
214
|
+
"username": "ubuntu",
|
|
215
|
+
"authMethod": "key",
|
|
216
|
+
"privateKeyPath": "~/.ssh/id_rsa"
|
|
217
|
+
}
|
|
218
|
+
],
|
|
219
|
+
"settings": {
|
|
220
|
+
"defaultConnectTimeout": 30000,
|
|
221
|
+
"defaultKeepaliveInterval": 60000,
|
|
222
|
+
"commandTimeout": 60000,
|
|
223
|
+
"maxConnections": 5,
|
|
224
|
+
"logCommands": true
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### 认证方式
|
|
230
|
+
|
|
231
|
+
| 方式 | 配置 | 说明 |
|
|
232
|
+
|------|------|------|
|
|
233
|
+
| **SSH Agent** | `"authMethod": "agent"` | 推荐,使用系统 SSH agent |
|
|
234
|
+
| **密钥文件** | `"authMethod": "key", "privateKeyPath": "~/.ssh/id_rsa"` | 默认,直接读取密钥文件 |
|
|
235
|
+
| **密码** | `"authMethod": "password", "password": "xxx"` | 不推荐,密码会明文存储 |
|
|
236
|
+
|
|
237
|
+
详见 [CONFIG-GUIDE.md](CONFIG-GUIDE.md)
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## 附录 B:使用示例
|
|
242
|
+
|
|
243
|
+
### 基本用法
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
用户:列出可用的服务器
|
|
247
|
+
Claude: 发现 2 个配置的服务器:prod-server、test-server
|
|
248
|
+
|
|
249
|
+
用户:连接到 prod-server
|
|
250
|
+
Claude: [调用 ssh_connect] 连接成功!connectionId: xxx
|
|
251
|
+
|
|
252
|
+
用户:执行命令:uptime
|
|
253
|
+
Claude: [调用 ssh_exec] 返回:up 30 days, 2 users, load average: 0.1, 0.2, 0.5
|
|
254
|
+
|
|
255
|
+
用户:断开连接
|
|
256
|
+
Claude: [调用 ssh_disconnect] 已断开
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### 自动化部署
|
|
260
|
+
|
|
261
|
+
```
|
|
262
|
+
用户:部署最新代码到生产服务器
|
|
263
|
+
Claude: 好的,我来执行部署流程...
|
|
264
|
+
1. 连接 prod-server
|
|
265
|
+
2. cd /opt/myapp && git pull
|
|
266
|
+
3. npm ci --production
|
|
267
|
+
4. sudo systemctl restart myapp
|
|
268
|
+
5. 检查服务状态
|
|
269
|
+
6. 断开连接
|
|
270
|
+
部署完成!
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
275
|
+
## 附录 C:安全说明
|
|
276
|
+
|
|
277
|
+
- 🔒 **推荐 SSH Agent** - 优先使用 `authMethod: "agent"`
|
|
278
|
+
- 🔒 **配置文件权限** - 确保 `~/.hydrossh/config.json` 权限设置为仅自己可读
|
|
279
|
+
- 🔒 **配置查看过滤** - `ssh_view_config` 工具会自动过滤密码和密钥路径
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## 附录 D:故障排查
|
|
284
|
+
|
|
285
|
+
| 问题 | 解决方案 |
|
|
286
|
+
|------|---------|
|
|
287
|
+
| SSH Agent 未运行 | Windows: 启动 "OpenSSH Authentication Agent" 服务 |
|
|
288
|
+
| 连接超时 | 检查服务器地址、端口、网络连通性 |
|
|
289
|
+
| 命令未找到 | 确认 npm 全局安装成功,或检查 PATH 环境变量 |
|
|
290
|
+
| 配置未加载 | 检查 `~/.claude.json` 格式是否正确 |
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 附录 E:命令参考
|
|
295
|
+
|
|
296
|
+
### 开发命令
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
npm run build # 编译构建
|
|
300
|
+
npm run dev # 开发模式(热重载)
|
|
301
|
+
npm test # 运行测试
|
|
302
|
+
npm run lint # 代码检查
|
|
303
|
+
npm run format # 代码格式化
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### MCP 工具参数
|
|
307
|
+
|
|
308
|
+
| 工具 | 参数 | 说明 |
|
|
309
|
+
|------|------|------|
|
|
310
|
+
| `ssh_list_servers` | 无 | 列出所有配置的服务器 |
|
|
311
|
+
| `ssh_connect` | `serverId`, `timeout?` | 连接到服务器 |
|
|
312
|
+
| `ssh_exec` | `command`, `connectionId?`, `timeout?`, `cwd?` | 执行命令 |
|
|
313
|
+
| `ssh_get_status` | `connectionId?` | 获取连接状态(不传返回全部) |
|
|
314
|
+
| `ssh_disconnect` | `connectionId?` | 断开连接(不传断开最近的一个) |
|
|
315
|
+
| `ssh_add_server` | `id`, `name`, `host`, `username`, `port?`, `authMethod?`, `privateKeyPath?`, `password?` | 添加服务器配置 |
|
|
316
|
+
| `ssh_remove_server` | `serverId` | 删除服务器配置 |
|
|
317
|
+
| `ssh_update_server` | `serverId`, `name?`, `host?`, `port?`, `username?`, `authMethod?`, `privateKeyPath?`, `password?` | 更新服务器配置 |
|
|
318
|
+
| `ssh_view_config` | 无 | 查看配置(过滤敏感信息) |
|
|
319
|
+
| `ssh_help` | `topic?` | 显示帮助信息 |
|
|
320
|
+
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
## License
|
|
324
|
+
|
|
325
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-hydrocoder-ssh",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "SSH MCP Server for Claude Code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"dist/types.js",
|
|
15
15
|
"example-config.json",
|
|
16
16
|
"README.md",
|
|
17
|
+
"README_CN.md",
|
|
18
|
+
"CONFIG-GUIDE.md",
|
|
19
|
+
"CONFIG-GUIDE_EN.md",
|
|
17
20
|
"LICENSE"
|
|
18
21
|
],
|
|
19
22
|
"scripts": {
|