Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/mcp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class ActorsMcpServer {
public readonly tools: Map<string, ToolWrap>;
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
Expand All @@ -63,7 +63,7 @@ export class ActorsMcpServer {
},
);
this.tools = new Map();
this.setupErrorHandling();
this.setupErrorHandling(setupSIGINTHandler);
this.setupToolHandlers();

// Add default tools
Expand Down Expand Up @@ -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 {
Expand Down