Skip to main content
Glama

create_instance

Create a new Compute Engine instance on Google Cloud Platform by specifying project ID, zone, instance name, machine type, source image, disk size, network, and optional external IP.

Instructions

    Create a new Compute Engine instance.
    
    Args:
        project_id: The ID of the GCP project
        zone: The zone to create the instance in (e.g., "us-central1-a")
        instance_name: The name for the new instance
        machine_type: The machine type (e.g., "e2-medium")
        source_image: The source image for the boot disk (e.g., "projects/debian-cloud/global/images/family/debian-11")
        boot_disk_size_gb: The size of the boot disk in GB (default: 10)
        network: The network to connect to (default: "default")
        subnet: The subnetwork to connect to (optional)
        external_ip: Whether to allocate an external IP (default: True)
    
    Returns:
        Status message indicating whether the instance was created successfully
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
boot_disk_size_gbNo
external_ipNo
instance_nameYes
machine_typeYes
networkNodefault
project_idYes
source_imageYes
subnetNo
zoneYes

Implementation Reference

  • The @mcp.tool()-decorated function that implements the core logic for creating a GCP Compute Engine instance using the Google Cloud compute_v1 client. It configures disk, network, service account, and calls insert() to create the VM.
        @mcp.tool()
        def create_instance(project_id: str, zone: str, instance_name: str, machine_type: str, 
                          source_image: str, boot_disk_size_gb: int = 10, 
                          network: str = "default", subnet: str = "", 
                          external_ip: bool = True) -> str:
            """
            Create a new Compute Engine instance.
            
            Args:
                project_id: The ID of the GCP project
                zone: The zone to create the instance in (e.g., "us-central1-a")
                instance_name: The name for the new instance
                machine_type: The machine type (e.g., "e2-medium")
                source_image: The source image for the boot disk (e.g., "projects/debian-cloud/global/images/family/debian-11")
                boot_disk_size_gb: The size of the boot disk in GB (default: 10)
                network: The network to connect to (default: "default")
                subnet: The subnetwork to connect to (optional)
                external_ip: Whether to allocate an external IP (default: True)
            
            Returns:
                Status message indicating whether the instance was created successfully
            """
            try:
                from google.cloud import compute_v1
                
                # Initialize the clients
                instances_client = compute_v1.InstancesClient()
                
                # Format the machine type
                machine_type_url = f"projects/{project_id}/zones/{zone}/machineTypes/{machine_type}"
                
                # Create the disk configuration
                boot_disk = compute_v1.AttachedDisk()
                boot_disk.boot = True
                initialize_params = compute_v1.AttachedDiskInitializeParams()
                initialize_params.source_image = source_image
                initialize_params.disk_size_gb = boot_disk_size_gb
                boot_disk.initialize_params = initialize_params
                boot_disk.auto_delete = True
                
                # Create the network configuration
                network_interface = compute_v1.NetworkInterface()
                if network.startswith("projects/"):
                    network_interface.network = network
                else:
                    network_interface.network = f"projects/{project_id}/global/networks/{network}"
                
                if subnet:
                    if subnet.startswith("projects/"):
                        network_interface.subnetwork = subnet
                    else:
                        network_interface.subnetwork = f"projects/{project_id}/regions/{zone.rsplit('-', 1)[0]}/subnetworks/{subnet}"
                
                if external_ip:
                    access_config = compute_v1.AccessConfig()
                    access_config.name = "External NAT"
                    access_config.type_ = "ONE_TO_ONE_NAT"
                    access_config.network_tier = "PREMIUM"
                    network_interface.access_configs = [access_config]
                
                # Create the instance
                instance = compute_v1.Instance()
                instance.name = instance_name
                instance.machine_type = machine_type_url
                instance.disks = [boot_disk]
                instance.network_interfaces = [network_interface]
                
                # Create a default service account for the instance
                service_account = compute_v1.ServiceAccount()
                service_account.email = "default"
                service_account.scopes = ["https://www.googleapis.com/auth/cloud-platform"]
                instance.service_accounts = [service_account]
                
                # Create the instance
                operation = instances_client.insert(
                    project=project_id,
                    zone=zone,
                    instance_resource=instance
                )
                
                # Wait for the create 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 instance {instance_name}: {operation.error.errors[0].message}"
                
                # Get the created instance to return its details
                created_instance = instances_client.get(project=project_id, zone=zone, instance=instance_name)
                
                # Get the instance IP addresses
                internal_ip = "None"
                external_ip = "None"
                
                if created_instance.network_interfaces:
                    internal_ip = created_instance.network_interfaces[0].network_i_p or "None"
                    if created_instance.network_interfaces[0].access_configs:
                        external_ip = created_instance.network_interfaces[0].access_configs[0].nat_i_p or "None"
                
                return f"""
    Instance {instance_name} created successfully in zone {zone}.
    
    Details:
    - Machine Type: {machine_type}
    - Internal IP: {internal_ip}
    - External IP: {external_ip}
    - Status: {created_instance.status}
    """
            except Exception as e:
                return f"Error creating instance: {str(e)}"
  • The register_tools function for the compute module defines and registers the create_instance tool (and others) via @mcp.tool() decorators inside it.
    def register_tools(mcp):
        """Register all compute tools with the MCP server."""
  • Top-level registration in the MCP server that invokes the compute module's register_tools(mcp), thereby registering the create_instance tool.
    compute_tools.register_tools(mcp)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Create' implies a write/mutation operation, it doesn't mention critical behaviors: required permissions (IAM roles), cost implications, rate limits, whether the operation is idempotent, or what happens on failure. The return statement is vague ('Status message') without specifying format or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with a clear purpose statement followed by organized Args/Returns sections. Every sentence serves a purpose, though the return statement could be more specific. The formatting with bullet-like parameter explanations is efficient and scannable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex 9-parameter creation tool with no annotations and no output schema, the description provides good parameter semantics but lacks critical behavioral context. It covers what parameters mean but not how the tool behaves operationally (permissions, costs, errors). The return description is minimal ('Status message'), leaving output format ambiguous.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by providing clear semantic explanations for all 9 parameters. Each parameter includes purpose clarification (e.g., 'zone to create the instance in'), format examples (e.g., 'us-central1-a'), and default values where applicable. This adds significant value beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new Compute Engine instance') with the exact resource, distinguishing it from sibling tools like 'delete_instance', 'start_instance', and 'stop_instance'. It uses precise technical terminology that matches the GCP context.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., authentication, project setup), nor does it differentiate from related tools like 'create_snapshot' or 'create_backup'. The agent must infer usage context solely from the tool name and description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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