UNPKG

opendoor-mcp

Version:

Production-grade MCP server with multi-language code execution, VS Code integration, and browser automation

112 lines 3.97 kB
import { Logger } from '../utils/Logger.js'; export class HealthService { logger = Logger.getInstance(); constructor() { // Initialize health service } async getHealthStatus() { const status = { status: 'healthy', timestamp: new Date().toISOString(), version: '2.0.0', uptime: process.uptime(), memory: process.memoryUsage(), services: { execution_manager: await this.checkExecutionManagerHealth(), session_manager: await this.checkSessionManagerHealth(), security_manager: await this.checkSecurityManagerHealth() }, metrics: { memory_usage: this.getMemoryUsage(), cpu_usage: await this.getCpuUsage(), node_env: process.env.NODE_ENV || 'development', platform: process.platform, arch: process.arch } }; // Determine overall status const serviceStatuses = Object.values(status.services); if (serviceStatuses.some((s) => s.status === 'unhealthy')) { status.status = 'unhealthy'; } else if (serviceStatuses.some((s) => s.status === 'degraded')) { status.status = 'degraded'; } return status; } async checkExecutionManagerHealth() { try { // Basic health check for execution manager return { status: 'healthy', execution_method: 'local_processes', isolation: 'process_isolation' }; } catch (error) { this.logger.error('Execution manager health check failed:', error); return { status: 'unhealthy', error: error instanceof Error ? error.message : 'Unknown error' }; } } async checkSessionManagerHealth() { try { // Basic health check for session manager return { status: 'healthy', storage: 'memory_with_redis_fallback', cleanup: 'enabled' }; } catch (error) { this.logger.error('Session manager health check failed:', error); return { status: 'unhealthy', error: error instanceof Error ? error.message : 'Unknown error' }; } } async checkSecurityManagerHealth() { try { // Basic health check for security manager return { status: 'healthy', code_validation: 'enabled', rate_limiting: 'enabled', authentication: 'optional' }; } catch (error) { this.logger.error('Security manager health check failed:', error); return { status: 'unhealthy', error: error instanceof Error ? error.message : 'Unknown error' }; } } getMemoryUsage() { const usage = process.memoryUsage(); return { rss_mb: Math.round(usage.rss / 1024 / 1024), heap_used_mb: Math.round(usage.heapUsed / 1024 / 1024), heap_total_mb: Math.round(usage.heapTotal / 1024 / 1024), external_mb: Math.round(usage.external / 1024 / 1024) }; } async getCpuUsage() { return new Promise((resolve) => { const startUsage = process.cpuUsage(); setTimeout(() => { const currentUsage = process.cpuUsage(startUsage); resolve({ user_microseconds: currentUsage.user, system_microseconds: currentUsage.system, total_microseconds: currentUsage.user + currentUsage.system }); }, 100); }); } } //# sourceMappingURL=HealthService.js.map