From de7a91a1cf54a6c037919f97a3199456d545cb97 Mon Sep 17 00:00:00 2001 From: MQ Date: Tue, 13 May 2025 10:09:37 +0200 Subject: [PATCH] allow disabling of process.on SIGINT handler --- src/mcp/server.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/mcp/server.ts b/src/mcp/server.ts index c0921c4b..4ff759fd 100644 --- a/src/mcp/server.ts +++ b/src/mcp/server.ts @@ -45,7 +45,7 @@ export class ActorsMcpServer { public readonly tools: Map; private readonly options: ActorsMcpServerOptions; - constructor(options: ActorsMcpServerOptions = {}) { + constructor(options: ActorsMcpServerOptions = {}, setupSIGINTHandler = true) { this.options = { enableAddingActors: options.enableAddingActors ?? false, enableDefaultActors: options.enableDefaultActors ?? true, // Default to true for backward compatibility @@ -63,7 +63,7 @@ export class ActorsMcpServer { }, ); this.tools = new Map(); - this.setupErrorHandling(); + this.setupErrorHandling(setupSIGINTHandler); this.setupToolHandlers(); // Add default tools @@ -160,14 +160,17 @@ export class ActorsMcpServer { return Array.from(this.tools.keys()); } - private setupErrorHandling(): void { + private setupErrorHandling(setupSIGINTHandler = true): void { this.server.onerror = (error) => { console.error('[MCP Error]', error); // eslint-disable-line no-console }; - process.on('SIGINT', async () => { - await this.server.close(); - process.exit(0); - }); + // Allow disable of SIGINT handler to prevent max listeners warning + if (setupSIGINTHandler) { + process.on('SIGINT', async () => { + await this.server.close(); + process.exit(0); + }); + } } private setupToolHandlers(): void {