Memory Management APIs and Graceful Shutdown
This release addresses GitHub Discussion #331 where users reported orphaned MCP sessions consuming excessive memory.
New Features
Cache Cleanup Functions
clear_all_caches()- Clear storage and service cachesget_memory_usage()- Get process memory statistics (RSS, VMS, available memory)get_cache_stats()- Get cache hit/miss statisticsclear_model_caches()- Clear embedding model cachesget_model_cache_stats()- Get model cache statistics
Graceful Shutdown
_cleanup_on_shutdown()- Cleanup function for signal handlers- Updated
shutdown()method with proper cache and connection cleanup - Added
atexithandler for normal process exit - SIGTERM and SIGINT handlers now call cleanup before exit
Memory Management API Endpoints
GET /api/memory-stats- Get detailed memory usage (process memory + cache stats + model cache stats)POST /api/clear-caches- Clear all caches manually (returns memory freed)
Documentation
- New file:
docs/troubleshooting/memory-management.md- Comprehensive guide for monitoring and managing memory
Benefits
- Prevents memory leaks from orphaned sessions
- Enables proactive memory monitoring and cleanup
- Graceful resource release on server shutdown
- Production-ready memory management for long-running deployments
Installation
pip install --upgrade mcp-memory-serviceOr with uv:
uv pip install --upgrade mcp-memory-serviceRelated
Full Changelog: v8.70.0...v8.71.0