Skip to main content
Glama
vandreus

UniFi MCP Server

by vandreus

get_host

Retrieve host information from UniFi network infrastructure to manage devices, clients, and access controls through the UniFi Cloud API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'get_host' MCP tool. It takes hostId, calls the unifi.getHost helper, and returns a formatted text response with JSON data.
    handler: async ({ hostId }) => {
      const host = await unifi.getHost(hostId);
      return {
        content: [{ type: 'text', text: JSON.stringify(host, null, 2) }]
      };
    }
  • Zod input schema for the 'get_host' tool, validating the required 'hostId' parameter.
    schema: z.object({
      hostId: z.string().describe('The host ID')
    }),
  • Tool configuration object for 'get_host' exported as part of networkTools, which includes description, schema, and handler.
    get_host: {
      description: 'Get details of a specific UniFi OS host',
      schema: z.object({
        hostId: z.string().describe('The host ID')
      }),
      handler: async ({ hostId }) => {
        const host = await unifi.getHost(hostId);
        return {
          content: [{ type: 'text', text: JSON.stringify(host, null, 2) }]
        };
      }
    },
  • src/server.js:27-32 (registration)
    Registration of all tool modules, including networkTools containing 'get_host', into the MCP server using registerToolsFromModule.
    // Register all tool modules
    registerToolsFromModule(networkTools);
    registerToolsFromModule(deviceTools);
    registerToolsFromModule(clientTools);
    registerToolsFromModule(protectTools);
    registerToolsFromModule(accessTools);
  • Supporting helper function that performs the actual UniFi Cloud API GET request to retrieve host details by ID.
    export async function getHost(hostId) {
      const response = await cloudApi.get(`/v1/hosts/${hostId}`);
      return response.data;
    }

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