@owine/unifi-network-mcp 2.15.0 → 3.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 (56) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +257 -77
  3. package/dist/client.d.ts +26 -1
  4. package/dist/client.js +199 -24
  5. package/dist/config.d.ts +11 -0
  6. package/dist/config.js +102 -3
  7. package/dist/guard.d.ts +46 -0
  8. package/dist/guard.js +180 -0
  9. package/dist/index.js +17 -4
  10. package/dist/instructions.d.ts +9 -0
  11. package/dist/instructions.js +32 -0
  12. package/dist/tls.d.ts +14 -0
  13. package/dist/tls.js +58 -0
  14. package/dist/tools/acl.js +123 -50
  15. package/dist/tools/classic.d.ts +3 -0
  16. package/dist/tools/classic.js +54 -0
  17. package/dist/tools/client-history.js +22 -12
  18. package/dist/tools/clients.js +10 -9
  19. package/dist/tools/devices.js +21 -20
  20. package/dist/tools/dns-policies.js +27 -27
  21. package/dist/tools/exposure.d.ts +3 -0
  22. package/dist/tools/exposure.js +118 -0
  23. package/dist/tools/firewall.d.ts +2 -1
  24. package/dist/tools/firewall.js +200 -75
  25. package/dist/tools/hotspot.js +35 -28
  26. package/dist/tools/index.d.ts +13 -1
  27. package/dist/tools/index.js +67 -4
  28. package/dist/tools/networks.d.ts +2 -1
  29. package/dist/tools/networks.js +44 -31
  30. package/dist/tools/sites.js +2 -2
  31. package/dist/tools/supporting.js +22 -21
  32. package/dist/tools/switching.js +16 -15
  33. package/dist/tools/system.js +1 -1
  34. package/dist/tools/traffic-matching.d.ts +2 -1
  35. package/dist/tools/traffic-matching.js +22 -20
  36. package/dist/tools/wifi.js +76 -30
  37. package/dist/utils/full-put.d.ts +11 -2
  38. package/dist/utils/full-put.js +25 -2
  39. package/dist/utils/output-schemas.d.ts +241 -4
  40. package/dist/utils/output-schemas.js +225 -49
  41. package/dist/utils/params.d.ts +12 -0
  42. package/dist/utils/params.js +21 -0
  43. package/dist/utils/pick.d.ts +6 -0
  44. package/dist/utils/pick.js +11 -0
  45. package/dist/utils/responses.d.ts +2 -0
  46. package/dist/utils/responses.js +28 -2
  47. package/dist/utils/safety.d.ts +35 -1
  48. package/dist/utils/safety.js +53 -3
  49. package/dist/utils/secrets.js +3 -0
  50. package/dist/utils/wan-exposure.d.ts +69 -0
  51. package/dist/utils/wan-exposure.js +245 -0
  52. package/dist/write-log.d.ts +52 -0
  53. package/dist/write-log.js +178 -0
  54. package/dist/write-tools.d.ts +27 -0
  55. package/dist/write-tools.js +50 -0
  56. package/package.json +19 -15
@@ -6,24 +6,25 @@ const responses_js_1 = require("../utils/responses.js");
6
6
  const query_js_1 = require("../utils/query.js");
7
7
  const safety_js_1 = require("../utils/safety.js");
8
8
  const output_schemas_js_1 = require("../utils/output-schemas.js");
9
+ const params_js_1 = require("../utils/params.js");
9
10
  function registerSupportingTools(server, client) {
10
11
  server.registerTool("unifi_list_wans", {
11
12
  description: "List WAN interface definitions at a site. Returns: id, name only (verified against 11.0.83 — the Integration API exposes no live link status or throughput rates here). Use for: WAN inventory, multi-WAN topology.",
12
13
  inputSchema: {
13
- siteId: zod_1.z.string().describe("Site ID"),
14
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
14
15
  offset: zod_1.z
15
16
  .number()
16
17
  .int()
17
18
  .nonnegative()
18
19
  .optional()
19
- .describe("Number of records to skip (default: 0)"),
20
+ .describe("Number of records to skip"),
20
21
  limit: zod_1.z
21
22
  .number()
22
23
  .int()
23
24
  .min(0)
24
25
  .max(200)
25
26
  .optional()
26
- .describe("Number of records to return (default: 25, max: 200)"),
27
+ .describe("Number of records to return (API default: 25)"),
27
28
  },
28
29
  outputSchema: output_schemas_js_1.listWansOutputSchema,
29
30
  annotations: safety_js_1.READ_ONLY,
@@ -40,20 +41,20 @@ function registerSupportingTools(server, client) {
40
41
  server.registerTool("unifi_list_vpn_tunnels", {
41
42
  description: "List site-to-site VPN tunnels (IPsec, WireGuard, OpenVPN site-to-site) at a site. Returns: tunnel definitions per row (per-row schema not rendered in 11.0.83 docs and no tunnels to sample live; the older 10.4.57 spec lists id, type (IPSEC/OPENVPN/WIREGUARD), name, metadata.origin/source — call to inspect). For roaming client VPN servers, see unifi_list_vpn_servers.",
42
43
  inputSchema: {
43
- siteId: zod_1.z.string().describe("Site ID"),
44
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
44
45
  offset: zod_1.z
45
46
  .number()
46
47
  .int()
47
48
  .nonnegative()
48
49
  .optional()
49
- .describe("Number of records to skip (default: 0)"),
50
+ .describe("Number of records to skip"),
50
51
  limit: zod_1.z
51
52
  .number()
52
53
  .int()
53
54
  .min(0)
54
55
  .max(200)
55
56
  .optional()
56
- .describe("Number of records to return (default: 25, max: 200)"),
57
+ .describe("Number of records to return (API default: 25)"),
57
58
  filter: zod_1.z
58
59
  .string()
59
60
  .optional()
@@ -74,20 +75,20 @@ function registerSupportingTools(server, client) {
74
75
  server.registerTool("unifi_list_vpn_servers", {
75
76
  description: "List VPN servers (roaming/client-access VPNs) at a site. Returns: id, type (L2TP, OPENVPN, PPTP, UID, WIREGUARD), name, enabled, metadata.origin.",
76
77
  inputSchema: {
77
- siteId: zod_1.z.string().describe("Site ID"),
78
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
78
79
  offset: zod_1.z
79
80
  .number()
80
81
  .int()
81
82
  .nonnegative()
82
83
  .optional()
83
- .describe("Number of records to skip (default: 0)"),
84
+ .describe("Number of records to skip"),
84
85
  limit: zod_1.z
85
86
  .number()
86
87
  .int()
87
88
  .min(0)
88
89
  .max(200)
89
90
  .optional()
90
- .describe("Number of records to return (default: 25, max: 200)"),
91
+ .describe("Number of records to return (API default: 25)"),
91
92
  filter: zod_1.z
92
93
  .string()
93
94
  .optional()
@@ -108,20 +109,20 @@ function registerSupportingTools(server, client) {
108
109
  server.registerTool("unifi_list_radius_profiles", {
109
110
  description: "List RADIUS profiles (auth/accounting server configurations referenced by WiFi WPA-Enterprise, switch 802.1X port auth, VPN). Returns: id, name, metadata (origin, configurable).",
110
111
  inputSchema: {
111
- siteId: zod_1.z.string().describe("Site ID"),
112
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
112
113
  offset: zod_1.z
113
114
  .number()
114
115
  .int()
115
116
  .nonnegative()
116
117
  .optional()
117
- .describe("Number of records to skip (default: 0)"),
118
+ .describe("Number of records to skip"),
118
119
  limit: zod_1.z
119
120
  .number()
120
121
  .int()
121
122
  .min(0)
122
123
  .max(200)
123
124
  .optional()
124
- .describe("Number of records to return (default: 25, max: 200)"),
125
+ .describe("Number of records to return (API default: 25)"),
125
126
  filter: zod_1.z
126
127
  .string()
127
128
  .optional()
@@ -142,20 +143,20 @@ function registerSupportingTools(server, client) {
142
143
  server.registerTool("unifi_list_device_tags", {
143
144
  description: "List device tags at a site. Tags group APs/switches for selective WiFi broadcast (via broadcastingDeviceFilter on a WiFi network). Returns: id, name, deviceIds[], metadata.",
144
145
  inputSchema: {
145
- siteId: zod_1.z.string().describe("Site ID"),
146
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
146
147
  offset: zod_1.z
147
148
  .number()
148
149
  .int()
149
150
  .nonnegative()
150
151
  .optional()
151
- .describe("Number of records to skip (default: 0)"),
152
+ .describe("Number of records to skip"),
152
153
  limit: zod_1.z
153
154
  .number()
154
155
  .int()
155
156
  .min(0)
156
157
  .max(200)
157
158
  .optional()
158
- .describe("Number of records to return (default: 25, max: 200)"),
159
+ .describe("Number of records to return (API default: 25)"),
159
160
  filter: zod_1.z
160
161
  .string()
161
162
  .optional()
@@ -181,14 +182,14 @@ function registerSupportingTools(server, client) {
181
182
  .int()
182
183
  .nonnegative()
183
184
  .optional()
184
- .describe("Number of records to skip (default: 0)"),
185
+ .describe("Number of records to skip"),
185
186
  limit: zod_1.z
186
187
  .number()
187
188
  .int()
188
189
  .min(0)
189
190
  .max(200)
190
191
  .optional()
191
- .describe("Number of records to return (default: 25, max: 200)"),
192
+ .describe("Number of records to return (API default: 25)"),
192
193
  filter: zod_1.z
193
194
  .string()
194
195
  .optional()
@@ -214,14 +215,14 @@ function registerSupportingTools(server, client) {
214
215
  .int()
215
216
  .nonnegative()
216
217
  .optional()
217
- .describe("Number of records to skip (default: 0)"),
218
+ .describe("Number of records to skip"),
218
219
  limit: zod_1.z
219
220
  .number()
220
221
  .int()
221
222
  .min(0)
222
223
  .max(200)
223
224
  .optional()
224
- .describe("Number of records to return (default: 25, max: 200)"),
225
+ .describe("Number of records to return (API default: 25)"),
225
226
  filter: zod_1.z
226
227
  .string()
227
228
  .optional()
@@ -247,14 +248,14 @@ function registerSupportingTools(server, client) {
247
248
  .int()
248
249
  .nonnegative()
249
250
  .optional()
250
- .describe("Number of records to skip (default: 0)"),
251
+ .describe("Number of records to skip"),
251
252
  limit: zod_1.z
252
253
  .number()
253
254
  .int()
254
255
  .min(0)
255
256
  .max(200)
256
257
  .optional()
257
- .describe("Number of records to return (default: 25, max: 200)"),
258
+ .describe("Number of records to return (API default: 25)"),
258
259
  filter: zod_1.z
259
260
  .string()
260
261
  .optional()
@@ -6,24 +6,25 @@ const responses_js_1 = require("../utils/responses.js");
6
6
  const query_js_1 = require("../utils/query.js");
7
7
  const safety_js_1 = require("../utils/safety.js");
8
8
  const output_schemas_js_1 = require("../utils/output-schemas.js");
9
+ const params_js_1 = require("../utils/params.js");
9
10
  function registerSwitchingTools(server, client) {
10
11
  server.registerTool("unifi_list_switch_stacks", {
11
12
  description: "List Switch Stacks (multiple physical switches managed as one logical unit) at a site. Returns: id, deviceId (the stack's primary device), name, units[] (the stacked switches — named `members` on consoles older than 10.6.106), lags[] (LAGs spanning the stack), metadata.origin. Per-unit schema is not rendered in the 11.0.83 docs — call unifi_get_switch_stack to inspect. Use for: identifying stacked switches; individual member configs/stats still come from unifi_get_device.",
12
13
  inputSchema: {
13
- siteId: zod_1.z.string().describe("Site ID"),
14
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
14
15
  offset: zod_1.z
15
16
  .number()
16
17
  .int()
17
18
  .nonnegative()
18
19
  .optional()
19
- .describe("Number of records to skip (default: 0)"),
20
+ .describe("Number of records to skip"),
20
21
  limit: zod_1.z
21
22
  .number()
22
23
  .int()
23
24
  .min(0)
24
25
  .max(200)
25
26
  .optional()
26
- .describe("Number of records to return (default: 25, max: 200)"),
27
+ .describe("Number of records to return (API default: 25)"),
27
28
  filter: zod_1.z
28
29
  .string()
29
30
  .optional()
@@ -44,8 +45,8 @@ function registerSwitchingTools(server, client) {
44
45
  server.registerTool("unifi_get_switch_stack", {
45
46
  description: "Get full details of a Switch Stack including all units and stacking topology. Returns the same fields as the list response but for a single stack: id, deviceId, name, units[] (named `members` before 10.6.106), lags[], metadata.origin.",
46
47
  inputSchema: {
47
- siteId: zod_1.z.string().describe("Site ID"),
48
- switchStackId: zod_1.z.string().describe("Switch Stack ID"),
48
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
49
+ switchStackId: (0, params_js_1.resourceId)().describe("Switch Stack ID"),
49
50
  },
50
51
  outputSchema: output_schemas_js_1.switchStackOutputSchema,
51
52
  annotations: safety_js_1.READ_ONLY,
@@ -61,20 +62,20 @@ function registerSwitchingTools(server, client) {
61
62
  server.registerTool("unifi_list_mc_lag_domains", {
62
63
  description: "List MC-LAG (Multi-Chassis Link Aggregation) Domains — pairs of switches presenting as one for LAG redundancy. Returns: id, name, peers[] (per the older 10.4.57 spec: {deviceId, linkPortIdxs[], role TOP|BOTTOM}; not live-verified), lags[] (LAGs spanning the domain), metadata.origin.",
63
64
  inputSchema: {
64
- siteId: zod_1.z.string().describe("Site ID"),
65
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
65
66
  offset: zod_1.z
66
67
  .number()
67
68
  .int()
68
69
  .nonnegative()
69
70
  .optional()
70
- .describe("Number of records to skip (default: 0)"),
71
+ .describe("Number of records to skip"),
71
72
  limit: zod_1.z
72
73
  .number()
73
74
  .int()
74
75
  .min(0)
75
76
  .max(200)
76
77
  .optional()
77
- .describe("Number of records to return (default: 25, max: 200)"),
78
+ .describe("Number of records to return (API default: 25)"),
78
79
  filter: zod_1.z
79
80
  .string()
80
81
  .optional()
@@ -95,8 +96,8 @@ function registerSwitchingTools(server, client) {
95
96
  server.registerTool("unifi_get_mc_lag_domain", {
96
97
  description: "Get full details of an MC-LAG Domain (peer switches and member LAGs).",
97
98
  inputSchema: {
98
- siteId: zod_1.z.string().describe("Site ID"),
99
- mcLagDomainId: zod_1.z.string().describe("MC-LAG Domain ID"),
99
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
100
+ mcLagDomainId: (0, params_js_1.resourceId)().describe("MC-LAG Domain ID"),
100
101
  },
101
102
  outputSchema: output_schemas_js_1.mcLagDomainOutputSchema,
102
103
  annotations: safety_js_1.READ_ONLY,
@@ -112,20 +113,20 @@ function registerSwitchingTools(server, client) {
112
113
  server.registerTool("unifi_list_lags", {
113
114
  description: "List LAGs (Link Aggregation Groups — bonded switch ports) at a site. Returns: id, type (LOCAL/SWITCH_STACK/MULTI_CHASSIS), members[] ({deviceId, portIdxs[]}), switchStackId (SWITCH_STACK) or mcLagDomainId (MULTI_CHASSIS), metadata.origin.",
114
115
  inputSchema: {
115
- siteId: zod_1.z.string().describe("Site ID"),
116
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
116
117
  offset: zod_1.z
117
118
  .number()
118
119
  .int()
119
120
  .nonnegative()
120
121
  .optional()
121
- .describe("Number of records to skip (default: 0)"),
122
+ .describe("Number of records to skip"),
122
123
  limit: zod_1.z
123
124
  .number()
124
125
  .int()
125
126
  .min(0)
126
127
  .max(200)
127
128
  .optional()
128
- .describe("Number of records to return (default: 25, max: 200)"),
129
+ .describe("Number of records to return (API default: 25)"),
129
130
  filter: zod_1.z
130
131
  .string()
131
132
  .optional()
@@ -146,8 +147,8 @@ function registerSwitchingTools(server, client) {
146
147
  server.registerTool("unifi_get_lag", {
147
148
  description: "Get full details of a LAG including its type (LOCAL/SWITCH_STACK/MULTI_CHASSIS) and member ports.",
148
149
  inputSchema: {
149
- siteId: zod_1.z.string().describe("Site ID"),
150
- lagId: zod_1.z.string().describe("LAG ID"),
150
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
151
+ lagId: (0, params_js_1.resourceId)().describe("LAG ID"),
151
152
  },
152
153
  outputSchema: output_schemas_js_1.lagOutputSchema,
153
154
  annotations: safety_js_1.READ_ONLY,
@@ -6,7 +6,7 @@ const safety_js_1 = require("../utils/safety.js");
6
6
  const output_schemas_js_1 = require("../utils/output-schemas.js");
7
7
  function registerSystemTools(server, client) {
8
8
  server.registerTool("unifi_get_info", {
9
- description: "Get UniFi Network application info. Returns: applicationVersion. NOTE: verified against 10.6.106 on a UniFi OS console — the Integration API returns ONLY applicationVersion here; there is no isUniFiOSConsole or other field. Use for: version checks before calling version-gated tools.",
9
+ description: "Get UniFi Network application info. Returns: applicationVersion only — the Integration API returns no isUniFiOSConsole or other field here. Use for: checking the Network version when a tool's description notes version-specific behaviour.",
10
10
  inputSchema: {},
11
11
  outputSchema: output_schemas_js_1.getInfoOutputSchema,
12
12
  annotations: safety_js_1.READ_ONLY,
@@ -1,3 +1,4 @@
1
1
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
2
  import { NetworkClient } from "../client.js";
3
- export declare function registerTrafficMatchingTools(server: McpServer, client: NetworkClient, readOnly?: boolean): void;
3
+ import { type WanPolicy } from "../utils/wan-exposure.js";
4
+ export declare function registerTrafficMatchingTools(server: McpServer, client: NetworkClient, readOnly?: boolean, wan?: WanPolicy): void;
@@ -6,28 +6,30 @@ const responses_js_1 = require("../utils/responses.js");
6
6
  const query_js_1 = require("../utils/query.js");
7
7
  const safety_js_1 = require("../utils/safety.js");
8
8
  const output_schemas_js_1 = require("../utils/output-schemas.js");
9
+ const params_js_1 = require("../utils/params.js");
10
+ const wan_exposure_js_1 = require("../utils/wan-exposure.js");
9
11
  const matchingItems = zod_1.z
10
- .array(zod_1.z.object({ type: zod_1.z.string().describe("Item type, e.g. PORT_NUMBER, IP_ADDRESS, SUBNET") }).passthrough())
12
+ .array(zod_1.z.object({ type: zod_1.z.string().describe("Item type, e.g. PORT_NUMBER, IP_ADDRESS, SUBNET") }).loose())
11
13
  .min(1)
12
14
  .describe("Non-empty array of tagged item objects, e.g. [{type:'PORT_NUMBER', value:443}]");
13
- function registerTrafficMatchingTools(server, client, readOnly = false) {
15
+ function registerTrafficMatchingTools(server, client, readOnly = false, wan = wan_exposure_js_1.DEFAULT_WAN_POLICY) {
14
16
  server.registerTool("unifi_list_traffic_matching_lists", {
15
17
  description: "List traffic matching lists at a site — named collections of ports or IPs reused in firewall/ACL rules. Returns: id, type (PORTS/IPV4_ADDRESSES/IPV6_ADDRESSES), name, items[] (tagged objects such as {type:'PORT_NUMBER', value:22} or {type:'SUBNET', value:'<cidr>'}). Use for: finding the matching-list ID to reference from a firewall policy.",
16
18
  inputSchema: {
17
- siteId: zod_1.z.string().describe("Site ID"),
19
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
18
20
  offset: zod_1.z
19
21
  .number()
20
22
  .int()
21
23
  .nonnegative()
22
24
  .optional()
23
- .describe("Number of records to skip (default: 0)"),
25
+ .describe("Number of records to skip"),
24
26
  limit: zod_1.z
25
27
  .number()
26
28
  .int()
27
29
  .min(0)
28
30
  .max(200)
29
31
  .optional()
30
- .describe("Number of records to return (default: 25, max: 200)"),
32
+ .describe("Number of records to return (API default: 25)"),
31
33
  filter: zod_1.z
32
34
  .string()
33
35
  .optional()
@@ -48,8 +50,8 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
48
50
  server.registerTool("unifi_get_traffic_matching_list", {
49
51
  description: "Get a specific traffic matching list by ID (full items array).",
50
52
  inputSchema: {
51
- siteId: zod_1.z.string().describe("Site ID"),
52
- trafficMatchingListId: zod_1.z.string().describe("Traffic matching list ID"),
53
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
54
+ trafficMatchingListId: (0, params_js_1.resourceId)().describe("Traffic matching list ID"),
53
55
  },
54
56
  outputSchema: output_schemas_js_1.trafficMatchingListOutputSchema,
55
57
  annotations: safety_js_1.READ_ONLY,
@@ -67,7 +69,7 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
67
69
  server.registerTool("unifi_create_traffic_matching_list", {
68
70
  description: "Create a new traffic matching list. Items are tagged objects, not strings (live-verified 11.0.83): PORTS lists take {type:'PORT_NUMBER', value:443} (the older 10.4.57 spec also lists {type:'PORT_NUMBER_RANGE', start, stop}); IPV4_ADDRESSES lists take {type:'IP_ADDRESS', value:'192.0.2.1'} or {type:'SUBNET', value:'192.0.2.0/24'} (spec also: IP_ADDRESS_RANGE {start, stop}); IPV6_ADDRESSES lists take IP_ADDRESS or SUBNET. Idempotency: not safe to retry — re-running creates a duplicate list.",
69
71
  inputSchema: {
70
- siteId: zod_1.z.string().describe("Site ID"),
72
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
71
73
  type: zod_1.z
72
74
  .enum(["PORTS", "IPV4_ADDRESSES", "IPV6_ADDRESSES"])
73
75
  .describe("List type"),
@@ -78,7 +80,7 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
78
80
  .optional()
79
81
  .describe("Preview this action without executing it"),
80
82
  },
81
- outputSchema: output_schemas_js_1.trafficMatchingListOutputSchema,
83
+ outputSchema: (0, output_schemas_js_1.writeResult)(output_schemas_js_1.trafficMatchingListOutputSchema),
82
84
  annotations: safety_js_1.WRITE_NOT_IDEMPOTENT,
83
85
  }, async ({ siteId, type, name, items, dryRun }) => {
84
86
  try {
@@ -95,8 +97,8 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
95
97
  server.registerTool("unifi_update_traffic_matching_list", {
96
98
  description: "Replace a traffic matching list (full PUT — type, name and the complete items array are all required; read the current list with unifi_get_traffic_matching_list first). Items are tagged objects, not strings (live-verified 11.0.83): PORTS lists take {type:'PORT_NUMBER', value:443} (the older 10.4.57 spec also lists {type:'PORT_NUMBER_RANGE', start, stop}); IPV4_ADDRESSES lists take {type:'IP_ADDRESS', value:'192.0.2.1'} or {type:'SUBNET', value:'192.0.2.0/24'} (spec also: IP_ADDRESS_RANGE {start, stop}); IPV6_ADDRESSES lists take IP_ADDRESS or SUBNET.",
97
99
  inputSchema: {
98
- siteId: zod_1.z.string().describe("Site ID"),
99
- trafficMatchingListId: zod_1.z.string().describe("Traffic matching list ID"),
100
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
101
+ trafficMatchingListId: (0, params_js_1.resourceId)().describe("Traffic matching list ID"),
100
102
  type: zod_1.z
101
103
  .enum(["PORTS", "IPV4_ADDRESSES", "IPV6_ADDRESSES"])
102
104
  .describe("List type"),
@@ -107,11 +109,14 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
107
109
  .optional()
108
110
  .describe("Preview this action without executing it"),
109
111
  },
110
- outputSchema: output_schemas_js_1.trafficMatchingListOutputSchema,
112
+ outputSchema: (0, output_schemas_js_1.writeResult)(output_schemas_js_1.trafficMatchingListOutputSchema),
111
113
  annotations: safety_js_1.WRITE,
112
114
  }, async ({ siteId, trafficMatchingListId, type, name, items, dryRun }) => {
113
115
  try {
114
116
  const body = { type, name, items };
117
+ const exposure = await new wan_exposure_js_1.WanExposure(client, wan, siteId).matchingList(trafficMatchingListId);
118
+ if (exposure)
119
+ return (0, wan_exposure_js_1.wanRefusal)(exposure, "PUT", `/sites/${siteId}/traffic-matching-lists/${trafficMatchingListId}`);
115
120
  if (dryRun)
116
121
  return (0, safety_js_1.formatDryRun)("PUT", `/sites/${siteId}/traffic-matching-lists/${trafficMatchingListId}`, body);
117
122
  const data = await client.put(`/sites/${siteId}/traffic-matching-lists/${trafficMatchingListId}`, body);
@@ -124,12 +129,9 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
124
129
  server.registerTool("unifi_delete_traffic_matching_list", {
125
130
  description: "DESTRUCTIVE: Delete a traffic matching list",
126
131
  inputSchema: {
127
- siteId: zod_1.z.string().describe("Site ID"),
128
- trafficMatchingListId: zod_1.z.string().describe("Traffic matching list ID"),
129
- confirm: zod_1.z
130
- .boolean()
131
- .optional()
132
- .describe("Must be true to execute this destructive action"),
132
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
133
+ trafficMatchingListId: (0, params_js_1.resourceId)().describe("Traffic matching list ID"),
134
+ confirm: (0, safety_js_1.confirmDestructive)(),
133
135
  dryRun: zod_1.z
134
136
  .boolean()
135
137
  .optional()
@@ -137,12 +139,12 @@ function registerTrafficMatchingTools(server, client, readOnly = false) {
137
139
  },
138
140
  annotations: safety_js_1.DESTRUCTIVE,
139
141
  }, async ({ siteId, trafficMatchingListId, confirm, dryRun }) => {
140
- const guard = (0, safety_js_1.requireConfirmation)(confirm, "This will delete the traffic matching list");
142
+ const guard = dryRun ? null : (0, safety_js_1.requireConfirmation)(confirm, "This will delete the traffic matching list");
141
143
  if (guard)
142
144
  return guard;
143
145
  try {
144
146
  if (dryRun)
145
- return (0, safety_js_1.formatDryRun)("DELETE", `/sites/${siteId}/traffic-matching-lists/${trafficMatchingListId}`, {});
147
+ return (0, safety_js_1.formatDryRun)("DELETE", `/sites/${siteId}/traffic-matching-lists/${trafficMatchingListId}`);
146
148
  const data = await client.delete(`/sites/${siteId}/traffic-matching-lists/${trafficMatchingListId}`);
147
149
  return (0, responses_js_1.formatSuccess)(data);
148
150
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerWifiTools = registerWifiTools;
4
+ const node_util_1 = require("node:util");
4
5
  const zod_1 = require("zod");
5
6
  const responses_js_1 = require("../utils/responses.js");
6
7
  const query_js_1 = require("../utils/query.js");
@@ -8,6 +9,7 @@ const safety_js_1 = require("../utils/safety.js");
8
9
  const full_put_js_1 = require("../utils/full-put.js");
9
10
  const secrets_js_1 = require("../utils/secrets.js");
10
11
  const output_schemas_js_1 = require("../utils/output-schemas.js");
12
+ const params_js_1 = require("../utils/params.js");
11
13
  // Request-body fields per broadcast type, from the 11.0.83 POST/PUT schemas.
12
14
  // IOT_OPTIMIZED accepts a strict subset of STANDARD.
13
15
  const IOT_OPTIMIZED_FIELDS = [
@@ -126,6 +128,41 @@ function checkBody(body, updates) {
126
128
  throw new Error(`Missing required fields for type ${String(body.type)}: ${missing.join(", ")}`);
127
129
  }
128
130
  }
131
+ function securityType(ssid) {
132
+ const security = ssid.securityConfiguration;
133
+ return security !== null && typeof security === "object" && "type" in security ? security.type : undefined;
134
+ }
135
+ function isOpen(ssid) {
136
+ const type = securityType(ssid);
137
+ return typeof type === "string" && type.toUpperCase() === "OPEN";
138
+ }
139
+ // On an open SSID, these decide who can join and what joining reaches.
140
+ const OPEN_ACCESS_FIELDS = ["network", "hotspotConfiguration", "clientIsolationEnabled", "clientFilteringPolicy"];
141
+ /**
142
+ * What a WiFi write would open, if anything. before is undefined on create.
143
+ * An open SSID lets anyone in range join, so switching one on, or changing
144
+ * what it leads to or how joining is gated, counts as well as the security
145
+ * type itself.
146
+ */
147
+ function wifiOpening(before, after) {
148
+ if (before === undefined)
149
+ return isOpen(after) ? "This creates an open SSID with no encryption" : undefined;
150
+ const [from, to] = [securityType(before), securityType(after)];
151
+ if (!(0, node_util_1.isDeepStrictEqual)(from, to))
152
+ return `This changes the SSID's security from ${String(from)} to ${String(to)}`;
153
+ if (!isOpen(after) || after.enabled === false)
154
+ return undefined;
155
+ if (before.enabled === false)
156
+ return "This enables an open SSID with no encryption";
157
+ const changed = OPEN_ACCESS_FIELDS.filter((field) => !(0, node_util_1.isDeepStrictEqual)(before[field], after[field]));
158
+ return changed.length > 0
159
+ ? `This changes who can join an open SSID, or what joining reaches (${changed.join(", ")})`
160
+ : undefined;
161
+ }
162
+ const confirmSecurity = zod_1.z
163
+ .boolean()
164
+ .optional()
165
+ .describe("Set true to confirm creating or enabling an open SSID, changing an SSID's security type, or changing an open SSID's network, captive portal (hotspotConfiguration), client isolation or client filtering; not needed with dryRun: true");
129
166
  const includeSecrets = zod_1.z
130
167
  .boolean()
131
168
  .optional()
@@ -135,20 +172,20 @@ function registerWifiTools(server, client, readOnly = false) {
135
172
  server.registerTool("unifi_list_wifi", {
136
173
  description: `List all WiFi broadcasts (SSIDs) at a site. Returns (sparse list view, live-verified on 11.0.83): id, name (SSID), type (STANDARD/IOT_OPTIMIZED), enabled, metadata.origin, network reference (absent on PPSK SSIDs), securityConfiguration.type, broadcastingFrequenciesGHz, hotspotConfiguration (empty object when set). Booleans such as hideName/bandSteeringEnabled/clientIsolationEnabled, the full security configuration and optional configs are only returned by unifi_get_wifi. ${readRedaction} Use for: SSID inventory. For per-AP radio state (channel, txPower), use unifi_get_device on the AP.`,
137
174
  inputSchema: {
138
- siteId: zod_1.z.string().describe("Site ID"),
175
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
139
176
  offset: zod_1.z
140
177
  .number()
141
178
  .int()
142
179
  .nonnegative()
143
180
  .optional()
144
- .describe("Number of records to skip (default: 0)"),
181
+ .describe("Number of records to skip"),
145
182
  limit: zod_1.z
146
183
  .number()
147
184
  .int()
148
185
  .min(0)
149
186
  .max(200)
150
187
  .optional()
151
- .describe("Number of records to return (default: 25, max: 200)"),
188
+ .describe("Number of records to return (API default: 25)"),
152
189
  filter: zod_1.z
153
190
  .string()
154
191
  .optional()
@@ -170,8 +207,8 @@ function registerWifiTools(server, client, readOnly = false) {
170
207
  server.registerTool("unifi_get_wifi", {
171
208
  description: `Get full configuration for a WiFi broadcast (SSID). Returns the list fields plus the booleans (hideName, clientIsolationEnabled, uapsdEnabled, multicastToUnicastConversionEnabled, bandSteeringEnabled, arpProxyEnabled, bssTransitionEnabled, advertiseDeviceName, channel2gLockedTo6, dtimPeriod2gLockedTo3), the full securityConfiguration (type, pmfMode, fastRoamingEnabled, saeConfiguration, presharedKeys[] on PPSK SSIDs, …), and optional configs when configured (omitted otherwise): clientFilteringPolicy, blackoutScheduleConfiguration, hotspotConfiguration, mdnsProxyConfiguration, handoffSuggestionsConfiguration, dtimPeriodByFrequencyGHzOverride, broadcastingDeviceFilter, mloEnabled. ${readRedaction}`,
172
209
  inputSchema: {
173
- siteId: zod_1.z.string().describe("Site ID"),
174
- wifiBroadcastId: zod_1.z.string().describe("WiFi Broadcast ID"),
210
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
211
+ wifiBroadcastId: (0, params_js_1.resourceId)().describe("WiFi Broadcast ID"),
175
212
  includeSecrets,
176
213
  },
177
214
  outputSchema: output_schemas_js_1.getWifiOutputSchema,
@@ -190,7 +227,7 @@ function registerWifiTools(server, client, readOnly = false) {
190
227
  server.registerTool("unifi_create_wifi", {
191
228
  description: `Create a new WiFi network (SSID). Required for both types: type, name, enabled, securityConfiguration, multicastToUnicastConversionEnabled, clientIsolationEnabled, hideName, uapsdEnabled, channel2gLockedTo6, dtimPeriod2gLockedTo3. STANDARD additionally requires broadcastingFrequenciesGHz, arpProxyEnabled, bssTransitionEnabled, advertiseDeviceName; fields marked "STANDARD only" are rejected for IOT_OPTIMIZED (per 11.0.83 docs). The response echo has passphrases redacted. Idempotency: not safe to retry — re-running creates a duplicate SSID.`,
192
229
  inputSchema: {
193
- siteId: zod_1.z.string().describe("Site ID"),
230
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
194
231
  ...wifiFields,
195
232
  name: zod_1.z.string().min(1).describe("SSID name"),
196
233
  enabled: zod_1.z.boolean().describe("Enable the WiFi network"),
@@ -204,22 +241,27 @@ function registerWifiTools(server, client, readOnly = false) {
204
241
  uapsdEnabled: zod_1.z.boolean().describe("Enable Unscheduled Automatic Power Save Delivery"),
205
242
  channel2gLockedTo6: zod_1.z.boolean().describe("Lock 2.4GHz channel to 6 on all broadcasting devices"),
206
243
  dtimPeriod2gLockedTo3: zod_1.z.boolean().describe("Lock 2.4GHz DTIM period to 3"),
244
+ confirm: confirmSecurity,
207
245
  dryRun: zod_1.z
208
246
  .boolean()
209
247
  .optional()
210
248
  .describe("Preview this action without executing it"),
211
249
  },
212
- outputSchema: output_schemas_js_1.getWifiOutputSchema,
250
+ outputSchema: (0, output_schemas_js_1.writeResult)(output_schemas_js_1.getWifiOutputSchema),
213
251
  annotations: safety_js_1.WRITE_NOT_IDEMPOTENT,
214
- }, async ({ siteId, dryRun, ...fields }) => {
252
+ }, async ({ siteId, confirm, dryRun, ...fields }) => {
215
253
  try {
216
254
  const body = toBodyFields(fields);
217
255
  checkBody(body, body);
256
+ const opening = wifiOpening(undefined, body);
257
+ const guard = (0, safety_js_1.requireConfirmationIf)(opening, confirm, dryRun);
258
+ if (guard)
259
+ return guard;
218
260
  if ((0, secrets_js_1.containsRedacted)(body)) {
219
261
  throw new Error(`securityConfiguration contains "${secrets_js_1.REDACTED}" — a new SSID needs the real passphrase`);
220
262
  }
221
263
  if (dryRun)
222
- return (0, safety_js_1.formatDryRun)("POST", `/sites/${siteId}/wifi/broadcasts`, (0, secrets_js_1.redactSecrets)(body));
264
+ return (0, safety_js_1.formatDryRun)("POST", `/sites/${siteId}/wifi/broadcasts`, (0, secrets_js_1.redactSecrets)(body), opening);
223
265
  const data = await client.post(`/sites/${siteId}/wifi/broadcasts`, body);
224
266
  return (0, responses_js_1.formatSuccess)((0, secrets_js_1.redactSecrets)(data), { structured: true });
225
267
  }
@@ -228,30 +270,37 @@ function registerWifiTools(server, client, readOnly = false) {
228
270
  }
229
271
  });
230
272
  server.registerTool("unifi_update_wifi", {
231
- description: `Update an existing WiFi network. Pass only the fields to change. The API's PUT replaces the whole SSID (11.0.83 documents 14 required fields for STANDARD, 10 for IOT_OPTIMIZED), so this tool reads the current SSID, keeps every documented body field, overlays your changes and sends the full body — omitted fields keep their current values instead of being reset. Pass null to clear an optional config (e.g. broadcastingDeviceFilter: null broadcasts from all APs). Passphrases are kept unless you send a new one; "${secrets_js_1.REDACTED}" values are treated as "keep". dryRun shows the merged body (secrets redacted).`,
273
+ description: `Update an existing WiFi network. Pass only the fields to change. The API's PUT replaces the whole SSID and requires every documented required field, so this tool reads the current SSID, keeps every documented body field, overlays your changes and sends the full body — omitted fields keep their current values instead of being reset. Pass null to clear an optional config (e.g. broadcastingDeviceFilter: null broadcasts from all APs). Top-level objects are replaced whole: to change one security setting, start from the securityConfiguration unifi_get_wifi returns and edit it, since a partial object drops the passphrase or presharedKeys it omits. Passphrases are kept if you omit securityConfiguration or echo its "${secrets_js_1.REDACTED}" values; send a new one to change it. dryRun shows the merged body (secrets redacted).`,
232
274
  inputSchema: {
233
- siteId: zod_1.z.string().describe("Site ID"),
234
- wifiBroadcastId: zod_1.z.string().describe("WiFi Broadcast ID"),
275
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
276
+ wifiBroadcastId: (0, params_js_1.resourceId)().describe("WiFi Broadcast ID"),
235
277
  ...wifiFields,
278
+ confirm: confirmSecurity,
236
279
  dryRun: zod_1.z
237
280
  .boolean()
238
281
  .optional()
239
282
  .describe("Preview the merged PUT body without executing it (still reads the current SSID)"),
240
283
  },
241
- outputSchema: output_schemas_js_1.getWifiOutputSchema,
284
+ outputSchema: (0, output_schemas_js_1.writeResult)(output_schemas_js_1.getWifiOutputSchema),
242
285
  annotations: safety_js_1.WRITE,
243
- }, async ({ siteId, wifiBroadcastId, dryRun, ...fields }) => {
286
+ }, async ({ siteId, wifiBroadcastId, confirm, dryRun, ...fields }) => {
244
287
  try {
245
288
  const path = `/sites/${siteId}/wifi/broadcasts/${wifiBroadcastId}`;
246
- const current = (0, full_put_js_1.asObject)(await client.get(path), "the current WiFi broadcast");
247
- const updates = (0, secrets_js_1.restoreRedacted)(toBodyFields(fields), current);
248
- const { allowed } = fieldsForType(updates.type ?? current.type);
249
- const body = (0, full_put_js_1.mergeForPut)(current, updates, allowed);
250
- checkBody(body, updates);
251
- if (dryRun)
252
- return (0, safety_js_1.formatDryRun)("PUT", path, (0, secrets_js_1.redactSecrets)(body));
253
- const data = await client.put(path, body);
254
- return (0, responses_js_1.formatSuccess)((0, secrets_js_1.redactSecrets)(data), { structured: true });
289
+ return await (0, full_put_js_1.withResourceLock)(path, async () => {
290
+ const current = (0, full_put_js_1.asObject)(await client.get(path), "the current WiFi broadcast");
291
+ const updates = (0, secrets_js_1.restoreRedacted)(toBodyFields(fields), current);
292
+ const { allowed } = fieldsForType(updates.type ?? current.type);
293
+ const body = (0, full_put_js_1.mergeForPut)(current, updates, allowed);
294
+ checkBody(body, updates);
295
+ const opening = wifiOpening(current, body);
296
+ const guard = (0, safety_js_1.requireConfirmationIf)(opening, confirm, dryRun);
297
+ if (guard)
298
+ return guard;
299
+ if (dryRun)
300
+ return (0, safety_js_1.formatDryRun)("PUT", path, (0, secrets_js_1.redactSecrets)(body), opening);
301
+ const data = await client.put(path, body);
302
+ return (0, responses_js_1.formatSuccess)((0, secrets_js_1.redactSecrets)(data), { structured: true });
303
+ });
255
304
  }
256
305
  catch (err) {
257
306
  return (0, responses_js_1.formatError)(err);
@@ -260,17 +309,14 @@ function registerWifiTools(server, client, readOnly = false) {
260
309
  server.registerTool("unifi_delete_wifi", {
261
310
  description: "DESTRUCTIVE: Delete a WiFi network — all clients on this SSID will be disconnected",
262
311
  inputSchema: {
263
- siteId: zod_1.z.string().describe("Site ID"),
264
- wifiBroadcastId: zod_1.z.string().describe("WiFi Broadcast ID"),
312
+ siteId: (0, params_js_1.resourceId)().describe("Site ID"),
313
+ wifiBroadcastId: (0, params_js_1.resourceId)().describe("WiFi Broadcast ID"),
265
314
  force: zod_1.z
266
315
  .boolean()
267
316
  .optional()
268
317
  .default(false)
269
318
  .describe("Force delete (default: false)"),
270
- confirm: zod_1.z
271
- .boolean()
272
- .optional()
273
- .describe("Must be true to execute this destructive action"),
319
+ confirm: (0, safety_js_1.confirmDestructive)(),
274
320
  dryRun: zod_1.z
275
321
  .boolean()
276
322
  .optional()
@@ -278,7 +324,7 @@ function registerWifiTools(server, client, readOnly = false) {
278
324
  },
279
325
  annotations: safety_js_1.DESTRUCTIVE,
280
326
  }, async ({ siteId, wifiBroadcastId, force, confirm, dryRun }) => {
281
- const guard = (0, safety_js_1.requireConfirmation)(confirm, "This will delete the WiFi network and disconnect all clients on this SSID");
327
+ const guard = dryRun ? null : (0, safety_js_1.requireConfirmation)(confirm, "This will delete the WiFi network and disconnect all clients on this SSID");
282
328
  if (guard)
283
329
  return guard;
284
330
  try {