Skip to content

Architecture

João Miguel Tabosa Vaz Marques Silva edited this page Nov 17, 2025 · 2 revisions

This page describes the internal architecture of the TP-Link Omada MCP server.

At a high level, the server consists of:

  • An MCP server (stdio or HTTP)
  • An OmadaClient that wraps the Omada OpenAPI
  • A set of MCP tools mapped onto Omada operations
  • Configuration, types, and OpenAPI references

Top-Level Overview

Entry points

  • Stdio MCP server

    • Set up in src/server/stdio.ts and src/index.ts.
    • Uses @modelcontextprotocol/sdk to implement MCP over stdin/stdout.
  • HTTP MCP server

    • Configured in src/server/http.ts, src/server/stream.ts, and src/server/sse.ts.
    • Uses either:
      • Streamable HTTP (MCP_HTTP_TRANSPORT=stream) or
      • Legacy HTTP+SSE (MCP_HTTP_TRANSPORT=sse).

Server creation

In src/server/common.ts:

export function createServer(client: OmadaClient): McpServer {
  const server = new McpServer({
    name: 'tplink-omada-mcp',
    version: '0.1.0',
  });

  setupServerLogging(server);
  registerAllTools(server, client);

  return server;
}
  • setupServerLogging configures logging according to MCP_SERVER_LOG_LEVEL and MCP_SERVER_LOG_FORMAT.
  • registerAllTools (from src/tools/index.ts) registers every MCP tool and attaches handlers that call OmadaClient.

Omada Client

File: src/omadaClient/index.ts
Type: class OmadaClient

The OmadaClient is a typed, structured wrapper around the TP-Link Omada OpenAPI. It is organized by Omada API tag:

  • SiteOperations – sites
  • DeviceOperations – devices and switch stacks
  • ClientOperations – clients, most-active, activity, past connections
  • SecurityOperations – threat lists and security events
  • AuthManager – OAuth client credentials
  • RequestHandler – authenticated HTTP client (Axios)

Construction

In OmadaClient constructor:

  • An Axios instance is created with:
    • baseURL = OMADA_BASE_URL
    • https.Agent({ rejectUnauthorized: strictSsl })
    • optional timeout
  • AuthManager is created with clientId, clientSecret, omadacId.
  • RequestHandler wraps Axios and injects OAuth tokens.
  • Operation modules are instantiated with the request handler and the buildOmadaPath utility.

Path construction

buildOmadaPath encodes the Omada controller ID and ensures the proper API prefix:

private buildOmadaPath(relativePath: string): string {
  const normalized = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;
  return `/openapi/v1/${encodeURIComponent(this.omadacId)}${normalized}`;
}

This ensures all calls go to /openapi/v1/{omadacId}/..., as required by Omada’s OpenAPI.

Public methods

OmadaClient exposes methods used by tools, for example:

  • Sites:
    • listSites(): Promise<OmadaSiteSummary[]>
  • Devices:
    • listDevices(siteId?: string)
    • getDevice(identifier: string, siteId?: string)
    • getSwitchStackDetail(stackId: string, siteId?: string)
    • searchDevices(searchKey: string)
    • listDevicesStats(options: GetDeviceStatsOptions)
  • Clients:
    • listClients(siteId?: string)
    • getClient(identifier: string, siteId?: string)
    • listMostActiveClients(siteId?: string)
    • listClientsActivity(options?: GetClientActivityOptions)
    • listClientsPastConnections(options: ListClientsPastConnectionsOptions)
  • Security:
    • getThreatList(options: GetThreatListOptions)
  • Generic:
    • callApi<T = unknown>(config: AxiosRequestConfig): Promise<T>

Each of these is backed by a specific Omada OpenAPI endpoint, documented under docs/openapi and reflected in the operation classes.


MCP Tools Layer

Files: src/tools/*.ts

Each tool file:

  1. Imports the McpServer type and OmadaClient.
  2. Imports an input schema and utility functions from src/server/common.ts (e.g. wrapToolHandler, toToolResult).
  3. Calls server.registerTool(name, { description, inputSchema }, handler).

Example (src/tools/getClient.ts):

server.registerTool(
  'getClient',
  {
    description: 'Fetch details for a specific Omada client.',
    inputSchema: clientIdSchema.shape,
  },
  wrapToolHandler('getClient', async ({ clientId, siteId }) =>
    toToolResult(await client.getClient(clientId, siteId)),
  ),
);

The handler:

  • Validates and parses input using the Zod schema.
  • Calls the appropriate OmadaClient method.
  • Wraps the result in an MCP_tool-compatible response.

For a catalog of tools and detailed examples, see Tools.


Transports and MCP Protocol

The server uses the official MCP TypeScript SDK: @modelcontextprotocol/sdk/server/mcp.js.

Supported transports:

  • Stdio: Bi-directional JSON-RPC over stdin/stdout (standard MCP).
  • Streamable HTTP (default when HTTP is enabled):
    • Implements MCP protocol version 2025-03-26.
    • Uses a single /mcp endpoint with GET, POST, DELETE.
  • HTTP+SSE (legacy):
    • Implements MCP protocol version 2024-11-05.
    • Uses:
      • GET /sse – SSE stream.
      • POST /messages – JSON-RPC messages.

See HTTP Transport for a detailed description of both HTTP modes.


Types and OpenAPI References

  • src/types/index.ts defines shared TypeScript types:
    • OmadaSiteSummary, OmadaDeviceInfo, OmadaClientInfo, OmadaDeviceStats, ThreatInfo, etc.
  • docs/openapi/ contains reference Omada OpenAPI specs arranged by API tag (sites, devices, clients, security), allowing tools and operations to remain aligned with the controller’s API.

These types ensure MCP tools return structured, predictable data that AI clients can reliably consume.

For specifics on each tool and how it maps to Omada API operations, see Tools.

Clone this wiki locally