@pyrokine/mcp-ssh 2.4.3 → 3.1.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.
@@ -125,7 +125,7 @@ export function registerOperationTools(server) {
125
125
  inputSchema: operationReadSchema,
126
126
  }, (args) => handleOperationRead(args));
127
127
  server.registerTool('ssh_operation_cancel', {
128
- description: '校验远端 operation marker 后发送 TERM;marker 无法证明时拒绝取消',
128
+ description: '校验远端 operation marker 和进程身份后执行取消;POSIX 发送 TERM,Windows 在 PID、创建时间和 marker 验证后执行 taskkill /T /F;无法证明身份时拒绝取消',
129
129
  inputSchema: operationIdSchema,
130
130
  }, (args) => handleOperationCancel(args));
131
131
  server.registerTool('ssh_operation_list', {
package/dist/tools/pty.js CHANGED
@@ -31,7 +31,7 @@ const ptyWriteSchema = z.object({
31
31
  const ptyReadSchema = z.object({
32
32
  ptyId: z.string().describe('PTY 会话 ID'),
33
33
  mode: z.enum(['screen', 'raw']).optional().describe('输出模式:screen(当前屏幕)或 raw(原始流),默认 screen'),
34
- clear: z.boolean().optional().describe('(仅 raw 模式) 读取后是否清空缓冲区,默认 true'),
34
+ clear: z.boolean().optional().describe('(仅 raw 模式) 读取后是否清空缓冲区并重置 rawBufferTruncated,默认 true'),
35
35
  });
36
36
  const ptyResizeSchema = z.object({
37
37
  ptyId: z.string().describe('PTY 会话 ID'),
@@ -163,7 +163,9 @@ write 返回 accepted=true 表示数据已被本地 stream 接收。backpressure
163
163
 
164
164
  两种模式:
165
165
  - screen(默认):返回当前屏幕内容(解析后的纯文本,适合 top/btop/htop 等全屏刷新工具)
166
- - raw:返回原始 ANSI 流(包含转义序列,适合需要完整终端数据的场景)
166
+ - raw:data 为 UTF-8 文本预览,dataBase64 为原始 ANSI/二进制字节的无损 base64
167
+
168
+ bufferSize、unreadRawBytes 和 rawBufferLimit 均按原始字节计数。rawBufferTruncated=true 表示本次 clear 之后已有更早的 raw 输出因上限被丢弃;raw 读取使用默认 clear=true 时,响应返回清理前的计数和标志,然后重置缓冲区。
167
169
 
168
170
  示例:
169
171
  - 获取 top 当前画面: ssh_pty_read(ptyId="xxx")
@@ -179,7 +181,7 @@ write 返回 accepted=true 表示数据已被本地 stream 接收。backpressure
179
181
  inputSchema: ptyCloseSchema,
180
182
  }, (args) => handlePtyClose(args));
181
183
  server.registerTool('ssh_pty_list', {
182
- description: '列出所有 PTY 会话',
184
+ description: '列出所有 PTY 会话。bufferSize、unreadRawBytes 和 rawBufferLimit 使用原始字节,rawBufferTruncated 表示更早的 raw 输出已因缓冲区上限被丢弃。',
183
185
  inputSchema: ptyListSchema,
184
186
  }, () => handlePtyList());
185
187
  }
@@ -12,8 +12,8 @@ export function expandTilde(p) {
12
12
  if (p === '~') {
13
13
  return os.homedir();
14
14
  }
15
- if (p.startsWith('~/')) {
16
- return path.join(os.homedir(), p.slice(2));
15
+ if (p.startsWith('~/') || p.startsWith('~\\')) {
16
+ return path.join(os.homedir(), p.slice(2).replace(/\\/g, path.sep));
17
17
  }
18
18
  return p;
19
19
  }
package/dist/types.d.ts CHANGED
@@ -1,9 +1,32 @@
1
1
  /**
2
2
  * SSH MCP Pro - 类型定义
3
3
  */
4
+ import type { Readable } from 'stream';
5
+ export interface CommandChannel extends Readable {
6
+ readonly stderr: Readable;
7
+ readonly ready?: Promise<void>;
8
+ close(): void;
9
+ }
10
+ export interface OpenSshMasterInfo {
11
+ backend: 'openssh';
12
+ masterReused: true;
13
+ identityStatus: 'master_trusted';
14
+ masterPid: number;
15
+ observedLogin?: {
16
+ uid: number;
17
+ username: string;
18
+ sshConnection?: string;
19
+ };
20
+ }
4
21
  export declare const DEFAULT_EXEC_MAX_OUTPUT_SIZE: number;
5
22
  export declare const HARD_EXEC_MAX_OUTPUT_SIZE: number;
23
+ export type RemotePlatform = 'posix' | 'windows';
24
+ export type CommandShell = 'posix' | 'cmd' | 'powershell';
25
+ export type RemotePathStyle = 'posix' | 'win32' | 'sftp-posix';
26
+ export type RsyncProfile = 'posix' | 'native-win32' | 'msys2' | 'cygwin';
6
27
  export interface SSHConnectionConfig {
28
+ backend?: 'ssh2' | 'openssh';
29
+ controlPath?: string;
7
30
  host: string;
8
31
  port: number;
9
32
  username: string;
@@ -11,6 +34,12 @@ export interface SSHConnectionConfig {
11
34
  privateKeyPath?: string;
12
35
  privateKey?: string;
13
36
  passphrase?: string;
37
+ agent?: string;
38
+ remotePlatform?: RemotePlatform;
39
+ commandShell?: CommandShell;
40
+ remotePathStyle?: RemotePathStyle;
41
+ rsyncExecutable?: string;
42
+ rsyncProfile?: RsyncProfile;
14
43
  alias?: string;
15
44
  template?: string;
16
45
  runAs?: string;
@@ -24,6 +53,9 @@ export interface SSHConnectionConfig {
24
53
  jumpHost?: SSHConnectionConfig;
25
54
  }
26
55
  export interface SSHSessionBrief {
56
+ backend?: 'ssh2' | 'openssh';
57
+ masterReused?: boolean;
58
+ identityStatus?: 'master_trusted';
27
59
  alias: string;
28
60
  identity: string;
29
61
  runAs?: string;
@@ -34,22 +66,32 @@ export interface SSHSessionDetail extends SSHSessionBrief {
34
66
  host: string;
35
67
  port: number;
36
68
  username: string;
37
- authMethod: 'key' | 'password' | 'agent' | 'inline-key';
69
+ authMethod: 'key' | 'password' | 'agent' | 'inline-key' | 'master';
38
70
  connectedAt: number;
39
71
  hasJumpHost: boolean;
72
+ remotePlatform: RemotePlatform;
73
+ commandShell: CommandShell;
74
+ remotePathStyle: RemotePathStyle;
40
75
  }
41
76
  export interface ExternalTransferCapability {
77
+ backend?: 'ssh2' | 'openssh';
78
+ controlPath?: string;
42
79
  alias: string;
43
80
  identity: string;
44
81
  host: string;
45
82
  port: number;
46
83
  username: string;
47
- authMethod: 'key-path' | 'password' | 'agent' | 'inline-key';
84
+ authMethod: 'key-path' | 'password' | 'agent' | 'inline-key' | 'master';
48
85
  keyPath?: string;
49
86
  hasJumpHost: boolean;
50
87
  routeSafeForOpenSsh: boolean;
51
88
  rsyncEligible: boolean;
52
89
  decisionReason: string;
90
+ agent?: string;
91
+ rsyncExecutable?: string;
92
+ rsyncProfile?: RsyncProfile;
93
+ commandShell?: CommandShell;
94
+ remotePathStyle?: RemotePathStyle;
53
95
  }
54
96
  export type ConnectionFailureStage = 'preflight' | 'authentication' | 'ready_timeout' | 'transport_or_handshake' | 'unknown';
55
97
  export type ConnectionStep = 'key_read' | 'jump_connect' | 'jump_forward' | 'target_connect';
@@ -58,6 +100,7 @@ export interface ConnectionFailureDetails {
58
100
  connectionStep?: ConnectionStep;
59
101
  retryable: boolean;
60
102
  suggestion?: string;
103
+ keyAclStatus?: 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
61
104
  }
62
105
  export interface ExecOptions {
63
106
  timeout?: number;
@@ -120,6 +163,7 @@ export interface OperationInfo {
120
163
  pid: number | null;
121
164
  processGroup: boolean;
122
165
  markerVerified: boolean;
166
+ processCreatedAt?: string;
123
167
  cancelRequested: boolean;
124
168
  startedAt: number;
125
169
  finishedAt: number | null;
@@ -150,6 +194,7 @@ export interface OperationCancelResult extends OperationInfo {
150
194
  success: boolean;
151
195
  cancelRequested: boolean;
152
196
  retryable: boolean;
197
+ cancellationStatus: 'requested' | 'unknown' | 'unsupported' | 'not_applicable';
153
198
  verificationError?: string;
154
199
  }
155
200
  export interface FileInfo {
@@ -159,6 +204,7 @@ export interface FileInfo {
159
204
  isDirectory: boolean;
160
205
  isFile: boolean;
161
206
  isSymlink: boolean;
207
+ mode: number;
162
208
  permissions: string;
163
209
  owner: number;
164
210
  group: number;
@@ -199,9 +245,24 @@ export interface PtySessionInfo {
199
245
  bufferSize: number;
200
246
  unreadRawBytes: number;
201
247
  rawBufferLimit: number;
248
+ rawBufferTruncated: boolean;
202
249
  foregroundProcess: string;
203
250
  active: boolean;
204
251
  }
252
+ export interface PtyReadResult {
253
+ data: string;
254
+ dataBase64?: string;
255
+ active: boolean;
256
+ rows: number;
257
+ cols: number;
258
+ lastInputAt: number | null;
259
+ lastOutputAt: number | null;
260
+ lastReadAt: number;
261
+ unreadRawBytes: number;
262
+ rawBufferLimit: number;
263
+ rawBufferTruncated: boolean;
264
+ foregroundProcess: string;
265
+ }
205
266
  export interface PtyWriteResult {
206
267
  accepted: true;
207
268
  backpressured: boolean;
package/dist/utf8.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export declare function isUtf8ContinuationByte(value: number): boolean;
2
2
  export declare function ensureUtf8Boundary(buffer: Buffer, offset: number, field: string): void;
3
+ export declare function retainUtf8Suffix(buffer: Buffer, maxBytes: number): Buffer;
3
4
  export declare function utf8SafeEnd(buffer: Buffer, start: number, requestedEnd: number, stream: string, limitedByMaxBytes?: boolean): number;
package/dist/utf8.js CHANGED
@@ -21,6 +21,16 @@ export function ensureUtf8Boundary(buffer, offset, field) {
21
21
  throw new Error(`${field} must point to a UTF-8 character boundary`);
22
22
  }
23
23
  }
24
+ export function retainUtf8Suffix(buffer, maxBytes) {
25
+ if (buffer.length <= maxBytes) {
26
+ return buffer;
27
+ }
28
+ let start = buffer.length - maxBytes;
29
+ while (start < buffer.length && isUtf8ContinuationByte(buffer[start])) {
30
+ ++start;
31
+ }
32
+ return buffer.subarray(start);
33
+ }
24
34
  export function utf8SafeEnd(buffer, start, requestedEnd, stream, limitedByMaxBytes = requestedEnd < buffer.length) {
25
35
  let end = requestedEnd;
26
36
  if (limitedByMaxBytes) {
@@ -0,0 +1,4 @@
1
+ export type AclStatus = 'key_path_usable' | 'key_acl_insecure' | 'key_acl_unverified';
2
+ export declare function windowsAclScript(filePath: string, apply: boolean): string;
3
+ export declare function windowsTemporaryPathScript(name: string): string;
4
+ export declare function checkWindowsAcl(filePath: string, apply?: boolean): AclStatus;
@@ -0,0 +1,109 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { encodedPowershell, quotePowershell } from './remote-platform.js';
3
+ export function windowsAclScript(filePath, apply) {
4
+ const target = quotePowershell(filePath);
5
+ return `
6
+ $ErrorActionPreference = 'Stop'
7
+ $path = ${target}
8
+ $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
9
+ $system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18')
10
+ $administrators = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544')
11
+ $allowed = @($identity.Value, $system.Value, $administrators.Value)
12
+ $acl = Get-Acl -LiteralPath $path
13
+ ${apply
14
+ ? `
15
+ $acl.SetAccessRuleProtection($true, $false)
16
+ foreach ($rule in @($acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))) {
17
+ $acl.RemoveAccessRuleSpecific($rule)
18
+ }
19
+ foreach ($sid in @($identity, $system, $administrators)) {
20
+ $rule = [System.Security.AccessControl.FileSystemAccessRule]::new($sid, [System.Security.AccessControl.FileSystemRights]::FullControl, [System.Security.AccessControl.AccessControlType]::Allow)
21
+ $acl.AddAccessRule($rule)
22
+ }
23
+ Set-Acl -LiteralPath $path -AclObject $acl
24
+ $acl = Get-Acl -LiteralPath $path
25
+ `
26
+ : ''}
27
+ if (-not $acl.AreAccessRulesProtected -or
28
+ $allowed -notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {
29
+ [Console]::WriteLine('insecure'); exit 0
30
+ }
31
+ $own = $false
32
+ foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
33
+ if ($rule.AccessControlType -eq 'Allow') {
34
+ if ($allowed -notcontains $rule.IdentityReference.Value) { [Console]::WriteLine('insecure'); exit 0 }
35
+ if ($rule.IdentityReference.Value -eq $identity.Value) { $own = $true }
36
+ }
37
+ }
38
+ if (-not $own) { [Console]::WriteLine('insecure'); exit 0 }
39
+ $item = Get-Item -LiteralPath $path -Force
40
+ if ($item -is [IO.FileInfo]) {
41
+ try {
42
+ $stream = [IO.File]::Open($path, [IO.FileMode]::Open, [IO.FileAccess]::Read, [IO.FileShare]::ReadWrite)
43
+ $stream.Dispose()
44
+ } catch {
45
+ [Console]::WriteLine('unverified'); exit 0
46
+ }
47
+ }
48
+ [Console]::WriteLine('usable')
49
+ `;
50
+ }
51
+ export function windowsTemporaryPathScript(name) {
52
+ return `
53
+ $ErrorActionPreference = 'Stop'
54
+ $temp = [IO.Path]::GetTempPath()
55
+ $identity = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
56
+ $system = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-18')
57
+ $administrators = [System.Security.Principal.SecurityIdentifier]::new('S-1-5-32-544')
58
+ $allowed = @($identity.Value, $system.Value, $administrators.Value)
59
+ $directory = Get-Item -LiteralPath $temp -Force
60
+ if ($directory -isnot [IO.DirectoryInfo]) { throw 'privacy_not_enforced_on_windows: temporary path is not a directory' }
61
+ $current = $directory
62
+ while ($null -ne $current) {
63
+ if (($current.Attributes -band [IO.FileAttributes]::ReparsePoint) -ne 0) {
64
+ throw 'privacy_not_enforced_on_windows: temporary directory has a reparse point'
65
+ }
66
+ $acl = Get-Acl -LiteralPath $current.FullName
67
+ if ($current.FullName -eq $directory.FullName -and $allowed -notcontains $acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value) {
68
+ throw 'privacy_not_enforced_on_windows: temporary directory owner is not trusted'
69
+ }
70
+ $rights = [System.Security.AccessControl.FileSystemRights]::Delete -bor
71
+ [System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor
72
+ [System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor
73
+ [System.Security.AccessControl.FileSystemRights]::TakeOwnership
74
+ if ($current.FullName -eq $directory.FullName) {
75
+ $rights = $rights -bor [System.Security.AccessControl.FileSystemRights]::Write
76
+ }
77
+ foreach ($rule in $acl.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier])) {
78
+ if ($rule.AccessControlType -eq 'Allow' -and
79
+ $allowed -notcontains $rule.IdentityReference.Value -and
80
+ ($rule.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly) -eq 0 -and
81
+ ($rule.FileSystemRights -band $rights) -ne 0) {
82
+ throw 'privacy_not_enforced_on_windows: temporary directory allows another user to replace entries'
83
+ }
84
+ }
85
+ $current = $current.Parent
86
+ }
87
+ [Console]::WriteLine([IO.Path]::Combine($directory.FullName, ${quotePowershell(name)}))
88
+ `;
89
+ }
90
+ export function checkWindowsAcl(filePath, apply = false) {
91
+ if (process.platform !== 'win32') {
92
+ throw new Error('Windows ACL verification requires a native Windows process');
93
+ }
94
+ const command = encodedPowershell(windowsAclScript(filePath, apply));
95
+ const encoded = command.split(' ').at(-1);
96
+ const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-EncodedCommand', encoded], {
97
+ timeout: 10_000,
98
+ encoding: 'utf8',
99
+ windowsHide: true,
100
+ maxBuffer: 16_384,
101
+ });
102
+ if (result.error || result.status !== 0) {
103
+ return 'key_acl_unverified';
104
+ }
105
+ if (result.stdout.trim() === 'usable') {
106
+ return 'key_path_usable';
107
+ }
108
+ return result.stdout.trim() === 'insecure' ? 'key_acl_insecure' : 'key_acl_unverified';
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyrokine/mcp-ssh",
3
- "version": "2.4.3",
3
+ "version": "3.1.0",
4
4
  "description": "A comprehensive SSH MCP Server for Claude Code",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "url": "git+https://github.com/Pyrokine/claude-tools.git"
34
34
  },
35
35
  "dependencies": {
36
- "@modelcontextprotocol/sdk": "^1.30.0",
36
+ "@modelcontextprotocol/sdk": "^1.32.1",
37
37
  "@xterm/headless": "^6.0.0",
38
38
  "ssh2": "^1.17.0",
39
39
  "zod": "^4.4.3"
@@ -56,5 +56,6 @@
56
56
  "README.md",
57
57
  "README_zh.md",
58
58
  "LICENSE"
59
- ]
59
+ ],
60
+ "gitHead": "8ecb805b68619692cf9b1a72eb0bc58e5e3f8b26"
60
61
  }