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
JavaScript
/**
* 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