@teamnetwork-nz/sonicwall-api-mcp-server 0.8.0 → 0.9.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 +11 -4
- package/dist/env.js +41 -0
- package/dist/index.js +469 -252
- package/dist/strict-tools.js +53 -0
- package/dist/write-gate.js +39 -0
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -29,6 +29,48 @@ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
|
29
29
|
|
|
30
30
|
// src/config.ts
|
|
31
31
|
var fs = __toESM(require("fs"));
|
|
32
|
+
|
|
33
|
+
// src/write-gate.ts
|
|
34
|
+
function readWriteEnabled(canonicalName, legacy, env = process.env) {
|
|
35
|
+
const canonical = env[canonicalName];
|
|
36
|
+
if (canonical !== void 0) return canonical.toLowerCase() === "true";
|
|
37
|
+
if (!legacy || env[legacy.name] === void 0) return false;
|
|
38
|
+
process.stderr.write(`[deprecated] ${legacy.name} is deprecated; use ${canonicalName}=true to enable writes.
|
|
39
|
+
`);
|
|
40
|
+
const value = env[legacy.name].toLowerCase();
|
|
41
|
+
return legacy.readonlySemantics ? value === "false" : value === "true";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/env.ts
|
|
45
|
+
function parsePositiveInt(name, raw, fallback, maximum) {
|
|
46
|
+
if (raw === void 0 || raw.trim() === "") return fallback;
|
|
47
|
+
if (!/^\d+$/.test(raw.trim())) {
|
|
48
|
+
throw new Error(`${name} must be an integer from 1 to ${maximum}`);
|
|
49
|
+
}
|
|
50
|
+
const value = Number(raw);
|
|
51
|
+
if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
|
|
52
|
+
throw new Error(`${name} must be an integer from 1 to ${maximum}`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/config.ts
|
|
58
|
+
var import_zod = require("zod");
|
|
59
|
+
var DeviceProfileSchema = import_zod.z.object({
|
|
60
|
+
name: import_zod.z.string().min(1),
|
|
61
|
+
host: import_zod.z.string().min(1),
|
|
62
|
+
username: import_zod.z.string().min(1),
|
|
63
|
+
password: import_zod.z.string().min(1),
|
|
64
|
+
port: import_zod.z.number().int().min(1).max(65535),
|
|
65
|
+
sslVerify: import_zod.z.boolean(),
|
|
66
|
+
readOnly: import_zod.z.boolean(),
|
|
67
|
+
requestTimeout: import_zod.z.number().int().min(1).max(300)
|
|
68
|
+
}).strict();
|
|
69
|
+
var ConfigSchema = import_zod.z.object({
|
|
70
|
+
profiles: import_zod.z.array(DeviceProfileSchema).min(1),
|
|
71
|
+
transport: import_zod.z.enum(["stdio", "http"]),
|
|
72
|
+
ssePort: import_zod.z.number().int().min(1).max(65535)
|
|
73
|
+
}).strict();
|
|
32
74
|
function loadConfig() {
|
|
33
75
|
const devicesFile = process.env.SONICWALL_DEVICES_FILE;
|
|
34
76
|
let profiles = [];
|
|
@@ -37,7 +79,7 @@ function loadConfig() {
|
|
|
37
79
|
if (!Array.isArray(data) || data.length === 0) {
|
|
38
80
|
throw new Error("SONICWALL_DEVICES_FILE must be a non-empty JSON array");
|
|
39
81
|
}
|
|
40
|
-
profiles = data.map((d) => ({
|
|
82
|
+
profiles = data.map((d) => DeviceProfileSchema.parse({
|
|
41
83
|
name: d.name,
|
|
42
84
|
host: d.host,
|
|
43
85
|
username: d.username,
|
|
@@ -56,22 +98,22 @@ function loadConfig() {
|
|
|
56
98
|
"Set SONICWALL_HOST, SONICWALL_USERNAME, and SONICWALL_PASSWORD (or SONICWALL_DEVICES_FILE for multi-device)"
|
|
57
99
|
);
|
|
58
100
|
}
|
|
59
|
-
profiles = [{
|
|
101
|
+
profiles = [DeviceProfileSchema.parse({
|
|
60
102
|
name: process.env.SONICWALL_DEVICE_NAME ?? "default",
|
|
61
103
|
host,
|
|
62
104
|
username,
|
|
63
105
|
password,
|
|
64
|
-
port:
|
|
106
|
+
port: parsePositiveInt("SONICWALL_PORT", process.env.SONICWALL_PORT, 443, 65535),
|
|
65
107
|
sslVerify: (process.env.SONICWALL_SSL_VERIFY ?? "true") !== "false",
|
|
66
|
-
readOnly: (
|
|
67
|
-
requestTimeout:
|
|
68
|
-
}];
|
|
108
|
+
readOnly: !readWriteEnabled("SONICWALL_READWRITE", { name: "SONICWALL_READ_ONLY", readonlySemantics: true }),
|
|
109
|
+
requestTimeout: parsePositiveInt("SONICWALL_REQUEST_TIMEOUT", process.env.SONICWALL_REQUEST_TIMEOUT, 30, 300)
|
|
110
|
+
})];
|
|
69
111
|
}
|
|
70
|
-
return {
|
|
112
|
+
return ConfigSchema.parse({
|
|
71
113
|
profiles,
|
|
72
114
|
transport: process.env.SONICWALL_TRANSPORT ?? "stdio",
|
|
73
|
-
ssePort:
|
|
74
|
-
};
|
|
115
|
+
ssePort: parsePositiveInt("SONICWALL_SSE_PORT", process.env.SONICWALL_SSE_PORT, 8e3, 65535)
|
|
116
|
+
});
|
|
75
117
|
}
|
|
76
118
|
|
|
77
119
|
// src/auth.ts
|
|
@@ -264,8 +306,8 @@ var AuthManager = class {
|
|
|
264
306
|
throw new AuthenticationError("Login rejected \u2014 check username and password.");
|
|
265
307
|
}
|
|
266
308
|
if (resp.status >= 400) {
|
|
267
|
-
const
|
|
268
|
-
throw new AuthenticationError(`Login failed with HTTP ${resp.status}: ${
|
|
309
|
+
const text2 = await resp.text().catch(() => "");
|
|
310
|
+
throw new AuthenticationError(`Login failed with HTTP ${resp.status}: ${text2.slice(0, 200)}`);
|
|
269
311
|
}
|
|
270
312
|
try {
|
|
271
313
|
const body = await resp.json();
|
|
@@ -290,7 +332,7 @@ var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
|
290
332
|
var ReadOnlyError = class extends Error {
|
|
291
333
|
constructor(method, path) {
|
|
292
334
|
super(
|
|
293
|
-
`${method} ${path} is a write operation but the server is in read-only mode. Set
|
|
335
|
+
`${method} ${path} is a write operation but the server is in read-only mode. Set SONICWALL_READWRITE=true to enable write access.`
|
|
294
336
|
);
|
|
295
337
|
this.name = "ReadOnlyError";
|
|
296
338
|
}
|
|
@@ -377,7 +419,7 @@ var SonicWallClient = class {
|
|
|
377
419
|
await this.auth.logout(this.baseUrl);
|
|
378
420
|
}
|
|
379
421
|
async request(method, path, options) {
|
|
380
|
-
const isWrite = WRITE_METHODS.has(method.toUpperCase());
|
|
422
|
+
const isWrite = WRITE_METHODS.has(method.toUpperCase()) && !options?.readonlyAction;
|
|
381
423
|
if (this.profile.readOnly && isWrite) {
|
|
382
424
|
throw new ReadOnlyError(method.toUpperCase(), path);
|
|
383
425
|
}
|
|
@@ -430,8 +472,8 @@ var SonicWallClient = class {
|
|
|
430
472
|
await this._throwApiError(resp);
|
|
431
473
|
}
|
|
432
474
|
this.auth.touch();
|
|
433
|
-
const
|
|
434
|
-
return
|
|
475
|
+
const text2 = await resp.text();
|
|
476
|
+
return text2 ? JSON.parse(text2) : {};
|
|
435
477
|
}
|
|
436
478
|
throw new Error("unreachable");
|
|
437
479
|
}
|
|
@@ -464,6 +506,10 @@ var SonicWallClient = class {
|
|
|
464
506
|
post(path, body) {
|
|
465
507
|
return this.request("POST", path, { body });
|
|
466
508
|
}
|
|
509
|
+
/** Execute a POST endpoint whose semantics are read-only (for example diagnostics). */
|
|
510
|
+
postAction(path, body) {
|
|
511
|
+
return this.request("POST", path, { body, readonlyAction: true });
|
|
512
|
+
}
|
|
467
513
|
put(path, body) {
|
|
468
514
|
return this.request("PUT", path, { body });
|
|
469
515
|
}
|
|
@@ -524,7 +570,7 @@ var DeviceRegistry = class {
|
|
|
524
570
|
};
|
|
525
571
|
|
|
526
572
|
// src/tools/system.ts
|
|
527
|
-
var
|
|
573
|
+
var import_zod2 = require("zod");
|
|
528
574
|
function registerSystemTools(server, registry) {
|
|
529
575
|
server.tool(
|
|
530
576
|
"list_devices",
|
|
@@ -542,7 +588,7 @@ function registerSystemTools(server, registry) {
|
|
|
542
588
|
server.tool(
|
|
543
589
|
"get_system_status",
|
|
544
590
|
"Return device model, firmware version, serial number, and uptime.",
|
|
545
|
-
{ device:
|
|
591
|
+
{ device: import_zod2.z.string().optional() },
|
|
546
592
|
async ({ device }) => {
|
|
547
593
|
try {
|
|
548
594
|
const client = await registry.getClient(device);
|
|
@@ -556,7 +602,7 @@ function registerSystemTools(server, registry) {
|
|
|
556
602
|
server.tool(
|
|
557
603
|
"commit_config",
|
|
558
604
|
"Commit all staged configuration changes so they take effect on the appliance. Must be called after any create/update/delete operation or changes will be lost.",
|
|
559
|
-
{ device:
|
|
605
|
+
{ device: import_zod2.z.string().optional() },
|
|
560
606
|
async ({ device }) => {
|
|
561
607
|
try {
|
|
562
608
|
const client = await registry.getClient(device);
|
|
@@ -570,7 +616,7 @@ function registerSystemTools(server, registry) {
|
|
|
570
616
|
server.tool(
|
|
571
617
|
"discard_config",
|
|
572
618
|
"Discard all staged configuration changes without applying them.",
|
|
573
|
-
{ device:
|
|
619
|
+
{ device: import_zod2.z.string().optional() },
|
|
574
620
|
async ({ device }) => {
|
|
575
621
|
try {
|
|
576
622
|
const client = await registry.getClient(device);
|
|
@@ -584,7 +630,7 @@ function registerSystemTools(server, registry) {
|
|
|
584
630
|
server.tool(
|
|
585
631
|
"get_pending_config",
|
|
586
632
|
"Show configuration changes that have been staged but not yet committed.",
|
|
587
|
-
{ device:
|
|
633
|
+
{ device: import_zod2.z.string().optional() },
|
|
588
634
|
async ({ device }) => {
|
|
589
635
|
try {
|
|
590
636
|
const client = await registry.getClient(device);
|
|
@@ -598,15 +644,15 @@ function registerSystemTools(server, registry) {
|
|
|
598
644
|
}
|
|
599
645
|
|
|
600
646
|
// src/tools/address-objects.ts
|
|
601
|
-
var
|
|
647
|
+
var import_zod3 = require("zod");
|
|
602
648
|
var ALL_TYPES = ["ipv4", "ipv6", "fqdn", "mac"];
|
|
603
649
|
function registerAddressObjectTools(server, registry) {
|
|
604
650
|
server.tool(
|
|
605
651
|
"list_address_objects",
|
|
606
652
|
"List address objects on the appliance. type: filter by 'ipv4', 'ipv6', 'fqdn', 'mac', or 'all' (default).",
|
|
607
653
|
{
|
|
608
|
-
type:
|
|
609
|
-
device:
|
|
654
|
+
type: import_zod3.z.enum(["ipv4", "ipv6", "fqdn", "mac", "all"]).optional().default("all"),
|
|
655
|
+
device: import_zod3.z.string().optional()
|
|
610
656
|
},
|
|
611
657
|
async ({ type, device }) => {
|
|
612
658
|
try {
|
|
@@ -637,9 +683,9 @@ function registerAddressObjectTools(server, registry) {
|
|
|
637
683
|
"get_address_object",
|
|
638
684
|
"Retrieve a single address object by name and type.",
|
|
639
685
|
{
|
|
640
|
-
name:
|
|
641
|
-
type:
|
|
642
|
-
device:
|
|
686
|
+
name: import_zod3.z.string(),
|
|
687
|
+
type: import_zod3.z.enum(["ipv4", "ipv6", "fqdn", "mac"]),
|
|
688
|
+
device: import_zod3.z.string().optional()
|
|
643
689
|
},
|
|
644
690
|
async ({ name, type, device }) => {
|
|
645
691
|
try {
|
|
@@ -655,14 +701,14 @@ function registerAddressObjectTools(server, registry) {
|
|
|
655
701
|
"create_address_object_ipv4",
|
|
656
702
|
"Create an IPv4 address object. Provide exactly one of: host (single IP or CIDR), network+subnet_mask, or range_begin+range_end. Changes are STAGED; call commit_config to apply.",
|
|
657
703
|
{
|
|
658
|
-
name:
|
|
659
|
-
zone:
|
|
660
|
-
host:
|
|
661
|
-
network:
|
|
662
|
-
subnet_mask:
|
|
663
|
-
range_begin:
|
|
664
|
-
range_end:
|
|
665
|
-
device:
|
|
704
|
+
name: import_zod3.z.string(),
|
|
705
|
+
zone: import_zod3.z.string(),
|
|
706
|
+
host: import_zod3.z.string().optional(),
|
|
707
|
+
network: import_zod3.z.string().optional(),
|
|
708
|
+
subnet_mask: import_zod3.z.string().optional(),
|
|
709
|
+
range_begin: import_zod3.z.string().optional(),
|
|
710
|
+
range_end: import_zod3.z.string().optional(),
|
|
711
|
+
device: import_zod3.z.string().optional()
|
|
666
712
|
},
|
|
667
713
|
async ({ name, zone, host, network, subnet_mask, range_begin, range_end, device }) => {
|
|
668
714
|
try {
|
|
@@ -688,12 +734,12 @@ function registerAddressObjectTools(server, registry) {
|
|
|
688
734
|
"create_address_object_ipv6",
|
|
689
735
|
"Create an IPv6 address object. Provide either address (single IPv6) or network+prefix_length. Changes are STAGED; call commit_config to apply.",
|
|
690
736
|
{
|
|
691
|
-
name:
|
|
692
|
-
zone:
|
|
693
|
-
address:
|
|
694
|
-
network:
|
|
695
|
-
prefix_length:
|
|
696
|
-
device:
|
|
737
|
+
name: import_zod3.z.string(),
|
|
738
|
+
zone: import_zod3.z.string(),
|
|
739
|
+
address: import_zod3.z.string().optional(),
|
|
740
|
+
network: import_zod3.z.string().optional(),
|
|
741
|
+
prefix_length: import_zod3.z.number().optional(),
|
|
742
|
+
device: import_zod3.z.string().optional()
|
|
697
743
|
},
|
|
698
744
|
async ({ name, zone, address, network, prefix_length, device }) => {
|
|
699
745
|
try {
|
|
@@ -717,10 +763,10 @@ function registerAddressObjectTools(server, registry) {
|
|
|
717
763
|
"create_address_object_fqdn",
|
|
718
764
|
"Create an FQDN address object. Changes are STAGED; call commit_config to apply.",
|
|
719
765
|
{
|
|
720
|
-
name:
|
|
721
|
-
zone:
|
|
722
|
-
domain:
|
|
723
|
-
device:
|
|
766
|
+
name: import_zod3.z.string(),
|
|
767
|
+
zone: import_zod3.z.string(),
|
|
768
|
+
domain: import_zod3.z.string(),
|
|
769
|
+
device: import_zod3.z.string().optional()
|
|
724
770
|
},
|
|
725
771
|
async ({ name, zone, domain, device }) => {
|
|
726
772
|
try {
|
|
@@ -738,14 +784,14 @@ function registerAddressObjectTools(server, registry) {
|
|
|
738
784
|
"update_address_object",
|
|
739
785
|
"Update an existing address object. Only supplied fields are changed (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
740
786
|
{
|
|
741
|
-
name:
|
|
742
|
-
type:
|
|
743
|
-
zone:
|
|
744
|
-
host:
|
|
745
|
-
network:
|
|
746
|
-
subnet_mask:
|
|
747
|
-
domain:
|
|
748
|
-
device:
|
|
787
|
+
name: import_zod3.z.string(),
|
|
788
|
+
type: import_zod3.z.enum(["ipv4", "ipv6", "fqdn", "mac"]),
|
|
789
|
+
zone: import_zod3.z.string().optional(),
|
|
790
|
+
host: import_zod3.z.string().optional(),
|
|
791
|
+
network: import_zod3.z.string().optional(),
|
|
792
|
+
subnet_mask: import_zod3.z.string().optional(),
|
|
793
|
+
domain: import_zod3.z.string().optional(),
|
|
794
|
+
device: import_zod3.z.string().optional()
|
|
749
795
|
},
|
|
750
796
|
async ({ name, type, zone, host, network, subnet_mask, domain, device }) => {
|
|
751
797
|
try {
|
|
@@ -770,9 +816,9 @@ function registerAddressObjectTools(server, registry) {
|
|
|
770
816
|
"delete_address_object",
|
|
771
817
|
"Delete an address object by name and type. Changes are STAGED; call commit_config to apply.",
|
|
772
818
|
{
|
|
773
|
-
name:
|
|
774
|
-
type:
|
|
775
|
-
device:
|
|
819
|
+
name: import_zod3.z.string(),
|
|
820
|
+
type: import_zod3.z.enum(["ipv4", "ipv6", "fqdn", "mac"]),
|
|
821
|
+
device: import_zod3.z.string().optional()
|
|
776
822
|
},
|
|
777
823
|
async ({ name, type, device }) => {
|
|
778
824
|
try {
|
|
@@ -787,14 +833,14 @@ function registerAddressObjectTools(server, registry) {
|
|
|
787
833
|
}
|
|
788
834
|
|
|
789
835
|
// src/tools/address-groups.ts
|
|
790
|
-
var
|
|
836
|
+
var import_zod4 = require("zod");
|
|
791
837
|
function registerAddressGroupTools(server, registry) {
|
|
792
838
|
server.tool(
|
|
793
839
|
"list_address_groups",
|
|
794
840
|
"List address groups on the appliance. type: filter by 'ipv4', 'ipv6', or 'all' (default).",
|
|
795
841
|
{
|
|
796
|
-
type:
|
|
797
|
-
device:
|
|
842
|
+
type: import_zod4.z.enum(["ipv4", "ipv6", "all"]).optional().default("all"),
|
|
843
|
+
device: import_zod4.z.string().optional()
|
|
798
844
|
},
|
|
799
845
|
async ({ type, device }) => {
|
|
800
846
|
try {
|
|
@@ -825,9 +871,9 @@ function registerAddressGroupTools(server, registry) {
|
|
|
825
871
|
"get_address_group",
|
|
826
872
|
"Retrieve a single address group by name.",
|
|
827
873
|
{
|
|
828
|
-
name:
|
|
829
|
-
type:
|
|
830
|
-
device:
|
|
874
|
+
name: import_zod4.z.string(),
|
|
875
|
+
type: import_zod4.z.enum(["ipv4", "ipv6"]),
|
|
876
|
+
device: import_zod4.z.string().optional()
|
|
831
877
|
},
|
|
832
878
|
async ({ name, type, device }) => {
|
|
833
879
|
try {
|
|
@@ -843,10 +889,10 @@ function registerAddressGroupTools(server, registry) {
|
|
|
843
889
|
"create_address_group",
|
|
844
890
|
"Create an address group with the given member object names. members: list of address object names. Changes are STAGED; call commit_config to apply.",
|
|
845
891
|
{
|
|
846
|
-
name:
|
|
847
|
-
type:
|
|
848
|
-
members:
|
|
849
|
-
device:
|
|
892
|
+
name: import_zod4.z.string(),
|
|
893
|
+
type: import_zod4.z.enum(["ipv4", "ipv6"]),
|
|
894
|
+
members: import_zod4.z.array(import_zod4.z.string()),
|
|
895
|
+
device: import_zod4.z.string().optional()
|
|
850
896
|
},
|
|
851
897
|
async ({ name, type, members, device }) => {
|
|
852
898
|
try {
|
|
@@ -865,10 +911,10 @@ function registerAddressGroupTools(server, registry) {
|
|
|
865
911
|
"add_address_group_member",
|
|
866
912
|
"Add a member address object to an existing address group. Changes are STAGED; call commit_config to apply.",
|
|
867
913
|
{
|
|
868
|
-
group_name:
|
|
869
|
-
type:
|
|
870
|
-
member_name:
|
|
871
|
-
device:
|
|
914
|
+
group_name: import_zod4.z.string(),
|
|
915
|
+
type: import_zod4.z.enum(["ipv4", "ipv6"]),
|
|
916
|
+
member_name: import_zod4.z.string(),
|
|
917
|
+
device: import_zod4.z.string().optional()
|
|
872
918
|
},
|
|
873
919
|
async ({ group_name, type, member_name, device }) => {
|
|
874
920
|
try {
|
|
@@ -894,10 +940,10 @@ function registerAddressGroupTools(server, registry) {
|
|
|
894
940
|
"remove_address_group_member",
|
|
895
941
|
"Remove a member address object from an address group. Changes are STAGED; call commit_config to apply.",
|
|
896
942
|
{
|
|
897
|
-
group_name:
|
|
898
|
-
type:
|
|
899
|
-
member_name:
|
|
900
|
-
device:
|
|
943
|
+
group_name: import_zod4.z.string(),
|
|
944
|
+
type: import_zod4.z.enum(["ipv4", "ipv6"]),
|
|
945
|
+
member_name: import_zod4.z.string(),
|
|
946
|
+
device: import_zod4.z.string().optional()
|
|
901
947
|
},
|
|
902
948
|
async ({ group_name, type, member_name, device }) => {
|
|
903
949
|
try {
|
|
@@ -920,9 +966,9 @@ function registerAddressGroupTools(server, registry) {
|
|
|
920
966
|
"delete_address_group",
|
|
921
967
|
"Delete an address group by name. Changes are STAGED; call commit_config to apply.",
|
|
922
968
|
{
|
|
923
|
-
name:
|
|
924
|
-
type:
|
|
925
|
-
device:
|
|
969
|
+
name: import_zod4.z.string(),
|
|
970
|
+
type: import_zod4.z.enum(["ipv4", "ipv6"]),
|
|
971
|
+
device: import_zod4.z.string().optional()
|
|
926
972
|
},
|
|
927
973
|
async ({ name, type, device }) => {
|
|
928
974
|
try {
|
|
@@ -937,13 +983,13 @@ function registerAddressGroupTools(server, registry) {
|
|
|
937
983
|
}
|
|
938
984
|
|
|
939
985
|
// src/tools/service-objects.ts
|
|
940
|
-
var
|
|
986
|
+
var import_zod5 = require("zod");
|
|
941
987
|
var PROTOCOLS = ["TCP", "UDP", "ICMP", "ICMPv6", "IGMP", "GRE", "ESP", "AH", "OTHER"];
|
|
942
988
|
function registerServiceObjectTools(server, registry) {
|
|
943
989
|
server.tool(
|
|
944
990
|
"list_service_objects",
|
|
945
991
|
"List all service objects on the appliance.",
|
|
946
|
-
{ device:
|
|
992
|
+
{ device: import_zod5.z.string().optional() },
|
|
947
993
|
async ({ device }) => {
|
|
948
994
|
try {
|
|
949
995
|
const client = await registry.getClient(device);
|
|
@@ -957,7 +1003,7 @@ function registerServiceObjectTools(server, registry) {
|
|
|
957
1003
|
server.tool(
|
|
958
1004
|
"get_service_object",
|
|
959
1005
|
"Retrieve a service object by name.",
|
|
960
|
-
{ name:
|
|
1006
|
+
{ name: import_zod5.z.string(), device: import_zod5.z.string().optional() },
|
|
961
1007
|
async ({ name, device }) => {
|
|
962
1008
|
try {
|
|
963
1009
|
const client = await registry.getClient(device);
|
|
@@ -972,13 +1018,13 @@ function registerServiceObjectTools(server, registry) {
|
|
|
972
1018
|
"create_service_object",
|
|
973
1019
|
"Create a service object. For TCP/UDP: provide port_begin (and optionally port_end for a range). For ICMP/ICMPv6: provide icmp_type and optionally icmp_code. Changes are STAGED; call commit_config to apply.",
|
|
974
1020
|
{
|
|
975
|
-
name:
|
|
976
|
-
protocol:
|
|
977
|
-
port_begin:
|
|
978
|
-
port_end:
|
|
979
|
-
icmp_type:
|
|
980
|
-
icmp_code:
|
|
981
|
-
device:
|
|
1021
|
+
name: import_zod5.z.string(),
|
|
1022
|
+
protocol: import_zod5.z.enum(PROTOCOLS),
|
|
1023
|
+
port_begin: import_zod5.z.number().optional(),
|
|
1024
|
+
port_end: import_zod5.z.number().optional(),
|
|
1025
|
+
icmp_type: import_zod5.z.number().optional(),
|
|
1026
|
+
icmp_code: import_zod5.z.number().optional(),
|
|
1027
|
+
device: import_zod5.z.string().optional()
|
|
982
1028
|
},
|
|
983
1029
|
async ({ name, protocol, port_begin, port_end, icmp_type, icmp_code, device }) => {
|
|
984
1030
|
try {
|
|
@@ -1005,12 +1051,12 @@ function registerServiceObjectTools(server, registry) {
|
|
|
1005
1051
|
"update_service_object",
|
|
1006
1052
|
"Update port or ICMP fields on an existing service object (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
1007
1053
|
{
|
|
1008
|
-
name:
|
|
1009
|
-
port_begin:
|
|
1010
|
-
port_end:
|
|
1011
|
-
icmp_type:
|
|
1012
|
-
icmp_code:
|
|
1013
|
-
device:
|
|
1054
|
+
name: import_zod5.z.string(),
|
|
1055
|
+
port_begin: import_zod5.z.number().optional(),
|
|
1056
|
+
port_end: import_zod5.z.number().optional(),
|
|
1057
|
+
icmp_type: import_zod5.z.number().optional(),
|
|
1058
|
+
icmp_code: import_zod5.z.number().optional(),
|
|
1059
|
+
device: import_zod5.z.string().optional()
|
|
1014
1060
|
},
|
|
1015
1061
|
async ({ name, port_begin, port_end, icmp_type, icmp_code, device }) => {
|
|
1016
1062
|
try {
|
|
@@ -1047,7 +1093,7 @@ function registerServiceObjectTools(server, registry) {
|
|
|
1047
1093
|
server.tool(
|
|
1048
1094
|
"delete_service_object",
|
|
1049
1095
|
"Delete a service object by name. Changes are STAGED; call commit_config to apply.",
|
|
1050
|
-
{ name:
|
|
1096
|
+
{ name: import_zod5.z.string(), device: import_zod5.z.string().optional() },
|
|
1051
1097
|
async ({ name, device }) => {
|
|
1052
1098
|
try {
|
|
1053
1099
|
const client = await registry.getClient(device);
|
|
@@ -1061,12 +1107,12 @@ function registerServiceObjectTools(server, registry) {
|
|
|
1061
1107
|
}
|
|
1062
1108
|
|
|
1063
1109
|
// src/tools/service-groups.ts
|
|
1064
|
-
var
|
|
1110
|
+
var import_zod6 = require("zod");
|
|
1065
1111
|
function registerServiceGroupTools(server, registry) {
|
|
1066
1112
|
server.tool(
|
|
1067
1113
|
"list_service_groups",
|
|
1068
1114
|
"List all service groups on the appliance.",
|
|
1069
|
-
{ device:
|
|
1115
|
+
{ device: import_zod6.z.string().optional() },
|
|
1070
1116
|
async ({ device }) => {
|
|
1071
1117
|
try {
|
|
1072
1118
|
const client = await registry.getClient(device);
|
|
@@ -1080,7 +1126,7 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1080
1126
|
server.tool(
|
|
1081
1127
|
"get_service_group",
|
|
1082
1128
|
"Retrieve a service group by name.",
|
|
1083
|
-
{ name:
|
|
1129
|
+
{ name: import_zod6.z.string(), device: import_zod6.z.string().optional() },
|
|
1084
1130
|
async ({ name, device }) => {
|
|
1085
1131
|
try {
|
|
1086
1132
|
const client = await registry.getClient(device);
|
|
@@ -1095,9 +1141,9 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1095
1141
|
"create_service_group",
|
|
1096
1142
|
"Create a service group containing the given service object names. Changes are STAGED; call commit_config to apply.",
|
|
1097
1143
|
{
|
|
1098
|
-
name:
|
|
1099
|
-
members:
|
|
1100
|
-
device:
|
|
1144
|
+
name: import_zod6.z.string(),
|
|
1145
|
+
members: import_zod6.z.array(import_zod6.z.string()),
|
|
1146
|
+
device: import_zod6.z.string().optional()
|
|
1101
1147
|
},
|
|
1102
1148
|
async ({ name, members, device }) => {
|
|
1103
1149
|
try {
|
|
@@ -1115,9 +1161,9 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1115
1161
|
"add_service_group_member",
|
|
1116
1162
|
"Add a service object to an existing service group (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
1117
1163
|
{
|
|
1118
|
-
group_name:
|
|
1119
|
-
member_name:
|
|
1120
|
-
device:
|
|
1164
|
+
group_name: import_zod6.z.string(),
|
|
1165
|
+
member_name: import_zod6.z.string(),
|
|
1166
|
+
device: import_zod6.z.string().optional()
|
|
1121
1167
|
},
|
|
1122
1168
|
async ({ group_name, member_name, device }) => {
|
|
1123
1169
|
try {
|
|
@@ -1141,9 +1187,9 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1141
1187
|
"remove_service_group_member",
|
|
1142
1188
|
"Remove a service object from a service group (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
1143
1189
|
{
|
|
1144
|
-
group_name:
|
|
1145
|
-
member_name:
|
|
1146
|
-
device:
|
|
1190
|
+
group_name: import_zod6.z.string(),
|
|
1191
|
+
member_name: import_zod6.z.string(),
|
|
1192
|
+
device: import_zod6.z.string().optional()
|
|
1147
1193
|
},
|
|
1148
1194
|
async ({ group_name, member_name, device }) => {
|
|
1149
1195
|
try {
|
|
@@ -1163,7 +1209,7 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1163
1209
|
server.tool(
|
|
1164
1210
|
"delete_service_group",
|
|
1165
1211
|
"Delete a service group by name. Changes are STAGED; call commit_config to apply.",
|
|
1166
|
-
{ name:
|
|
1212
|
+
{ name: import_zod6.z.string(), device: import_zod6.z.string().optional() },
|
|
1167
1213
|
async ({ name, device }) => {
|
|
1168
1214
|
try {
|
|
1169
1215
|
const client = await registry.getClient(device);
|
|
@@ -1177,12 +1223,12 @@ function registerServiceGroupTools(server, registry) {
|
|
|
1177
1223
|
}
|
|
1178
1224
|
|
|
1179
1225
|
// src/tools/access-rules.ts
|
|
1180
|
-
var
|
|
1226
|
+
var import_zod7 = require("zod");
|
|
1181
1227
|
function zoneName(v) {
|
|
1182
1228
|
if (typeof v === "string") return v;
|
|
1183
1229
|
if (v && typeof v === "object") {
|
|
1184
|
-
const
|
|
1185
|
-
if (typeof
|
|
1230
|
+
const z18 = v.zone;
|
|
1231
|
+
if (typeof z18 === "string") return z18;
|
|
1186
1232
|
}
|
|
1187
1233
|
return void 0;
|
|
1188
1234
|
}
|
|
@@ -1194,10 +1240,10 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1194
1240
|
"list_access_rules",
|
|
1195
1241
|
"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.",
|
|
1196
1242
|
{
|
|
1197
|
-
ip_version:
|
|
1198
|
-
from_zone:
|
|
1199
|
-
to_zone:
|
|
1200
|
-
device:
|
|
1243
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1244
|
+
from_zone: import_zod7.z.string().optional(),
|
|
1245
|
+
to_zone: import_zod7.z.string().optional(),
|
|
1246
|
+
device: import_zod7.z.string().optional()
|
|
1201
1247
|
},
|
|
1202
1248
|
async ({ ip_version, from_zone, to_zone, device }) => {
|
|
1203
1249
|
try {
|
|
@@ -1225,9 +1271,9 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1225
1271
|
"get_access_rule",
|
|
1226
1272
|
"Retrieve a single access rule by UUID. Pass a rule's uuid value from list_access_rules as rule_uuid.",
|
|
1227
1273
|
{
|
|
1228
|
-
rule_uuid:
|
|
1229
|
-
ip_version:
|
|
1230
|
-
device:
|
|
1274
|
+
rule_uuid: import_zod7.z.string().uuid(),
|
|
1275
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1276
|
+
device: import_zod7.z.string().optional()
|
|
1231
1277
|
},
|
|
1232
1278
|
async ({ rule_uuid, ip_version, device }) => {
|
|
1233
1279
|
try {
|
|
@@ -1243,20 +1289,20 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1243
1289
|
"create_access_rule",
|
|
1244
1290
|
"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.",
|
|
1245
1291
|
{
|
|
1246
|
-
ip_version:
|
|
1247
|
-
name:
|
|
1248
|
-
action:
|
|
1249
|
-
from_zone:
|
|
1250
|
-
to_zone:
|
|
1251
|
-
source:
|
|
1252
|
-
destination:
|
|
1253
|
-
service:
|
|
1254
|
-
enabled:
|
|
1255
|
-
log:
|
|
1256
|
-
priority:
|
|
1257
|
-
geo_ip_policy:
|
|
1258
|
-
comment:
|
|
1259
|
-
device:
|
|
1292
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]),
|
|
1293
|
+
name: import_zod7.z.string(),
|
|
1294
|
+
action: import_zod7.z.enum(["allow", "deny", "discard"]),
|
|
1295
|
+
from_zone: import_zod7.z.string(),
|
|
1296
|
+
to_zone: import_zod7.z.string(),
|
|
1297
|
+
source: import_zod7.z.string(),
|
|
1298
|
+
destination: import_zod7.z.string(),
|
|
1299
|
+
service: import_zod7.z.string(),
|
|
1300
|
+
enabled: import_zod7.z.boolean().optional().default(true),
|
|
1301
|
+
log: import_zod7.z.boolean().optional().default(true),
|
|
1302
|
+
priority: import_zod7.z.number().optional(),
|
|
1303
|
+
geo_ip_policy: import_zod7.z.string().optional(),
|
|
1304
|
+
comment: import_zod7.z.string().optional(),
|
|
1305
|
+
device: import_zod7.z.string().optional()
|
|
1260
1306
|
},
|
|
1261
1307
|
async ({ ip_version, name, action, from_zone, to_zone, source, destination, service, enabled, log, priority, geo_ip_policy, comment, device }) => {
|
|
1262
1308
|
try {
|
|
@@ -1288,17 +1334,17 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1288
1334
|
"update_access_rule",
|
|
1289
1335
|
"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.",
|
|
1290
1336
|
{
|
|
1291
|
-
rule_uuid:
|
|
1292
|
-
ip_version:
|
|
1293
|
-
action:
|
|
1294
|
-
source:
|
|
1295
|
-
destination:
|
|
1296
|
-
service:
|
|
1297
|
-
enabled:
|
|
1298
|
-
log:
|
|
1299
|
-
geo_ip_policy:
|
|
1300
|
-
comment:
|
|
1301
|
-
device:
|
|
1337
|
+
rule_uuid: import_zod7.z.string().uuid(),
|
|
1338
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1339
|
+
action: import_zod7.z.enum(["allow", "deny", "discard"]).optional(),
|
|
1340
|
+
source: import_zod7.z.string().optional(),
|
|
1341
|
+
destination: import_zod7.z.string().optional(),
|
|
1342
|
+
service: import_zod7.z.string().optional(),
|
|
1343
|
+
enabled: import_zod7.z.boolean().optional(),
|
|
1344
|
+
log: import_zod7.z.boolean().optional(),
|
|
1345
|
+
geo_ip_policy: import_zod7.z.string().optional(),
|
|
1346
|
+
comment: import_zod7.z.string().optional(),
|
|
1347
|
+
device: import_zod7.z.string().optional()
|
|
1302
1348
|
},
|
|
1303
1349
|
async ({ rule_uuid, ip_version, action, source, destination, service, enabled, log, geo_ip_policy, comment, device }) => {
|
|
1304
1350
|
try {
|
|
@@ -1340,9 +1386,9 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1340
1386
|
"delete_access_rule",
|
|
1341
1387
|
"Delete an access rule by UUID. Copy rule_uuid from list_access_rules. Changes are STAGED; call commit_config to apply.",
|
|
1342
1388
|
{
|
|
1343
|
-
rule_uuid:
|
|
1344
|
-
ip_version:
|
|
1345
|
-
device:
|
|
1389
|
+
rule_uuid: import_zod7.z.string().uuid(),
|
|
1390
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1391
|
+
device: import_zod7.z.string().optional()
|
|
1346
1392
|
},
|
|
1347
1393
|
async ({ rule_uuid, ip_version, device }) => {
|
|
1348
1394
|
try {
|
|
@@ -1358,9 +1404,9 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1358
1404
|
"enable_access_rule",
|
|
1359
1405
|
"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.",
|
|
1360
1406
|
{
|
|
1361
|
-
rule_uuid:
|
|
1362
|
-
ip_version:
|
|
1363
|
-
device:
|
|
1407
|
+
rule_uuid: import_zod7.z.string().uuid(),
|
|
1408
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1409
|
+
device: import_zod7.z.string().optional()
|
|
1364
1410
|
},
|
|
1365
1411
|
async ({ rule_uuid, ip_version, device }) => {
|
|
1366
1412
|
try {
|
|
@@ -1383,9 +1429,9 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1383
1429
|
"disable_access_rule",
|
|
1384
1430
|
"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.",
|
|
1385
1431
|
{
|
|
1386
|
-
rule_uuid:
|
|
1387
|
-
ip_version:
|
|
1388
|
-
device:
|
|
1432
|
+
rule_uuid: import_zod7.z.string().uuid(),
|
|
1433
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1434
|
+
device: import_zod7.z.string().optional()
|
|
1389
1435
|
},
|
|
1390
1436
|
async ({ rule_uuid, ip_version, device }) => {
|
|
1391
1437
|
try {
|
|
@@ -1407,7 +1453,7 @@ function registerAccessRuleTools(server, registry) {
|
|
|
1407
1453
|
}
|
|
1408
1454
|
|
|
1409
1455
|
// src/tools/nat-policies.ts
|
|
1410
|
-
var
|
|
1456
|
+
var import_zod8 = require("zod");
|
|
1411
1457
|
function interfaceValue(value) {
|
|
1412
1458
|
return value.toLowerCase() === "any" ? "any" : value;
|
|
1413
1459
|
}
|
|
@@ -1424,7 +1470,7 @@ async function resolveRef(client, kind, value, ipVersion, allowOriginal) {
|
|
|
1424
1470
|
throw e;
|
|
1425
1471
|
}
|
|
1426
1472
|
}
|
|
1427
|
-
var prioritySchema =
|
|
1473
|
+
var prioritySchema = import_zod8.z.union([import_zod8.z.number().int().min(1), import_zod8.z.literal("auto")]).optional().describe("Rule order: lower number = evaluated first. A positive integer sets a manual priority; 'auto' lets SonicOS assign it.");
|
|
1428
1474
|
function priorityField(priority) {
|
|
1429
1475
|
return priority === "auto" ? { auto: true } : { manual: priority };
|
|
1430
1476
|
}
|
|
@@ -1433,8 +1479,8 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1433
1479
|
"list_nat_policies",
|
|
1434
1480
|
"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.",
|
|
1435
1481
|
{
|
|
1436
|
-
ip_version:
|
|
1437
|
-
device:
|
|
1482
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1483
|
+
device: import_zod8.z.string().optional()
|
|
1438
1484
|
},
|
|
1439
1485
|
async ({ ip_version, device }) => {
|
|
1440
1486
|
try {
|
|
@@ -1450,9 +1496,9 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1450
1496
|
"get_nat_policy",
|
|
1451
1497
|
"Retrieve a NAT policy by UUID. Pass a policy's uuid value from list_nat_policies as policy_uuid.",
|
|
1452
1498
|
{
|
|
1453
|
-
policy_uuid:
|
|
1454
|
-
ip_version:
|
|
1455
|
-
device:
|
|
1499
|
+
policy_uuid: import_zod8.z.string().uuid(),
|
|
1500
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1501
|
+
device: import_zod8.z.string().optional()
|
|
1456
1502
|
},
|
|
1457
1503
|
async ({ policy_uuid, ip_version, device }) => {
|
|
1458
1504
|
try {
|
|
@@ -1468,21 +1514,21 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1468
1514
|
"create_nat_policy",
|
|
1469
1515
|
"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.",
|
|
1470
1516
|
{
|
|
1471
|
-
name:
|
|
1472
|
-
original_source:
|
|
1473
|
-
translated_source:
|
|
1474
|
-
original_destination:
|
|
1475
|
-
translated_destination:
|
|
1476
|
-
original_service:
|
|
1477
|
-
translated_service:
|
|
1478
|
-
inbound_interface:
|
|
1479
|
-
outbound_interface:
|
|
1480
|
-
ip_version:
|
|
1481
|
-
enabled:
|
|
1482
|
-
dns_doctoring:
|
|
1517
|
+
name: import_zod8.z.string(),
|
|
1518
|
+
original_source: import_zod8.z.string(),
|
|
1519
|
+
translated_source: import_zod8.z.string(),
|
|
1520
|
+
original_destination: import_zod8.z.string(),
|
|
1521
|
+
translated_destination: import_zod8.z.string(),
|
|
1522
|
+
original_service: import_zod8.z.string(),
|
|
1523
|
+
translated_service: import_zod8.z.string(),
|
|
1524
|
+
inbound_interface: import_zod8.z.string().optional().default("Any"),
|
|
1525
|
+
outbound_interface: import_zod8.z.string().optional().default("Any"),
|
|
1526
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1527
|
+
enabled: import_zod8.z.boolean().optional().default(true),
|
|
1528
|
+
dns_doctoring: import_zod8.z.boolean().optional().default(false),
|
|
1483
1529
|
priority: prioritySchema,
|
|
1484
|
-
comment:
|
|
1485
|
-
device:
|
|
1530
|
+
comment: import_zod8.z.string().optional(),
|
|
1531
|
+
device: import_zod8.z.string().optional()
|
|
1486
1532
|
},
|
|
1487
1533
|
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 }) => {
|
|
1488
1534
|
try {
|
|
@@ -1515,21 +1561,21 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1515
1561
|
"update_nat_policy",
|
|
1516
1562
|
"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.",
|
|
1517
1563
|
{
|
|
1518
|
-
policy_uuid:
|
|
1519
|
-
ip_version:
|
|
1520
|
-
original_source:
|
|
1521
|
-
translated_source:
|
|
1522
|
-
original_destination:
|
|
1523
|
-
translated_destination:
|
|
1524
|
-
original_service:
|
|
1525
|
-
translated_service:
|
|
1526
|
-
inbound_interface:
|
|
1527
|
-
outbound_interface:
|
|
1528
|
-
enabled:
|
|
1529
|
-
dns_doctoring:
|
|
1564
|
+
policy_uuid: import_zod8.z.string().uuid(),
|
|
1565
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1566
|
+
original_source: import_zod8.z.string().optional(),
|
|
1567
|
+
translated_source: import_zod8.z.string().optional(),
|
|
1568
|
+
original_destination: import_zod8.z.string().optional(),
|
|
1569
|
+
translated_destination: import_zod8.z.string().optional(),
|
|
1570
|
+
original_service: import_zod8.z.string().optional(),
|
|
1571
|
+
translated_service: import_zod8.z.string().optional(),
|
|
1572
|
+
inbound_interface: import_zod8.z.string().optional(),
|
|
1573
|
+
outbound_interface: import_zod8.z.string().optional(),
|
|
1574
|
+
enabled: import_zod8.z.boolean().optional(),
|
|
1575
|
+
dns_doctoring: import_zod8.z.boolean().optional(),
|
|
1530
1576
|
priority: prioritySchema,
|
|
1531
|
-
comment:
|
|
1532
|
-
device:
|
|
1577
|
+
comment: import_zod8.z.string().optional(),
|
|
1578
|
+
device: import_zod8.z.string().optional()
|
|
1533
1579
|
},
|
|
1534
1580
|
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 }) => {
|
|
1535
1581
|
try {
|
|
@@ -1563,9 +1609,9 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1563
1609
|
"delete_nat_policy",
|
|
1564
1610
|
"Delete a NAT policy by UUID. Copy policy_uuid from list_nat_policies. Changes are STAGED; call commit_config to apply.",
|
|
1565
1611
|
{
|
|
1566
|
-
policy_uuid:
|
|
1567
|
-
ip_version:
|
|
1568
|
-
device:
|
|
1612
|
+
policy_uuid: import_zod8.z.string().uuid(),
|
|
1613
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1614
|
+
device: import_zod8.z.string().optional()
|
|
1569
1615
|
},
|
|
1570
1616
|
async ({ policy_uuid, ip_version, device }) => {
|
|
1571
1617
|
try {
|
|
@@ -1590,9 +1636,9 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1590
1636
|
"enable_nat_policy",
|
|
1591
1637
|
"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.",
|
|
1592
1638
|
{
|
|
1593
|
-
policy_uuid:
|
|
1594
|
-
ip_version:
|
|
1595
|
-
device:
|
|
1639
|
+
policy_uuid: import_zod8.z.string().uuid(),
|
|
1640
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1641
|
+
device: import_zod8.z.string().optional()
|
|
1596
1642
|
},
|
|
1597
1643
|
async ({ policy_uuid, ip_version, device }) => {
|
|
1598
1644
|
try {
|
|
@@ -1607,9 +1653,9 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1607
1653
|
"disable_nat_policy",
|
|
1608
1654
|
"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.",
|
|
1609
1655
|
{
|
|
1610
|
-
policy_uuid:
|
|
1611
|
-
ip_version:
|
|
1612
|
-
device:
|
|
1656
|
+
policy_uuid: import_zod8.z.string().uuid(),
|
|
1657
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1658
|
+
device: import_zod8.z.string().optional()
|
|
1613
1659
|
},
|
|
1614
1660
|
async ({ policy_uuid, ip_version, device }) => {
|
|
1615
1661
|
try {
|
|
@@ -1623,12 +1669,12 @@ function registerNatPolicyTools(server, registry) {
|
|
|
1623
1669
|
}
|
|
1624
1670
|
|
|
1625
1671
|
// src/tools/security-policies.ts
|
|
1626
|
-
var
|
|
1672
|
+
var import_zod9 = require("zod");
|
|
1627
1673
|
function zoneName2(v) {
|
|
1628
1674
|
if (typeof v === "string") return v;
|
|
1629
1675
|
if (v && typeof v === "object") {
|
|
1630
|
-
const
|
|
1631
|
-
if (typeof
|
|
1676
|
+
const z18 = v.zone;
|
|
1677
|
+
if (typeof z18 === "string") return z18;
|
|
1632
1678
|
}
|
|
1633
1679
|
return void 0;
|
|
1634
1680
|
}
|
|
@@ -1640,10 +1686,10 @@ function registerSecurityPolicyTools(server, registry) {
|
|
|
1640
1686
|
"list_security_policies",
|
|
1641
1687
|
"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.",
|
|
1642
1688
|
{
|
|
1643
|
-
ip_version:
|
|
1644
|
-
from_zone:
|
|
1645
|
-
to_zone:
|
|
1646
|
-
device:
|
|
1689
|
+
ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1690
|
+
from_zone: import_zod9.z.string().optional(),
|
|
1691
|
+
to_zone: import_zod9.z.string().optional(),
|
|
1692
|
+
device: import_zod9.z.string().optional()
|
|
1647
1693
|
},
|
|
1648
1694
|
async ({ ip_version, from_zone, to_zone, device }) => {
|
|
1649
1695
|
try {
|
|
@@ -1671,9 +1717,9 @@ function registerSecurityPolicyTools(server, registry) {
|
|
|
1671
1717
|
"get_security_policy",
|
|
1672
1718
|
"Retrieve a security policy by its numeric ID.",
|
|
1673
1719
|
{
|
|
1674
|
-
policy_id:
|
|
1675
|
-
ip_version:
|
|
1676
|
-
device:
|
|
1720
|
+
policy_id: import_zod9.z.number(),
|
|
1721
|
+
ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1722
|
+
device: import_zod9.z.string().optional()
|
|
1677
1723
|
},
|
|
1678
1724
|
async ({ policy_id, ip_version, device }) => {
|
|
1679
1725
|
try {
|
|
@@ -1689,20 +1735,20 @@ function registerSecurityPolicyTools(server, registry) {
|
|
|
1689
1735
|
"create_security_policy",
|
|
1690
1736
|
"Create a security policy. action: typically 'allow' or 'deny'. source_address/destination_address: address object or group name, or 'Any'. service: service object or group name, or 'Any'. Changes are STAGED; call commit_config to apply.",
|
|
1691
1737
|
{
|
|
1692
|
-
name:
|
|
1693
|
-
source_zone:
|
|
1694
|
-
destination_zone:
|
|
1695
|
-
source_address:
|
|
1696
|
-
destination_address:
|
|
1697
|
-
service:
|
|
1698
|
-
action:
|
|
1699
|
-
ip_version:
|
|
1700
|
-
users:
|
|
1701
|
-
schedule:
|
|
1702
|
-
enabled:
|
|
1703
|
-
log:
|
|
1704
|
-
comment:
|
|
1705
|
-
device:
|
|
1738
|
+
name: import_zod9.z.string(),
|
|
1739
|
+
source_zone: import_zod9.z.string(),
|
|
1740
|
+
destination_zone: import_zod9.z.string(),
|
|
1741
|
+
source_address: import_zod9.z.string(),
|
|
1742
|
+
destination_address: import_zod9.z.string(),
|
|
1743
|
+
service: import_zod9.z.string(),
|
|
1744
|
+
action: import_zod9.z.string(),
|
|
1745
|
+
ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1746
|
+
users: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
1747
|
+
schedule: import_zod9.z.string().optional(),
|
|
1748
|
+
enabled: import_zod9.z.boolean().optional().default(true),
|
|
1749
|
+
log: import_zod9.z.boolean().optional().default(true),
|
|
1750
|
+
comment: import_zod9.z.string().optional(),
|
|
1751
|
+
device: import_zod9.z.string().optional()
|
|
1706
1752
|
},
|
|
1707
1753
|
async ({ name, source_zone, destination_zone, source_address, destination_address, service, action, ip_version, users, schedule, enabled, log, comment, device }) => {
|
|
1708
1754
|
try {
|
|
@@ -1734,16 +1780,16 @@ function registerSecurityPolicyTools(server, registry) {
|
|
|
1734
1780
|
"update_security_policy",
|
|
1735
1781
|
"Update fields on an existing security policy (GET-then-PUT). Only provided fields are changed. Changes are STAGED; call commit_config to apply.",
|
|
1736
1782
|
{
|
|
1737
|
-
policy_id:
|
|
1738
|
-
ip_version:
|
|
1739
|
-
action:
|
|
1740
|
-
source_address:
|
|
1741
|
-
destination_address:
|
|
1742
|
-
service:
|
|
1743
|
-
enabled:
|
|
1744
|
-
log:
|
|
1745
|
-
comment:
|
|
1746
|
-
device:
|
|
1783
|
+
policy_id: import_zod9.z.number(),
|
|
1784
|
+
ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1785
|
+
action: import_zod9.z.string().optional(),
|
|
1786
|
+
source_address: import_zod9.z.string().optional(),
|
|
1787
|
+
destination_address: import_zod9.z.string().optional(),
|
|
1788
|
+
service: import_zod9.z.string().optional(),
|
|
1789
|
+
enabled: import_zod9.z.boolean().optional(),
|
|
1790
|
+
log: import_zod9.z.boolean().optional(),
|
|
1791
|
+
comment: import_zod9.z.string().optional(),
|
|
1792
|
+
device: import_zod9.z.string().optional()
|
|
1747
1793
|
},
|
|
1748
1794
|
async ({ policy_id, ip_version, action, source_address, destination_address, service, enabled, log, comment, device }) => {
|
|
1749
1795
|
try {
|
|
@@ -1777,9 +1823,9 @@ function registerSecurityPolicyTools(server, registry) {
|
|
|
1777
1823
|
"delete_security_policy",
|
|
1778
1824
|
"Delete a security policy by ID. Changes are STAGED; call commit_config to apply.",
|
|
1779
1825
|
{
|
|
1780
|
-
policy_id:
|
|
1781
|
-
ip_version:
|
|
1782
|
-
device:
|
|
1826
|
+
policy_id: import_zod9.z.number(),
|
|
1827
|
+
ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1828
|
+
device: import_zod9.z.string().optional()
|
|
1783
1829
|
},
|
|
1784
1830
|
async ({ policy_id, ip_version, device }) => {
|
|
1785
1831
|
try {
|
|
@@ -1794,7 +1840,7 @@ function registerSecurityPolicyTools(server, registry) {
|
|
|
1794
1840
|
}
|
|
1795
1841
|
|
|
1796
1842
|
// src/tools/geo-ip.ts
|
|
1797
|
-
var
|
|
1843
|
+
var import_zod10 = require("zod");
|
|
1798
1844
|
function parseGeoLookup(ip, raw) {
|
|
1799
1845
|
const parsed = {
|
|
1800
1846
|
ip,
|
|
@@ -1839,7 +1885,7 @@ function registerGeoIpTools(server, registry) {
|
|
|
1839
1885
|
server.tool(
|
|
1840
1886
|
"lookup_ip_country",
|
|
1841
1887
|
"Look up the geographic location of an IP address using the appliance's built-in GeoIP database. Returns country, city, region, and botnet classification if available. Requires an active GeoIP subscription.",
|
|
1842
|
-
{ ip:
|
|
1888
|
+
{ ip: import_zod10.z.string(), device: import_zod10.z.string().optional() },
|
|
1843
1889
|
async ({ ip, device }) => {
|
|
1844
1890
|
try {
|
|
1845
1891
|
const client = await registry.getClient(device);
|
|
@@ -1854,7 +1900,7 @@ function registerGeoIpTools(server, registry) {
|
|
|
1854
1900
|
}
|
|
1855
1901
|
|
|
1856
1902
|
// src/tools/logs.ts
|
|
1857
|
-
var
|
|
1903
|
+
var import_zod11 = require("zod");
|
|
1858
1904
|
async function getWithFallback(client, candidates) {
|
|
1859
1905
|
let lastError;
|
|
1860
1906
|
for (const path of candidates) {
|
|
@@ -1874,7 +1920,7 @@ function registerLogTools(server, registry) {
|
|
|
1874
1920
|
server.tool(
|
|
1875
1921
|
"get_log_categories",
|
|
1876
1922
|
"List SonicOS log category configuration. This describes available event categories; it does not return recorded runtime log entries.",
|
|
1877
|
-
{ device:
|
|
1923
|
+
{ device: import_zod11.z.string().optional() },
|
|
1878
1924
|
async ({ device }) => {
|
|
1879
1925
|
try {
|
|
1880
1926
|
const client = await registry.getClient(device);
|
|
@@ -1888,7 +1934,7 @@ function registerLogTools(server, registry) {
|
|
|
1888
1934
|
server.tool(
|
|
1889
1935
|
"list_log_event_definitions",
|
|
1890
1936
|
"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.",
|
|
1891
|
-
{ device:
|
|
1937
|
+
{ device: import_zod11.z.string().optional() },
|
|
1892
1938
|
async ({ device }) => {
|
|
1893
1939
|
try {
|
|
1894
1940
|
const client = await registry.getClient(device);
|
|
@@ -1902,12 +1948,12 @@ function registerLogTools(server, registry) {
|
|
|
1902
1948
|
}
|
|
1903
1949
|
|
|
1904
1950
|
// src/tools/zones.ts
|
|
1905
|
-
var
|
|
1951
|
+
var import_zod12 = require("zod");
|
|
1906
1952
|
function registerZoneTools(server, registry) {
|
|
1907
1953
|
server.tool(
|
|
1908
1954
|
"list_zones",
|
|
1909
1955
|
"List all security zones (LAN, WAN, DMZ, etc.) with their security type and interface membership. Use this to discover valid zone names before creating access rules or security policies.",
|
|
1910
|
-
{ device:
|
|
1956
|
+
{ device: import_zod12.z.string().optional() },
|
|
1911
1957
|
async ({ device }) => {
|
|
1912
1958
|
try {
|
|
1913
1959
|
const client = await registry.getClient(device);
|
|
@@ -1921,7 +1967,7 @@ function registerZoneTools(server, registry) {
|
|
|
1921
1967
|
server.tool(
|
|
1922
1968
|
"get_zone",
|
|
1923
1969
|
"Retrieve a single security zone by name.",
|
|
1924
|
-
{ name:
|
|
1970
|
+
{ name: import_zod12.z.string(), device: import_zod12.z.string().optional() },
|
|
1925
1971
|
async ({ name, device }) => {
|
|
1926
1972
|
try {
|
|
1927
1973
|
const client = await registry.getClient(device);
|
|
@@ -1935,7 +1981,7 @@ function registerZoneTools(server, registry) {
|
|
|
1935
1981
|
}
|
|
1936
1982
|
|
|
1937
1983
|
// src/tools/interfaces.ts
|
|
1938
|
-
var
|
|
1984
|
+
var import_zod13 = require("zod");
|
|
1939
1985
|
var SECRET_FIELD = /(?:password|passwd|secret|private_key|pre_shared_key|community)$/i;
|
|
1940
1986
|
function redactSecrets(value) {
|
|
1941
1987
|
if (Array.isArray(value)) return value.map(redactSecrets);
|
|
@@ -1951,7 +1997,7 @@ function registerInterfaceTools(server, registry) {
|
|
|
1951
1997
|
server.tool(
|
|
1952
1998
|
"list_interfaces",
|
|
1953
1999
|
"List IPv4 network interfaces with their IP assignment, zone, and mode (static/DHCP). Use this to discover the appliance's addressing and which interfaces belong to which zone.",
|
|
1954
|
-
{ device:
|
|
2000
|
+
{ device: import_zod13.z.string().optional() },
|
|
1955
2001
|
async ({ device }) => {
|
|
1956
2002
|
try {
|
|
1957
2003
|
const client = await registry.getClient(device);
|
|
@@ -1965,7 +2011,7 @@ function registerInterfaceTools(server, registry) {
|
|
|
1965
2011
|
server.tool(
|
|
1966
2012
|
"get_interface",
|
|
1967
2013
|
'Retrieve a single IPv4 interface by name (e.g. "X0").',
|
|
1968
|
-
{ name:
|
|
2014
|
+
{ name: import_zod13.z.string(), device: import_zod13.z.string().optional() },
|
|
1969
2015
|
async ({ name, device }) => {
|
|
1970
2016
|
try {
|
|
1971
2017
|
const client = await registry.getClient(device);
|
|
@@ -1979,12 +2025,12 @@ function registerInterfaceTools(server, registry) {
|
|
|
1979
2025
|
}
|
|
1980
2026
|
|
|
1981
2027
|
// src/tools/schedules.ts
|
|
1982
|
-
var
|
|
2028
|
+
var import_zod14 = require("zod");
|
|
1983
2029
|
function registerScheduleTools(server, registry) {
|
|
1984
2030
|
server.tool(
|
|
1985
2031
|
"list_schedules",
|
|
1986
2032
|
'List schedule objects (recurring time windows like "Work Hours"). Security policies reference schedules by name to restrict when a rule is active \u2014 use this to discover valid schedule names.',
|
|
1987
|
-
{ device:
|
|
2033
|
+
{ device: import_zod14.z.string().optional() },
|
|
1988
2034
|
async ({ device }) => {
|
|
1989
2035
|
try {
|
|
1990
2036
|
const client = await registry.getClient(device);
|
|
@@ -1998,7 +2044,7 @@ function registerScheduleTools(server, registry) {
|
|
|
1998
2044
|
server.tool(
|
|
1999
2045
|
"get_schedule",
|
|
2000
2046
|
"Retrieve a single schedule object by name.",
|
|
2001
|
-
{ name:
|
|
2047
|
+
{ name: import_zod14.z.string(), device: import_zod14.z.string().optional() },
|
|
2002
2048
|
async ({ name, device }) => {
|
|
2003
2049
|
try {
|
|
2004
2050
|
const client = await registry.getClient(device);
|
|
@@ -2012,14 +2058,14 @@ function registerScheduleTools(server, registry) {
|
|
|
2012
2058
|
}
|
|
2013
2059
|
|
|
2014
2060
|
// src/tools/route-policies.ts
|
|
2015
|
-
var
|
|
2061
|
+
var import_zod15 = require("zod");
|
|
2016
2062
|
function registerRoutePolicyTools(server, registry) {
|
|
2017
2063
|
server.tool(
|
|
2018
2064
|
"list_route_policies",
|
|
2019
2065
|
"List static/policy-based routes with their destination, gateway, interface, and metric. Useful for understanding how traffic is routed off the appliance.",
|
|
2020
2066
|
{
|
|
2021
|
-
ip_version:
|
|
2022
|
-
device:
|
|
2067
|
+
ip_version: import_zod15.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
2068
|
+
device: import_zod15.z.string().optional()
|
|
2023
2069
|
},
|
|
2024
2070
|
async ({ ip_version, device }) => {
|
|
2025
2071
|
try {
|
|
@@ -2033,6 +2079,142 @@ function registerRoutePolicyTools(server, registry) {
|
|
|
2033
2079
|
);
|
|
2034
2080
|
}
|
|
2035
2081
|
|
|
2082
|
+
// src/tools/diagnostics.ts
|
|
2083
|
+
var import_zod16 = require("zod");
|
|
2084
|
+
function text(value) {
|
|
2085
|
+
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
2086
|
+
}
|
|
2087
|
+
function failure(e) {
|
|
2088
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
2089
|
+
}
|
|
2090
|
+
function actionPath(action, host, iface, preferIpv6 = false) {
|
|
2091
|
+
const base = `diag/${action}-action/${encodeURIComponent(host)}`;
|
|
2092
|
+
if (!iface) return base;
|
|
2093
|
+
return `${base}/interface/${encodeURIComponent(iface)}/${preferIpv6 ? "true" : "false"}`;
|
|
2094
|
+
}
|
|
2095
|
+
async function readArpCache(client) {
|
|
2096
|
+
const paths = ["reporting/arp/caches", "arp/entries"];
|
|
2097
|
+
let lastError;
|
|
2098
|
+
for (const path of paths) {
|
|
2099
|
+
try {
|
|
2100
|
+
return await client.get(path);
|
|
2101
|
+
} catch (e) {
|
|
2102
|
+
lastError = e;
|
|
2103
|
+
if (!(e instanceof APIError) || ![400, 404].includes(e.status)) throw e;
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
throw lastError;
|
|
2107
|
+
}
|
|
2108
|
+
function matchingEntries(value, ip) {
|
|
2109
|
+
const matches2 = [];
|
|
2110
|
+
const visit = (item) => {
|
|
2111
|
+
if (Array.isArray(item)) {
|
|
2112
|
+
for (const child of item) visit(child);
|
|
2113
|
+
} else if (item && typeof item === "object") {
|
|
2114
|
+
const object = item;
|
|
2115
|
+
if (Object.values(object).some((v) => typeof v === "string" && v === ip)) matches2.push(object);
|
|
2116
|
+
else for (const child of Object.values(object)) visit(child);
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
visit(value);
|
|
2120
|
+
return matches2;
|
|
2121
|
+
}
|
|
2122
|
+
function registerDiagnosticTools(server, registry) {
|
|
2123
|
+
const targetSchema = {
|
|
2124
|
+
host: import_zod16.z.string().min(1).describe("Destination IP address or hostname"),
|
|
2125
|
+
interface: import_zod16.z.string().min(1).optional().describe("Source interface, such as X1; omit to let SonicOS choose"),
|
|
2126
|
+
prefer_ipv6: import_zod16.z.boolean().optional().default(false),
|
|
2127
|
+
device: import_zod16.z.string().optional()
|
|
2128
|
+
};
|
|
2129
|
+
server.tool(
|
|
2130
|
+
"ping_from_appliance",
|
|
2131
|
+
"Ping an IP address or hostname from the SonicWall appliance, optionally through a specific interface. This is a live, read-only diagnostic.",
|
|
2132
|
+
targetSchema,
|
|
2133
|
+
async ({ host, interface: iface, prefer_ipv6, device }) => {
|
|
2134
|
+
try {
|
|
2135
|
+
const client = await registry.getClient(device);
|
|
2136
|
+
return text(await client.postAction(actionPath("ping", host, iface, prefer_ipv6)));
|
|
2137
|
+
} catch (e) {
|
|
2138
|
+
return failure(e);
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
);
|
|
2142
|
+
server.tool(
|
|
2143
|
+
"traceroute_from_appliance",
|
|
2144
|
+
"Trace the network path from the SonicWall appliance to an IP address or hostname, optionally through a specific interface. This can take several minutes.",
|
|
2145
|
+
targetSchema,
|
|
2146
|
+
async ({ host, interface: iface, prefer_ipv6, device }) => {
|
|
2147
|
+
try {
|
|
2148
|
+
const client = await registry.getClient(device);
|
|
2149
|
+
return text(await client.postAction(actionPath("traceroute", host, iface, prefer_ipv6)));
|
|
2150
|
+
} catch (e) {
|
|
2151
|
+
return failure(e);
|
|
2152
|
+
}
|
|
2153
|
+
}
|
|
2154
|
+
);
|
|
2155
|
+
server.tool(
|
|
2156
|
+
"find_network_path",
|
|
2157
|
+
"Ask the appliance to resolve the network path for a destination, including the route/interface selected by SonicOS.",
|
|
2158
|
+
{ host: import_zod16.z.string().min(1), device: import_zod16.z.string().optional() },
|
|
2159
|
+
async ({ host, device }) => {
|
|
2160
|
+
try {
|
|
2161
|
+
const client = await registry.getClient(device);
|
|
2162
|
+
return text(await client.postAction(`diag/network-path-action/${encodeURIComponent(host)}`));
|
|
2163
|
+
} catch (e) {
|
|
2164
|
+
return failure(e);
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
);
|
|
2168
|
+
server.tool(
|
|
2169
|
+
"lookup_arp",
|
|
2170
|
+
"Read the appliance ARP cache. When ip is supplied, return only entries exactly matching that address.",
|
|
2171
|
+
{ ip: import_zod16.z.string().min(1).optional(), device: import_zod16.z.string().optional() },
|
|
2172
|
+
async ({ ip, device }) => {
|
|
2173
|
+
try {
|
|
2174
|
+
const client = await registry.getClient(device);
|
|
2175
|
+
const result = await readArpCache(client);
|
|
2176
|
+
return text(ip ? { ip, entries: matchingEntries(result, ip) } : result);
|
|
2177
|
+
} catch (e) {
|
|
2178
|
+
return failure(e);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
);
|
|
2182
|
+
server.tool(
|
|
2183
|
+
"diagnose_ip",
|
|
2184
|
+
"Run a combined, read-only diagnosis for an IP from the appliance: collect network-path selection, interface configuration, route policies, matching ARP state, ping, and optionally traceroute. Individual failures are reported without aborting the remaining checks.",
|
|
2185
|
+
{
|
|
2186
|
+
ip: import_zod16.z.string().ip(),
|
|
2187
|
+
interface: import_zod16.z.string().min(1).optional(),
|
|
2188
|
+
include_traceroute: import_zod16.z.boolean().optional().default(true),
|
|
2189
|
+
device: import_zod16.z.string().optional()
|
|
2190
|
+
},
|
|
2191
|
+
async ({ ip, interface: iface, include_traceroute, device }) => {
|
|
2192
|
+
try {
|
|
2193
|
+
const client = await registry.getClient(device);
|
|
2194
|
+
const checks = { target: ip, requested_interface: iface ?? null };
|
|
2195
|
+
const capture = async (name, fn) => {
|
|
2196
|
+
try {
|
|
2197
|
+
checks[name] = await fn();
|
|
2198
|
+
} catch (e) {
|
|
2199
|
+
checks[name] = { error: e.message };
|
|
2200
|
+
}
|
|
2201
|
+
};
|
|
2202
|
+
await capture("network_path", () => client.postAction(`diag/network-path-action/${encodeURIComponent(ip)}`));
|
|
2203
|
+
await capture("interfaces", () => client.get("interfaces/ipv4"));
|
|
2204
|
+
await capture("route_policies", () => client.get("route-policies/ipv4"));
|
|
2205
|
+
await capture("arp", async () => ({ entries: matchingEntries(await readArpCache(client), ip) }));
|
|
2206
|
+
await capture("ping", () => client.postAction(actionPath("ping", ip, iface)));
|
|
2207
|
+
if (include_traceroute) {
|
|
2208
|
+
await capture("traceroute", () => client.postAction(actionPath("traceroute", ip, iface)));
|
|
2209
|
+
}
|
|
2210
|
+
return text(checks);
|
|
2211
|
+
} catch (e) {
|
|
2212
|
+
return failure(e);
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
);
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2036
2218
|
// src/http-server.ts
|
|
2037
2219
|
var import_node_crypto = require("crypto");
|
|
2038
2220
|
var import_node_http = __toESM(require("http"));
|
|
@@ -2112,6 +2294,38 @@ function createHttpServer(factory, o) {
|
|
|
2112
2294
|
});
|
|
2113
2295
|
}
|
|
2114
2296
|
|
|
2297
|
+
// src/package-info.ts
|
|
2298
|
+
var import_node_fs = require("fs");
|
|
2299
|
+
var import_node_path = require("path");
|
|
2300
|
+
var packageJson = JSON.parse((0, import_node_fs.readFileSync)((0, import_node_path.join)(__dirname, "..", "package.json"), "utf8"));
|
|
2301
|
+
var packageName = packageJson.name ?? "sonicwall-api-mcp-server";
|
|
2302
|
+
var packageVersion = packageJson.version ?? "0.0.0";
|
|
2303
|
+
|
|
2304
|
+
// src/strict-tools.ts
|
|
2305
|
+
var import_zod17 = require("zod");
|
|
2306
|
+
function isSchema(value) {
|
|
2307
|
+
return typeof value === "object" && value !== null && "_def" in value;
|
|
2308
|
+
}
|
|
2309
|
+
function isRawShape(value) {
|
|
2310
|
+
if (typeof value !== "object" || value === null || isSchema(value)) return false;
|
|
2311
|
+
const values = Object.values(value);
|
|
2312
|
+
return values.length === 0 || values.some(isSchema);
|
|
2313
|
+
}
|
|
2314
|
+
function strictSchema(schema) {
|
|
2315
|
+
if (schema === void 0) return import_zod17.z.object({}).strict();
|
|
2316
|
+
if (isRawShape(schema)) return import_zod17.z.object(schema).strict();
|
|
2317
|
+
if (isSchema(schema) && typeof schema.strict === "function") return schema.strict();
|
|
2318
|
+
return schema;
|
|
2319
|
+
}
|
|
2320
|
+
function enforceStrictToolInputs(server) {
|
|
2321
|
+
const mutable = server;
|
|
2322
|
+
const createRegisteredTool = mutable._createRegisteredTool.bind(server);
|
|
2323
|
+
mutable._createRegisteredTool = (...args) => {
|
|
2324
|
+
args[3] = strictSchema(args[3]);
|
|
2325
|
+
return createRegisteredTool(...args);
|
|
2326
|
+
};
|
|
2327
|
+
}
|
|
2328
|
+
|
|
2115
2329
|
// src/index.ts
|
|
2116
2330
|
async function main() {
|
|
2117
2331
|
let config;
|
|
@@ -2131,8 +2345,8 @@ async function main() {
|
|
|
2131
2345
|
const registry = new DeviceRegistry(config.profiles);
|
|
2132
2346
|
const createConfiguredServer = () => {
|
|
2133
2347
|
const server = new import_mcp.McpServer({
|
|
2134
|
-
name:
|
|
2135
|
-
version:
|
|
2348
|
+
name: packageName,
|
|
2349
|
+
version: packageVersion,
|
|
2136
2350
|
instructions: `SonicWall NSA MCP server \u2014 full read/write access to SonicWall firewalls via the SonicOS REST API.
|
|
2137
2351
|
|
|
2138
2352
|
## Device targeting
|
|
@@ -2152,6 +2366,7 @@ IMPORTANT: All create/update/delete operations are STAGED and do not take effect
|
|
|
2152
2366
|
- 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.
|
|
2153
2367
|
- 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.
|
|
2154
2368
|
- 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.
|
|
2369
|
+
- For reachability problems, use diagnose_ip for a combined appliance-side network-path, interface, route-policy, ARP, ping, and traceroute report. Use the individual diagnostic tools when you need a targeted test or a specific source interface.
|
|
2155
2370
|
- 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.
|
|
2156
2371
|
|
|
2157
2372
|
## Read-only API note
|
|
@@ -2160,6 +2375,7 @@ The SonicOS REST API is configuration-focused. Connection/flow ("traffic") logs
|
|
|
2160
2375
|
## Concurrent sessions
|
|
2161
2376
|
SonicOS allows only ONE concurrent API session per appliance. If a session error occurs, an existing admin or API session may need to be ended first.`
|
|
2162
2377
|
});
|
|
2378
|
+
enforceStrictToolInputs(server);
|
|
2163
2379
|
registerSystemTools(server, registry);
|
|
2164
2380
|
registerAddressObjectTools(server, registry);
|
|
2165
2381
|
registerAddressGroupTools(server, registry);
|
|
@@ -2174,6 +2390,7 @@ SonicOS allows only ONE concurrent API session per appliance. If a session error
|
|
|
2174
2390
|
registerInterfaceTools(server, registry);
|
|
2175
2391
|
registerScheduleTools(server, registry);
|
|
2176
2392
|
registerRoutePolicyTools(server, registry);
|
|
2393
|
+
registerDiagnosticTools(server, registry);
|
|
2177
2394
|
return server;
|
|
2178
2395
|
};
|
|
2179
2396
|
const transport = config.transport;
|
|
@@ -2181,8 +2398,8 @@ SonicOS allows only ONE concurrent API session per appliance. If a session error
|
|
|
2181
2398
|
await createConfiguredServer().connect(new import_stdio.StdioServerTransport());
|
|
2182
2399
|
} else if (transport === "http") {
|
|
2183
2400
|
const host = process.env["SONICWALL_HTTP_HOST"] ?? "127.0.0.1";
|
|
2184
|
-
const port =
|
|
2185
|
-
createHttpServer(createConfiguredServer, { host, port, serverName:
|
|
2401
|
+
const port = parsePositiveInt("SONICWALL_HTTP_PORT", process.env["SONICWALL_HTTP_PORT"], 3e3, 65535);
|
|
2402
|
+
createHttpServer(createConfiguredServer, { host, port, serverName: packageName, bearerToken: process.env["SONICWALL_HTTP_BEARER_TOKEN"], allowedHosts: process.env["SONICWALL_HTTP_ALLOWED_HOSTS"]?.split(",").map((v) => v.trim()).filter(Boolean), allowedOrigins: process.env["SONICWALL_HTTP_ALLOWED_ORIGINS"]?.split(",").map((v) => v.trim()).filter(Boolean), maxBodyBytes: parsePositiveInt("SONICWALL_HTTP_MAX_BODY_BYTES", process.env["SONICWALL_HTTP_MAX_BODY_BYTES"], 1048576, 16777216) }).listen(port, host, () => process.stderr.write(`sonicwall-mcp: HTTP listening on ${host}:${port}/mcp
|
|
2186
2403
|
`));
|
|
2187
2404
|
} else {
|
|
2188
2405
|
process.stderr.write(
|