UNPKG

@utaba/ucm-mcp-server

Version:

Universal Context Manager MCP Server - AI Productivity Platform

50 lines 2.23 kB
import https from 'https'; import fs from 'fs'; /** * Factory for creating HTTPS agents with custom CA certificate support * Enables secure connections to self-signed certificate environments */ export class HttpsAgentFactory { /** * Create an HTTPS agent with optional custom CA certificate * * @param options - Configuration options for the HTTPS agent * @param logger - Logger instance for diagnostic messages * @returns https.Agent configured with custom CA if provided, otherwise undefined * @throws Error if certificate file cannot be read or is invalid */ static createAgent(options, logger) { // If no CA certificate path provided, return undefined to use default behavior if (!options.caCertPath) { return undefined; } try { // Load the CA certificate from file const caCert = fs.readFileSync(options.caCertPath, 'utf-8'); // Create HTTPS agent with custom CA certificate // rejectUnauthorized: true ensures full certificate validation is maintained const agent = new https.Agent({ ca: caCert }); if (logger) { logger.info('HttpsAgentFactory', `✓ Loaded CA certificate from: ${options.caCertPath}`); } return agent; } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; const detailedMessage = `Failed to load CA certificate from ${options.caCertPath}: ${errorMessage}`; if (logger) { logger.warn('HttpsAgentFactory', detailedMessage); logger.warn('HttpsAgentFactory', 'Continuing without custom CA certificate - using default certificate validation'); } else { console.warn(`⚠️ ${detailedMessage}`); console.warn('⚠️ Continuing without custom CA certificate - using default certificate validation'); } // Return undefined to fall back to default behavior instead of crashing return undefined; } } } //# sourceMappingURL=HttpsAgentFactory.js.map