list-hosts
Returns all UniFi console hosts, including UDM, UDM Pro, and Cloud Key models. Required for inventory or mapping your network hardware.
Instructions
List all UniFi console hosts (UDM, UDM Pro, Cloud Key, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| extractFields | No | Comma-separated dotted paths to project from response (e.g. 'id,name,owner.name,columns.*.name'). Use `*` as wildcard for arrays/objects. Wrap field names with dots in backticks. Reduces response tokens dramatically on large entities. |
Implementation Reference
- src/tools/hosts.ts:12-19 (handler)The listHosts async function that executes the tool logic. Calls GET /hosts via unifiClient, optionally extracts fields, or returns a default set of fields (id, hostname, state, hardware shortname, firmware version).
export async function listHosts(params: z.infer<typeof listHostsSchema> = {}) { const response = await unifiClient.get<{ data: unknown[] }>("/hosts"); if (params.extractFields) return response.data; return applyExtractFields( response.data, "*.id,*.reportedState.hostname,*.reportedState.state,*.reportedState.hardware.shortname,*.reportedState.firmwareVersion", ); } - src/tools/hosts.ts:8-10 (schema)Zod schema for list-hosts input validation. Accepts an optional extractFields string for field filtering.
export const listHostsSchema = z.object({ extractFields: ef, }); - src/index.ts:109-111 (registration)Registration of the 'list-hosts' tool with the MCP server. Calls tool() which registers it in the 'raw' category and calls server.tool() with the schema and wrapped handler.
tool("list-hosts", "List all UniFi console hosts (UDM, UDM Pro, Cloud Key, etc.)", listHostsSchema.shape, wrapToolHandler(listHosts)); - src/index.ts:21-21 (registration)Import of listHostsSchema and listHosts from ./tools/hosts.js
import { listHostsSchema, listHosts, getHostSchema, getHost } from "./tools/hosts.js";