Skip to main content
Glama
michaelrice
by michaelrice

create_vm

Provision a virtual machine that boots from the network, with configurable OS type, disk provisioning, and network profile.

Instructions

Create a VM that network boots first. vm_type: esxi, ubuntu, rhel (or any type defined in config templates). disk_provisioning: thin (default) or thick. network_profile: named profile from target config (e.g. standard, secure-boot).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
vm_typeYes
targetNo
network_profileNo
cpuNo
ram_mbNo
disk_gbNo
disk_provisioningNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main tool handler function for 'create_vm'. It loads config, resolves target/template, connects to vCenter, and delegates VM creation to _create_vm.
    def create_vm(
        name: str,
        vm_type: str,
        target: str | None = None,
        network_profile: str | None = None,
        cpu: int | None = None,
        ram_mb: int | None = None,
        disk_gb: int | None = None,
        disk_provisioning: str | None = None,
    ) -> str:
        """
        Create a VM that network boots first.
        vm_type: esxi, ubuntu, rhel (or any type defined in config templates).
        disk_provisioning: thin (default) or thick.
        network_profile: named profile from target config (e.g. standard, secure-boot).
        """
        try:
            cfg = load_config()
            target_cfg = resolve_target(cfg, target)
            tmpl = resolve_template(
                cfg, vm_type,
                cpu=cpu, ram_mb=ram_mb,
                disk_gb=disk_gb, disk_provisioning=disk_provisioning,
            )
            profile_name = network_profile or target_cfg["default_network"]
            if profile_name not in target_cfg["networks"]:
                return f"Error: network profile '{profile_name}' not in target config"
            portgroup_names = target_cfg["networks"][profile_name]
    
            with vcenter_connection(target_cfg) as si:
                content = si.RetrieveContent()
                vm = _create_vm(content, target_cfg, name, tmpl, portgroup_names)
                return f"Created VM '{vm.name}' (moref: {vm._moId})"
        except Exception as e:
            return f"Error: {e}"
  • Internal helper that constructs SCSI controller, disk, NICs, boot order, and calls CreateVM_Task to provision the VM.
    def _create_vm(content, target_cfg: dict, name: str, tmpl: dict, portgroup_names: list):
        dc = _get_datacenter(content, target_cfg)
        resource_pool = _get_resource_pool(content, target_cfg, dc)
        datastore = get_obj(content, [vim.Datastore], target_cfg["datastore"])
        if not datastore:
            raise ValueError(f"Datastore '{target_cfg['datastore']}' not found")
    
        vm_folder = dc.vmFolder
    
        # SCSI controller (key=1000)
        scsi = vim.vm.device.VirtualLsiLogicController()
        scsi.key = 1000
        scsi.busNumber = 0
        scsi.sharedBus = vim.vm.device.VirtualSCSIController.Sharing.noSharing
        scsi_spec = _add_spec(scsi)
    
        # Disk (key=2000, attached to SCSI key=1000)
        if tmpl["disk_provisioning"] not in ("thin", "thick"):
            raise ValueError(
                f"disk_provisioning must be 'thin' or 'thick', got '{tmpl['disk_provisioning']}'"
            )
        disk_backing = vim.vm.device.VirtualDisk.FlatVer2BackingInfo()
        disk_backing.diskMode = "persistent"
        disk_backing.thinProvisioned = (tmpl["disk_provisioning"] == "thin")
    
        disk = vim.vm.device.VirtualDisk()
        disk.key = 2000
        disk.unitNumber = 0
        disk.controllerKey = 1000
        disk.capacityInKB = tmpl["disk_gb"] * 1024 * 1024
        disk.backing = disk_backing
        disk_spec = _add_spec(
            disk,
            file_op=vim.vm.device.VirtualDeviceSpec.FileOperation.create,
        )
    
        # NICs (keys start at 4000)
        if not portgroup_names:
            raise ValueError(f"Network profile has no portgroups defined")
        nic_specs = []
        nic_keys = []
        for i, pg_name in enumerate(portgroup_names):
            key = 4000 + i
            nic_keys.append(key)
            network = get_obj(content, [vim.Network], pg_name)
            if not network:
                raise ValueError(f"Network/portgroup '{pg_name}' not found")
    
            nic = vim.vm.device.VirtualVmxnet3()
            nic.key = key
            nic.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
            nic.connectable.startConnected = True
            nic.connectable.allowGuestControl = True
    
            if isinstance(network, vim.dvs.DistributedVirtualPortgroup):
                dvs_uuid = network.config.distributedVirtualSwitch.uuid
                port_backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo()
                port_backing.port = vim.dvs.PortConnection()
                port_backing.port.switchUuid = dvs_uuid
                port_backing.port.portgroupKey = network.key
                nic.backing = port_backing
            else:
                std_backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
                std_backing.network = network
                std_backing.deviceName = pg_name
                nic.backing = std_backing
    
            nic_specs.append(_add_spec(nic))
    
        # Boot order: first NIC
        boot_nic = vim.vm.BootOptions.BootableEthernetDevice()
        boot_nic.deviceKey = nic_keys[0]
        boot_opts = vim.vm.BootOptions()
        boot_opts.bootOrder = [boot_nic]
    
        # VM config spec
        config = vim.vm.ConfigSpec()
        config.name = name
        config.numCPUs = tmpl["cpu"]
        config.memoryMB = tmpl["ram_mb"]
        config.guestId = tmpl["guest_id"]
        config.files = vim.vm.FileInfo()
        config.files.vmPathName = f"[{target_cfg['datastore']}]"
        config.deviceChange = [scsi_spec, disk_spec] + nic_specs
        config.bootOptions = boot_opts
    
        if tmpl.get("vhv"):
            config.nestedHVEnabled = True
    
        task = vm_folder.CreateVM_Task(config=config, pool=resource_pool)
        wait_for_task(task)
        return task.info.result
  • Decorator registration: @mcp.tool() on create_vm registers it with the MCP server.
    def register_create_tools(mcp) -> None:
        @mcp.tool()
  • Server calls register_create_tools(mcp) to wire up the tool.
    register_create_tools(mcp)
Behavior3/5

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

With no annotations, the description carries the burden but only mentions 'network boots first' as a behavioral trait. It does not disclose whether the operation is idempotent, requires authentication, or what happens on conflict.

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

Conciseness5/5

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

The description is very concise, using four short lines with no unnecessary words. Each sentence adds value and is front-loaded with the primary purpose.

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

Completeness2/5

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

Given 8 parameters and no output schema details, the description is incomplete: it omits required fields, resource constraints, and 5 parameters entirely. An output schema exists but does not compensate for missing parameter explanations.

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

Parameters2/5

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

Schema coverage is 0%, and the description only explains three parameters (vm_type, disk_provisioning, network_profile) out of eight. Critical parameters like name, cpu, ram_mb, and disk_gb are left undocumented.

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 verb 'Create' and the resource 'VM', and adds specificity with 'network boots first'. Sibling tools are management operations, so there is no confusion with alternatives.

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

Usage Guidelines3/5

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

The description gives examples for vm_type and disk_provisioning defaults, but does not provide explicit guidance on when to use this tool versus alternatives, nor does it mention prerequisites or constraints.

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

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/michaelrice/vcenter-mcp'

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