@owine/unifi-network-mcp 2.15.0 → 3.0.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.
- package/LICENSE +21 -0
- package/README.md +226 -73
- package/dist/client.d.ts +13 -1
- package/dist/client.js +142 -16
- package/dist/config.d.ts +11 -0
- package/dist/config.js +102 -3
- package/dist/guard.d.ts +46 -0
- package/dist/guard.js +171 -0
- package/dist/index.js +15 -4
- package/dist/instructions.d.ts +9 -0
- package/dist/instructions.js +32 -0
- package/dist/tls.d.ts +14 -0
- package/dist/tls.js +58 -0
- package/dist/tools/acl.js +123 -50
- package/dist/tools/client-history.js +20 -10
- package/dist/tools/clients.js +10 -9
- package/dist/tools/devices.js +21 -20
- package/dist/tools/dns-policies.js +27 -27
- package/dist/tools/firewall.d.ts +2 -1
- package/dist/tools/firewall.js +200 -75
- package/dist/tools/hotspot.js +35 -28
- package/dist/tools/index.d.ts +13 -1
- package/dist/tools/index.js +63 -4
- package/dist/tools/networks.d.ts +2 -1
- package/dist/tools/networks.js +44 -31
- package/dist/tools/sites.js +2 -2
- package/dist/tools/supporting.js +22 -21
- package/dist/tools/switching.js +16 -15
- package/dist/tools/system.js +1 -1
- package/dist/tools/traffic-matching.d.ts +2 -1
- package/dist/tools/traffic-matching.js +22 -20
- package/dist/tools/wifi.js +76 -30
- package/dist/utils/full-put.d.ts +11 -2
- package/dist/utils/full-put.js +25 -2
- package/dist/utils/output-schemas.d.ts +26 -4
- package/dist/utils/output-schemas.js +80 -48
- package/dist/utils/params.d.ts +7 -0
- package/dist/utils/params.js +12 -0
- package/dist/utils/responses.d.ts +2 -0
- package/dist/utils/responses.js +28 -2
- package/dist/utils/safety.d.ts +35 -1
- package/dist/utils/safety.js +53 -3
- package/dist/utils/secrets.js +3 -0
- package/dist/utils/wan-exposure.d.ts +69 -0
- package/dist/utils/wan-exposure.js +245 -0
- package/dist/write-log.d.ts +52 -0
- package/dist/write-log.js +178 -0
- package/dist/write-tools.d.ts +27 -0
- package/dist/write-tools.js +50 -0
- package/package.json +17 -13
package/dist/tools/switching.js
CHANGED
|
@@ -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:
|
|
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
|
|
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
|
|
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:
|
|
48
|
-
switchStackId:
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
99
|
-
mcLagDomainId:
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
150
|
-
lagId:
|
|
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,
|
package/dist/tools/system.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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") }).
|
|
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:
|
|
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
|
|
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
|
|
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:
|
|
52
|
-
trafficMatchingListId:
|
|
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:
|
|
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:
|
|
99
|
-
trafficMatchingListId:
|
|
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:
|
|
128
|
-
trafficMatchingListId:
|
|
129
|
-
confirm:
|
|
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
|
}
|
package/dist/tools/wifi.js
CHANGED
|
@@ -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:
|
|
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
|
|
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
|
|
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:
|
|
174
|
-
wifiBroadcastId:
|
|
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:
|
|
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
|
|
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:
|
|
234
|
-
wifiBroadcastId:
|
|
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
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
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:
|
|
264
|
-
wifiBroadcastId:
|
|
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:
|
|
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 {
|
package/dist/utils/full-put.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Read-merge-write support for UniFi's full-replacement PUT endpoints.
|
|
3
3
|
*
|
|
4
|
-
* Several Integration API PUTs (WiFi broadcasts, networks, firewall policies
|
|
5
|
-
* replace the whole resource: required fields must all be present, and some
|
|
4
|
+
* Several Integration API PUTs (WiFi broadcasts, networks, firewall policies,
|
|
5
|
+
* ACL rules, DNS policies) replace the whole resource: required fields must all be present, and some
|
|
6
6
|
* optional fields carry meaning when omitted (a missing `dhcpGuarding`
|
|
7
7
|
* disables DHCP guarding; a missing `reportFlowEnabled` reverts to true). A
|
|
8
8
|
* sparse body therefore either fails or silently resets settings.
|
|
@@ -21,3 +21,12 @@ export declare function unsupportedFields(updates: JsonObject, allowedFields: re
|
|
|
21
21
|
export declare function missingFields(body: JsonObject, requiredFields: readonly string[]): string[];
|
|
22
22
|
/** Copy only the defined entries, so optional inputs the caller skipped are not sent. */
|
|
23
23
|
export declare function definedEntries(values: JsonObject): JsonObject;
|
|
24
|
+
/**
|
|
25
|
+
* Run one read-merge-write cycle at a time per resource. Agents often split
|
|
26
|
+
* "rename X and enable logging" into parallel calls; unserialised, both read
|
|
27
|
+
* the old resource and the second PUT silently reverts the first change.
|
|
28
|
+
* The queue is per process and keyed on the exact path string, so every
|
|
29
|
+
* writer of a resource (including the firewall-policy PATCH) must lock the
|
|
30
|
+
* same path.
|
|
31
|
+
*/
|
|
32
|
+
export declare function withResourceLock<T>(path: string, fn: () => Promise<T>): Promise<T>;
|
package/dist/utils/full-put.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Read-merge-write support for UniFi's full-replacement PUT endpoints.
|
|
4
4
|
*
|
|
5
|
-
* Several Integration API PUTs (WiFi broadcasts, networks, firewall policies
|
|
6
|
-
* replace the whole resource: required fields must all be present, and some
|
|
5
|
+
* Several Integration API PUTs (WiFi broadcasts, networks, firewall policies,
|
|
6
|
+
* ACL rules, DNS policies) replace the whole resource: required fields must all be present, and some
|
|
7
7
|
* optional fields carry meaning when omitted (a missing `dhcpGuarding`
|
|
8
8
|
* disables DHCP guarding; a missing `reportFlowEnabled` reverts to true). A
|
|
9
9
|
* sparse body therefore either fails or silently resets settings.
|
|
@@ -19,6 +19,7 @@ exports.mergeForPut = mergeForPut;
|
|
|
19
19
|
exports.unsupportedFields = unsupportedFields;
|
|
20
20
|
exports.missingFields = missingFields;
|
|
21
21
|
exports.definedEntries = definedEntries;
|
|
22
|
+
exports.withResourceLock = withResourceLock;
|
|
22
23
|
function asObject(value, what) {
|
|
23
24
|
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
24
25
|
throw new Error(`Expected ${what} to be a JSON object`);
|
|
@@ -49,3 +50,25 @@ function missingFields(body, requiredFields) {
|
|
|
49
50
|
function definedEntries(values) {
|
|
50
51
|
return Object.fromEntries(Object.entries(values).filter(([, value]) => value !== undefined));
|
|
51
52
|
}
|
|
53
|
+
const resourceQueues = new Map();
|
|
54
|
+
/**
|
|
55
|
+
* Run one read-merge-write cycle at a time per resource. Agents often split
|
|
56
|
+
* "rename X and enable logging" into parallel calls; unserialised, both read
|
|
57
|
+
* the old resource and the second PUT silently reverts the first change.
|
|
58
|
+
* The queue is per process and keyed on the exact path string, so every
|
|
59
|
+
* writer of a resource (including the firewall-policy PATCH) must lock the
|
|
60
|
+
* same path.
|
|
61
|
+
*/
|
|
62
|
+
async function withResourceLock(path, fn) {
|
|
63
|
+
const previous = resourceQueues.get(path) ?? Promise.resolve();
|
|
64
|
+
const run = previous.then(fn);
|
|
65
|
+
const settled = run.then(() => undefined, () => undefined);
|
|
66
|
+
resourceQueues.set(path, settled);
|
|
67
|
+
try {
|
|
68
|
+
return await run;
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
if (resourceQueues.get(path) === settled)
|
|
72
|
+
resourceQueues.delete(path);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -1,14 +1,33 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Output schemas for
|
|
3
|
-
*
|
|
2
|
+
* Output schemas for every read tool, and for write tools whose response
|
|
3
|
+
* echoes the resource (loose strategy: every non-key
|
|
4
|
+
* field optional, every nested object uses .loose() to allow
|
|
4
5
|
* firmware/hardware-specific fields to flow through unchanged).
|
|
5
6
|
*
|
|
6
7
|
* Verified against UniFi Network API 11.0.83. Where the docs collapse
|
|
7
8
|
* nested arrays/objects (e.g. interfaces.ports[], radios[]), the schema
|
|
8
|
-
* uses
|
|
9
|
-
* haven't verified.
|
|
9
|
+
* uses loose records so the contract doesn't lock to fields we
|
|
10
|
+
* haven't verified. Tools register these raw shapes, and registerAllTools()
|
|
11
|
+
* publishes each as a loose object (src/tools/index.ts), so fields a schema
|
|
12
|
+
* does not list never fail client-side validation.
|
|
10
13
|
*/
|
|
11
14
|
import { z } from "zod";
|
|
15
|
+
/**
|
|
16
|
+
* The outputSchema to publish for a tool: always a loose object, whether the
|
|
17
|
+
* tool passed a raw shape or a Zod object (the SDK accepts both). Wrapping a
|
|
18
|
+
* Zod object in z.looseObject() would build a broken schema that makes
|
|
19
|
+
* tools/list throw for every tool.
|
|
20
|
+
*/
|
|
21
|
+
export declare function looseOutput(schema: z.ZodRawShape | z.ZodObject): z.ZodObject;
|
|
22
|
+
export declare function writeResult<T extends z.ZodRawShape>(shape: T): { -readonly [k in keyof { -readonly [P in keyof T]: T[P]; }]: z.ZodOptional<{ -readonly [P in keyof T]: T[P]; }[k]>; } & {
|
|
23
|
+
readonly dryRun: z.ZodOptional<z.ZodLiteral<true>>;
|
|
24
|
+
readonly wouldExecute: z.ZodOptional<z.ZodObject<{
|
|
25
|
+
method: z.ZodString;
|
|
26
|
+
path: z.ZodString;
|
|
27
|
+
body: z.ZodOptional<z.ZodUnknown>;
|
|
28
|
+
}, z.core.$loose>>;
|
|
29
|
+
readonly confirmationRequired: z.ZodOptional<z.ZodString>;
|
|
30
|
+
};
|
|
12
31
|
export declare const getInfoOutputSchema: {
|
|
13
32
|
applicationVersion: z.ZodOptional<z.ZodString>;
|
|
14
33
|
};
|
|
@@ -709,6 +728,9 @@ export declare const listClientHistoryOutputSchema: {
|
|
|
709
728
|
status: z.ZodOptional<z.ZodString>;
|
|
710
729
|
}, z.core.$loose>>;
|
|
711
730
|
readonly count: z.ZodNumber;
|
|
731
|
+
readonly totalCount: z.ZodNumber;
|
|
732
|
+
readonly limit: z.ZodNumber;
|
|
733
|
+
readonly truncated: z.ZodBoolean;
|
|
712
734
|
readonly withinHours: z.ZodNumber;
|
|
713
735
|
readonly coverage: z.ZodString;
|
|
714
736
|
};
|