Skip to main content
Glama
dknell

System Information MCP Server

by dknell

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
NameRequiredDescriptionDefault
pathNo

Implementation Reference

  • 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)
  • 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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/dknell/mcp-system-info'

If you have feedback or need assistance with the MCP directory API, please join our Discord server