get_disk_info_tool
Retrieve disk usage details for specific paths or all mounted disks to monitor and manage storage effectively with System Information MCP Server.
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)Handler and registration for the 'get_disk_info_tool' MCP tool using @app.tool() decorator. Delegates execution to the get_disk_info helper function.@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 implementation of disk information retrieval in get_disk_info function using psutil.disk_partitions() and disk_usage(). Handles both specific paths and all disks, with caching via @cache_result.@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