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)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves data ('Get all'), implying a read-only operation, but doesn't clarify aspects like authentication needs, rate limits, or what 'currently connected' entails (e.g., real-time vs. cached data). This leaves significant gaps for a tool that interacts with network clients.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence that efficiently conveys the core purpose without unnecessary words. It's front-loaded with the essential information, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the lack of annotations and output schema, the description is insufficiently complete. It doesn't explain what the return data looks like (e.g., list format, fields included), nor does it address behavioral aspects like error handling or data freshness, which are critical for network monitoring tools.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'include_offline' clearly documented in the schema itself. The description doesn't add any parameter-specific details beyond what the schema provides, so it meets the baseline score without compensating or detracting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get all') and resource ('currently connected clients on the UniFi network'), making the tool's purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_devices' or 'get_device_activity', which might also retrieve client-related information, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_devices' or 'get_device_activity', nor does it specify prerequisites or exclusions, leaving the agent to infer usage from context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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