get_disk_info_tool
Retrieve disk usage information for mounted disks or specific paths to monitor storage capacity and availability.
Instructions
Retrieve disk usage information.
Args: path: Specific path to check (default: all mounted disks)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No |
Implementation Reference
- src/system_info_mcp/server.py:52-60 (handler)The handler function for get_disk_info_tool, registered with @app.tool(), which calls the underlying get_disk_info implementation.@app.tool() def get_disk_info_tool(path: Optional[str] = None) -> Dict[str, Any]: """Retrieve disk usage information. Args: path: Specific path to check (default: all mounted disks) """ return get_disk_info(path=path)
- src/system_info_mcp/tools.py:114-177 (helper)Core helper function implementing the disk information logic using psutil.disk_usage and disk_partitions, with error handling and formatting.@cache_result("disk_info", ttl=10) def get_disk_info(path: Optional[str] = None) -> Dict[str, Any]: """Retrieve disk usage information.""" try: disks = [] if path: # Get info for specific path try: usage = psutil.disk_usage(path) disks.append( { "mountpoint": path, "device": "N/A", "fstype": "N/A", "total": usage.total, "used": usage.used, "free": usage.free, "percent": round((usage.used / usage.total) * 100, 1), "total_gb": bytes_to_gb(usage.total), "used_gb": bytes_to_gb(usage.used), "free_gb": bytes_to_gb(usage.free), } ) except (OSError, PermissionError) as e: logger.warning(f"Could not get disk info for path {path}: {e}") else: # Get info for all mounted disks partitions = psutil.disk_partitions() for partition in partitions: try: usage = psutil.disk_usage(partition.mountpoint) disks.append( { "mountpoint": partition.mountpoint, "device": partition.device, "fstype": partition.fstype, "total": usage.total, "used": usage.used, "free": usage.free, "percent": ( round((usage.used / usage.total) * 100, 1) if usage.total else 0 ), "total_gb": bytes_to_gb(usage.total), "used_gb": bytes_to_gb(usage.used), "free_gb": bytes_to_gb(usage.free), } ) except (OSError, PermissionError) as e: logger.warning( f"Could not get usage for {partition.mountpoint}: {e}" ) continue return {"disks": disks} except Exception as e: logger.error(f"Error getting disk info: {e}") raise