@coffeerunhobby/mcp-ha-connect 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +12 -1
  2. package/dist/omadaClient/index.d.ts +7 -0
  3. package/dist/omadaClient/index.js +6 -0
  4. package/dist/omadaClient/index.js.map +1 -1
  5. package/dist/omadaClient/request.d.ts +4 -0
  6. package/dist/omadaClient/request.js +6 -0
  7. package/dist/omadaClient/request.js.map +1 -1
  8. package/dist/omadaClient/site.d.ts +129 -0
  9. package/dist/omadaClient/site.js +184 -0
  10. package/dist/omadaClient/site.js.map +1 -1
  11. package/dist/server/instructions.js +1 -1
  12. package/dist/server/instructions.js.map +1 -1
  13. package/dist/tools/omada/getSiteNtpStatus.d.ts +3 -0
  14. package/dist/tools/omada/getSiteNtpStatus.js +8 -0
  15. package/dist/tools/omada/getSiteNtpStatus.js.map +1 -0
  16. package/dist/tools/omada/index.js +7 -2
  17. package/dist/tools/omada/index.js.map +1 -1
  18. package/dist/tools/omada/namespace.js +8 -0
  19. package/dist/tools/omada/namespace.js.map +1 -1
  20. package/dist/tools/omada/setSiteNtpServers.d.ts +10 -0
  21. package/dist/tools/omada/setSiteNtpServers.js +22 -0
  22. package/dist/tools/omada/setSiteNtpServers.js.map +1 -0
  23. package/dist/version.d.ts +1 -1
  24. package/dist/version.js +1 -1
  25. package/docs/CHANGELOG.md +5 -0
  26. package/openapi.json +1 -1
  27. package/package.json +1 -1
  28. package/src/omadaClient/index.ts +12 -1
  29. package/src/omadaClient/request.ts +7 -0
  30. package/src/omadaClient/site.ts +264 -1
  31. package/src/server/instructions.ts +1 -1
  32. package/src/tools/omada/getSiteNtpStatus.ts +14 -0
  33. package/src/tools/omada/index.ts +7 -2
  34. package/src/tools/omada/namespace.ts +8 -0
  35. package/src/tools/omada/setSiteNtpServers.ts +36 -0
  36. package/src/version.ts +1 -1
  37. package/tests/omadaClient/ntp.test.ts +366 -0
  38. package/tests/tools/omada/graph.test.ts +21 -2
@@ -360,6 +360,14 @@ export const OMADA_RESOURCES: ResourceNode[] = [
360
360
  description: 'Internet/WAN connection information for the site.',
361
361
  fetch: (c, a) => c.getInternetInfo(a.siteId),
362
362
  },
363
+ {
364
+ path: '/network/ntp',
365
+ kind: 'leaf',
366
+ permission: Q,
367
+ estimatedSize: 'small',
368
+ description: 'NTP (network time) server configuration and status for the site.',
369
+ fetch: (c, a) => c.getSiteNtpStatus(a.siteId),
370
+ },
363
371
  {
364
372
  path: '/network/lan-networks',
365
373
  kind: 'collection',
@@ -0,0 +1,36 @@
1
+ import type { McpServer } from '@modelcontextprotocol/server';
2
+ import { z } from 'zod';
3
+
4
+ import type { OmadaClient } from '../../omadaClient/index.js';
5
+ import { MAX_NTP_SERVERS } from '../../omadaClient/site.js';
6
+ import { toToolResult, wrapToolHandler, Permission } from '../common.js';
7
+
8
+ export const setSiteNtpServersSchema = z.object({
9
+ servers: z
10
+ .array(z.string().min(1))
11
+ .max(MAX_NTP_SERVERS)
12
+ .describe(`NTP server addresses (hostname or IPv4), in priority order; at most ${MAX_NTP_SERVERS}. Replaces the current list.`),
13
+ enabled: z.boolean().optional().describe('Turn the site NTP setting on (default) or off'),
14
+ siteId: z.string().min(1).optional(),
15
+ dryRun: z.boolean().optional().describe('If true, return the exact change without writing it'),
16
+ });
17
+
18
+ export function registerSetSiteNtpServersTool(server: McpServer, client: OmadaClient): void {
19
+ server.registerTool(
20
+ 'omada_setSiteNtpServers',
21
+ {
22
+ description:
23
+ "Set a site's NTP (network time) servers, replacing the current list. " +
24
+ 'Omada stores NTP in the site settings, so this re-writes the site settings with only the NTP fields changed; ' +
25
+ 'the result shows the list before and after. Use dryRun first to preview. ' +
26
+ 'Wrong time breaks certificates, logs and schedules on every network device - confirm with the user before applying.',
27
+ inputSchema: setSiteNtpServersSchema,
28
+ },
29
+ wrapToolHandler(
30
+ 'omada_setSiteNtpServers',
31
+ async ({ servers, enabled, siteId, dryRun }: z.infer<typeof setSiteNtpServersSchema>) =>
32
+ toToolResult(await client.setSiteNtpServers(servers, { enabled, siteId, dryRun })),
33
+ Permission.CONFIGURE
34
+ )
35
+ );
36
+ }
package/src/version.ts CHANGED
@@ -2,4 +2,4 @@
2
2
  * Package version - hardcoded at build time for reliability
3
3
  * Keep in sync with package.json version
4
4
  */
5
- export const VERSION = '2.0.0';
5
+ export const VERSION = '2.1.0';
@@ -0,0 +1,366 @@
1
+ /**
2
+ * Unit tests for the site NTP operations:
3
+ * - ntpAddressError / buildSiteUpdateBody (pure helpers)
4
+ * - SiteOperations.getSiteNtpStatus / setSiteNtpServers (read-modify-write of PUT /sites/{siteId})
5
+ * - the omada_getSiteNtpStatus / omada_setSiteNtpServers tools (RBAC + argument plumbing)
6
+ */
7
+
8
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
9
+ import type { McpServer } from '@modelcontextprotocol/server';
10
+
11
+ import type { OmadaClient } from '../../src/omadaClient/index.js';
12
+ import type { RequestHandler } from '../../src/omadaClient/request.js';
13
+ import { SiteOperations, buildSiteUpdateBody, ntpAddressError, type OmadaSiteInfo } from '../../src/omadaClient/site.js';
14
+ import { registerGetSiteNtpStatusTool } from '../../src/tools/omada/getSiteNtpStatus.js';
15
+ import { registerSetSiteNtpServersTool } from '../../src/tools/omada/setSiteNtpServers.js';
16
+ import { Permission } from '../../src/permissions/index.js';
17
+
18
+ const buildPath = (p: string): string => `/openapi/v1/omadac1${p.startsWith('/') ? p : `/${p}`}`;
19
+
20
+ function createMockRequest() {
21
+ return {
22
+ get: vi.fn(),
23
+ put: vi.fn(),
24
+ // Mirrors the real ensureSuccess: unwrap result, throw on errorCode !== 0
25
+ ensureSuccess: vi.fn((response: { errorCode: number; msg?: string; result?: unknown }) => {
26
+ if (response.errorCode !== 0) {
27
+ throw new Error(response.msg ?? `Omada error ${String(response.errorCode)}`);
28
+ }
29
+ return response.result;
30
+ }),
31
+ };
32
+ }
33
+
34
+ const ok = (result?: unknown) => ({ errorCode: 0, msg: 'Success', result });
35
+
36
+ /** A site as GET /sites/{siteId} returns it, including read-only DST fields. */
37
+ function siteFixture(overrides: Partial<OmadaSiteInfo> = {}): OmadaSiteInfo {
38
+ return {
39
+ siteId: 'site-1',
40
+ name: 'Tower',
41
+ type: 0,
42
+ tagIds: ['tag-a'],
43
+ region: 'RO',
44
+ timeZone: 'Europe/Bucharest',
45
+ scenario: 'Home',
46
+ ntpEnable: false,
47
+ ntpServers: ['old.example.org'],
48
+ dst: {
49
+ enable: true,
50
+ mode: 1,
51
+ start: { month: 3, serial: 5, day: 7, hour: 3, minute: 0 },
52
+ end: { month: 10, serial: 5, day: 7, hour: 4, minute: 0 },
53
+ offset: 3600000,
54
+ status: true,
55
+ startTime: 1774746000000,
56
+ endTime: 1792890000000,
57
+ nextStart: 1806195600000,
58
+ },
59
+ longitude: 25.6,
60
+ latitude: 45.65,
61
+ address: 'Brasov',
62
+ supportES: true,
63
+ supportL2: true,
64
+ ...overrides,
65
+ };
66
+ }
67
+
68
+ const APPROVED = ['82.76.255.14', '194.102.58.251'];
69
+
70
+ describe('ntpAddressError', () => {
71
+ it.each(['82.76.255.14', '194.102.58.251', 'time.nipne.ro', 'ro.pool.ntp.org', '0.0.0.0'])(
72
+ 'accepts %s',
73
+ (address) => {
74
+ expect(ntpAddressError(address)).toBeNull();
75
+ }
76
+ );
77
+
78
+ it.each([
79
+ '999.1.1.1',
80
+ '1.2.3',
81
+ '1.2.3.4.5',
82
+ '01.2.3.4',
83
+ 'localhost',
84
+ 'http://time.nipne.ro',
85
+ 'time nipne.ro',
86
+ '-bad.example.org',
87
+ 'x',
88
+ '',
89
+ ])('rejects %s', (address) => {
90
+ expect(ntpAddressError(address)).toMatch(/not a valid/);
91
+ });
92
+ });
93
+
94
+ describe('buildSiteUpdateBody', () => {
95
+ it('carries over every writable site field and changes only NTP', () => {
96
+ const body = buildSiteUpdateBody(siteFixture(), APPROVED, true);
97
+
98
+ expect(body).toEqual({
99
+ name: 'Tower',
100
+ region: 'RO',
101
+ timeZone: 'Europe/Bucharest',
102
+ scenario: 'Home',
103
+ tagIds: ['tag-a'],
104
+ ntpEnable: true,
105
+ ntpServers: [{ address: '82.76.255.14' }, { address: '194.102.58.251' }],
106
+ dst: {
107
+ enable: true,
108
+ mode: 1,
109
+ start: { month: 3, serial: 5, day: 7, hour: 3, minute: 0 },
110
+ end: { month: 10, serial: 5, day: 7, hour: 4, minute: 0 },
111
+ offset: 3600000,
112
+ },
113
+ longitude: 25.6,
114
+ latitude: 45.65,
115
+ address: 'Brasov',
116
+ supportES: true,
117
+ supportL2: true,
118
+ });
119
+ });
120
+
121
+ it('drops read-only fields (siteId, type, DST status/timestamps)', () => {
122
+ const body = buildSiteUpdateBody(siteFixture(), APPROVED, true) as unknown as Record<string, unknown>;
123
+
124
+ expect(body).not.toHaveProperty('siteId');
125
+ expect(body).not.toHaveProperty('type');
126
+ expect(Object.keys(body.dst as object).sort()).toEqual(['enable', 'end', 'mode', 'offset', 'start']);
127
+ });
128
+
129
+ it('omits optional fields the site does not have instead of sending undefined', () => {
130
+ const site: OmadaSiteInfo = { region: 'RO', timeZone: 'Europe/Bucharest', scenario: 'Home' };
131
+ const body = buildSiteUpdateBody(site, APPROVED, true);
132
+
133
+ expect(Object.keys(body).sort()).toEqual(['ntpEnable', 'ntpServers', 'region', 'scenario', 'timeZone']);
134
+ });
135
+
136
+ it.each(['region', 'timeZone', 'scenario'] as const)('refuses to build a body when %s is missing', (field) => {
137
+ const site = siteFixture({ [field]: undefined } as Partial<OmadaSiteInfo>);
138
+
139
+ expect(() => buildSiteUpdateBody(site, APPROVED, true)).toThrow(new RegExp(`missing '${field}'.*refusing to write`));
140
+ });
141
+ });
142
+
143
+ describe('SiteOperations NTP', () => {
144
+ let request: ReturnType<typeof createMockRequest>;
145
+ let ops: SiteOperations;
146
+
147
+ beforeEach(() => {
148
+ request = createMockRequest();
149
+ ops = new SiteOperations(request as unknown as RequestHandler, buildPath, 'site-1');
150
+ });
151
+
152
+ it('getSiteNtpStatus GETs the site ntp setting', async () => {
153
+ request.get.mockResolvedValue(ok({ ntpEnable: true }));
154
+
155
+ await expect(ops.getSiteNtpStatus()).resolves.toEqual({ ntpEnable: true });
156
+ expect(request.get).toHaveBeenCalledWith('/openapi/v1/omadac1/sites/site-1/setting/ntp');
157
+ });
158
+
159
+ it('dryRun returns the exact PUT body and does not write', async () => {
160
+ request.get.mockResolvedValue(ok(siteFixture()));
161
+
162
+ const result = await ops.setSiteNtpServers(APPROVED, { dryRun: true });
163
+
164
+ expect(request.put).not.toHaveBeenCalled();
165
+ expect(result.applied).toBe(false);
166
+ expect(result.before).toEqual({ ntpEnable: false, ntpServers: ['old.example.org'] });
167
+ expect(result.after).toEqual({ ntpEnable: true, ntpServers: APPROVED });
168
+ expect(result.request).toEqual(buildSiteUpdateBody(siteFixture(), APPROVED, true));
169
+ });
170
+
171
+ it('PUTs the full site body, then reports what the controller holds afterwards', async () => {
172
+ request.get
173
+ .mockResolvedValueOnce(ok(siteFixture()))
174
+ .mockResolvedValueOnce(ok(siteFixture()))
175
+ .mockResolvedValueOnce(ok(siteFixture({ ntpEnable: true, ntpServers: APPROVED })));
176
+ request.put.mockResolvedValue(ok());
177
+
178
+ const result = await ops.setSiteNtpServers(APPROVED);
179
+
180
+ expect(request.get).toHaveBeenNthCalledWith(1, '/openapi/v1/omadac1/sites/site-1');
181
+ expect(request.put).toHaveBeenCalledWith(
182
+ '/openapi/v1/omadac1/sites/site-1',
183
+ buildSiteUpdateBody(siteFixture(), APPROVED, true)
184
+ );
185
+ expect(request.get).toHaveBeenCalledTimes(3);
186
+ expect(result).toMatchObject({
187
+ siteId: 'site-1',
188
+ siteName: 'Tower',
189
+ applied: true,
190
+ before: { ntpEnable: false, ntpServers: ['old.example.org'] },
191
+ after: { ntpEnable: true, ntpServers: APPROVED },
192
+ });
193
+ });
194
+
195
+ it('reports the controller state, even when it differs from the request', async () => {
196
+ request.get
197
+ .mockResolvedValueOnce(ok(siteFixture()))
198
+ .mockResolvedValueOnce(ok(siteFixture()))
199
+ .mockResolvedValueOnce(ok(siteFixture({ ntpEnable: true, ntpServers: ['82.76.255.14'] })));
200
+ request.put.mockResolvedValue(ok());
201
+
202
+ const result = await ops.setSiteNtpServers(APPROVED);
203
+
204
+ expect(result.after.ntpServers).toEqual(['82.76.255.14']);
205
+ });
206
+
207
+ it('uses an explicit siteId and encodes it', async () => {
208
+ request.get.mockResolvedValue(ok(siteFixture()));
209
+
210
+ await ops.setSiteNtpServers(APPROVED, { siteId: 'a/b', dryRun: true });
211
+
212
+ expect(request.get).toHaveBeenCalledWith('/openapi/v1/omadac1/sites/a%2Fb');
213
+ });
214
+
215
+ it('allows turning NTP off with an empty list', async () => {
216
+ request.get.mockResolvedValue(ok(siteFixture({ ntpEnable: true })));
217
+
218
+ const result = await ops.setSiteNtpServers([], { enabled: false, dryRun: true });
219
+
220
+ expect(result.request.ntpEnable).toBe(false);
221
+ expect(result.request.ntpServers).toEqual([]);
222
+ });
223
+
224
+ it.each([
225
+ { servers: [] as string[], enabled: true, error: /At least one NTP server/ },
226
+ { servers: ['1.1.1.1', '2.2.2.2', '3.3.3.3', '4.4.4.4', '5.5.5.5', '6.6.6.6'], enabled: true, error: /at most 5/ },
227
+ { servers: ['82.76.255.14', '999.1.1.1'], enabled: true, error: /'999.1.1.1' is not a valid IPv4/ },
228
+ { servers: ['82.76.255.14', '82.76.255.14'], enabled: true, error: /duplicates/ },
229
+ ])('rejects $servers before contacting the controller', async ({ servers, enabled, error }) => {
230
+ await expect(ops.setSiteNtpServers(servers, { enabled })).rejects.toThrow(error);
231
+ expect(request.get).not.toHaveBeenCalled();
232
+ expect(request.put).not.toHaveBeenCalled();
233
+ });
234
+
235
+ it('propagates a controller rejection of the PUT and does not report success', async () => {
236
+ request.get.mockResolvedValue(ok(siteFixture()));
237
+ request.put.mockResolvedValue({ errorCode: -1, msg: 'Permission denied' });
238
+
239
+ await expect(ops.setSiteNtpServers(APPROVED)).rejects.toThrow('Permission denied');
240
+ expect(request.get).toHaveBeenCalledTimes(2);
241
+ });
242
+
243
+ it('refuses to write when a non-NTP setting changed between the read and the write', async () => {
244
+ request.get
245
+ .mockResolvedValueOnce(ok(siteFixture()))
246
+ .mockResolvedValueOnce(ok(siteFixture({ timeZone: 'Europe/London' })));
247
+
248
+ await expect(ops.setSiteNtpServers(APPROVED)).rejects.toThrow(/changed while preparing.*nothing was written/);
249
+ expect(request.put).not.toHaveBeenCalled();
250
+ });
251
+
252
+ it('ignores NTP-only differences between the two reads (NTP is what is being set)', async () => {
253
+ request.get
254
+ .mockResolvedValueOnce(ok(siteFixture()))
255
+ .mockResolvedValueOnce(ok(siteFixture({ ntpServers: ['someone.else.org'] })))
256
+ .mockResolvedValueOnce(ok(siteFixture({ ntpEnable: true, ntpServers: APPROVED })));
257
+ request.put.mockResolvedValue(ok());
258
+
259
+ await expect(ops.setSiteNtpServers(APPROVED)).resolves.toMatchObject({ applied: true });
260
+ });
261
+
262
+ it('serializes concurrent writes to the same site: the second reads only after the first wrote', async () => {
263
+ const events: string[] = [];
264
+ let state = siteFixture();
265
+ request.get.mockImplementation(async () => {
266
+ events.push('get');
267
+ await new Promise((r) => setTimeout(r, 5));
268
+ return ok(state);
269
+ });
270
+ request.put.mockImplementation(async (_path: string, body: { ntpServers: Array<{ address: string }> }) => {
271
+ events.push('put');
272
+ await new Promise((r) => setTimeout(r, 5));
273
+ state = { ...state, ntpEnable: true, ntpServers: body.ntpServers.map((s) => s.address) };
274
+ return ok();
275
+ });
276
+
277
+ const [first, second] = await Promise.all([
278
+ ops.setSiteNtpServers(['82.76.255.14']),
279
+ ops.setSiteNtpServers(['194.102.58.251']),
280
+ ]);
281
+
282
+ expect(events).toEqual(['get', 'get', 'put', 'get', 'get', 'get', 'put', 'get']);
283
+ expect(first.after.ntpServers).toEqual(['82.76.255.14']);
284
+ expect(second.before.ntpServers).toEqual(['82.76.255.14']);
285
+ expect(second.after.ntpServers).toEqual(['194.102.58.251']);
286
+ });
287
+
288
+ it('a failed write does not block the next one', async () => {
289
+ request.get.mockResolvedValue(ok(siteFixture()));
290
+ request.put.mockResolvedValueOnce({ errorCode: -1, msg: 'boom' }).mockResolvedValueOnce(ok());
291
+
292
+ await expect(ops.setSiteNtpServers(APPROVED)).rejects.toThrow('boom');
293
+ await expect(ops.setSiteNtpServers(APPROVED)).resolves.toMatchObject({ applied: true });
294
+ });
295
+
296
+ it('does not write when the site info lacks a required field', async () => {
297
+ request.get.mockResolvedValue(ok(siteFixture({ scenario: '' })));
298
+
299
+ await expect(ops.setSiteNtpServers(APPROVED)).rejects.toThrow(/missing 'scenario'/);
300
+ expect(request.put).not.toHaveBeenCalled();
301
+ });
302
+ });
303
+
304
+ // ---- Tools -------------------------------------------------------------------
305
+
306
+ type Handler = (args: unknown, extra: unknown) => Promise<{ content: { text: string }[] }>;
307
+
308
+ function createMockServer() {
309
+ const handlers = new Map<string, Handler>();
310
+ return {
311
+ registerTool: vi.fn((name: string, _config: unknown, handler: Handler) => {
312
+ handlers.set(name, handler);
313
+ }),
314
+ handlers,
315
+ } as unknown as McpServer & { handlers: Map<string, Handler> };
316
+ }
317
+
318
+ const extraWith = (permissions: number) => ({
319
+ sessionId: 'test-session',
320
+ http: { authInfo: { extra: { permissions } } },
321
+ });
322
+
323
+ const parse = (result: { content: { text: string }[] }) => JSON.parse(result.content[0].text) as Record<string, unknown>;
324
+
325
+ describe('omada NTP tools', () => {
326
+ let server: ReturnType<typeof createMockServer>;
327
+ let client: { getSiteNtpStatus: ReturnType<typeof vi.fn>; setSiteNtpServers: ReturnType<typeof vi.fn> };
328
+
329
+ beforeEach(() => {
330
+ server = createMockServer();
331
+ client = { getSiteNtpStatus: vi.fn(), setSiteNtpServers: vi.fn() };
332
+ registerGetSiteNtpStatusTool(server, client as unknown as OmadaClient);
333
+ registerSetSiteNtpServersTool(server, client as unknown as OmadaClient);
334
+ });
335
+
336
+ it('omada_getSiteNtpStatus needs only QUERY', async () => {
337
+ client.getSiteNtpStatus.mockResolvedValue({ ntpEnable: true });
338
+
339
+ const result = await server.handlers.get('omada_getSiteNtpStatus')!({ siteId: 's1' }, extraWith(Permission.QUERY));
340
+
341
+ expect(parse(result)).toEqual({ ntpEnable: true });
342
+ expect(client.getSiteNtpStatus).toHaveBeenCalledWith('s1');
343
+ });
344
+
345
+ it('omada_setSiteNtpServers is denied to a CONTROL + QUERY caller (needs CONFIGURE)', async () => {
346
+ const result = await server.handlers.get('omada_setSiteNtpServers')!(
347
+ { servers: APPROVED },
348
+ extraWith(Permission.QUERY | Permission.CONTROL)
349
+ );
350
+
351
+ expect(parse(result)).toMatchObject({ error: 'Permission denied' });
352
+ expect(parse(result).message).toContain('CONFIGURE');
353
+ expect(client.setSiteNtpServers).not.toHaveBeenCalled();
354
+ });
355
+
356
+ it('omada_setSiteNtpServers passes servers and options through for a CONFIGURE caller', async () => {
357
+ client.setSiteNtpServers.mockResolvedValue({ applied: false });
358
+
359
+ await server.handlers.get('omada_setSiteNtpServers')!(
360
+ { servers: APPROVED, siteId: 's1', dryRun: true },
361
+ extraWith(Permission.CONFIGURE)
362
+ );
363
+
364
+ expect(client.setSiteNtpServers).toHaveBeenCalledWith(APPROVED, { enabled: undefined, siteId: 's1', dryRun: true });
365
+ });
366
+ });
@@ -31,6 +31,7 @@ function createMockClient() {
31
31
  getClient: vi.fn(),
32
32
  listMostActiveClients: vi.fn(),
33
33
  getInternetInfo: vi.fn(),
34
+ getSiteNtpStatus: vi.fn(),
34
35
  getLanNetworkList: vi.fn(),
35
36
  getLanProfileList: vi.fn(),
36
37
  getWlanGroupList: vi.fn(),
@@ -78,11 +79,11 @@ describe('Omada graph tools - registration', () => {
78
79
  expect(server.handlers.has('omada_read')).toBe(true);
79
80
  });
80
81
 
81
- it('graph mode registers browse + read + 7 typed writes, and NO typed getters', () => {
82
+ it('graph mode registers browse + read + 8 typed writes, and NO typed getters', () => {
82
83
  const server = createMockServer();
83
84
  const client = createMockClient();
84
85
  const count = registerOmadaTools(server, client, 'graph');
85
- expect(count).toBe(9);
86
+ expect(count).toBe(10);
86
87
  const names = [...server.handlers.keys()];
87
88
  expect(names).toContain('omada_browse');
88
89
  expect(names).toContain('omada_read');
@@ -91,9 +92,11 @@ describe('Omada graph tools - registration', () => {
91
92
  // v1.6 action tools ride along in graph mode too (writes stay typed).
92
93
  expect(names).toContain('omada_cyclePoePort');
93
94
  expect(names).toContain('omada_setSsidEnabled');
95
+ expect(names).toContain('omada_setSiteNtpServers');
94
96
  // Typed read getters must NOT be present in graph mode.
95
97
  expect(names).not.toContain('omada_listSites');
96
98
  expect(names).not.toContain('omada_getFirewallSetting');
99
+ expect(names).not.toContain('omada_getSiteNtpStatus');
97
100
  });
98
101
 
99
102
  it('eager mode (default) registers the typed getters, not the graph tools', () => {
@@ -291,6 +294,22 @@ describe('omada_read', () => {
291
294
  expect(data.missing).toEqual(['wlanId']);
292
295
  });
293
296
 
297
+ it('reads /network/ntp via getSiteNtpStatus, forwarding an explicit siteId', async () => {
298
+ (client.getSiteNtpStatus as ReturnType<typeof vi.fn>).mockResolvedValue({ ntpEnable: true, ntpServers: ['82.76.255.14'] });
299
+ const { isError, data } = parseResult(await read({ path: '/network/ntp', siteId: 'site9' }, readonlyExtra));
300
+ expect(isError).toBeFalsy();
301
+ expect(data).toEqual({ ntpEnable: true, ntpServers: ['82.76.255.14'] });
302
+ expect(client.getSiteNtpStatus).toHaveBeenCalledWith('site9');
303
+ expect(client.getInternetInfo).not.toHaveBeenCalled();
304
+ });
305
+
306
+ it('denies /network/ntp without QUERY and never calls the controller', async () => {
307
+ const { isError, data } = parseResult(await read({ path: '/network/ntp' }, noPermsExtra));
308
+ expect(isError).toBe(true);
309
+ expect(data.error).toBe('Permission denied');
310
+ expect(client.getSiteNtpStatus).not.toHaveBeenCalled();
311
+ });
312
+
294
313
  it('enforces per-path permission (fail closed) for under-privileged callers', async () => {
295
314
  const { isError, data } = parseResult(await read({ path: '/sites' }, noPermsExtra));
296
315
  expect(isError).toBe(true);