list_disks
Retrieve and list Compute Engine persistent disks within a specified GCP project. Optionally filter results by zone for targeted disk management and monitoring.
Instructions
List Compute Engine persistent disks in a GCP project.
Args:
project_id: The ID of the GCP project to list disks for
zone: Optional zone to filter disks (e.g., "us-central1-a")
Returns:
List of persistent disks in the specified GCP project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes | ||
| zone | No |
Implementation Reference
- src/gcp_mcp/gcp_modules/compute/tools.py:343-343 (registration)Registers the list_disks tool using the @mcp.tool() decorator, which also derives the schema from the function signature and docstring.@mcp.tool()
- The handler function that implements the list_disks tool. It lists persistent disks in a GCP project, optionally filtered by zone, using the Google Cloud Compute API. Formats and returns a string list of disks with details like name, type, size, status, and attachment info.def list_disks(project_id: str, zone: str = "") -> str: """ List Compute Engine persistent disks in a GCP project. Args: project_id: The ID of the GCP project to list disks for zone: Optional zone to filter disks (e.g., "us-central1-a") Returns: List of persistent disks in the specified GCP project """ try: from google.cloud import compute_v1 # Initialize the Disks client client = compute_v1.DisksClient() disks_list = [] if zone: # List disks in the specified zone request = compute_v1.ListDisksRequest( project=project_id, zone=zone ) disks = client.list(request=request) for disk in disks: size_gb = disk.size_gb disk_type = disk.type.split('/')[-1] if disk.type else "Unknown" status = disk.status users = len(disk.users) if disk.users else 0 users_str = f"Attached to {users} instance(s)" if users > 0 else "Not attached" disks_list.append(f"- {disk.name} (Zone: {zone}, Type: {disk_type}, Size: {size_gb} GB, Status: {status}, {users_str})") else: # List disks in all zones zones_client = compute_v1.ZonesClient() zones_request = compute_v1.ListZonesRequest(project=project_id) zones = zones_client.list(request=zones_request) for zone_item in zones: zone_name = zone_item.name request = compute_v1.ListDisksRequest( project=project_id, zone=zone_name ) try: disks = client.list(request=request) for disk in disks: size_gb = disk.size_gb disk_type = disk.type.split('/')[-1] if disk.type else "Unknown" status = disk.status users = len(disk.users) if disk.users else 0 users_str = f"Attached to {users} instance(s)" if users > 0 else "Not attached" disks_list.append(f"- {disk.name} (Zone: {zone_name}, Type: {disk_type}, Size: {size_gb} GB, Status: {status}, {users_str})") except Exception: # Skip zones where we can't list disks continue if not disks_list: zone_msg = f" in zone {zone}" if zone else "" return f"No persistent disks found{zone_msg} for project {project_id}." disks_str = "\n".join(disks_list) zone_msg = f" in zone {zone}" if zone else "" return f""" Persistent Disks{zone_msg} in GCP Project {project_id}: {disks_str} """ except Exception as e: return f"Error listing persistent disks: {str(e)}"