get_storage_analysis
Analyze disk storage across all partitions to monitor capacity and usage for effective space management and troubleshooting.
Instructions
Get disk and storage analysis - all partitions, capacity, usage.
Comprehensive storage overview including all mounted volumes and usage stats. Critical for disk space management and storage troubleshooting.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/sysinfo/server.py:114-130 (handler)The main handler function for the 'get_storage_analysis' tool, decorated with @mcp.tool which registers it with the FastMCP server. It adds a header with timestamp, calls the helper get_storage_info() to collect storage data, handles exceptions, and formats the output as a ToolResult using text_response.@mcp.tool def get_storage_analysis() -> ToolResult: """Get disk and storage analysis - all partitions, capacity, usage. Comprehensive storage overview including all mounted volumes and usage stats. Critical for disk space management and storage troubleshooting. """ info_sections = [] info_sections.append("# Storage Analysis") info_sections.append(f"*Generated: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}*\n") try: info_sections.extend(get_storage_info()) except Exception as e: info_sections.append(f"⚠️ **Storage detection error**: {str(e)}") return text_response("\n".join(info_sections))
- src/sysinfo/collectors.py:559-588 (helper)Supporting utility function that implements the core storage analysis logic using psutil.disk_partitions() and disk_usage(). Iterates over all disk partitions, calculates capacity and usage statistics, determines disk types, skips temporary filesystems and inaccessible drives, and returns formatted list of storage information.def get_storage_info() -> List[str]: """Get disk and storage information""" info = [] info.append("\n## 💾 Storage") disk_partitions = psutil.disk_partitions() for partition in disk_partitions: try: disk_usage = psutil.disk_usage(partition.mountpoint) total_gb = disk_usage.total / (1024**3) free_gb = disk_usage.free / (1024**3) used_percent = (disk_usage.used / disk_usage.total) * 100 # Determine disk type disk_type = "Fixed" if partition.opts and 'removable' in partition.opts: disk_type = "Removable" elif partition.fstype in ['tmpfs', 'devtmpfs']: continue # Skip temporary filesystems info.append(f"\n### {partition.device} ({partition.mountpoint})") info.append(f"- **Type**: {disk_type} ({partition.fstype})") info.append(f"- **Total**: {total_gb:.1f} GB") info.append(f"- **Free**: {free_gb:.1f} GB ({100-used_percent:.1f}% free)") info.append(f"- **Used**: {used_percent:.1f}%") except (PermissionError, OSError): continue # Skip inaccessible drives return info