UNPKG

ai-debug-local-mcp

Version:

๐ŸŽฏ ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

106 lines โ€ข 3.95 kB
/** * Memory-Efficient Logger for AI-Debug MCP Server * Prevents memory crashes during large-scale tool registration */ export class MemoryEfficientLogger { static logBuffer = []; static MAX_BUFFER_SIZE = 100; static duplicateToolCount = 0; static registrationSummary = new Map(); /** * Log tool registration with memory efficiency * Batches duplicate messages and provides summaries */ static logToolRegistration(toolName, isDuplicate = false) { if (isDuplicate) { this.duplicateToolCount++; // Don't log individual duplicates - just count them return; } // Count registrations by handler type const handlerType = toolName.split('_')[0]; this.registrationSummary.set(handlerType, (this.registrationSummary.get(handlerType) || 0) + 1); } /** * Log handler registration with summary instead of verbose output */ static logHandlerRegistration(handlerName, toolCount) { this.addToBuffer(`โœ… ${handlerName}: ${toolCount} tools registered`); } /** * Output registration summary instead of individual messages */ static outputRegistrationSummary() { console.log('๐Ÿ”ง AI-Debug MCP Server - Tool Registration Summary:'); console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”'); let totalTools = 0; for (const [handlerType, count] of this.registrationSummary.entries()) { totalTools += count; console.log(` ๐Ÿ“ฆ ${handlerType}: ${count} tools`); } if (this.duplicateToolCount > 0) { console.log(` โ„น๏ธ Duplicate registrations: ${this.duplicateToolCount} (skipped)`); } console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”'); console.log(`๐Ÿ› ๏ธ Total: ${totalTools} unique tools available`); console.log('๐Ÿ›ก๏ธ Memory-optimized registration complete'); console.log(''); } /** * Add message to buffer with automatic flushing */ static addToBuffer(message) { this.logBuffer.push(message); if (this.logBuffer.length >= this.MAX_BUFFER_SIZE) { this.flushBuffer(); } } /** * Flush buffer to console */ static flushBuffer() { if (this.logBuffer.length > 0) { console.log(this.logBuffer.join('\n')); this.logBuffer = []; } } /** * Memory monitoring utilities */ static logMemoryUsage(context) { const used = process.memoryUsage(); const mb = (bytes) => Math.round(bytes / 1024 / 1024); console.log(`๐Ÿ“Š Memory Usage (${context}):`); console.log(` Heap Used: ${mb(used.heapUsed)} MB`); console.log(` Heap Total: ${mb(used.heapTotal)} MB`); console.log(` External: ${mb(used.external)} MB`); } /** * Check if memory usage is approaching danger zone */ static isMemoryPressure() { const used = process.memoryUsage(); const heapUsedMB = used.heapUsed / 1024 / 1024; const heapTotalMB = used.heapTotal / 1024 / 1024; // Warning if heap usage > 80% or > 2GB return heapUsedMB > (heapTotalMB * 0.8) || heapUsedMB > 2048; } /** * Force garbage collection if available */ static forceGC() { if (global.gc) { global.gc(); console.log('๐Ÿงน Forced garbage collection'); } } /** * Reset all counters and buffers */ static reset() { this.logBuffer = []; this.duplicateToolCount = 0; this.registrationSummary.clear(); } } //# sourceMappingURL=memory-efficient-logger.js.map