delete_instance
Remove a Compute Engine instance on GCP by specifying the project ID, zone, and instance name. Returns a status message confirming deletion.
Instructions
Delete a Compute Engine instance.
Args:
project_id: The ID of the GCP project
zone: The zone where the instance is located (e.g., "us-central1-a")
instance_name: The name of the instance to delete
Returns:
Status message indicating whether the instance was deleted successfully
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instance_name | Yes | ||
| project_id | Yes | ||
| zone | Yes |
Implementation Reference
- The delete_instance tool handler, registered via @mcp.tool() decorator, implements deletion of a GCP Compute Engine instance by calling the delete method on InstancesClient and polling the operation status.@mcp.tool() def delete_instance(project_id: str, zone: str, instance_name: str) -> str: """ Delete a Compute Engine instance. Args: project_id: The ID of the GCP project zone: The zone where the instance is located (e.g., "us-central1-a") instance_name: The name of the instance to delete Returns: Status message indicating whether the instance was deleted successfully """ try: from google.cloud import compute_v1 # Initialize the Compute Engine client client = compute_v1.InstancesClient() # Delete the instance operation = client.delete(project=project_id, zone=zone, instance=instance_name) # 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 deleting instance {instance_name}: {operation.error.errors[0].message}" return f"Instance {instance_name} in zone {zone} deleted successfully." except Exception as e: return f"Error deleting instance: {str(e)}"
- src/gcp_mcp/gcp_modules/compute/tools.py:6-7 (registration)The register_tools function where all compute tools, including delete_instance, are registered using @mcp.tool() decorators.def register_tools(mcp): """Register all compute tools with the MCP server."""