diff --git a/src/controllers/serverController.ts b/src/controllers/serverController.ts index f4d2da8..3cf1cb4 100644 --- a/src/controllers/serverController.ts +++ b/src/controllers/serverController.ts @@ -156,11 +156,6 @@ export const createServer = async (req: Request, res: Response): Promise = return; } - // Set default keep-alive interval for SSE servers if not specified - if ((config.type === 'sse' || (!config.type && config.url)) && !config.keepAliveInterval) { - config.keepAliveInterval = 60000; // Default 60 seconds for SSE servers - } - // Set owner property - use current user's username, default to 'admin' if (!config.owner) { const currentUser = (req as any).user; @@ -299,11 +294,6 @@ export const updateServer = async (req: Request, res: Response): Promise = return; } - // Set default keep-alive interval for SSE servers if not specified - if ((config.type === 'sse' || (!config.type && config.url)) && !config.keepAliveInterval) { - config.keepAliveInterval = 60000; // Default 60 seconds for SSE servers - } - // Set owner property if not provided - use current user's username, default to 'admin' if (!config.owner) { const currentUser = (req as any).user; diff --git a/src/services/mcpService.ts b/src/services/mcpService.ts index 9f8bd65..a47c6fd 100644 --- a/src/services/mcpService.ts +++ b/src/services/mcpService.ts @@ -31,11 +31,17 @@ const servers: { [sessionId: string]: Server } = {}; // Helper function to set up keep-alive ping for SSE connections const setupKeepAlive = (serverInfo: ServerInfo, serverConfig: ServerConfig): void => { - // Only set up keep-alive for SSE connections + // Only set up keep-alive for SSE connections when keepAlive is explicitly enabled if (!(serverInfo.transport instanceof SSEClientTransport)) { return; } + // Check if keepAlive is explicitly enabled (default is false to avoid excessive API calls) + if (serverConfig.keepAlive !== true) { + console.log(`Keep-alive ping disabled for server: ${serverInfo.name} (set keepAlive: true to enable)`); + return; + } + // Clear any existing interval first if (serverInfo.keepAliveIntervalId) { clearInterval(serverInfo.keepAliveIntervalId); diff --git a/src/types/index.ts b/src/types/index.ts index 5df5602..60c79da 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -266,7 +266,8 @@ export interface ServerConfig { headers?: Record; // HTTP headers for SSE/streamable-http/openapi servers enabled?: boolean; // Flag to enable/disable the server owner?: string; // Owner of the server, defaults to 'admin' user - keepAliveInterval?: number; // Keep-alive ping interval in milliseconds (default: 60000ms for SSE servers) + keepAlive?: boolean; // Enable keep-alive ping for SSE servers (default: false - disabled to avoid excessive API calls) + keepAliveInterval?: number; // Keep-alive ping interval in milliseconds (default: 60000ms when keepAlive is enabled) tools?: Record; // Tool-specific configurations with enable/disable state and custom descriptions prompts?: Record; // Prompt-specific configurations with enable/disable state and custom descriptions options?: Partial>; // MCP request options configuration diff --git a/tests/utils/mockSettings.ts b/tests/utils/mockSettings.ts index 187b6aa..c94ca9c 100644 --- a/tests/utils/mockSettings.ts +++ b/tests/utils/mockSettings.ts @@ -13,6 +13,7 @@ export const createMockSettings = (overrides: Partial = {}): McpSet args: ['-y', 'time-mcp'], env: {}, enabled: true, + keepAlive: false, keepAliveInterval: 30000, type: 'stdio', } as ServerConfig,