Skip to main content
Glama
vandreus

UniFi MCP Server

by vandreus

get_client_bandwidth_summary

Retrieve bandwidth usage summaries for network clients to monitor data consumption and identify high-usage devices on UniFi networks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function that implements the tool logic: fetches client list, computes aggregate bandwidth stats (total RX/TX, by wired/wireless, top 10 users), formats bytes, and returns JSON summary.
    handler: async ({ hostId }) => {
      let clients;
      if (hostId) {
        const response = await unifi.getClientsForHost(hostId);
        clients = response.data || [];
      } else {
        const response = await unifi.listAllClients();
        clients = response.data || [];
      }
    
      // Calculate bandwidth stats
      const summary = {
        totalClients: clients.length,
        totalRxBytes: 0,
        totalTxBytes: 0,
        byConnectionType: {
          wired: { count: 0, rxBytes: 0, txBytes: 0 },
          wireless: { count: 0, rxBytes: 0, txBytes: 0 }
        },
        topByUsage: []
      };
    
      const clientsWithUsage = clients.map(c => {
        const rx = c.rxBytes || c.rx_bytes || 0;
        const tx = c.txBytes || c.tx_bytes || 0;
        summary.totalRxBytes += rx;
        summary.totalTxBytes += tx;
    
        const isWired = c.isWired || c.is_wired;
        if (isWired) {
          summary.byConnectionType.wired.count++;
          summary.byConnectionType.wired.rxBytes += rx;
          summary.byConnectionType.wired.txBytes += tx;
        } else {
          summary.byConnectionType.wireless.count++;
          summary.byConnectionType.wireless.rxBytes += rx;
          summary.byConnectionType.wireless.txBytes += tx;
        }
    
        return {
          name: c.name || c.hostname || c.mac,
          mac: c.mac,
          totalUsage: rx + tx,
          rxBytes: rx,
          txBytes: tx
        };
      });
    
      // Sort by usage and get top 10
      summary.topByUsage = clientsWithUsage
        .sort((a, b) => b.totalUsage - a.totalUsage)
        .slice(0, 10);
    
      // Format bytes
      const formatBytes = (bytes) => {
        if (bytes < 1024) return `${bytes} B`;
        if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(2)} KB`;
        if (bytes < 1024 * 1024 * 1024) return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
        return `${(bytes / 1024 / 1024 / 1024).toFixed(2)} GB`;
      };
    
      summary.totalRxFormatted = formatBytes(summary.totalRxBytes);
      summary.totalTxFormatted = formatBytes(summary.totalTxBytes);
    
      return {
        content: [{ type: 'text', text: JSON.stringify(summary, null, 2) }]
      };
    }
  • Zod schema defining the optional 'hostId' input parameter for filtering clients by host.
    schema: z.object({
      hostId: z.string().optional().describe('Optional: Filter by host ID')
    }),
  • src/server.js:30-30 (registration)
    Registers the entire clientTools module (including get_client_bandwidth_summary) with the MCP server using the dynamic registration function.
    registerToolsFromModule(clientTools);
  • src/server.js:16-25 (registration)
    Helper function that iterates over a tools module and registers each tool individually on the MCP server.
    const registerToolsFromModule = (toolsModule) => {
      Object.entries(toolsModule).forEach(([name, toolConfig]) => {
        server.tool(
          name,
          toolConfig.schema,
          toolConfig.handler,
          { description: toolConfig.description }
        );
      });
    };
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/vandreus/Unifi-MCP'

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