@midscene/shared 1.5.3-beta-20260309062917.0 → 1.5.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/dist/es/mcp/base-server.mjs +11 -13
- package/dist/lib/mcp/base-server.js +11 -13
- package/package.json +1 -1
- package/src/mcp/base-server.ts +11 -13
|
@@ -51,10 +51,10 @@ class BaseMCPServer {
|
|
|
51
51
|
}
|
|
52
52
|
this.toolsManager.attachToServer(this.mcpServer);
|
|
53
53
|
}
|
|
54
|
-
performCleanup() {
|
|
54
|
+
async performCleanup() {
|
|
55
55
|
console.error(`${this.config.name} closing...`);
|
|
56
56
|
this.mcpServer.close();
|
|
57
|
-
this.toolsManager?.destroy?.().catch(console.error);
|
|
57
|
+
await this.toolsManager?.destroy?.().catch(console.error);
|
|
58
58
|
}
|
|
59
59
|
async launch() {
|
|
60
60
|
console.log = (...args)=>{
|
|
@@ -83,11 +83,12 @@ class BaseMCPServer {
|
|
|
83
83
|
console.error(`[${this.config.name}] Unhandled Rejection:`, reason);
|
|
84
84
|
if (reason instanceof Error) console.error('Stack:', reason.stack);
|
|
85
85
|
});
|
|
86
|
-
process.stdin.on('close', ()=>
|
|
86
|
+
process.stdin.on('close', ()=>{
|
|
87
|
+
this.performCleanup().finally(()=>process.exit(0));
|
|
88
|
+
});
|
|
87
89
|
const cleanup = ()=>{
|
|
88
90
|
console.error(`${this.config.name} shutting down...`);
|
|
89
|
-
this.performCleanup();
|
|
90
|
-
process.exit(0);
|
|
91
|
+
this.performCleanup().finally(()=>process.exit(0));
|
|
91
92
|
};
|
|
92
93
|
process.once('SIGINT', cleanup);
|
|
93
94
|
process.once('SIGTERM', cleanup);
|
|
@@ -169,9 +170,9 @@ class BaseMCPServer {
|
|
|
169
170
|
}
|
|
170
171
|
sessions.clear();
|
|
171
172
|
return new Promise((resolve)=>{
|
|
172
|
-
server.close((err)=>{
|
|
173
|
+
server.close(async (err)=>{
|
|
173
174
|
if (err) console.error('Error closing HTTP server:', err);
|
|
174
|
-
this.performCleanup();
|
|
175
|
+
await this.performCleanup();
|
|
175
176
|
resolve();
|
|
176
177
|
});
|
|
177
178
|
});
|
|
@@ -237,19 +238,16 @@ class BaseMCPServer {
|
|
|
237
238
|
sessions.clear();
|
|
238
239
|
try {
|
|
239
240
|
server.close(()=>{
|
|
240
|
-
this.performCleanup();
|
|
241
|
-
process.exit(0);
|
|
241
|
+
this.performCleanup().finally(()=>process.exit(0));
|
|
242
242
|
});
|
|
243
243
|
setTimeout(()=>{
|
|
244
244
|
console.error('Forcefully shutting down after timeout');
|
|
245
|
-
this.performCleanup();
|
|
246
|
-
process.exit(1);
|
|
245
|
+
this.performCleanup().finally(()=>process.exit(1));
|
|
247
246
|
}, 5000);
|
|
248
247
|
} catch (error) {
|
|
249
248
|
const message = error instanceof Error ? error.message : String(error);
|
|
250
249
|
console.error(`Error closing HTTP server: ${message}`);
|
|
251
|
-
this.performCleanup();
|
|
252
|
-
process.exit(1);
|
|
250
|
+
this.performCleanup().finally(()=>process.exit(1));
|
|
253
251
|
}
|
|
254
252
|
};
|
|
255
253
|
process.once('SIGINT', cleanup);
|
|
@@ -91,10 +91,10 @@ class BaseMCPServer {
|
|
|
91
91
|
}
|
|
92
92
|
this.toolsManager.attachToServer(this.mcpServer);
|
|
93
93
|
}
|
|
94
|
-
performCleanup() {
|
|
94
|
+
async performCleanup() {
|
|
95
95
|
console.error(`${this.config.name} closing...`);
|
|
96
96
|
this.mcpServer.close();
|
|
97
|
-
this.toolsManager?.destroy?.().catch(console.error);
|
|
97
|
+
await this.toolsManager?.destroy?.().catch(console.error);
|
|
98
98
|
}
|
|
99
99
|
async launch() {
|
|
100
100
|
console.log = (...args)=>{
|
|
@@ -123,11 +123,12 @@ class BaseMCPServer {
|
|
|
123
123
|
console.error(`[${this.config.name}] Unhandled Rejection:`, reason);
|
|
124
124
|
if (reason instanceof Error) console.error('Stack:', reason.stack);
|
|
125
125
|
});
|
|
126
|
-
process.stdin.on('close', ()=>
|
|
126
|
+
process.stdin.on('close', ()=>{
|
|
127
|
+
this.performCleanup().finally(()=>process.exit(0));
|
|
128
|
+
});
|
|
127
129
|
const cleanup = ()=>{
|
|
128
130
|
console.error(`${this.config.name} shutting down...`);
|
|
129
|
-
this.performCleanup();
|
|
130
|
-
process.exit(0);
|
|
131
|
+
this.performCleanup().finally(()=>process.exit(0));
|
|
131
132
|
};
|
|
132
133
|
process.once('SIGINT', cleanup);
|
|
133
134
|
process.once('SIGTERM', cleanup);
|
|
@@ -209,9 +210,9 @@ class BaseMCPServer {
|
|
|
209
210
|
}
|
|
210
211
|
sessions.clear();
|
|
211
212
|
return new Promise((resolve)=>{
|
|
212
|
-
server.close((err)=>{
|
|
213
|
+
server.close(async (err)=>{
|
|
213
214
|
if (err) console.error('Error closing HTTP server:', err);
|
|
214
|
-
this.performCleanup();
|
|
215
|
+
await this.performCleanup();
|
|
215
216
|
resolve();
|
|
216
217
|
});
|
|
217
218
|
});
|
|
@@ -277,19 +278,16 @@ class BaseMCPServer {
|
|
|
277
278
|
sessions.clear();
|
|
278
279
|
try {
|
|
279
280
|
server.close(()=>{
|
|
280
|
-
this.performCleanup();
|
|
281
|
-
process.exit(0);
|
|
281
|
+
this.performCleanup().finally(()=>process.exit(0));
|
|
282
282
|
});
|
|
283
283
|
setTimeout(()=>{
|
|
284
284
|
console.error('Forcefully shutting down after timeout');
|
|
285
|
-
this.performCleanup();
|
|
286
|
-
process.exit(1);
|
|
285
|
+
this.performCleanup().finally(()=>process.exit(1));
|
|
287
286
|
}, 5000);
|
|
288
287
|
} catch (error) {
|
|
289
288
|
const message = error instanceof Error ? error.message : String(error);
|
|
290
289
|
console.error(`Error closing HTTP server: ${message}`);
|
|
291
|
-
this.performCleanup();
|
|
292
|
-
process.exit(1);
|
|
290
|
+
this.performCleanup().finally(()=>process.exit(1));
|
|
293
291
|
}
|
|
294
292
|
};
|
|
295
293
|
process.once('SIGINT', cleanup);
|
package/package.json
CHANGED
package/src/mcp/base-server.ts
CHANGED
|
@@ -130,10 +130,10 @@ export abstract class BaseMCPServer {
|
|
|
130
130
|
/**
|
|
131
131
|
* Perform cleanup on shutdown
|
|
132
132
|
*/
|
|
133
|
-
private performCleanup(): void {
|
|
133
|
+
private async performCleanup(): Promise<void> {
|
|
134
134
|
console.error(`${this.config.name} closing...`);
|
|
135
135
|
this.mcpServer.close();
|
|
136
|
-
this.toolsManager?.destroy?.().catch(console.error);
|
|
136
|
+
await this.toolsManager?.destroy?.().catch(console.error);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
|
@@ -181,13 +181,14 @@ export abstract class BaseMCPServer {
|
|
|
181
181
|
});
|
|
182
182
|
|
|
183
183
|
// Setup cleanup handlers
|
|
184
|
-
process.stdin.on('close', () =>
|
|
184
|
+
process.stdin.on('close', () => {
|
|
185
|
+
this.performCleanup().finally(() => process.exit(0));
|
|
186
|
+
});
|
|
185
187
|
|
|
186
188
|
// Setup signal handlers for graceful shutdown
|
|
187
189
|
const cleanup = () => {
|
|
188
190
|
console.error(`${this.config.name} shutting down...`);
|
|
189
|
-
this.performCleanup();
|
|
190
|
-
process.exit(0);
|
|
191
|
+
this.performCleanup().finally(() => process.exit(0));
|
|
191
192
|
};
|
|
192
193
|
|
|
193
194
|
process.once('SIGINT', cleanup);
|
|
@@ -336,11 +337,11 @@ export abstract class BaseMCPServer {
|
|
|
336
337
|
sessions.clear();
|
|
337
338
|
|
|
338
339
|
return new Promise<void>((resolve) => {
|
|
339
|
-
server.close((err) => {
|
|
340
|
+
server.close(async (err) => {
|
|
340
341
|
if (err) {
|
|
341
342
|
console.error('Error closing HTTP server:', err);
|
|
342
343
|
}
|
|
343
|
-
this.performCleanup();
|
|
344
|
+
await this.performCleanup();
|
|
344
345
|
resolve();
|
|
345
346
|
});
|
|
346
347
|
});
|
|
@@ -456,21 +457,18 @@ export abstract class BaseMCPServer {
|
|
|
456
457
|
try {
|
|
457
458
|
server.close(() => {
|
|
458
459
|
// Server closed callback - all connections finished
|
|
459
|
-
this.performCleanup();
|
|
460
|
-
process.exit(0);
|
|
460
|
+
this.performCleanup().finally(() => process.exit(0));
|
|
461
461
|
});
|
|
462
462
|
|
|
463
463
|
// Set a timeout in case server.close() hangs
|
|
464
464
|
setTimeout(() => {
|
|
465
465
|
console.error('Forcefully shutting down after timeout');
|
|
466
|
-
this.performCleanup();
|
|
467
|
-
process.exit(1);
|
|
466
|
+
this.performCleanup().finally(() => process.exit(1));
|
|
468
467
|
}, 5000);
|
|
469
468
|
} catch (error: unknown) {
|
|
470
469
|
const message = error instanceof Error ? error.message : String(error);
|
|
471
470
|
console.error(`Error closing HTTP server: ${message}`);
|
|
472
|
-
this.performCleanup();
|
|
473
|
-
process.exit(1);
|
|
471
|
+
this.performCleanup().finally(() => process.exit(1));
|
|
474
472
|
}
|
|
475
473
|
};
|
|
476
474
|
|