get_devices
Retrieve all network devices including access points, switches, and gateways from UniFi infrastructure for monitoring and management.
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)Executes the get_devices tool by fetching devices from UniFiClient and formatting the output using format_devices.case "get_devices": devices = await client.get_devices() return [TextContent(type="text", text=format_devices(devices))]
- src/unifi_mcp/server.py:21-29 (schema)Input/output schema definition for the get_devices tool (no input parameters required).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)Registers the list_tools function which includes the get_devices tool in the MCP server.@server.list_tools() async def list_tools() -> list[Tool]:
- src/unifi_mcp/server.py:247-272 (helper)Helper function to format the list of devices into a human-readable string for the tool response.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)
- UniFiClient method that retrieves the list of devices from the UniFi Controller API, called by the tool handler.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")