Repository navigation
Architecture
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
OmadaClientthat wraps the Omada OpenAPI - A set of MCP tools mapped onto Omada operations
- Configuration, types, and OpenAPI references
-
Stdio MCP server
- Set up in
src/server/stdio.tsandsrc/index.ts. - Uses
@modelcontextprotocol/sdkto implement MCP over stdin/stdout.
- Set up in
-
HTTP MCP server
- Configured in
src/server/http.ts,src/server/stream.ts, andsrc/server/sse.ts. - Uses either:
- Streamable HTTP (
MCP_HTTP_TRANSPORT=stream) or - Legacy HTTP+SSE (
MCP_HTTP_TRANSPORT=sse).
- Streamable HTTP (
- Configured in
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;
}-
setupServerLoggingconfigures logging according toMCP_SERVER_LOG_LEVELandMCP_SERVER_LOG_FORMAT. -
registerAllTools(fromsrc/tools/index.ts) registers every MCP tool and attaches handlers that callOmadaClient.
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)
In OmadaClient constructor:
- An Axios instance is created with:
baseURL = OMADA_BASE_URLhttps.Agent({ rejectUnauthorized: strictSsl })- optional
timeout
-
AuthManageris created withclientId,clientSecret,omadacId. -
RequestHandlerwraps Axios and injects OAuth tokens. - Operation modules are instantiated with the request handler and the
buildOmadaPathutility.
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.
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.
Files: src/tools/*.ts
Each tool file:
- Imports the
McpServertype andOmadaClient. - Imports an input schema and utility functions from
src/server/common.ts(e.g.wrapToolHandler,toToolResult). - 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
OmadaClientmethod. - Wraps the result in an MCP_tool-compatible response.
For a catalog of tools and detailed examples, see Tools.
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
/mcpendpoint withGET,POST,DELETE.
- Implements MCP protocol version
-
HTTP+SSE (legacy):
- Implements MCP protocol version
2024-11-05. - Uses:
-
GET /sse– SSE stream. -
POST /messages– JSON-RPC messages.
-
- Implements MCP protocol version
See HTTP Transport for a detailed description of both HTTP modes.
-
src/types/index.tsdefines 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.