-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestpkg:mcppackages/mcp-server - adapters, toolspackages/mcp-server - adapters, tools
Description
Problem
No memory monitoring for long-running MCP processes. While circular buffers exist, there's no usage tracking or automatic restart thresholds. AI tools become unresponsive after heavy use due to unbounded memory growth.
Current state:
- Circular buffers exist but no memory monitoring
- No automatic restart thresholds
- No heap usage tracking
- Production MCP servers can grow unbounded
Impact
- Reliability: MCP server becomes unresponsive after heavy use
- User Experience: AI tools slow down or crash during long sessions
- Production: No visibility into memory issues
- Success Criteria: <500MB steady state memory usage
Solution
Add memory monitoring with automatic restart thresholds:
- Track heap usage periodically (every 30s)
- Log warnings when approaching thresholds
- Emit health check failures when over threshold
- Optional: Graceful restart when critical threshold hit
Implementation approach:
// Memory monitoring service
interface MemoryStats {
heapUsed: number;
heapTotal: number;
rss: number;
external: number;
}
class MemoryMonitor {
private checkInterval = 30000; // 30s
private warnThresholdMB = 400;
private criticalThresholdMB = 500;
start() {
setInterval(() => {
const mem = process.memoryUsage();
const heapMB = mem.heapUsed / 1024 / 1024;
if (heapMB > this.criticalThresholdMB) {
logger.error(`Memory critical: ${heapMB}MB`);
// Emit health check failure
} else if (heapMB > this.warnThresholdMB) {
logger.warn(`Memory warning: ${heapMB}MB`);
}
}, this.checkInterval);
}
}Acceptance Criteria
- Memory usage logged every 30s in debug mode
- Warning emitted at 400MB heap usage
- Critical error at 500MB heap usage
- Health check reports memory status
- Circular buffer limits enforced (already exists)
- No memory leaks in 24h stress test
Files to Create/Modify
packages/mcp-server/src/monitoring/memory-monitor.ts- New monitoring servicepackages/mcp-server/bin/dev-agent-mcp.ts- Wire up monitorpackages/mcp-server/src/adapters/built-in/health-adapter.ts- Report memory- Tests for memory monitoring
Priority: P1 - Production stability
Part of: #104 - Performance & Reliability Critical Path
Future Enhancement
Consider automatic graceful restart when hitting critical threshold (v2):
- Notify client of restart
- Save current state
- Spawn new process
- Transfer connections
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestpkg:mcppackages/mcp-server - adapters, toolspackages/mcp-server - adapters, tools