@teamnetwork-nz/sonicwall-api-mcp-server 0.5.0 → 0.6.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/README.md +3 -3
- package/dist/index.js +177 -179
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A [Model Context Protocol](https://modelcontextprotocol.io/) server that provide
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Log
|
|
7
|
+
- **Log configuration** — inspect log categories and event-definition settings (not runtime event history)
|
|
8
8
|
- **Address objects & groups** — CRUD for IPv4, IPv6, FQDN, and MAC address objects and their groups
|
|
9
9
|
- **Service objects & groups** — CRUD for protocol/port service definitions
|
|
10
10
|
- **Access rules** — create, update, enable/disable, and delete firewall access rules (IPv4 & IPv6)
|
|
@@ -14,7 +14,7 @@ A [Model Context Protocol](https://modelcontextprotocol.io/) server that provide
|
|
|
14
14
|
- **GeoIP lookup** — identify the country/botnet classification of an IP address
|
|
15
15
|
- **Config management** — view and commit (or discard) staged changes
|
|
16
16
|
|
|
17
|
-
> The SonicOS REST API is configuration-focused.
|
|
17
|
+
> The SonicOS REST API is configuration-focused. Runtime event/threat/connection logs and GeoIP *policy* objects are not exposed as REST endpoints and therefore have no tools. `get_log_categories` and `list_log_event_definitions` inspect logging configuration only.
|
|
18
18
|
|
|
19
19
|
Supports SonicOS 6.5.x, 7.x, and 8.x with automatic version detection.
|
|
20
20
|
|
|
@@ -165,7 +165,7 @@ The server supplies MCP `instructions` that are automatically delivered to the c
|
|
|
165
165
|
|
|
166
166
|
- **Staged configuration** — always `commit_config` after a related set of changes, or `discard_config` to abandon
|
|
167
167
|
- **Datetime handling** — log timestamps use the appliance's local timezone; no UTC conversion needed
|
|
168
|
-
- **Log
|
|
168
|
+
- **Log configuration scope** — log tools expose categories and event definitions, not searchable runtime history
|
|
169
169
|
- **Object and rule management** — recommended workflow for creating address objects and firewall rules
|
|
170
170
|
- **Concurrent sessions** — SonicOS limit of one active API session per appliance
|
|
171
171
|
|
package/dist/index.js
CHANGED
|
@@ -779,7 +779,7 @@ var import_zod3 = require("zod");
|
|
|
779
779
|
function registerAddressGroupTools(server, registry) {
|
|
780
780
|
server.tool(
|
|
781
781
|
"list_address_groups",
|
|
782
|
-
"List address groups on the appliance.",
|
|
782
|
+
"List address groups on the appliance. type: filter by 'ipv4', 'ipv6', or 'all' (default).",
|
|
783
783
|
{
|
|
784
784
|
type: import_zod3.z.enum(["ipv4", "ipv6", "all"]).optional().default("all"),
|
|
785
785
|
device: import_zod3.z.string().optional()
|
|
@@ -1166,10 +1166,21 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1166
1166
|
|
|
1167
1167
|
// src/tools/access-rules.ts
|
|
1168
1168
|
var import_zod6 = require("zod");
|
|
1169
|
+
function zoneName(v) {
|
|
1170
|
+
if (typeof v === "string") return v;
|
|
1171
|
+
if (v && typeof v === "object") {
|
|
1172
|
+
const z15 = v.zone;
|
|
1173
|
+
if (typeof z15 === "string") return z15;
|
|
1174
|
+
}
|
|
1175
|
+
return void 0;
|
|
1176
|
+
}
|
|
1177
|
+
function matchesZone(value, filter) {
|
|
1178
|
+
return value !== void 0 && value.toLowerCase() === filter.toLowerCase();
|
|
1179
|
+
}
|
|
1169
1180
|
function registerAccessRuleTools(server, registry) {
|
|
1170
1181
|
server.tool(
|
|
1171
1182
|
"list_access_rules",
|
|
1172
|
-
"List firewall access rules, optionally filtered by source and/or destination zone.",
|
|
1183
|
+
"List firewall access rules, optionally filtered by source and/or destination zone. Filtering is applied client-side over the complete ruleset; matched is the number returned and total is the unfiltered rule count (not pagination). Use each rule's uuid value as rule_uuid for get/update/enable/disable/delete tools.",
|
|
1173
1184
|
{
|
|
1174
1185
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1175
1186
|
from_zone: import_zod6.z.string().optional(),
|
|
@@ -1179,10 +1190,19 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1179
1190
|
async ({ ip_version, from_zone, to_zone, device }) => {
|
|
1180
1191
|
try {
|
|
1181
1192
|
const client = await registry.getClient(device);
|
|
1182
|
-
const
|
|
1183
|
-
if (from_zone
|
|
1184
|
-
|
|
1185
|
-
|
|
1193
|
+
const result = await client.get(`access-rules/${ip_version}`);
|
|
1194
|
+
if (from_zone || to_zone) {
|
|
1195
|
+
const all = result.access_rules ?? [];
|
|
1196
|
+
const filtered = all.filter((entry) => {
|
|
1197
|
+
const rule = entry[ip_version];
|
|
1198
|
+
if (!rule) return false;
|
|
1199
|
+
if (from_zone && !matchesZone(zoneName(rule.from), from_zone)) return false;
|
|
1200
|
+
if (to_zone && !matchesZone(zoneName(rule.to), to_zone)) return false;
|
|
1201
|
+
return true;
|
|
1202
|
+
});
|
|
1203
|
+
const out = { access_rules: filtered, matched: filtered.length, total: all.length };
|
|
1204
|
+
return { content: [{ type: "text", text: JSON.stringify(out, null, 2) }] };
|
|
1205
|
+
}
|
|
1186
1206
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1187
1207
|
} catch (e) {
|
|
1188
1208
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
@@ -1191,16 +1211,16 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1191
1211
|
);
|
|
1192
1212
|
server.tool(
|
|
1193
1213
|
"get_access_rule",
|
|
1194
|
-
"Retrieve a single access rule by
|
|
1214
|
+
"Retrieve a single access rule by UUID. Pass a rule's uuid value from list_access_rules as rule_uuid.",
|
|
1195
1215
|
{
|
|
1196
|
-
|
|
1216
|
+
rule_uuid: import_zod6.z.string().uuid(),
|
|
1197
1217
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1198
1218
|
device: import_zod6.z.string().optional()
|
|
1199
1219
|
},
|
|
1200
|
-
async ({
|
|
1220
|
+
async ({ rule_uuid, ip_version, device }) => {
|
|
1201
1221
|
try {
|
|
1202
1222
|
const client = await registry.getClient(device);
|
|
1203
|
-
const result = await client.get(`access-rules/${ip_version}/${
|
|
1223
|
+
const result = await client.get(`access-rules/${ip_version}/uuid/${encodeURIComponent(rule_uuid)}`);
|
|
1204
1224
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1205
1225
|
} catch (e) {
|
|
1206
1226
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
@@ -1209,7 +1229,7 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1209
1229
|
);
|
|
1210
1230
|
server.tool(
|
|
1211
1231
|
"create_access_rule",
|
|
1212
|
-
"Create a firewall access rule. source/destination/service: name of an existing address/service object or 'Any'. geo_ip_policy:
|
|
1232
|
+
"Create a firewall access rule. source/destination/service: name of an existing address/service object or 'Any'. geo_ip_policy: name of a GeoIP policy that already exists on the appliance (GeoIP policies cannot be created or listed via this server \u2014 manage them in the appliance web UI). Changes are STAGED; call commit_config to apply.",
|
|
1213
1233
|
{
|
|
1214
1234
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]),
|
|
1215
1235
|
name: import_zod6.z.string(),
|
|
@@ -1254,9 +1274,9 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1254
1274
|
);
|
|
1255
1275
|
server.tool(
|
|
1256
1276
|
"update_access_rule",
|
|
1257
|
-
"Update
|
|
1277
|
+
"Update an access rule selected by UUID (GET-then-PUT). Pass a rule's uuid value from list_access_rules as rule_uuid. Only provided fields are changed. geo_ip_policy: name of an existing appliance GeoIP policy, or '' to remove it. Changes are STAGED; call commit_config to apply.",
|
|
1258
1278
|
{
|
|
1259
|
-
|
|
1279
|
+
rule_uuid: import_zod6.z.string().uuid(),
|
|
1260
1280
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1261
1281
|
action: import_zod6.z.enum(["allow", "deny", "discard"]).optional(),
|
|
1262
1282
|
source: import_zod6.z.string().optional(),
|
|
@@ -1268,10 +1288,11 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1268
1288
|
comment: import_zod6.z.string().optional(),
|
|
1269
1289
|
device: import_zod6.z.string().optional()
|
|
1270
1290
|
},
|
|
1271
|
-
async ({
|
|
1291
|
+
async ({ rule_uuid, ip_version, action, source, destination, service, enabled, log, geo_ip_policy, comment, device }) => {
|
|
1272
1292
|
try {
|
|
1273
1293
|
const client = await registry.getClient(device);
|
|
1274
|
-
const
|
|
1294
|
+
const path = `access-rules/${ip_version}/uuid/${encodeURIComponent(rule_uuid)}`;
|
|
1295
|
+
const current = await client.get(path);
|
|
1275
1296
|
const rules = current.access_rules;
|
|
1276
1297
|
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1277
1298
|
if (action !== void 0) rule.action = action;
|
|
@@ -1294,7 +1315,7 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1294
1315
|
rule.security_profile = { geo_ip_policy: { name: geo_ip_policy } };
|
|
1295
1316
|
}
|
|
1296
1317
|
}
|
|
1297
|
-
const result = await client.put(
|
|
1318
|
+
const result = await client.put(path, {
|
|
1298
1319
|
access_rules: [{ [ip_version]: rule }]
|
|
1299
1320
|
});
|
|
1300
1321
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
@@ -1305,16 +1326,16 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1305
1326
|
);
|
|
1306
1327
|
server.tool(
|
|
1307
1328
|
"delete_access_rule",
|
|
1308
|
-
"Delete an access rule by
|
|
1329
|
+
"Delete an access rule by UUID. Copy rule_uuid from list_access_rules. Changes are STAGED; call commit_config to apply.",
|
|
1309
1330
|
{
|
|
1310
|
-
|
|
1331
|
+
rule_uuid: import_zod6.z.string().uuid(),
|
|
1311
1332
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1312
1333
|
device: import_zod6.z.string().optional()
|
|
1313
1334
|
},
|
|
1314
|
-
async ({
|
|
1335
|
+
async ({ rule_uuid, ip_version, device }) => {
|
|
1315
1336
|
try {
|
|
1316
1337
|
const client = await registry.getClient(device);
|
|
1317
|
-
const result = await client.delete(`access-rules/${ip_version}/${
|
|
1338
|
+
const result = await client.delete(`access-rules/${ip_version}/uuid/${encodeURIComponent(rule_uuid)}`);
|
|
1318
1339
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1319
1340
|
} catch (e) {
|
|
1320
1341
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
@@ -1323,20 +1344,21 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1323
1344
|
);
|
|
1324
1345
|
server.tool(
|
|
1325
1346
|
"enable_access_rule",
|
|
1326
|
-
"Enable
|
|
1347
|
+
"Enable an access rule selected by UUID without modifying other fields. Copy rule_uuid from list_access_rules. Changes are STAGED; call commit_config to apply.",
|
|
1327
1348
|
{
|
|
1328
|
-
|
|
1349
|
+
rule_uuid: import_zod6.z.string().uuid(),
|
|
1329
1350
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1330
1351
|
device: import_zod6.z.string().optional()
|
|
1331
1352
|
},
|
|
1332
|
-
async ({
|
|
1353
|
+
async ({ rule_uuid, ip_version, device }) => {
|
|
1333
1354
|
try {
|
|
1334
1355
|
const client = await registry.getClient(device);
|
|
1335
|
-
const
|
|
1356
|
+
const path = `access-rules/${ip_version}/uuid/${encodeURIComponent(rule_uuid)}`;
|
|
1357
|
+
const current = await client.get(path);
|
|
1336
1358
|
const rules = current.access_rules;
|
|
1337
1359
|
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1338
1360
|
rule.enable = true;
|
|
1339
|
-
const result = await client.put(
|
|
1361
|
+
const result = await client.put(path, {
|
|
1340
1362
|
access_rules: [{ [ip_version]: rule }]
|
|
1341
1363
|
});
|
|
1342
1364
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
@@ -1347,20 +1369,21 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1347
1369
|
);
|
|
1348
1370
|
server.tool(
|
|
1349
1371
|
"disable_access_rule",
|
|
1350
|
-
"Disable an access rule without deleting it. Changes are STAGED; call commit_config to apply.",
|
|
1372
|
+
"Disable an access rule selected by UUID without deleting it. Copy rule_uuid from list_access_rules. Changes are STAGED; call commit_config to apply.",
|
|
1351
1373
|
{
|
|
1352
|
-
|
|
1374
|
+
rule_uuid: import_zod6.z.string().uuid(),
|
|
1353
1375
|
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1354
1376
|
device: import_zod6.z.string().optional()
|
|
1355
1377
|
},
|
|
1356
|
-
async ({
|
|
1378
|
+
async ({ rule_uuid, ip_version, device }) => {
|
|
1357
1379
|
try {
|
|
1358
1380
|
const client = await registry.getClient(device);
|
|
1359
|
-
const
|
|
1381
|
+
const path = `access-rules/${ip_version}/uuid/${encodeURIComponent(rule_uuid)}`;
|
|
1382
|
+
const current = await client.get(path);
|
|
1360
1383
|
const rules = current.access_rules;
|
|
1361
1384
|
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1362
1385
|
rule.enable = false;
|
|
1363
|
-
const result = await client.put(
|
|
1386
|
+
const result = await client.put(path, {
|
|
1364
1387
|
access_rules: [{ [ip_version]: rule }]
|
|
1365
1388
|
});
|
|
1366
1389
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
@@ -1379,7 +1402,7 @@ function setNameField(obj, key, value) {
|
|
|
1379
1402
|
function registerNatPolicyTools(server, registry) {
|
|
1380
1403
|
server.tool(
|
|
1381
1404
|
"list_nat_policies",
|
|
1382
|
-
"List all NAT policies.",
|
|
1405
|
+
"List all NAT policies. ip_version: 'ipv4' (default) or 'ipv6'. Use each policy's uuid value as policy_uuid for get/update/enable/disable/delete tools.",
|
|
1383
1406
|
{
|
|
1384
1407
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1385
1408
|
device: import_zod7.z.string().optional()
|
|
@@ -1396,16 +1419,16 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1396
1419
|
);
|
|
1397
1420
|
server.tool(
|
|
1398
1421
|
"get_nat_policy",
|
|
1399
|
-
"Retrieve a NAT policy by
|
|
1422
|
+
"Retrieve a NAT policy by UUID. Pass a policy's uuid value from list_nat_policies as policy_uuid.",
|
|
1400
1423
|
{
|
|
1401
|
-
|
|
1424
|
+
policy_uuid: import_zod7.z.string().uuid(),
|
|
1402
1425
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1403
1426
|
device: import_zod7.z.string().optional()
|
|
1404
1427
|
},
|
|
1405
|
-
async ({
|
|
1428
|
+
async ({ policy_uuid, ip_version, device }) => {
|
|
1406
1429
|
try {
|
|
1407
1430
|
const client = await registry.getClient(device);
|
|
1408
|
-
const result = await client.get(`nat-policies/${ip_version}/${
|
|
1431
|
+
const result = await client.get(`nat-policies/${ip_version}/uuid/${encodeURIComponent(policy_uuid)}`);
|
|
1409
1432
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1410
1433
|
} catch (e) {
|
|
1411
1434
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
@@ -1427,23 +1450,25 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1427
1450
|
outbound_interface: import_zod7.z.string().optional().default("Any"),
|
|
1428
1451
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1429
1452
|
enabled: import_zod7.z.boolean().optional().default(true),
|
|
1453
|
+
dns_doctoring: import_zod7.z.boolean().optional().default(false),
|
|
1430
1454
|
comment: import_zod7.z.string().optional(),
|
|
1431
1455
|
device: import_zod7.z.string().optional()
|
|
1432
1456
|
},
|
|
1433
|
-
async ({ name, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, ip_version, enabled, comment, device }) => {
|
|
1457
|
+
async ({ name, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, ip_version, enabled, dns_doctoring, comment, device }) => {
|
|
1434
1458
|
try {
|
|
1435
1459
|
const client = await registry.getClient(device);
|
|
1436
1460
|
const policy = {
|
|
1437
1461
|
name,
|
|
1438
1462
|
enable: enabled,
|
|
1439
|
-
|
|
1463
|
+
source: { name: original_source },
|
|
1440
1464
|
translated_source: { name: translated_source },
|
|
1441
|
-
|
|
1465
|
+
destination: { name: original_destination },
|
|
1442
1466
|
translated_destination: { name: translated_destination },
|
|
1443
|
-
|
|
1467
|
+
service: { name: original_service },
|
|
1444
1468
|
translated_service: { name: translated_service },
|
|
1445
|
-
|
|
1446
|
-
|
|
1469
|
+
inbound: { name: inbound_interface },
|
|
1470
|
+
outbound: { name: outbound_interface },
|
|
1471
|
+
dns_doctoring
|
|
1447
1472
|
};
|
|
1448
1473
|
if (comment) policy.comment = comment;
|
|
1449
1474
|
const result = await client.post(`nat-policies/${ip_version}`, {
|
|
@@ -1457,9 +1482,9 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1457
1482
|
);
|
|
1458
1483
|
server.tool(
|
|
1459
1484
|
"update_nat_policy",
|
|
1460
|
-
"Update
|
|
1485
|
+
"Update a NAT policy selected by UUID (GET-then-PUT). Pass a policy's uuid value from list_nat_policies as policy_uuid. dns_doctoring can be changed independently. Changes are STAGED; call commit_config to apply.",
|
|
1461
1486
|
{
|
|
1462
|
-
|
|
1487
|
+
policy_uuid: import_zod7.z.string().uuid(),
|
|
1463
1488
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1464
1489
|
original_source: import_zod7.z.string().optional(),
|
|
1465
1490
|
translated_source: import_zod7.z.string().optional(),
|
|
@@ -1470,26 +1495,29 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1470
1495
|
inbound_interface: import_zod7.z.string().optional(),
|
|
1471
1496
|
outbound_interface: import_zod7.z.string().optional(),
|
|
1472
1497
|
enabled: import_zod7.z.boolean().optional(),
|
|
1498
|
+
dns_doctoring: import_zod7.z.boolean().optional(),
|
|
1473
1499
|
comment: import_zod7.z.string().optional(),
|
|
1474
1500
|
device: import_zod7.z.string().optional()
|
|
1475
1501
|
},
|
|
1476
|
-
async ({
|
|
1502
|
+
async ({ policy_uuid, ip_version, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, enabled, dns_doctoring, comment, device }) => {
|
|
1477
1503
|
try {
|
|
1478
1504
|
const client = await registry.getClient(device);
|
|
1479
|
-
const
|
|
1505
|
+
const path = `nat-policies/${ip_version}/uuid/${encodeURIComponent(policy_uuid)}`;
|
|
1506
|
+
const current = await client.get(path);
|
|
1480
1507
|
const policies = current.nat_policies;
|
|
1481
1508
|
const policy = policies?.[0]?.[ip_version] ?? {};
|
|
1482
|
-
setNameField(policy, "
|
|
1509
|
+
setNameField(policy, "source", original_source);
|
|
1483
1510
|
setNameField(policy, "translated_source", translated_source);
|
|
1484
|
-
setNameField(policy, "
|
|
1511
|
+
setNameField(policy, "destination", original_destination);
|
|
1485
1512
|
setNameField(policy, "translated_destination", translated_destination);
|
|
1486
|
-
setNameField(policy, "
|
|
1513
|
+
setNameField(policy, "service", original_service);
|
|
1487
1514
|
setNameField(policy, "translated_service", translated_service);
|
|
1488
|
-
setNameField(policy, "
|
|
1489
|
-
setNameField(policy, "
|
|
1515
|
+
setNameField(policy, "inbound", inbound_interface);
|
|
1516
|
+
setNameField(policy, "outbound", outbound_interface);
|
|
1490
1517
|
if (enabled !== void 0) policy.enable = enabled;
|
|
1518
|
+
if (dns_doctoring !== void 0) policy.dns_doctoring = dns_doctoring;
|
|
1491
1519
|
if (comment !== void 0) policy.comment = comment;
|
|
1492
|
-
const result = await client.put(
|
|
1520
|
+
const result = await client.put(path, {
|
|
1493
1521
|
nat_policies: [{ [ip_version]: policy }]
|
|
1494
1522
|
});
|
|
1495
1523
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
@@ -1500,16 +1528,59 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1500
1528
|
);
|
|
1501
1529
|
server.tool(
|
|
1502
1530
|
"delete_nat_policy",
|
|
1503
|
-
"Delete a NAT policy by
|
|
1531
|
+
"Delete a NAT policy by UUID. Copy policy_uuid from list_nat_policies. Changes are STAGED; call commit_config to apply.",
|
|
1504
1532
|
{
|
|
1505
|
-
|
|
1533
|
+
policy_uuid: import_zod7.z.string().uuid(),
|
|
1506
1534
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1507
1535
|
device: import_zod7.z.string().optional()
|
|
1508
1536
|
},
|
|
1509
|
-
async ({
|
|
1537
|
+
async ({ policy_uuid, ip_version, device }) => {
|
|
1510
1538
|
try {
|
|
1511
1539
|
const client = await registry.getClient(device);
|
|
1512
|
-
const result = await client.delete(`nat-policies/${ip_version}/${
|
|
1540
|
+
const result = await client.delete(`nat-policies/${ip_version}/uuid/${encodeURIComponent(policy_uuid)}`);
|
|
1541
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1542
|
+
} catch (e) {
|
|
1543
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
);
|
|
1547
|
+
async function setNatPolicyEnabled(policyUuid, ipVersion, enabled, device) {
|
|
1548
|
+
const client = await registry.getClient(device);
|
|
1549
|
+
const path = `nat-policies/${ipVersion}/uuid/${encodeURIComponent(policyUuid)}`;
|
|
1550
|
+
const current = await client.get(path);
|
|
1551
|
+
const policies = current.nat_policies;
|
|
1552
|
+
const policy = policies?.[0]?.[ipVersion] ?? {};
|
|
1553
|
+
policy.enable = enabled;
|
|
1554
|
+
return client.put(path, { nat_policies: [{ [ipVersion]: policy }] });
|
|
1555
|
+
}
|
|
1556
|
+
server.tool(
|
|
1557
|
+
"enable_nat_policy",
|
|
1558
|
+
"Enable a NAT policy selected by UUID without modifying other fields. Copy policy_uuid from list_nat_policies. Changes are STAGED; call commit_config to apply.",
|
|
1559
|
+
{
|
|
1560
|
+
policy_uuid: import_zod7.z.string().uuid(),
|
|
1561
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1562
|
+
device: import_zod7.z.string().optional()
|
|
1563
|
+
},
|
|
1564
|
+
async ({ policy_uuid, ip_version, device }) => {
|
|
1565
|
+
try {
|
|
1566
|
+
const result = await setNatPolicyEnabled(policy_uuid, ip_version, true, device);
|
|
1567
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1568
|
+
} catch (e) {
|
|
1569
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1570
|
+
}
|
|
1571
|
+
}
|
|
1572
|
+
);
|
|
1573
|
+
server.tool(
|
|
1574
|
+
"disable_nat_policy",
|
|
1575
|
+
"Disable a NAT policy selected by UUID without deleting it. Copy policy_uuid from list_nat_policies. Changes are STAGED; call commit_config to apply.",
|
|
1576
|
+
{
|
|
1577
|
+
policy_uuid: import_zod7.z.string().uuid(),
|
|
1578
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1579
|
+
device: import_zod7.z.string().optional()
|
|
1580
|
+
},
|
|
1581
|
+
async ({ policy_uuid, ip_version, device }) => {
|
|
1582
|
+
try {
|
|
1583
|
+
const result = await setNatPolicyEnabled(policy_uuid, ip_version, false, device);
|
|
1513
1584
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1514
1585
|
} catch (e) {
|
|
1515
1586
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
@@ -1520,18 +1591,43 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1520
1591
|
|
|
1521
1592
|
// src/tools/security-policies.ts
|
|
1522
1593
|
var import_zod8 = require("zod");
|
|
1594
|
+
function zoneName2(v) {
|
|
1595
|
+
if (typeof v === "string") return v;
|
|
1596
|
+
if (v && typeof v === "object") {
|
|
1597
|
+
const z15 = v.zone;
|
|
1598
|
+
if (typeof z15 === "string") return z15;
|
|
1599
|
+
}
|
|
1600
|
+
return void 0;
|
|
1601
|
+
}
|
|
1602
|
+
function matchesZone2(value, filter) {
|
|
1603
|
+
return value !== void 0 && value.toLowerCase() === filter.toLowerCase();
|
|
1604
|
+
}
|
|
1523
1605
|
function registerSecurityPolicyTools(server, registry) {
|
|
1524
1606
|
server.tool(
|
|
1525
1607
|
"list_security_policies",
|
|
1526
|
-
"List
|
|
1608
|
+
"List security policies, optionally filtered by source and/or destination zone. Filtering is applied client-side (the SonicOS endpoint returns the full ruleset), so use from_zone/to_zone to keep responses small.",
|
|
1527
1609
|
{
|
|
1528
1610
|
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1611
|
+
from_zone: import_zod8.z.string().optional(),
|
|
1612
|
+
to_zone: import_zod8.z.string().optional(),
|
|
1529
1613
|
device: import_zod8.z.string().optional()
|
|
1530
1614
|
},
|
|
1531
|
-
async ({ ip_version, device }) => {
|
|
1615
|
+
async ({ ip_version, from_zone, to_zone, device }) => {
|
|
1532
1616
|
try {
|
|
1533
1617
|
const client = await registry.getClient(device);
|
|
1534
1618
|
const result = await client.get(`security-policies/${ip_version}`);
|
|
1619
|
+
if (from_zone || to_zone) {
|
|
1620
|
+
const all = result.security_policies ?? [];
|
|
1621
|
+
const filtered = all.filter((entry) => {
|
|
1622
|
+
const policy = entry[ip_version];
|
|
1623
|
+
if (!policy) return false;
|
|
1624
|
+
if (from_zone && !matchesZone2(zoneName2(policy.from), from_zone)) return false;
|
|
1625
|
+
if (to_zone && !matchesZone2(zoneName2(policy.to), to_zone)) return false;
|
|
1626
|
+
return true;
|
|
1627
|
+
});
|
|
1628
|
+
const out = { security_policies: filtered, matched: filtered.length, total: all.length };
|
|
1629
|
+
return { content: [{ type: "text", text: JSON.stringify(out, null, 2) }] };
|
|
1630
|
+
}
|
|
1535
1631
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1536
1632
|
} catch (e) {
|
|
1537
1633
|
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
@@ -1726,139 +1822,47 @@ function registerGeoIpTools(server, registry) {
|
|
|
1726
1822
|
|
|
1727
1823
|
// src/tools/logs.ts
|
|
1728
1824
|
var import_zod10 = require("zod");
|
|
1729
|
-
async function
|
|
1730
|
-
let
|
|
1825
|
+
async function getWithFallback(client, candidates) {
|
|
1826
|
+
let lastError;
|
|
1731
1827
|
for (const path of candidates) {
|
|
1732
1828
|
try {
|
|
1733
|
-
return await client.get(path
|
|
1734
|
-
} catch (
|
|
1735
|
-
if (
|
|
1736
|
-
|
|
1829
|
+
return await client.get(path);
|
|
1830
|
+
} catch (error) {
|
|
1831
|
+
if (error instanceof APIError && (error.status === 400 || error.status === 404)) {
|
|
1832
|
+
lastError = error;
|
|
1737
1833
|
continue;
|
|
1738
1834
|
}
|
|
1739
|
-
throw
|
|
1835
|
+
throw error;
|
|
1740
1836
|
}
|
|
1741
1837
|
}
|
|
1742
|
-
throw
|
|
1838
|
+
throw lastError;
|
|
1743
1839
|
}
|
|
1744
|
-
var EVENT_LOG_PATHS = ["log/events", "reporting/log/events"];
|
|
1745
1840
|
function registerLogTools(server, registry) {
|
|
1746
1841
|
server.tool(
|
|
1747
1842
|
"get_log_categories",
|
|
1748
|
-
"
|
|
1843
|
+
"List SonicOS log category configuration. This describes available event categories; it does not return recorded runtime log entries.",
|
|
1749
1844
|
{ device: import_zod10.z.string().optional() },
|
|
1750
1845
|
async ({ device }) => {
|
|
1751
1846
|
try {
|
|
1752
1847
|
const client = await registry.getClient(device);
|
|
1753
|
-
|
|
1754
|
-
const result = await getLogsWithFallback(
|
|
1755
|
-
client,
|
|
1756
|
-
["log/categories", "reporting/log/categories"],
|
|
1757
|
-
{}
|
|
1758
|
-
);
|
|
1759
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1760
|
-
} catch (e) {
|
|
1761
|
-
if (e instanceof APIError && (e.status === 404 || e.status === 400)) {
|
|
1762
|
-
const fallback = {
|
|
1763
|
-
categories: [
|
|
1764
|
-
"network access",
|
|
1765
|
-
"firewall",
|
|
1766
|
-
"vpn",
|
|
1767
|
-
"system",
|
|
1768
|
-
"security",
|
|
1769
|
-
"IPS",
|
|
1770
|
-
"anti-virus",
|
|
1771
|
-
"anti-spyware",
|
|
1772
|
-
"application control",
|
|
1773
|
-
"content filter",
|
|
1774
|
-
"decryption",
|
|
1775
|
-
"geoip",
|
|
1776
|
-
"authentication"
|
|
1777
|
-
]
|
|
1778
|
-
};
|
|
1779
|
-
return { content: [{ type: "text", text: JSON.stringify(fallback, null, 2) }] };
|
|
1780
|
-
}
|
|
1781
|
-
throw e;
|
|
1782
|
-
}
|
|
1783
|
-
} catch (e) {
|
|
1784
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
);
|
|
1788
|
-
server.tool(
|
|
1789
|
-
"get_event_logs",
|
|
1790
|
-
"Retrieve system/event logs from the appliance. count: max entries (default 100). category: e.g. 'network access', 'system', 'vpn'. priority: emergency/alert/critical/error/warning/notice/info/debug. start_time/end_time: ISO 8601. source_ip: filter by source IP. keyword: full-text search.",
|
|
1791
|
-
{
|
|
1792
|
-
count: import_zod10.z.number().optional().default(100),
|
|
1793
|
-
category: import_zod10.z.string().optional(),
|
|
1794
|
-
priority: import_zod10.z.enum(["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"]).optional(),
|
|
1795
|
-
start_time: import_zod10.z.string().optional(),
|
|
1796
|
-
end_time: import_zod10.z.string().optional(),
|
|
1797
|
-
source_ip: import_zod10.z.string().optional(),
|
|
1798
|
-
keyword: import_zod10.z.string().optional(),
|
|
1799
|
-
device: import_zod10.z.string().optional()
|
|
1800
|
-
},
|
|
1801
|
-
async ({ count, category, priority, start_time, end_time, source_ip, keyword, device }) => {
|
|
1802
|
-
try {
|
|
1803
|
-
const client = await registry.getClient(device);
|
|
1804
|
-
const params = { count };
|
|
1805
|
-
if (category) params.category = category;
|
|
1806
|
-
if (priority) params.priority = priority;
|
|
1807
|
-
if (start_time) params.start_time = start_time;
|
|
1808
|
-
if (end_time) params.end_time = end_time;
|
|
1809
|
-
if (source_ip) params.src_ip = source_ip;
|
|
1810
|
-
if (keyword) params.keyword = keyword;
|
|
1811
|
-
const result = await getLogsWithFallback(client, EVENT_LOG_PATHS, params);
|
|
1848
|
+
const result = await getWithFallback(client, ["log/categories", "reporting/log/categories"]);
|
|
1812
1849
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1813
|
-
} catch (
|
|
1814
|
-
return { content: [{ type: "text", text: `Error: ${
|
|
1850
|
+
} catch (error) {
|
|
1851
|
+
return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true };
|
|
1815
1852
|
}
|
|
1816
1853
|
}
|
|
1817
1854
|
);
|
|
1818
1855
|
server.tool(
|
|
1819
|
-
"
|
|
1820
|
-
"
|
|
1821
|
-
{
|
|
1822
|
-
|
|
1823
|
-
count: import_zod10.z.number().optional().default(200),
|
|
1824
|
-
start_time: import_zod10.z.string().optional(),
|
|
1825
|
-
end_time: import_zod10.z.string().optional(),
|
|
1826
|
-
device: import_zod10.z.string().optional()
|
|
1827
|
-
},
|
|
1828
|
-
async ({ query, count, start_time, end_time, device }) => {
|
|
1829
|
-
try {
|
|
1830
|
-
const client = await registry.getClient(device);
|
|
1831
|
-
const params = { count, keyword: query };
|
|
1832
|
-
if (start_time) params.start_time = start_time;
|
|
1833
|
-
if (end_time) params.end_time = end_time;
|
|
1834
|
-
const result = await getLogsWithFallback(client, EVENT_LOG_PATHS, params);
|
|
1835
|
-
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1836
|
-
} catch (e) {
|
|
1837
|
-
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
);
|
|
1841
|
-
server.tool(
|
|
1842
|
-
"get_threat_logs",
|
|
1843
|
-
"Retrieve IPS and threat-detection log events. severity: 'critical', 'high', 'medium', or 'low'.",
|
|
1844
|
-
{
|
|
1845
|
-
count: import_zod10.z.number().optional().default(50),
|
|
1846
|
-
severity: import_zod10.z.enum(["critical", "high", "medium", "low"]).optional(),
|
|
1847
|
-
start_time: import_zod10.z.string().optional(),
|
|
1848
|
-
end_time: import_zod10.z.string().optional(),
|
|
1849
|
-
device: import_zod10.z.string().optional()
|
|
1850
|
-
},
|
|
1851
|
-
async ({ count, severity, start_time, end_time, device }) => {
|
|
1856
|
+
"list_log_event_definitions",
|
|
1857
|
+
"List SonicOS event-definition configuration (event names, categories, priorities, and alert/syslog settings). This is not the appliance event history and cannot be searched by IP, message, or timestamp.",
|
|
1858
|
+
{ device: import_zod10.z.string().optional() },
|
|
1859
|
+
async ({ device }) => {
|
|
1852
1860
|
try {
|
|
1853
1861
|
const client = await registry.getClient(device);
|
|
1854
|
-
const
|
|
1855
|
-
if (severity) params.severity = severity;
|
|
1856
|
-
if (start_time) params.start_time = start_time;
|
|
1857
|
-
if (end_time) params.end_time = end_time;
|
|
1858
|
-
const result = await getLogsWithFallback(client, EVENT_LOG_PATHS, params);
|
|
1862
|
+
const result = await getWithFallback(client, ["log/events", "reporting/log/events"]);
|
|
1859
1863
|
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1860
|
-
} catch (
|
|
1861
|
-
return { content: [{ type: "text", text: `Error: ${
|
|
1864
|
+
} catch (error) {
|
|
1865
|
+
return { content: [{ type: "text", text: `Error: ${error.message}` }], isError: true };
|
|
1862
1866
|
}
|
|
1863
1867
|
}
|
|
1864
1868
|
);
|
|
@@ -2004,7 +2008,7 @@ async function main() {
|
|
|
2004
2008
|
const registry = new DeviceRegistry(config.profiles);
|
|
2005
2009
|
const server = new import_mcp.McpServer({
|
|
2006
2010
|
name: "sonicwall-mcp-server",
|
|
2007
|
-
version: "0.
|
|
2011
|
+
version: "0.6.0",
|
|
2008
2012
|
instructions: `SonicWall NSA MCP server \u2014 full read/write access to SonicWall firewalls via the SonicOS REST API.
|
|
2009
2013
|
|
|
2010
2014
|
## Device targeting
|
|
@@ -2013,22 +2017,16 @@ Use list_devices to discover available appliances and their names. Pass device='
|
|
|
2013
2017
|
## Staged configuration
|
|
2014
2018
|
IMPORTANT: All create/update/delete operations are STAGED and do not take effect until you call commit_config. Call discard_config to abandon staged changes. Always commit after completing a related set of changes, or discard if the user changes their mind. Never leave uncommitted changes unless the user explicitly asks to review before committing.
|
|
2015
2019
|
|
|
2016
|
-
##
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
## Log querying
|
|
2020
|
-
- Call get_log_categories first to discover valid category names for get_event_logs.
|
|
2021
|
-
- get_event_logs: general system/security events. Filter by category, priority, source_ip, or keyword.
|
|
2022
|
-
- get_threat_logs: IPS and AV detections. Filter by severity.
|
|
2023
|
-
- search_logs: full-text keyword search across event logs \u2014 use when you have a specific IP, hostname, or error string.
|
|
2024
|
-
- Default count is 100. Increase for broader searches, but keep it reasonable to avoid large payloads.
|
|
2020
|
+
## Log configuration
|
|
2021
|
+
- get_log_categories and list_log_event_definitions return logging configuration, not recorded event history.
|
|
2022
|
+
- SonicOS does not expose runtime event, threat, connection, or traffic history through the documented REST API. Do not use these tools to search for IP addresses or incidents.
|
|
2025
2023
|
|
|
2026
2024
|
## Object and rule management
|
|
2027
2025
|
- Address objects (IPv4/IPv6/FQDN/MAC) and groups are the building blocks of access rules and NAT policies. Use list_address_objects / list_address_groups to discover existing objects before creating rules.
|
|
2028
2026
|
- Service objects define protocol/port combinations. Use list_service_objects and list_service_groups to discover available services before referencing them in rules.
|
|
2029
2027
|
- Typical workflow for a new firewall rule: list_address_objects \u2192 create_address_object_ipv4/fqdn/etc if needed \u2192 list_service_objects \u2192 create_service_object if needed \u2192 create_access_rule \u2192 commit_config.
|
|
2030
2028
|
- Access rules (create_access_rule / list_access_rules) control traffic flow between zones with allow/deny/discard actions. Security policies (create_security_policy / list_security_policies) are zone-based and additionally support user and schedule filtering \u2014 use them when you need user-aware or time-restricted policies.
|
|
2031
|
-
- Always call list_access_rules, list_nat_policies, or list_security_policies before modifying, to confirm current state and avoid duplicates.
|
|
2029
|
+
- Always call list_access_rules, list_nat_policies, or list_security_policies before modifying, to confirm current state and avoid duplicates. Access-rule and NAT-policy mutations use the UUID returned by their list tools; numeric IDs are not accepted.
|
|
2032
2030
|
- Rules and policies reference zones and schedules by name: use list_zones and list_schedules to discover valid names. list_interfaces shows interface IP/zone assignments and list_route_policies shows static routing \u2014 both are read-only discovery aids.
|
|
2033
2031
|
- lookup_ip_country identifies which country an IP address belongs to (uses the appliance GeoIP database). Note: GeoIP *policy* management is not available via the SonicOS REST API.
|
|
2034
2032
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnetwork-nz/sonicwall-api-mcp-server",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server for SonicWall NSA appliance
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "MCP server for SonicWall NSA appliance configuration — objects, rules, NAT, routing, and GeoIP lookup",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
7
7
|
"model-context-protocol",
|