@pyrokine/mcp-ssh 2.0.0 → 2.0.1
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.
|
@@ -13,12 +13,11 @@ export interface ForwardDependencies {
|
|
|
13
13
|
export declare class ForwardManager {
|
|
14
14
|
private sessions;
|
|
15
15
|
private dispatchers;
|
|
16
|
+
private dependencies;
|
|
16
17
|
private idCounter;
|
|
17
18
|
private readonly idleTimeoutMs;
|
|
18
19
|
private idleSweeper;
|
|
19
20
|
constructor();
|
|
20
|
-
/** 用于测试或停服时手动停止 idle sweeper */
|
|
21
|
-
stopIdleSweeper(): void;
|
|
22
21
|
forwardLocal(deps: ForwardDependencies, alias: string, localPort: number, remoteHost: string, remotePort: number, localHost?: string): Promise<{
|
|
23
22
|
forwardId: string;
|
|
24
23
|
localPort: number;
|
package/dist/forward-manager.js
CHANGED
|
@@ -7,6 +7,7 @@ import * as net from 'net';
|
|
|
7
7
|
export class ForwardManager {
|
|
8
8
|
sessions = new Map();
|
|
9
9
|
dispatchers = new Map(); // alias → dispatcher
|
|
10
|
+
dependencies = null;
|
|
10
11
|
idCounter = 0;
|
|
11
12
|
// 默认 idle timeout 1 小时,长时间无连接活动的 forward 自动关闭
|
|
12
13
|
idleTimeoutMs = Number(process.env.SSH_MCP_FORWARD_IDLE_TIMEOUT_MS) || 3600_000;
|
|
@@ -14,14 +15,8 @@ export class ForwardManager {
|
|
|
14
15
|
constructor() {
|
|
15
16
|
this.startIdleSweeper();
|
|
16
17
|
}
|
|
17
|
-
/** 用于测试或停服时手动停止 idle sweeper */
|
|
18
|
-
stopIdleSweeper() {
|
|
19
|
-
if (this.idleSweeper) {
|
|
20
|
-
clearInterval(this.idleSweeper);
|
|
21
|
-
this.idleSweeper = null;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
18
|
async forwardLocal(deps, alias, localPort, remoteHost, remotePort, localHost = '127.0.0.1') {
|
|
19
|
+
this.dependencies = deps;
|
|
25
20
|
const client = deps.getClient(alias);
|
|
26
21
|
const forwardId = this.generateId();
|
|
27
22
|
return new Promise((resolve, reject) => {
|
|
@@ -74,6 +69,7 @@ export class ForwardManager {
|
|
|
74
69
|
});
|
|
75
70
|
}
|
|
76
71
|
async forwardRemote(deps, alias, remotePort, localHost, localPort, remoteHost = '127.0.0.1') {
|
|
72
|
+
this.dependencies = deps;
|
|
77
73
|
const client = deps.getClient(alias);
|
|
78
74
|
const forwardId = this.generateId();
|
|
79
75
|
return new Promise((resolve, reject) => {
|
|
@@ -189,7 +185,7 @@ export class ForwardManager {
|
|
|
189
185
|
}
|
|
190
186
|
if (fwd.activeConnections === 0 && now - fwd.lastActivityAt > this.idleTimeoutMs) {
|
|
191
187
|
console.warn(`[mcp-ssh] Forward ${id} (${fwd.type}, alias=${fwd.alias}) idle ${Math.round((now - fwd.lastActivityAt) / 1000)}s with 0 connections > ${Math.round(this.idleTimeoutMs / 1000)}s, auto-closing`);
|
|
192
|
-
this.close(id);
|
|
188
|
+
this.close(id, this.dependencies ?? undefined);
|
|
193
189
|
}
|
|
194
190
|
}
|
|
195
191
|
}
|
package/dist/pty-manager.d.ts
CHANGED
|
@@ -17,8 +17,6 @@ export declare class PtyManager {
|
|
|
17
17
|
private readonly idleTimeoutMs;
|
|
18
18
|
private idleSweeper;
|
|
19
19
|
constructor();
|
|
20
|
-
/** 用于测试或停服时手动停止 idle sweeper */
|
|
21
|
-
stopIdleSweeper(): void;
|
|
22
20
|
start(deps: PtyDependencies, alias: string, command: string, options?: PtyOptions): Promise<string>;
|
|
23
21
|
write(ptyId: string, data: string): boolean;
|
|
24
22
|
read(ptyId: string, options?: {
|
package/dist/pty-manager.js
CHANGED
|
@@ -15,13 +15,6 @@ export class PtyManager {
|
|
|
15
15
|
constructor() {
|
|
16
16
|
this.startIdleSweeper();
|
|
17
17
|
}
|
|
18
|
-
/** 用于测试或停服时手动停止 idle sweeper */
|
|
19
|
-
stopIdleSweeper() {
|
|
20
|
-
if (this.idleSweeper) {
|
|
21
|
-
clearInterval(this.idleSweeper);
|
|
22
|
-
this.idleSweeper = null;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
18
|
async start(deps, alias, command, options = {}) {
|
|
26
19
|
const ptyId = this.generateId();
|
|
27
20
|
const rows = options.rows || 24;
|
|
@@ -60,6 +53,13 @@ export class PtyManager {
|
|
|
60
53
|
});
|
|
61
54
|
stream.on('close', () => {
|
|
62
55
|
ptySession.active = false;
|
|
56
|
+
this.sessions.delete(ptyId);
|
|
57
|
+
try {
|
|
58
|
+
terminal.dispose();
|
|
59
|
+
}
|
|
60
|
+
catch (e) {
|
|
61
|
+
console.warn(`PTY ${ptyId} terminal dispose failed:`, e.message);
|
|
62
|
+
}
|
|
63
63
|
});
|
|
64
64
|
stream.on('error', (err) => {
|
|
65
65
|
ptySession.active = false;
|
package/dist/session-manager.js
CHANGED
|
@@ -131,7 +131,6 @@ export class SessionManager {
|
|
|
131
131
|
connected: this.isAlive(session),
|
|
132
132
|
connectedAt: session.connectedAt,
|
|
133
133
|
lastUsedAt: session.lastUsedAt,
|
|
134
|
-
env: session.config.env,
|
|
135
134
|
});
|
|
136
135
|
}
|
|
137
136
|
return result;
|
|
@@ -611,14 +610,13 @@ export class SessionManager {
|
|
|
611
610
|
persistSessions() {
|
|
612
611
|
const data = [];
|
|
613
612
|
for (const [alias, session] of this.sessions) {
|
|
614
|
-
//
|
|
613
|
+
// 不保存敏感信息(密码、密钥、环境变量)
|
|
615
614
|
data.push({
|
|
616
615
|
alias,
|
|
617
616
|
host: session.config.host,
|
|
618
617
|
port: session.config.port || 22,
|
|
619
618
|
username: session.config.username,
|
|
620
619
|
connectedAt: session.connectedAt,
|
|
621
|
-
env: session.config.env,
|
|
622
620
|
});
|
|
623
621
|
}
|
|
624
622
|
fs.promises
|
package/dist/types.d.ts
CHANGED
|
@@ -26,7 +26,6 @@ export interface SSHSessionInfo {
|
|
|
26
26
|
connected: boolean;
|
|
27
27
|
connectedAt: number;
|
|
28
28
|
lastUsedAt: number;
|
|
29
|
-
env?: Record<string, string>;
|
|
30
29
|
}
|
|
31
30
|
export interface ExecOptions {
|
|
32
31
|
timeout?: number;
|
|
@@ -69,7 +68,6 @@ export interface PersistedSession {
|
|
|
69
68
|
port: number;
|
|
70
69
|
username: string;
|
|
71
70
|
connectedAt: number;
|
|
72
|
-
env?: Record<string, string>;
|
|
73
71
|
}
|
|
74
72
|
export interface PtyOptions {
|
|
75
73
|
rows?: number;
|