list_hosts
Retrieve and filter hosts in Apache CloudStack based on zone, type, state, or hypervisor. Manage cloud infrastructure efficiently with this MCP tool.
Instructions
List hosts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hypervisor | No | Hypervisor type | |
| state | No | Host state | |
| type | No | Host type (Routing, Storage, etc.) | |
| zoneid | No | Zone ID to filter hosts |
Implementation Reference
- src/handlers/admin-handlers.ts:152-183 (handler)The main handler function for the 'list_hosts' tool. It queries the CloudStack API via the client, extracts host data, maps it to a simplified structure, and formats a detailed text response listing all hosts with their key attributes.async handleListHosts(args: any) { const result = await this.cloudStackClient.listHosts(args); const hosts = result.listhostsresponse?.host || []; const hostList = hosts.map((host: any) => ({ id: host.id, name: host.name, type: host.type, state: host.state, ipaddress: host.ipaddress, zonename: host.zonename, clustername: host.clustername, hypervisor: host.hypervisor, cpunumber: host.cpunumber, cpuspeed: host.cpuspeed, memorytotal: host.memorytotal, memoryused: host.memoryused })); return { content: [ { type: 'text', text: `Found ${hostList.length} hosts:\n\n${hostList .map((host: any) => `• ${host.name} (${host.id})\n Type: ${host.type}\n State: ${host.state}\n IP: ${host.ipaddress}\n Zone: ${host.zonename}\n Cluster: ${host.clustername}\n Hypervisor: ${host.hypervisor}\n CPUs: ${host.cpunumber} @ ${host.cpuspeed}MHz\n Memory: ${host.memoryused}/${host.memorytotal}MB\n` ) .join('\n')}` } ] }; }
- Tool schema definition for 'list_hosts', including name, description, and input schema specifying optional parameters like zoneid, type, state, hypervisor.{ name: 'list_hosts', description: 'List hosts', inputSchema: { type: 'object', properties: { zoneid: { type: 'string', description: 'Zone ID to filter hosts', }, type: { type: 'string', description: 'Host type (Routing, Storage, etc.)', }, state: { type: 'string', description: 'Host state', }, hypervisor: { type: 'string', description: 'Hypervisor type', }, }, additionalProperties: false, }, },
- src/server.ts:188-189 (registration)Registers the 'list_hosts' tool in the MCP server's CallToolRequest handler by mapping the tool name to the adminHandlers.handleListHosts method.case 'list_hosts': return await this.adminHandlers.handleListHosts(args);
- src/cloudstack-client.ts:256-258 (helper)Helper method in CloudStackClient that wraps the generic API request for the 'listHosts' CloudStack API endpoint.async listHosts(params: CloudStackParams = {}): Promise<CloudStackResponse> { return this.request('listHosts', params); }