get_cache_stats
Retrieve detailed statistics and information about the documentation cache to monitor and optimize storage and performance in the AutoDocs MCP Server environment.
Instructions
Get statistics about the documentation cache.
Returns: Cache statistics and information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/autodoc_mcp/main.py:572-618 (handler)MCP tool handler function for 'get_cache_stats'. Decorated with @mcp.tool for automatic registration. Delegates to cache_manager for stats and package list, with error handling.@mcp.tool async def get_cache_stats() -> dict[str, Any]: """ Get statistics about the documentation cache. Returns: Cache statistics and information """ if cache_manager is None: return { "success": False, "error": { "message": "Cache manager not initialized", "suggestion": "Try again or restart the MCP server", "severity": "critical", "code": "service_not_initialized", "recoverable": False, }, } try: stats = await cache_manager.get_cache_stats() cached_packages = await cache_manager.list_cached_packages() return { "success": True, "cache_stats": stats, "cached_packages": cached_packages, "total_packages": len(cached_packages), } except Exception as e: formatted_error = ErrorFormatter.format_exception( e, {"operation": "get_cache_stats"} ) logger.error("Failed to get cache stats", error=str(e)) return { "success": False, "error": { "message": formatted_error.message, "suggestion": formatted_error.suggestion, "severity": formatted_error.severity.value, "code": formatted_error.error_code, "recoverable": formatted_error.recoverable, }, }
- Core helper method in FileCacheManager that computes cache statistics: total entries, size in bytes, and cache directory path.async def get_cache_stats(self) -> dict[str, Any]: """Get cache statistics.""" try: cache_files = list(self.cache_dir.glob("*.json")) total_size = sum(f.stat().st_size for f in cache_files) return { "total_entries": len(cache_files), "total_size_bytes": total_size, "cache_dir": str(self.cache_dir), } except OSError as e: logger.error("Failed to get cache stats", error=str(e)) return {"error": str(e)}
- Helper method in FileCacheManager that lists all cached package names by scanning JSON files in the cache directory.async def list_cached_packages(self) -> list[str]: """List all cached package keys.""" try: return [f.stem for f in self.cache_dir.glob("*.json")] except OSError as e: logger.error("Failed to list cached packages", error=str(e)) return []
- src/autodoc_mcp/main.py:572-572 (registration)FastMCP decorator that registers the get_cache_stats function as a tool.@mcp.tool