Skip to main content
Glama
michaelrice
by michaelrice

delete_vm

Permanently remove a virtual machine from vCenter by specifying its name or ID. The VM is powered off if running before deletion.

Instructions

Permanently delete a VM (power off if running, then destroy from disk). Accepts display name or moref ID (e.g. 'vm-42').

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
name_or_idYes
targetNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The delete_vm tool handler: powers off the VM if running, then destroys it permanently from disk. Uses lookup_vm to find by name or moref ID.
    def delete_vm(name_or_id: str, target: str | None = None) -> str:
        """
        Permanently delete a VM (power off if running, then destroy from disk).
        Accepts display name or moref ID (e.g. 'vm-42').
        """
        try:
            cfg = load_config()
            target_cfg = resolve_target(cfg, target)
            with vcenter_connection(target_cfg) as si:
                vm = lookup_vm(si, name_or_id)
                vm_name = vm.name
                if vm.runtime.powerState == vim.VirtualMachinePowerState.poweredOn:
                    wait_for_task(vm.PowerOff())
                wait_for_task(vm.Destroy_Task())
                return f"VM '{vm_name}' has been permanently deleted"
        except Exception as e:
            return f"Error: {e}"
  • Registration function that wraps the delete_vm function with @mcp.tool() decorator to register it as an MCP tool.
    def register_delete_tools(mcp) -> None:
        @mcp.tool()
        def delete_vm(name_or_id: str, target: str | None = None) -> str:
            """
            Permanently delete a VM (power off if running, then destroy from disk).
            Accepts display name or moref ID (e.g. 'vm-42').
            """
            try:
                cfg = load_config()
                target_cfg = resolve_target(cfg, target)
                with vcenter_connection(target_cfg) as si:
                    vm = lookup_vm(si, name_or_id)
                    vm_name = vm.name
                    if vm.runtime.powerState == vim.VirtualMachinePowerState.poweredOn:
                        wait_for_task(vm.PowerOff())
                    wait_for_task(vm.Destroy_Task())
                    return f"VM '{vm_name}' has been permanently deleted"
            except Exception as e:
                return f"Error: {e}"
  • Registration call in the main server setup, importing and invoking register_delete_tools to register the delete_vm tool.
    register_delete_tools(mcp)
  • Helper function that resolves a VM by managed object reference ID (vm-XXX) or display name, used by delete_vm to locate the target VM.
    def lookup_vm(si, name_or_id: str):
        """
        Find a VM by moref ID (e.g. 'vm-42') or display name.
        Raises ValueError if not found or if multiple VMs share the same display name.
        """
        content = si.RetrieveContent()
    
        if _is_moref(name_or_id):
            ref = vim.VirtualMachine(name_or_id)
            ref._stub = si._stub
            return ref
    
        container = content.viewManager.CreateContainerView(
            content.rootFolder, [vim.VirtualMachine], True
        )
        matches = [vm for vm in container.view if vm.name == name_or_id]
        container.Destroy()
    
        if not matches:
            raise ValueError(f"No VM found with name '{name_or_id}'")
        if len(matches) > 1:
            morefs = [vm._moId for vm in matches]
            raise ValueError(
                f"Multiple VMs named '{name_or_id}': {morefs}. Use a moref ID instead."
            )
        return matches[0]
    
    
    def wait_for_task(task) -> None:
        """Wait for a vSphere task to complete. Raises on task error."""
        WaitForTask(task)
  • Helper function that awaits vSphere task completion, used by delete_vm to wait for PowerOff and Destroy_Task operations.
    def wait_for_task(task) -> None:
        """Wait for a vSphere task to complete. Raises on task error."""
        WaitForTask(task)
Behavior4/5

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

With no annotations, the description shoulders full transparency. It discloses the irreversible destructive action, the pre-step (power off), and the input format. Missing details like permission requirements or error behavior, but core behavioral traits are present.

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?

Two sentences with no extraneous information. Action and input format are front-loaded, making it efficient and clear.

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?

The description covers the action and key parameter but lacks explanation for the optional 'target' parameter and does not mention output schema or return behavior, leaving gaps for a complete understanding.

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%, so the description must explain all parameters. It clarifies that name_or_id accepts a display name or moref ID, but completely omits the 'target' parameter, leaving users without guidance on its purpose or usage.

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 explicitly states 'Permanently delete a VM' and details the process ('power off if running, then destroy from disk'), clearly differentiating it from sibling tools like list_vms or power_on_vm.

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 explains how to identify the VM (name or moref ID) but does not provide explicit guidance on when to use this tool versus alternatives, such as powering off or creating a snapshot.

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