list_snapshots
Retrieve a list of disk snapshots within a specified Google Cloud Platform (GCP) project to manage and review backup data efficiently.
Instructions
List disk snapshots in a GCP project.
Args:
project_id: The ID of the GCP project to list snapshots for
Returns:
List of disk snapshots in the specified GCP project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes |
Implementation Reference
- The handler function for the 'list_snapshots' tool, decorated with @mcp.tool() for registration. It lists disk snapshots in a GCP project using the Google Cloud Compute API, formats them into a string response.@mcp.tool() def list_snapshots(project_id: str) -> str: """ List disk snapshots in a GCP project. Args: project_id: The ID of the GCP project to list snapshots for Returns: List of disk snapshots in the specified GCP project """ try: from google.cloud import compute_v1 # Initialize the Snapshots client client = compute_v1.SnapshotsClient() # List snapshots request = compute_v1.ListSnapshotsRequest(project=project_id) snapshots = client.list(request=request) # Format the response snapshots_list = [] for snapshot in snapshots: size_gb = snapshot.disk_size_gb status = snapshot.status source_disk = snapshot.source_disk.split('/')[-1] if snapshot.source_disk else "Unknown" creation_time = snapshot.creation_timestamp if snapshot.creation_timestamp else "Unknown" snapshots_list.append(f"- {snapshot.name} (Source: {source_disk}, Size: {size_gb} GB, Status: {status}, Created: {creation_time})") if not snapshots_list: return f"No snapshots found for project {project_id}." snapshots_str = "\n".join(snapshots_list) return f""" Disk Snapshots in GCP Project {project_id}: {snapshots_str} """ except Exception as e: return f"Error listing snapshots: {str(e)}"
- src/gcp_mcp/gcp_modules/compute/tools.py:625-625 (registration)The @mcp.tool() decorator registers the list_snapshots function as an MCP tool.@mcp.tool()