list_virtual_machines
Retrieve a list of virtual machines in Apache CloudStack by filtering results using zone ID, VM state, or keywords for efficient cloud resource management.
Instructions
List virtual machines in CloudStack
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | No | Keyword to search VMs | |
| state | No | VM state (Running, Stopped, etc.) | |
| zoneid | No | Zone ID to filter VMs |
Implementation Reference
- The main execution logic for the list_virtual_machines tool. Fetches VMs from CloudStack API and formats a detailed text list response.async handleListVirtualMachines(args: any) { const result = await this.cloudStackClient.listVirtualMachines(args); const vms = result.listvirtualmachinesresponse?.virtualmachine || []; const vmList = vms.map((vm: any) => ({ id: vm.id, name: vm.name, displayname: vm.displayname, state: vm.state, zonename: vm.zonename, templatename: vm.templatename, serviceofferingname: vm.serviceofferingname, cpunumber: vm.cpunumber, memory: vm.memory, networkkbsread: vm.networkkbsread, networkkbswrite: vm.networkkbswrite, diskioread: vm.diskioread, diskiowrite: vm.diskiowrite, disksize: vm.disksize, created: vm.created, ipaddress: vm.nic?.[0]?.ipaddress, hostname: vm.hostname })); return { content: [ { type: 'text', text: `Found ${vmList.length} virtual machines:\n\n${vmList .map((vm: any) => `• ${vm.name} (${vm.id})\n Display Name: ${vm.displayname}\n State: ${vm.state}\n Zone: ${vm.zonename}\n Template: ${vm.templatename}\n Service Offering: ${vm.serviceofferingname}\n CPUs: ${vm.cpunumber}, RAM: ${vm.memory}MB\n IP Address: ${vm.ipaddress}\n Created: ${vm.created}\n` ) .join('\n')}` } ] }; }
- Tool schema definition specifying the name, description, and input parameters for list_virtual_machines.{ name: 'list_virtual_machines', description: 'List virtual machines in CloudStack', inputSchema: { type: 'object', properties: { zoneid: { type: 'string', description: 'Zone ID to filter VMs', }, state: { type: 'string', description: 'VM state (Running, Stopped, etc.)', }, keyword: { type: 'string', description: 'Keyword to search VMs', }, }, additionalProperties: false, }, },
- src/server.ts:108-109 (registration)MCP server registration that dispatches list_virtual_machines tool calls to the VM handler.case 'list_virtual_machines': return await this.vmHandlers.handleListVirtualMachines(args);