@@ -45,7 +45,7 @@ export class ActorsMcpServer {
4545 public readonly tools : Map < string , ToolWrap > ;
4646 private readonly options : ActorsMcpServerOptions ;
4747
48- constructor ( options : ActorsMcpServerOptions = { } ) {
48+ constructor ( options : ActorsMcpServerOptions = { } , setupSIGINTHandler = true ) {
4949 this . options = {
5050 enableAddingActors : options . enableAddingActors ?? false ,
5151 enableDefaultActors : options . enableDefaultActors ?? true , // Default to true for backward compatibility
@@ -63,7 +63,7 @@ export class ActorsMcpServer {
6363 } ,
6464 ) ;
6565 this . tools = new Map ( ) ;
66- this . setupErrorHandling ( ) ;
66+ this . setupErrorHandling ( setupSIGINTHandler ) ;
6767 this . setupToolHandlers ( ) ;
6868
6969 // Add default tools
@@ -160,14 +160,17 @@ export class ActorsMcpServer {
160160 return Array . from ( this . tools . keys ( ) ) ;
161161 }
162162
163- private setupErrorHandling ( ) : void {
163+ private setupErrorHandling ( setupSIGINTHandler = true ) : void {
164164 this . server . onerror = ( error ) => {
165165 console . error ( '[MCP Error]' , error ) ; // eslint-disable-line no-console
166166 } ;
167- process . on ( 'SIGINT' , async ( ) => {
168- await this . server . close ( ) ;
169- process . exit ( 0 ) ;
170- } ) ;
167+ // Allow disable of SIGINT handler to prevent max listeners warning
168+ if ( setupSIGINTHandler ) {
169+ process . on ( 'SIGINT' , async ( ) => {
170+ await this . server . close ( ) ;
171+ process . exit ( 0 ) ;
172+ } ) ;
173+ }
171174 }
172175
173176 private setupToolHandlers ( ) : void {
0 commit comments