diff --git a/package-lock.json b/package-lock.json index f271f49..764e9bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maplezzk/mcps", - "version": "1.1.5", + "version": "1.1.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@maplezzk/mcps", - "version": "1.1.5", + "version": "1.1.6", "license": "ISC", "dependencies": { "@modelcontextprotocol/sdk": "^1.25.3", diff --git a/package.json b/package.json index 82305b1..ecb1e3b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maplezzk/mcps", - "version": "1.1.5", + "version": "1.1.6", "description": "A CLI to manage and use MCP servers", "publishConfig": { "access": "public" diff --git a/src/commands/daemon.ts b/src/commands/daemon.ts index 32d6ce3..13fdb56 100644 --- a/src/commands/daemon.ts +++ b/src/commands/daemon.ts @@ -139,7 +139,8 @@ const startAction = async (options: any) => { env: { ...process.env, MCPS_DAEMON_DETACHED: 'true', - MCPS_VERBOSE: options.verbose ? 'true' : 'false' + MCPS_VERBOSE: options.verbose ? 'true' : 'false', + MCPS_CONNECTION_TIMEOUT: String((parseInt(options.connectionTimeout || process.env.MCPS_CONNECTION_TIMEOUT || '20', 10)) * 1000) } }); @@ -445,6 +446,7 @@ export const registerDaemonCommand = (program: Command) => { .description('Start the daemon') .option('-p, --port ', 'Daemon port', String(DAEMON_PORT)) .option('-t, --timeout ', 'Startup timeout in seconds (default: 30)') + .option('-c, --connection-timeout ', 'Server connection timeout in seconds (default: 20)') .option('-v, --verbose', 'Show detailed logs') .action((options) => startAction(options)); @@ -473,6 +475,7 @@ export const registerDaemonCommand = (program: Command) => { daemonCmd.command('start', { isDefault: true, hidden: true }) .description('Start the daemon (default)') .option('-t, --timeout ', 'Startup timeout in seconds (default: 30)') + .option('-c, --connection-timeout ', 'Server connection timeout in seconds (default: 20)') .action((options) => startAction(options)); daemonCmd.command('stop') diff --git a/src/core/pool.ts b/src/core/pool.ts index 4ade523..634f331 100644 --- a/src/core/pool.ts +++ b/src/core/pool.ts @@ -88,6 +88,9 @@ export class ConnectionPool { const verbose = process.env.MCPS_VERBOSE === 'true'; + // 获取连接超时时间(从环境变量或默认 20 秒) + const connectionTimeout = parseInt(process.env.MCPS_CONNECTION_TIMEOUT || '20000', 10); + // 过滤掉 disabled 的服务器 const enabledServers = servers.filter(server => { const disabled = (server as any).disabled === true; @@ -110,7 +113,7 @@ export class ConnectionPool { for (const server of enabledServers) { process.stdout.write(`- ${server.name}... `); try { - await this.getClient(server.name, { timeoutMs: 8000 }); + await this.getClient(server.name, { timeoutMs: connectionTimeout }); results.push({ name: server.name, success: true }); console.log('Connected ✓'); } catch (error: any) {