@pyrokine/mcp-ssh 1.2.2 → 1.3.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 +2 -2
- package/README_zh.md +2 -2
- package/dist/index.js +16 -1
- package/dist/tools/exec.js +6 -4
- package/package.json +2 -2
- package/src/index.ts +16 -1
- package/src/tools/exec.ts +8 -4
package/README.md
CHANGED
|
@@ -57,8 +57,8 @@ npm install -g @pyrokine/mcp-ssh
|
|
|
57
57
|
### From Source
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
git clone https://github.com/Pyrokine/claude-
|
|
61
|
-
cd claude-
|
|
60
|
+
git clone https://github.com/Pyrokine/claude-tools.git
|
|
61
|
+
cd claude-tools/mcp-ssh
|
|
62
62
|
npm install
|
|
63
63
|
npm run build
|
|
64
64
|
```
|
package/README_zh.md
CHANGED
|
@@ -57,8 +57,8 @@ npm install -g @pyrokine/mcp-ssh
|
|
|
57
57
|
### 从源码安装
|
|
58
58
|
|
|
59
59
|
```bash
|
|
60
|
-
git clone https://github.com/Pyrokine/claude-
|
|
61
|
-
cd claude-
|
|
60
|
+
git clone https://github.com/Pyrokine/claude-tools.git
|
|
61
|
+
cd claude-tools/mcp-ssh
|
|
62
62
|
npm install
|
|
63
63
|
npm run build
|
|
64
64
|
```
|
package/dist/index.js
CHANGED
|
@@ -16,13 +16,28 @@
|
|
|
16
16
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
17
17
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
18
18
|
import { registerConnectionTools, registerExecTools, registerFileTools, registerForwardTools, registerPtyTools, } from './tools/index.js';
|
|
19
|
-
const server = new McpServer({ name: 'ssh-mcp-pro', version: '1.
|
|
19
|
+
const server = new McpServer({ name: 'ssh-mcp-pro', version: '1.2.2' }, { capabilities: { tools: {} } });
|
|
20
20
|
registerConnectionTools(server);
|
|
21
21
|
registerExecTools(server);
|
|
22
22
|
registerFileTools(server);
|
|
23
23
|
registerPtyTools(server);
|
|
24
24
|
registerForwardTools(server);
|
|
25
25
|
async function main() {
|
|
26
|
+
// 防止父进程退出后成为孤儿进程持续占用 CPU
|
|
27
|
+
process.on('uncaughtException', (error) => {
|
|
28
|
+
if (error.code === 'EPIPE' || error.code === 'ERR_STREAM_DESTROYED') {
|
|
29
|
+
process.exit(0);
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
console.error('[MCP] Uncaught exception:', error);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
process.stdin.on('end', () => process.exit(0));
|
|
39
|
+
process.stdout.on('error', () => process.exit(0));
|
|
40
|
+
process.stderr.on('error', () => process.exit(0));
|
|
26
41
|
const transport = new StdioServerTransport();
|
|
27
42
|
await server.connect(transport);
|
|
28
43
|
console.error('SSH MCP Pro server started');
|
package/dist/tools/exec.js
CHANGED
|
@@ -11,7 +11,7 @@ import { formatError, formatResult } from './utils.js';
|
|
|
11
11
|
const execSchema = z.object({
|
|
12
12
|
alias: z.string().describe('连接别名'),
|
|
13
13
|
command: z.string().describe('要执行的命令'),
|
|
14
|
-
timeout: z.number().optional().describe('超时(毫秒),默认 30000'),
|
|
14
|
+
timeout: z.number().optional().describe('超时(毫秒),默认 30000。长时间命令可设更大值如 600000(10 分钟),或用 ssh_pty_start 替代'),
|
|
15
15
|
cwd: z.string().optional().describe('工作目录(可选)'),
|
|
16
16
|
env: z.record(z.string()).optional().describe('额外环境变量'),
|
|
17
17
|
pty: z.boolean().optional().describe('是否使用 PTY 模式(用于 top 等交互式命令)'),
|
|
@@ -21,7 +21,7 @@ const execAsUserSchema = z.object({
|
|
|
21
21
|
command: z.string().describe('要执行的命令'),
|
|
22
22
|
targetUser: z.string().describe('目标用户名'),
|
|
23
23
|
timeout: z.number().optional().describe('超时(毫秒)'),
|
|
24
|
-
loadProfile: z.boolean().optional().describe('
|
|
24
|
+
loadProfile: z.boolean().optional().describe('是否加载目标用户的 shell 配置(默认 true)。profile 加载慢导致超时时设为 false'),
|
|
25
25
|
});
|
|
26
26
|
const execSudoSchema = z.object({
|
|
27
27
|
alias: z.string().describe('连接别名'),
|
|
@@ -191,7 +191,7 @@ export function registerExecTools(server) {
|
|
|
191
191
|
|
|
192
192
|
适用场景: SSH 以 root 登录,但需要以其他用户(如 caros)执行命令。
|
|
193
193
|
|
|
194
|
-
默认加载目标用户的 shell
|
|
194
|
+
默认加载目标用户的 shell 配置以获取环境变量。如果 profile 加载耗时过长导致超时,设 loadProfile=false 跳过。
|
|
195
195
|
支持 bash(.bashrc)、zsh(.zshrc) 及其他 shell(.profile)。
|
|
196
196
|
|
|
197
197
|
示例: ssh_exec_as_user(alias="server", command="whoami", targetUser="caros")`,
|
|
@@ -202,7 +202,9 @@ export function registerExecTools(server) {
|
|
|
202
202
|
inputSchema: execSudoSchema,
|
|
203
203
|
}, (args) => handleExecSudo(args));
|
|
204
204
|
server.registerTool('ssh_exec_batch', {
|
|
205
|
-
description:
|
|
205
|
+
description: `批量执行多条命令。每条命令在独立 SSH channel 中执行,环境变量不共享。
|
|
206
|
+
|
|
207
|
+
如需命令间共享环境(如 export 变量),用分号拼接为单条命令通过 ssh_exec 执行。`,
|
|
206
208
|
inputSchema: execBatchSchema,
|
|
207
209
|
}, (args) => handleExecBatch(args));
|
|
208
210
|
server.registerTool('ssh_quick_exec', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyrokine/mcp-ssh",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A comprehensive SSH MCP Server for Claude Code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
|
-
"url": "https://github.com/Pyrokine/claude-
|
|
28
|
+
"url": "https://github.com/Pyrokine/claude-tools.git"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
package/src/index.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
} from './tools/index.js'
|
|
26
26
|
|
|
27
27
|
const server = new McpServer(
|
|
28
|
-
{ name: 'ssh-mcp-pro', version: '1.
|
|
28
|
+
{ name: 'ssh-mcp-pro', version: '1.2.2' },
|
|
29
29
|
{ capabilities: { tools: {} } },
|
|
30
30
|
)
|
|
31
31
|
|
|
@@ -36,6 +36,21 @@ registerPtyTools(server)
|
|
|
36
36
|
registerForwardTools(server)
|
|
37
37
|
|
|
38
38
|
async function main() {
|
|
39
|
+
// 防止父进程退出后成为孤儿进程持续占用 CPU
|
|
40
|
+
process.on('uncaughtException', (error: NodeJS.ErrnoException) => {
|
|
41
|
+
if (error.code === 'EPIPE' || error.code === 'ERR_STREAM_DESTROYED') {
|
|
42
|
+
process.exit(0)
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
console.error('[MCP] Uncaught exception:', error)
|
|
46
|
+
} catch {
|
|
47
|
+
process.exit(1)
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
process.stdin.on('end', () => process.exit(0))
|
|
51
|
+
process.stdout.on('error', () => process.exit(0))
|
|
52
|
+
process.stderr.on('error', () => process.exit(0))
|
|
53
|
+
|
|
39
54
|
const transport = new StdioServerTransport()
|
|
40
55
|
await server.connect(transport)
|
|
41
56
|
console.error('SSH MCP Pro server started')
|
package/src/tools/exec.ts
CHANGED
|
@@ -15,7 +15,8 @@ import {formatError, formatResult} from './utils.js'
|
|
|
15
15
|
const execSchema = z.object({
|
|
16
16
|
alias: z.string().describe('连接别名'),
|
|
17
17
|
command: z.string().describe('要执行的命令'),
|
|
18
|
-
timeout: z.number().optional().describe(
|
|
18
|
+
timeout: z.number().optional().describe(
|
|
19
|
+
'超时(毫秒),默认 30000。长时间命令可设更大值如 600000(10 分钟),或用 ssh_pty_start 替代'),
|
|
19
20
|
cwd: z.string().optional().describe('工作目录(可选)'),
|
|
20
21
|
env: z.record(z.string()).optional().describe('额外环境变量'),
|
|
21
22
|
pty: z.boolean().optional().describe('是否使用 PTY 模式(用于 top 等交互式命令)'),
|
|
@@ -26,7 +27,8 @@ const execAsUserSchema = z.object({
|
|
|
26
27
|
command: z.string().describe('要执行的命令'),
|
|
27
28
|
targetUser: z.string().describe('目标用户名'),
|
|
28
29
|
timeout: z.number().optional().describe('超时(毫秒)'),
|
|
29
|
-
loadProfile: z.boolean().optional().describe(
|
|
30
|
+
loadProfile: z.boolean().optional().describe(
|
|
31
|
+
'是否加载目标用户的 shell 配置(默认 true)。profile 加载慢导致超时时设为 false'),
|
|
30
32
|
})
|
|
31
33
|
|
|
32
34
|
const execSudoSchema = z.object({
|
|
@@ -226,7 +228,7 @@ export function registerExecTools(server: McpServer): void {
|
|
|
226
228
|
|
|
227
229
|
适用场景: SSH 以 root 登录,但需要以其他用户(如 caros)执行命令。
|
|
228
230
|
|
|
229
|
-
默认加载目标用户的 shell
|
|
231
|
+
默认加载目标用户的 shell 配置以获取环境变量。如果 profile 加载耗时过长导致超时,设 loadProfile=false 跳过。
|
|
230
232
|
支持 bash(.bashrc)、zsh(.zshrc) 及其他 shell(.profile)。
|
|
231
233
|
|
|
232
234
|
示例: ssh_exec_as_user(alias="server", command="whoami", targetUser="caros")`,
|
|
@@ -239,7 +241,9 @@ export function registerExecTools(server: McpServer): void {
|
|
|
239
241
|
}, (args) => handleExecSudo(args))
|
|
240
242
|
|
|
241
243
|
server.registerTool('ssh_exec_batch', {
|
|
242
|
-
description:
|
|
244
|
+
description: `批量执行多条命令。每条命令在独立 SSH channel 中执行,环境变量不共享。
|
|
245
|
+
|
|
246
|
+
如需命令间共享环境(如 export 变量),用分号拼接为单条命令通过 ssh_exec 执行。`,
|
|
243
247
|
inputSchema: execBatchSchema,
|
|
244
248
|
}, (args) => handleExecBatch(args))
|
|
245
249
|
|