@maplezzk/mcps 1.1.4 → 1.1.6
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/commands/daemon.js +57 -3
- package/dist/core/pool.js +3 -1
- package/package.json +1 -1
package/dist/commands/daemon.js
CHANGED
|
@@ -123,7 +123,8 @@ const startAction = async (options) => {
|
|
|
123
123
|
env: {
|
|
124
124
|
...process.env,
|
|
125
125
|
MCPS_DAEMON_DETACHED: 'true',
|
|
126
|
-
MCPS_VERBOSE: options.verbose ? 'true' : 'false'
|
|
126
|
+
MCPS_VERBOSE: options.verbose ? 'true' : 'false',
|
|
127
|
+
MCPS_CONNECTION_TIMEOUT: String((parseInt(options.connectionTimeout || process.env.MCPS_CONNECTION_TIMEOUT || '20', 10)) * 1000)
|
|
127
128
|
}
|
|
128
129
|
});
|
|
129
130
|
subprocess.unref();
|
|
@@ -182,8 +183,59 @@ const startAction = async (options) => {
|
|
|
182
183
|
};
|
|
183
184
|
const stopAction = async (options) => {
|
|
184
185
|
try {
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
const logPath = '/tmp/mcps-daemon/stdout.log';
|
|
187
|
+
const fs = await import('fs');
|
|
188
|
+
// 发送 stop 请求并显示日志
|
|
189
|
+
const requestPromise = daemonRequest('POST', '/stop');
|
|
190
|
+
// 显示关闭日志
|
|
191
|
+
const showLogs = async () => {
|
|
192
|
+
try {
|
|
193
|
+
if (!fs.existsSync(logPath)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
let lastSize = fs.statSync(logPath).size;
|
|
197
|
+
const startTime = Date.now();
|
|
198
|
+
const timeout = 5000; // 5秒超时
|
|
199
|
+
while (Date.now() - startTime < timeout) {
|
|
200
|
+
await new Promise(r => setTimeout(r, 200));
|
|
201
|
+
try {
|
|
202
|
+
const { size: currentSize } = fs.statSync(logPath);
|
|
203
|
+
if (currentSize > lastSize) {
|
|
204
|
+
const buffer = Buffer.alloc(currentSize - lastSize);
|
|
205
|
+
const fd = fs.openSync(logPath, 'r');
|
|
206
|
+
fs.readSync(fd, buffer, 0, currentSize - lastSize, lastSize);
|
|
207
|
+
fs.closeSync(fd);
|
|
208
|
+
const newLogs = buffer.toString('utf-8');
|
|
209
|
+
const relevantLogs = newLogs.split('\n').filter(line => {
|
|
210
|
+
return line.includes('Closing connection to') ||
|
|
211
|
+
line.includes('Shutting down');
|
|
212
|
+
});
|
|
213
|
+
if (relevantLogs.length > 0) {
|
|
214
|
+
relevantLogs.forEach(log => {
|
|
215
|
+
if (log.trim()) {
|
|
216
|
+
console.log(chalk.yellow(log));
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
lastSize = currentSize;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
catch (e) {
|
|
224
|
+
// 忽略读取错误
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
catch (e) {
|
|
229
|
+
// 忽略日志显示错误
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const [{ ok }] = await Promise.all([
|
|
233
|
+
requestPromise,
|
|
234
|
+
showLogs()
|
|
235
|
+
]);
|
|
236
|
+
if (ok) {
|
|
237
|
+
console.log(chalk.green('Daemon stopped successfully.'));
|
|
238
|
+
}
|
|
187
239
|
}
|
|
188
240
|
catch (e) {
|
|
189
241
|
console.error(chalk.red('Failed to stop daemon. Is it running?'));
|
|
@@ -350,6 +402,7 @@ export const registerDaemonCommand = (program) => {
|
|
|
350
402
|
.description('Start the daemon')
|
|
351
403
|
.option('-p, --port <number>', 'Daemon port', String(DAEMON_PORT))
|
|
352
404
|
.option('-t, --timeout <seconds>', 'Startup timeout in seconds (default: 30)')
|
|
405
|
+
.option('-c, --connection-timeout <seconds>', 'Server connection timeout in seconds (default: 20)')
|
|
353
406
|
.option('-v, --verbose', 'Show detailed logs')
|
|
354
407
|
.action((options) => startAction(options));
|
|
355
408
|
program.command('stop')
|
|
@@ -372,6 +425,7 @@ export const registerDaemonCommand = (program) => {
|
|
|
372
425
|
daemonCmd.command('start', { isDefault: true, hidden: true })
|
|
373
426
|
.description('Start the daemon (default)')
|
|
374
427
|
.option('-t, --timeout <seconds>', 'Startup timeout in seconds (default: 30)')
|
|
428
|
+
.option('-c, --connection-timeout <seconds>', 'Server connection timeout in seconds (default: 20)')
|
|
375
429
|
.action((options) => startAction(options));
|
|
376
430
|
daemonCmd.command('stop')
|
|
377
431
|
.description('Stop the running daemon')
|
package/dist/core/pool.js
CHANGED
|
@@ -79,6 +79,8 @@ export class ConnectionPool {
|
|
|
79
79
|
this.initializing = true;
|
|
80
80
|
this.initialized = false;
|
|
81
81
|
const verbose = process.env.MCPS_VERBOSE === 'true';
|
|
82
|
+
// 获取连接超时时间(从环境变量或默认 20 秒)
|
|
83
|
+
const connectionTimeout = parseInt(process.env.MCPS_CONNECTION_TIMEOUT || '20000', 10);
|
|
82
84
|
// 过滤掉 disabled 的服务器
|
|
83
85
|
const enabledServers = servers.filter(server => {
|
|
84
86
|
const disabled = server.disabled === true;
|
|
@@ -98,7 +100,7 @@ export class ConnectionPool {
|
|
|
98
100
|
for (const server of enabledServers) {
|
|
99
101
|
process.stdout.write(`- ${server.name}... `);
|
|
100
102
|
try {
|
|
101
|
-
await this.getClient(server.name, { timeoutMs:
|
|
103
|
+
await this.getClient(server.name, { timeoutMs: connectionTimeout });
|
|
102
104
|
results.push({ name: server.name, success: true });
|
|
103
105
|
console.log('Connected ✓');
|
|
104
106
|
}
|