@teamnetwork-nz/sonicwall-api-mcp-server 0.6.0 → 0.7.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/dist/index.js +57 -24
- package/package.json +50 -50
package/dist/index.js
CHANGED
|
@@ -377,9 +377,21 @@ var SonicWallClient = class {
|
|
|
377
377
|
await this.auth.logout(this.baseUrl);
|
|
378
378
|
}
|
|
379
379
|
async request(method, path, options) {
|
|
380
|
-
|
|
380
|
+
const isWrite = WRITE_METHODS.has(method.toUpperCase());
|
|
381
|
+
if (this.profile.readOnly && isWrite) {
|
|
381
382
|
throw new ReadOnlyError(method.toUpperCase(), path);
|
|
382
383
|
}
|
|
384
|
+
try {
|
|
385
|
+
return await this.send(method, path, options);
|
|
386
|
+
} catch (e) {
|
|
387
|
+
if (isWrite && e instanceof APIError && e.code === "E_NON_CONFIG") {
|
|
388
|
+
await this.send("POST", "config-mode");
|
|
389
|
+
return this.send(method, path, options);
|
|
390
|
+
}
|
|
391
|
+
throw e;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
async send(method, path, options) {
|
|
383
395
|
let url = `${this.baseUrl}/${path.replace(/^\//, "")}`;
|
|
384
396
|
if (options?.params && Object.keys(options.params).length > 0) {
|
|
385
397
|
const qs = new URLSearchParams(
|
|
@@ -1396,8 +1408,25 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1396
1408
|
|
|
1397
1409
|
// src/tools/nat-policies.ts
|
|
1398
1410
|
var import_zod7 = require("zod");
|
|
1399
|
-
function
|
|
1400
|
-
|
|
1411
|
+
function interfaceValue(value) {
|
|
1412
|
+
return value.toLowerCase() === "any" ? "any" : value;
|
|
1413
|
+
}
|
|
1414
|
+
async function resolveRef(client, kind, value, ipVersion, allowOriginal) {
|
|
1415
|
+
const lower = value.toLowerCase();
|
|
1416
|
+
if (lower === "any") return { any: true };
|
|
1417
|
+
if (allowOriginal && lower === "original") return { original: true };
|
|
1418
|
+
const groupPath = kind === "address" ? `address-groups/${ipVersion}/name/${encodeURIComponent(value)}` : `service-groups/name/${encodeURIComponent(value)}`;
|
|
1419
|
+
try {
|
|
1420
|
+
await client.get(groupPath);
|
|
1421
|
+
return { group: value };
|
|
1422
|
+
} catch (e) {
|
|
1423
|
+
if (e instanceof APIError) return { name: value };
|
|
1424
|
+
throw e;
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
var prioritySchema = import_zod7.z.union([import_zod7.z.number().int().min(1), import_zod7.z.literal("auto")]).optional().describe("Rule order: lower number = evaluated first. A positive integer sets a manual priority; 'auto' lets SonicOS assign it.");
|
|
1428
|
+
function priorityField(priority) {
|
|
1429
|
+
return priority === "auto" ? { auto: true } : { manual: priority };
|
|
1401
1430
|
}
|
|
1402
1431
|
function registerNatPolicyTools(server, registry) {
|
|
1403
1432
|
server.tool(
|
|
@@ -1437,7 +1466,7 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1437
1466
|
);
|
|
1438
1467
|
server.tool(
|
|
1439
1468
|
"create_nat_policy",
|
|
1440
|
-
"Create a NAT policy.
|
|
1469
|
+
"Create a NAT policy. Address and service fields take an object or group name (groups are detected automatically) or 'Any'; translated fields also accept 'Original' for no translation. Interfaces take a name like 'X1' or 'Any'. Optional priority sets rule order (lower number = evaluated first). Changes are STAGED; call commit_config to apply.",
|
|
1441
1470
|
{
|
|
1442
1471
|
name: import_zod7.z.string(),
|
|
1443
1472
|
original_source: import_zod7.z.string(),
|
|
@@ -1451,26 +1480,28 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1451
1480
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1452
1481
|
enabled: import_zod7.z.boolean().optional().default(true),
|
|
1453
1482
|
dns_doctoring: import_zod7.z.boolean().optional().default(false),
|
|
1483
|
+
priority: prioritySchema,
|
|
1454
1484
|
comment: import_zod7.z.string().optional(),
|
|
1455
1485
|
device: import_zod7.z.string().optional()
|
|
1456
1486
|
},
|
|
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 }) => {
|
|
1487
|
+
async ({ name, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, ip_version, enabled, dns_doctoring, priority, comment, device }) => {
|
|
1458
1488
|
try {
|
|
1459
1489
|
const client = await registry.getClient(device);
|
|
1460
1490
|
const policy = {
|
|
1461
1491
|
name,
|
|
1462
1492
|
enable: enabled,
|
|
1463
|
-
source:
|
|
1464
|
-
translated_source:
|
|
1465
|
-
destination:
|
|
1466
|
-
translated_destination:
|
|
1467
|
-
service:
|
|
1468
|
-
translated_service:
|
|
1469
|
-
inbound:
|
|
1470
|
-
outbound:
|
|
1493
|
+
source: await resolveRef(client, "address", original_source, ip_version, false),
|
|
1494
|
+
translated_source: await resolveRef(client, "address", translated_source, ip_version, true),
|
|
1495
|
+
destination: await resolveRef(client, "address", original_destination, ip_version, false),
|
|
1496
|
+
translated_destination: await resolveRef(client, "address", translated_destination, ip_version, true),
|
|
1497
|
+
service: await resolveRef(client, "service", original_service, ip_version, false),
|
|
1498
|
+
translated_service: await resolveRef(client, "service", translated_service, ip_version, true),
|
|
1499
|
+
inbound: interfaceValue(inbound_interface),
|
|
1500
|
+
outbound: interfaceValue(outbound_interface),
|
|
1471
1501
|
dns_doctoring
|
|
1472
1502
|
};
|
|
1473
1503
|
if (comment) policy.comment = comment;
|
|
1504
|
+
if (priority !== void 0) policy.priority = priorityField(priority);
|
|
1474
1505
|
const result = await client.post(`nat-policies/${ip_version}`, {
|
|
1475
1506
|
nat_policies: [{ [ip_version]: policy }]
|
|
1476
1507
|
});
|
|
@@ -1482,7 +1513,7 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1482
1513
|
);
|
|
1483
1514
|
server.tool(
|
|
1484
1515
|
"update_nat_policy",
|
|
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.",
|
|
1516
|
+
"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. priority changes rule order (lower number = evaluated first; 'auto' lets SonicOS assign it). Position 1 is held by the built-in IKE policy, so use 2 or higher; an unavailable priority can return success yet be ignored, so confirm with get_nat_policy. Changes are STAGED; call commit_config to apply.",
|
|
1486
1517
|
{
|
|
1487
1518
|
policy_uuid: import_zod7.z.string().uuid(),
|
|
1488
1519
|
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
@@ -1496,27 +1527,29 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1496
1527
|
outbound_interface: import_zod7.z.string().optional(),
|
|
1497
1528
|
enabled: import_zod7.z.boolean().optional(),
|
|
1498
1529
|
dns_doctoring: import_zod7.z.boolean().optional(),
|
|
1530
|
+
priority: prioritySchema,
|
|
1499
1531
|
comment: import_zod7.z.string().optional(),
|
|
1500
1532
|
device: import_zod7.z.string().optional()
|
|
1501
1533
|
},
|
|
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 }) => {
|
|
1534
|
+
async ({ policy_uuid, ip_version, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, enabled, dns_doctoring, priority, comment, device }) => {
|
|
1503
1535
|
try {
|
|
1504
1536
|
const client = await registry.getClient(device);
|
|
1505
1537
|
const path = `nat-policies/${ip_version}/uuid/${encodeURIComponent(policy_uuid)}`;
|
|
1506
1538
|
const current = await client.get(path);
|
|
1507
1539
|
const policies = current.nat_policies;
|
|
1508
1540
|
const policy = policies?.[0]?.[ip_version] ?? {};
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1541
|
+
if (original_source !== void 0) policy.source = await resolveRef(client, "address", original_source, ip_version, false);
|
|
1542
|
+
if (translated_source !== void 0) policy.translated_source = await resolveRef(client, "address", translated_source, ip_version, true);
|
|
1543
|
+
if (original_destination !== void 0) policy.destination = await resolveRef(client, "address", original_destination, ip_version, false);
|
|
1544
|
+
if (translated_destination !== void 0) policy.translated_destination = await resolveRef(client, "address", translated_destination, ip_version, true);
|
|
1545
|
+
if (original_service !== void 0) policy.service = await resolveRef(client, "service", original_service, ip_version, false);
|
|
1546
|
+
if (translated_service !== void 0) policy.translated_service = await resolveRef(client, "service", translated_service, ip_version, true);
|
|
1547
|
+
if (inbound_interface !== void 0) policy.inbound = interfaceValue(inbound_interface);
|
|
1548
|
+
if (outbound_interface !== void 0) policy.outbound = interfaceValue(outbound_interface);
|
|
1517
1549
|
if (enabled !== void 0) policy.enable = enabled;
|
|
1518
1550
|
if (dns_doctoring !== void 0) policy.dns_doctoring = dns_doctoring;
|
|
1519
1551
|
if (comment !== void 0) policy.comment = comment;
|
|
1552
|
+
if (priority !== void 0) policy.priority = priorityField(priority);
|
|
1520
1553
|
const result = await client.put(path, {
|
|
1521
1554
|
nat_policies: [{ [ip_version]: policy }]
|
|
1522
1555
|
});
|
|
@@ -2008,7 +2041,7 @@ async function main() {
|
|
|
2008
2041
|
const registry = new DeviceRegistry(config.profiles);
|
|
2009
2042
|
const server = new import_mcp.McpServer({
|
|
2010
2043
|
name: "sonicwall-mcp-server",
|
|
2011
|
-
version: "0.
|
|
2044
|
+
version: "0.7.0",
|
|
2012
2045
|
instructions: `SonicWall NSA MCP server \u2014 full read/write access to SonicWall firewalls via the SonicOS REST API.
|
|
2013
2046
|
|
|
2014
2047
|
## Device targeting
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@teamnetwork-nz/sonicwall-api-mcp-server",
|
|
3
|
-
"version": "0.
|
|
1
|
+
{
|
|
2
|
+
"name": "@teamnetwork-nz/sonicwall-api-mcp-server",
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "MCP server for SonicWall NSA appliance configuration — objects, rules, NAT, routing, and GeoIP lookup",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"mcp",
|
|
7
|
-
"model-context-protocol",
|
|
8
|
-
"sonicwall",
|
|
9
|
-
"firewall",
|
|
10
|
-
"sonicOS",
|
|
11
|
-
"api",
|
|
12
|
-
"network",
|
|
13
|
-
"security"
|
|
14
|
-
],
|
|
15
|
-
"homepage": "https://github.com/teamnetwork-nz/sonicwall-api-mcp-server",
|
|
16
|
-
"bugs": {
|
|
17
|
-
"url": "https://github.com/teamnetwork-nz/sonicwall-api-mcp-server/issues"
|
|
18
|
-
},
|
|
19
|
-
"license": "MIT",
|
|
20
|
-
"author": "Daryl",
|
|
21
|
-
"repository": {
|
|
22
|
-
"type": "git",
|
|
23
|
-
"url": "https://github.com/teamnetwork-nz/sonicwall-api-mcp-server.git"
|
|
24
|
-
},
|
|
25
|
-
"main": "dist/index.js",
|
|
26
|
-
"bin": {
|
|
27
|
-
"sonicwall-mcp": "./dist/index.js"
|
|
28
|
-
},
|
|
29
|
-
"files": [
|
|
30
|
-
"dist/",
|
|
31
|
-
"README.md",
|
|
32
|
-
"LICENSE"
|
|
33
|
-
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "tsup",
|
|
36
|
-
"prepublishOnly": "npm run build",
|
|
37
|
-
"start": "node dist/index.js"
|
|
38
|
-
},
|
|
39
|
-
"engines": {
|
|
40
|
-
"node": ">=18"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"@modelcontextprotocol/sdk": "^1.10.0",
|
|
44
|
-
"zod": "^3.23.0"
|
|
45
|
-
},
|
|
46
|
-
"devDependencies": {
|
|
47
|
-
"@types/node": "^20.0.0",
|
|
48
|
-
"tsup": "^8.0.0",
|
|
49
|
-
"typescript": "^5.4.0"
|
|
50
|
-
}
|
|
51
|
-
}
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"model-context-protocol",
|
|
8
|
+
"sonicwall",
|
|
9
|
+
"firewall",
|
|
10
|
+
"sonicOS",
|
|
11
|
+
"api",
|
|
12
|
+
"network",
|
|
13
|
+
"security"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/teamnetwork-nz/sonicwall-api-mcp-server",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/teamnetwork-nz/sonicwall-api-mcp-server/issues"
|
|
18
|
+
},
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"author": "Daryl",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/teamnetwork-nz/sonicwall-api-mcp-server.git"
|
|
24
|
+
},
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"bin": {
|
|
27
|
+
"sonicwall-mcp": "./dist/index.js"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist/",
|
|
31
|
+
"README.md",
|
|
32
|
+
"LICENSE"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"prepublishOnly": "npm run build",
|
|
37
|
+
"start": "node dist/index.js"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.10.0",
|
|
44
|
+
"zod": "^3.23.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^20.0.0",
|
|
48
|
+
"tsup": "^8.0.0",
|
|
49
|
+
"typescript": "^5.4.0"
|
|
50
|
+
}
|
|
51
|
+
}
|