get_devices
Retrieve all UniFi network devices including access points, switches, and gateways for monitoring and management through the UniFi MCP Server.
Instructions
Get all UniFi network devices (access points, switches, gateways)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/unifi_mcp/server.py:163-165 (handler)Handler logic for the 'get_devices' tool within the @server.call_tool() dispatch in call_tool function.case "get_devices": devices = await client.get_devices() return [TextContent(type="text", text=format_devices(devices))]
- src/unifi_mcp/server.py:21-29 (schema)Schema definition (Tool with name, description, inputSchema) for 'get_devices' in the list_tools function.Tool( name="get_devices", description="Get all UniFi network devices (access points, switches, gateways)", inputSchema={ "type": "object", "properties": {}, "required": [], }, ),
- src/unifi_mcp/server.py:16-17 (registration)Registration of tools via @server.list_tools() decorator on list_tools function.@server.list_tools() async def list_tools() -> list[Tool]:
- UniFiClient.get_devices() method that fetches devices from the UniFi API.async def get_devices(self) -> list[dict[str, Any]]: """Get all network devices. Returns: List of device dictionaries. """ return await self._request("GET", "/api/s/{site}/stat/device")
- src/unifi_mcp/server.py:247-273 (helper)format_devices helper function used to format the device list into readable text output.def format_devices(devices: list[dict[str, Any]]) -> str: """Format device list for display.""" if not devices: return "No devices found." lines = [f"Found {len(devices)} device(s):\n"] for device in devices: name = device.get("name", "Unknown") mac = device.get("mac", "Unknown") model = device.get("model", "Unknown") device_type = device.get("type", "Unknown") state = device.get("state", 0) state_str = "Online" if state == 1 else "Offline" ip = device.get("ip", "N/A") version = device.get("version", "N/A") lines.append(f"- {name}") lines.append(f" MAC: {mac}") lines.append(f" Model: {model} ({device_type})") lines.append(f" Status: {state_str}") lines.append(f" IP: {ip}") lines.append(f" Firmware: {version}") lines.append("") return "\n".join(lines)