Skip to main content
Glama
nntkio

UniFi MCP Server

by nntkio

get_clients

Retrieve all currently connected clients on a UniFi network to monitor active devices and manage network access. Optionally include offline clients for historical analysis.

Instructions

Get all currently connected clients on the UniFi network

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_offlineNoInclude offline/historical clients

Implementation Reference

  • The main handler logic for the 'get_clients' MCP tool within the call_tool function. It handles the tool invocation by checking the 'include_offline' parameter, fetching clients using UniFiClient methods, formatting them, and returning as TextContent.
    case "get_clients": include_offline = arguments.get("include_offline", False) if include_offline: clients = await client.get_all_clients() else: clients = await client.get_clients() return [TextContent(type="text", text=format_clients(clients))]
  • Input schema definition for the 'get_clients' tool, including the optional 'include_offline' boolean parameter, as returned by list_tools().
    Tool( name="get_clients", description="Get all currently connected clients on the UniFi network", inputSchema={ "type": "object", "properties": { "include_offline": { "type": "boolean", "description": "Include offline/historical clients", "default": False, } }, "required": [], }, ),
  • Registration of all tools including 'get_clients' via the @server.list_tools() decorator on the list_tools function.
    @server.list_tools() async def list_tools() -> list[Tool]:
  • Low-level helper method in UniFiClient that fetches currently connected clients ('sta' endpoint) from the UniFi controller API.
    async def get_clients(self) -> list[dict[str, Any]]: """Get all currently connected clients. Returns: List of client dictionaries. """ return await self._request("GET", "/api/s/{site}/stat/sta")
  • Helper function to format the list of clients into a human-readable string, used by the tool handler.
    def format_clients(clients: list[dict[str, Any]]) -> str: """Format client list for display.""" if not clients: return "No clients found." lines = [f"Found {len(clients)} client(s):\n"] for c in clients: hostname = c.get("hostname") or c.get("name") or "Unknown" mac = c.get("mac", "Unknown") ip = c.get("ip", "N/A") is_wired = c.get("is_wired", False) conn_type = "Wired" if is_wired else "Wireless" essid = c.get("essid", "") tx_bytes = c.get("tx_bytes", 0) rx_bytes = c.get("rx_bytes", 0) lines.append(f"- {hostname}") lines.append(f" MAC: {mac}") lines.append(f" IP: {ip}") lines.append(f" Connection: {conn_type}") if essid: lines.append(f" SSID: {essid}") lines.append( f" Traffic: TX {format_bytes(tx_bytes)} / RX {format_bytes(rx_bytes)}" ) lines.append("") return "\n".join(lines)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nntkio/unifiMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server