Skip to main content
Glama

create_snapshot

Generate a snapshot of a Compute Engine disk in Google Cloud Platform. Provide project ID, zone, disk name, and snapshot name to save disk data for backup or replication.

Instructions

    Create a snapshot of a Compute Engine disk.
    
    Args:
        project_id: The ID of the GCP project
        zone: The zone where the disk is located (e.g., "us-central1-a")
        disk_name: The name of the disk to snapshot
        snapshot_name: The name for the new snapshot
        description: Optional description for the snapshot
    
    Returns:
        Status message indicating whether the snapshot was created successfully
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
descriptionNo
disk_nameYes
project_idYes
snapshot_nameYes
zoneYes

Implementation Reference

  • The core handler function for the 'create_snapshot' MCP tool. It uses the Google Cloud Compute API to create a snapshot from a specified disk, waits for completion, and returns success or error message.
    @mcp.tool()
    def create_snapshot(project_id: str, zone: str, disk_name: str, snapshot_name: str, description: str = "") -> str:
        """
        Create a snapshot of a Compute Engine disk.
        
        Args:
            project_id: The ID of the GCP project
            zone: The zone where the disk is located (e.g., "us-central1-a")
            disk_name: The name of the disk to snapshot
            snapshot_name: The name for the new snapshot
            description: Optional description for the snapshot
        
        Returns:
            Status message indicating whether the snapshot was created successfully
        """
        try:
            from google.cloud import compute_v1
            
            # Initialize the Disks client
            disks_client = compute_v1.DisksClient()
            
            # Create the snapshot request
            snapshot = compute_v1.Snapshot()
            snapshot.name = snapshot_name
            if description:
                snapshot.description = description
            
            # Create the snapshot
            operation = disks_client.create_snapshot(
                project=project_id,
                zone=zone,
                disk=disk_name,
                snapshot_resource=snapshot
            )
            
            # Wait for the operation to complete
            operation_client = compute_v1.ZoneOperationsClient()
            
            # This is a synchronous call that will wait until the operation is complete
            while operation.status != compute_v1.Operation.Status.DONE:
                operation = operation_client.get(project=project_id, zone=zone, operation=operation.name.split('/')[-1])
                import time
                time.sleep(1)
            
            if operation.error:
                return f"Error creating snapshot {snapshot_name}: {operation.error.errors[0].message}"
            
            return f"Snapshot {snapshot_name} of disk {disk_name} in zone {zone} created successfully."
        except Exception as e:
            return f"Error creating snapshot: {str(e)}"
  • Registers the compute tools module, which includes the create_snapshot tool, by calling its register_tools function with the MCP server instance.
    compute_tools.register_tools(mcp)
  • The function that defines and registers all compute tools, including create_snapshot via decorators.
    def register_tools(mcp):

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/henihaddad/gcp-mcp'

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