UNPKG

mcp-cve-intelligence-server-lite-test

Version:

Lite Model Context Protocol server for comprehensive CVE intelligence gathering with multi-source exploit discovery, designed for security professionals and cybersecurity researchers - Alpha Release

147 lines 5.2 kB
import { createContextLogger } from '../utils/logger.js'; import { HttpTransportServer } from './http-transport-server.js'; import { StdioTransportServer } from './stdio-transport-server.js'; import { TransportSessionManager } from './transport-session-manager.js'; const logger = createContextLogger('TransportManager'); export class TransportManager { config; httpTransportServer; stdioTransportServer; sessionManager; mcpServerFactory; healthService; constructor(config, mcpServerFactory, healthService) { this.config = config; this.mcpServerFactory = mcpServerFactory; this.healthService = healthService; this.sessionManager = new TransportSessionManager(); } /** * Start transport based on configuration */ async startTransport(transportConfig) { const config = transportConfig || this.config.transport; logger.info('Starting transport', { type: config.type }); switch (config.type) { case 'stdio': return await this.startStdioTransport(); case 'http': { // Use the HTTP config from our centralized configuration const httpConfig = this.config.transport.http; return await this.startHttpTransport({ host: httpConfig.host, port: httpConfig.port, enableCors: httpConfig.enableCors, sessionManagement: httpConfig.sessionManagement, requestLogging: { enabled: this.config.logging.level === 'debug', level: this.config.logging.level === 'debug' ? 'debug' : 'info', includeBody: this.config.logging.level === 'debug', includeHeaders: this.config.logging.level === 'debug', }, }); } default: throw new Error(`Unsupported transport type: ${config.type}`); } } /** * Start stdio transport */ async startStdioTransport() { if (this.stdioTransportServer) { throw new Error('Stdio transport is already running'); } this.stdioTransportServer = new StdioTransportServer(this.mcpServerFactory); const transport = await this.stdioTransportServer.start(); // Register session this.sessionManager.createSession('stdio-main', 'stdio', { transportType: 'stdio', }); logger.info('Stdio transport started successfully'); return transport; } /** * Start HTTP transport */ async startHttpTransport(httpConfig) { if (this.httpTransportServer) { throw new Error('HTTP transport is already running'); } this.httpTransportServer = new HttpTransportServer(httpConfig, this.mcpServerFactory, this.healthService); await this.httpTransportServer.start(); logger.info('HTTP transport started successfully', { port: httpConfig.port, host: httpConfig.host, }); return this.httpTransportServer; } /** * Stop all transports */ async stopTransports() { logger.info('Stopping all transports'); const stopPromises = []; // Stop HTTP transport if running if (this.httpTransportServer) { stopPromises.push(this.httpTransportServer.stop()); this.httpTransportServer = undefined; } // Stop stdio transport if running if (this.stdioTransportServer) { stopPromises.push(this.stdioTransportServer.stop()); this.stdioTransportServer = undefined; } await Promise.all(stopPromises); logger.info('All transports stopped'); } /** * Get transport status */ getTransportStatus() { return { stdio: { active: this.stdioTransportServer?.isActive() ?? false, sessionCount: this.sessionManager.getSessionCountByType('stdio'), }, http: { active: this.httpTransportServer !== undefined, sessionCount: this.sessionManager.getSessionCountByType('http'), port: this.httpTransportServer && this.config.transport.type === 'http' ? this.config.transport.http.port : undefined, }, }; } /** * Get session manager */ getSessionManager() { return this.sessionManager; } /** * Get HTTP transport server (if running) */ getHttpTransportServer() { return this.httpTransportServer; } /** * Get stdio transport server (if running) */ getStdioTransportServer() { return this.stdioTransportServer; } /** * Get active session count */ getActiveSessionCount() { return this.sessionManager.getSessionCount(); } /** * Get session statistics */ getSessionStats() { return this.sessionManager.getSessionStats(); } } //# sourceMappingURL=transport-manager.js.map