@pyrokine/mcp-ssh 2.4.1 → 2.4.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/README.md +174 -130
- package/README_zh.md +232 -128
- package/dist/directory-verification.js +29 -4
- package/dist/file-ops.d.ts +13 -8
- package/dist/file-ops.js +191 -115
- package/dist/forward-manager.js +9 -3
- package/dist/operation-manager.d.ts +0 -5
- package/dist/operation-manager.js +13 -55
- package/dist/pty-manager.d.ts +3 -3
- package/dist/pty-manager.js +61 -15
- package/dist/session-manager.d.ts +3 -3
- package/dist/session-manager.js +44 -20
- package/dist/sftp-timeout.d.ts +9 -0
- package/dist/sftp-timeout.js +49 -0
- package/dist/tools/connection.js +75 -29
- package/dist/tools/exec.js +16 -6
- package/dist/tools/file.js +101 -55
- package/dist/tools/forward.js +6 -5
- package/dist/tools/operation.js +2 -1
- package/dist/tools/pty.js +17 -13
- package/dist/tools/schema.d.ts +4 -0
- package/dist/tools/schema.js +9 -0
- package/dist/types.d.ts +15 -0
- package/dist/utf8.d.ts +3 -0
- package/dist/utf8.js +44 -0
- package/package.json +8 -8
package/dist/tools/operation.js
CHANGED
|
@@ -30,7 +30,8 @@ const operationStartSchema = z.object({
|
|
|
30
30
|
.positive()
|
|
31
31
|
.max(MAX_OPERATION_START_TIMEOUT_MS)
|
|
32
32
|
.optional()
|
|
33
|
-
.describe(`等待 SSH operation channel 建立的超时,默认 ${DEFAULT_OPERATION_START_TIMEOUT_MS}ms
|
|
33
|
+
.describe(`等待 SSH operation channel 建立的超时,默认 ${DEFAULT_OPERATION_START_TIMEOUT_MS}ms,` +
|
|
34
|
+
`最大 ${MAX_OPERATION_START_TIMEOUT_MS}ms`),
|
|
34
35
|
});
|
|
35
36
|
const operationIdSchema = z.object({
|
|
36
37
|
operationId: z.string().describe('tracked operation ID'),
|
package/dist/tools/pty.js
CHANGED
|
@@ -11,8 +11,8 @@ import { formatError, formatResult } from './utils.js'; // ========== Schemas ==
|
|
|
11
11
|
const ptyStartSchema = z.object({
|
|
12
12
|
alias: z.string().describe('连接别名'),
|
|
13
13
|
command: z.string().describe('要执行的命令'),
|
|
14
|
-
rows: z.number().optional().describe('终端行数,默认 24'),
|
|
15
|
-
cols: z.number().optional().describe('终端列数,默认 80'),
|
|
14
|
+
rows: z.number().int().positive().optional().describe('终端行数,默认 24'),
|
|
15
|
+
cols: z.number().int().positive().optional().describe('终端列数,默认 80'),
|
|
16
16
|
term: z.string().optional().describe('终端类型,默认 xterm-256color'),
|
|
17
17
|
cwd: z.string().optional().describe('工作目录'),
|
|
18
18
|
env: z.record(z.string(), z.string()).optional().describe('环境变量'),
|
|
@@ -35,8 +35,8 @@ const ptyReadSchema = z.object({
|
|
|
35
35
|
});
|
|
36
36
|
const ptyResizeSchema = z.object({
|
|
37
37
|
ptyId: z.string().describe('PTY 会话 ID'),
|
|
38
|
-
rows: z.number().describe('新的行数'),
|
|
39
|
-
cols: z.number().describe('新的列数'),
|
|
38
|
+
rows: z.number().int().positive().describe('新的行数'),
|
|
39
|
+
cols: z.number().int().positive().describe('新的列数'),
|
|
40
40
|
});
|
|
41
41
|
const ptyCloseSchema = z.object({
|
|
42
42
|
ptyId: z.string().describe('PTY 会话 ID'),
|
|
@@ -65,8 +65,8 @@ async function handlePtyStart(args) {
|
|
|
65
65
|
}
|
|
66
66
|
async function handlePtyWrite(args) {
|
|
67
67
|
try {
|
|
68
|
-
const
|
|
69
|
-
return formatResult({ success, ptyId: args.ptyId });
|
|
68
|
+
const result = sessionManager.ptyWrite(args.ptyId, args.data);
|
|
69
|
+
return formatResult({ success: result.accepted, ptyId: args.ptyId, ...result });
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
72
|
return formatError(error);
|
|
@@ -75,13 +75,13 @@ async function handlePtyWrite(args) {
|
|
|
75
75
|
async function handlePtyRead(args) {
|
|
76
76
|
try {
|
|
77
77
|
const readResult = sessionManager.ptyRead(args.ptyId, {
|
|
78
|
-
mode: args.mode
|
|
78
|
+
mode: args.mode ?? 'screen',
|
|
79
79
|
clear: args.clear !== false,
|
|
80
80
|
});
|
|
81
81
|
return formatResult({
|
|
82
82
|
success: true,
|
|
83
83
|
ptyId: args.ptyId,
|
|
84
|
-
mode: args.mode
|
|
84
|
+
mode: args.mode ?? 'screen',
|
|
85
85
|
...readResult,
|
|
86
86
|
});
|
|
87
87
|
}
|
|
@@ -100,10 +100,12 @@ async function handlePtyResize(args) {
|
|
|
100
100
|
}
|
|
101
101
|
async function handlePtyClose(args) {
|
|
102
102
|
try {
|
|
103
|
-
const
|
|
103
|
+
const result = sessionManager.ptyClose(args.ptyId);
|
|
104
104
|
return formatResult({
|
|
105
|
-
|
|
106
|
-
message: success
|
|
105
|
+
...result,
|
|
106
|
+
message: result.success
|
|
107
|
+
? `PTY session closed: ${args.ptyId}`
|
|
108
|
+
: `PTY session close ${result.status}: ${args.ptyId}`,
|
|
107
109
|
});
|
|
108
110
|
}
|
|
109
111
|
catch (error) {
|
|
@@ -151,7 +153,9 @@ export function registerPtyTools(server) {
|
|
|
151
153
|
|
|
152
154
|
示例:
|
|
153
155
|
- 发送命令: ssh_pty_write(ptyId="xxx", data="ls -la\\r")
|
|
154
|
-
- 退出 top: ssh_pty_write(ptyId="xxx", data="q")
|
|
156
|
+
- 退出 top: ssh_pty_write(ptyId="xxx", data="q")
|
|
157
|
+
|
|
158
|
+
write 返回 accepted=true 表示数据已被本地 stream 接收。backpressured=true 仅表示缓冲区达到高水位,不表示数据丢失。`,
|
|
155
159
|
inputSchema: ptyWriteSchema,
|
|
156
160
|
}, (args) => handlePtyWrite(args));
|
|
157
161
|
server.registerTool('ssh_pty_read', {
|
|
@@ -171,7 +175,7 @@ export function registerPtyTools(server) {
|
|
|
171
175
|
inputSchema: ptyResizeSchema,
|
|
172
176
|
}, (args) => handlePtyResize(args));
|
|
173
177
|
server.registerTool('ssh_pty_close', {
|
|
174
|
-
description: '关闭 PTY
|
|
178
|
+
description: '关闭 PTY 会话,返回 closed、not_found、failed 或 unknown。可重试失败会保留会话供同一 ptyId 重试。',
|
|
175
179
|
inputSchema: ptyCloseSchema,
|
|
176
180
|
}, (args) => handlePtyClose(args));
|
|
177
181
|
server.registerTool('ssh_pty_list', {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const sshPortSchema = z.number().int().min(1).max(65535);
|
|
3
|
+
export const dynamicSshPortSchema = z.number().int().min(0).max(65535);
|
|
4
|
+
export const operationTimeoutSchema = z
|
|
5
|
+
.number()
|
|
6
|
+
.int()
|
|
7
|
+
.positive()
|
|
8
|
+
.max(3_600_000)
|
|
9
|
+
.describe('操作超时(毫秒),默认 600000,超时后远端状态可能未知');
|
package/dist/types.d.ts
CHANGED
|
@@ -202,7 +202,20 @@ export interface PtySessionInfo {
|
|
|
202
202
|
foregroundProcess: string;
|
|
203
203
|
active: boolean;
|
|
204
204
|
}
|
|
205
|
+
export interface PtyWriteResult {
|
|
206
|
+
accepted: true;
|
|
207
|
+
backpressured: boolean;
|
|
208
|
+
}
|
|
209
|
+
export type PtyCloseStatus = 'closed' | 'not_found' | 'failed' | 'unknown';
|
|
210
|
+
export interface PtyCloseResult {
|
|
211
|
+
success: boolean;
|
|
212
|
+
ptyId: string;
|
|
213
|
+
status: PtyCloseStatus;
|
|
214
|
+
retryable: boolean;
|
|
215
|
+
error?: string;
|
|
216
|
+
}
|
|
205
217
|
export type ForwardType = 'local' | 'remote';
|
|
218
|
+
export type ForwardLifecycle = 'pending' | 'active' | 'closing' | 'closed';
|
|
206
219
|
export interface PortForwardInfo {
|
|
207
220
|
id: string;
|
|
208
221
|
alias: string;
|
|
@@ -213,6 +226,8 @@ export interface PortForwardInfo {
|
|
|
213
226
|
remotePort: number;
|
|
214
227
|
createdAt: number;
|
|
215
228
|
active: boolean;
|
|
229
|
+
lifecycle: ForwardLifecycle;
|
|
230
|
+
acceptingConnections: boolean;
|
|
216
231
|
}
|
|
217
232
|
export type ForwardCloseMode = 'graceful' | 'force';
|
|
218
233
|
export interface ForwardCloseOptions {
|
package/dist/utf8.d.ts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare function isUtf8ContinuationByte(value: number): boolean;
|
|
2
|
+
export declare function ensureUtf8Boundary(buffer: Buffer, offset: number, field: string): void;
|
|
3
|
+
export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean): number;
|
package/dist/utf8.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function isUtf8ContinuationByte(value) {
|
|
2
|
+
return (value & 0xc0) === 0x80;
|
|
3
|
+
}
|
|
4
|
+
function utf8SequenceLength(value) {
|
|
5
|
+
if ((value & 0x80) === 0) {
|
|
6
|
+
return 1;
|
|
7
|
+
}
|
|
8
|
+
if ((value & 0xe0) === 0xc0) {
|
|
9
|
+
return 2;
|
|
10
|
+
}
|
|
11
|
+
if ((value & 0xf0) === 0xe0) {
|
|
12
|
+
return 3;
|
|
13
|
+
}
|
|
14
|
+
if ((value & 0xf8) === 0xf0) {
|
|
15
|
+
return 4;
|
|
16
|
+
}
|
|
17
|
+
return 1;
|
|
18
|
+
}
|
|
19
|
+
export function ensureUtf8Boundary(buffer, offset, field) {
|
|
20
|
+
if (offset < buffer.length && isUtf8ContinuationByte(buffer[offset])) {
|
|
21
|
+
throw new Error(`${field} must point to a UTF-8 character boundary`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length) {
|
|
25
|
+
let end = requestedEnd;
|
|
26
|
+
if (limitedByMaxBytes) {
|
|
27
|
+
while (end > start && isUtf8ContinuationByte(buffer[end])) {
|
|
28
|
+
--end;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (end > start) {
|
|
32
|
+
let sequenceStart = end - 1;
|
|
33
|
+
while (sequenceStart > start && isUtf8ContinuationByte(buffer[sequenceStart])) {
|
|
34
|
+
--sequenceStart;
|
|
35
|
+
}
|
|
36
|
+
if (sequenceStart + utf8SequenceLength(buffer[sequenceStart]) > end) {
|
|
37
|
+
end = sequenceStart;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (end === start && requestedEnd > start && limitedByMaxBytes) {
|
|
41
|
+
throw new Error(`maxBytes is too small to read the next UTF-8 character from ${stream}`);
|
|
42
|
+
}
|
|
43
|
+
return end;
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyrokine/mcp-ssh",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "A comprehensive SSH MCP Server for Claude Code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
"mcp-ssh": "dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "node node_modules/typescript7/bin/tsc",
|
|
11
|
+
"build": "npm run clean && node node_modules/typescript7/bin/tsc",
|
|
12
12
|
"start": "node dist/index.js",
|
|
13
13
|
"dev": "node node_modules/typescript7/bin/tsc && node dist/index.js",
|
|
14
14
|
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
15
|
-
"
|
|
16
|
-
"lint": "eslint \"src/**/*.ts\"",
|
|
17
|
-
"lint:fix": "eslint \"src/**/*.ts\" --fix",
|
|
15
|
+
"prepack": "npm run build",
|
|
16
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.mjs\"",
|
|
17
|
+
"lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.mjs\" --fix",
|
|
18
18
|
"test": "npm run build && node test/run-tests.mjs",
|
|
19
|
-
"format": "prettier --write src/",
|
|
20
|
-
"format:check": "prettier --check src/"
|
|
19
|
+
"format": "prettier --write --prose-wrap always src/ test/ README.md README_zh.md TESTING.md",
|
|
20
|
+
"format:check": "prettier --check --prose-wrap always src/ test/ README.md README_zh.md TESTING.md"
|
|
21
21
|
},
|
|
22
22
|
"keywords": [
|
|
23
23
|
"mcp",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "git+https://github.com/Pyrokine/claude-tools.git"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
37
37
|
"@xterm/headless": "^6.0.0",
|
|
38
38
|
"ssh2": "^1.17.0",
|
|
39
39
|
"zod": "^4.4.3"
|