@teamnetwork-nz/sonicwall-api-mcp-server 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +5 -2
  2. package/dist/index.js +237 -226
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -4,15 +4,18 @@ A [Model Context Protocol](https://modelcontextprotocol.io/) server that provide
4
4
 
5
5
  ## Features
6
6
 
7
- - **Log analysis** — retrieve, filter, and search event logs, traffic logs, and threat/IPS events
7
+ - **Log analysis** — retrieve, filter, and search event logs and threat/IPS events
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)
11
11
  - **NAT policies** — full CRUD for inbound/outbound NAT rules
12
12
  - **Security policies** — CRUD for zone-based security policies
13
- - **GeoIP filtering** — manage GeoIP country-block policies and assign them to access rules
13
+ - **Network discovery** — list zones, interfaces, schedules, and route policies (read-only)
14
+ - **GeoIP lookup** — identify the country/botnet classification of an IP address
14
15
  - **Config management** — view and commit (or discard) staged changes
15
16
 
17
+ > The SonicOS REST API is configuration-focused. Connection/flow ("traffic") logs and GeoIP *policy* objects are not exposed as REST endpoints and therefore have no tools.
18
+
16
19
  Supports SonicOS 6.5.x, 7.x, and 8.x with automatic version detection.
17
20
 
18
21
  ## Quick Start
package/dist/index.js CHANGED
@@ -338,6 +338,23 @@ var SonicWallClient = class {
338
338
  [`https://${host}:${port}/api/sonicos/v8`, 8],
339
339
  [`https://${host}:${port}/api/sonicos`, 7]
340
340
  ];
341
+ for (const [base, version] of candidates) {
342
+ try {
343
+ const resp = await fetch(`${base}/auth`, {
344
+ method: "POST",
345
+ headers: { "Accept": "application/json", "Content-Type": "application/json" },
346
+ body: "{}",
347
+ signal: AbortSignal.timeout(this.profile.requestTimeout * 1e3)
348
+ });
349
+ if (resp.status < 400 || resp.headers.get("WWW-Authenticate")) {
350
+ this.baseUrl = base;
351
+ this.version = version;
352
+ return;
353
+ }
354
+ } catch {
355
+ continue;
356
+ }
357
+ }
341
358
  for (const [base, version] of candidates) {
342
359
  try {
343
360
  const resp = await fetch(`${base}/system/status`, {
@@ -353,10 +370,8 @@ var SonicWallClient = class {
353
370
  continue;
354
371
  }
355
372
  }
356
- if (!this.baseUrl) {
357
- this.baseUrl = `https://${host}:${port}/api/sonicos`;
358
- this.version = 7;
359
- }
373
+ this.baseUrl = `https://${host}:${port}/api/sonicos`;
374
+ this.version = 7;
360
375
  }
361
376
  async close() {
362
377
  await this.auth.logout(this.baseUrl);
@@ -519,7 +534,7 @@ function registerSystemTools(server, registry) {
519
534
  async ({ device }) => {
520
535
  try {
521
536
  const client = await registry.getClient(device);
522
- const result = await client.get("system/status");
537
+ const result = await client.get("version");
523
538
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
524
539
  } catch (e) {
525
540
  return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
@@ -764,7 +779,7 @@ var import_zod3 = require("zod");
764
779
  function registerAddressGroupTools(server, registry) {
765
780
  server.tool(
766
781
  "list_address_groups",
767
- "List address groups on the appliance.",
782
+ "List address groups on the appliance. type: filter by 'ipv4', 'ipv6', or 'all' (default).",
768
783
  {
769
784
  type: import_zod3.z.enum(["ipv4", "ipv6", "all"]).optional().default("all"),
770
785
  device: import_zod3.z.string().optional()
@@ -1151,10 +1166,21 @@ function registerServiceGroupTools(server, registry) {
1151
1166
 
1152
1167
  // src/tools/access-rules.ts
1153
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
+ }
1154
1180
  function registerAccessRuleTools(server, registry) {
1155
1181
  server.tool(
1156
1182
  "list_access_rules",
1157
- "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 (the SonicOS endpoint returns the full ruleset), so use from_zone/to_zone to keep responses small.",
1158
1184
  {
1159
1185
  ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
1160
1186
  from_zone: import_zod6.z.string().optional(),
@@ -1164,10 +1190,19 @@ function registerAccessRuleTools(server, registry) {
1164
1190
  async ({ ip_version, from_zone, to_zone, device }) => {
1165
1191
  try {
1166
1192
  const client = await registry.getClient(device);
1167
- const params = {};
1168
- if (from_zone) params["from"] = from_zone;
1169
- if (to_zone) params["to"] = to_zone;
1170
- const result = await client.get(`access-rules/${ip_version}`, Object.keys(params).length ? params : void 0);
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
+ }
1171
1206
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1172
1207
  } catch (e) {
1173
1208
  return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
@@ -1194,7 +1229,7 @@ function registerAccessRuleTools(server, registry) {
1194
1229
  );
1195
1230
  server.tool(
1196
1231
  "create_access_rule",
1197
- "Create a firewall access rule. source/destination/service: name of an existing address/service object or 'Any'. geo_ip_policy: optional name of a GeoIP policy to attach. Changes are STAGED; call commit_config to apply.",
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.",
1198
1233
  {
1199
1234
  ip_version: import_zod6.z.enum(["ipv4", "ipv6"]),
1200
1235
  name: import_zod6.z.string(),
@@ -1239,7 +1274,7 @@ function registerAccessRuleTools(server, registry) {
1239
1274
  );
1240
1275
  server.tool(
1241
1276
  "update_access_rule",
1242
- "Update fields on an existing access rule (GET-then-PUT). Only provided fields are changed. Set geo_ip_policy to '' to remove it. Changes are STAGED; call commit_config to apply.",
1277
+ "Update fields on an existing access rule (GET-then-PUT). 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.",
1243
1278
  {
1244
1279
  rule_id: import_zod6.z.number(),
1245
1280
  ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
@@ -1364,7 +1399,7 @@ function setNameField(obj, key, value) {
1364
1399
  function registerNatPolicyTools(server, registry) {
1365
1400
  server.tool(
1366
1401
  "list_nat_policies",
1367
- "List all NAT policies.",
1402
+ "List all NAT policies. ip_version: 'ipv4' (default) or 'ipv6'.",
1368
1403
  {
1369
1404
  ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
1370
1405
  device: import_zod7.z.string().optional()
@@ -1505,18 +1540,43 @@ function registerNatPolicyTools(server, registry) {
1505
1540
 
1506
1541
  // src/tools/security-policies.ts
1507
1542
  var import_zod8 = require("zod");
1543
+ function zoneName2(v) {
1544
+ if (typeof v === "string") return v;
1545
+ if (v && typeof v === "object") {
1546
+ const z15 = v.zone;
1547
+ if (typeof z15 === "string") return z15;
1548
+ }
1549
+ return void 0;
1550
+ }
1551
+ function matchesZone2(value, filter) {
1552
+ return value !== void 0 && value.toLowerCase() === filter.toLowerCase();
1553
+ }
1508
1554
  function registerSecurityPolicyTools(server, registry) {
1509
1555
  server.tool(
1510
1556
  "list_security_policies",
1511
- "List all security policies.",
1557
+ "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.",
1512
1558
  {
1513
1559
  ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
1560
+ from_zone: import_zod8.z.string().optional(),
1561
+ to_zone: import_zod8.z.string().optional(),
1514
1562
  device: import_zod8.z.string().optional()
1515
1563
  },
1516
- async ({ ip_version, device }) => {
1564
+ async ({ ip_version, from_zone, to_zone, device }) => {
1517
1565
  try {
1518
1566
  const client = await registry.getClient(device);
1519
1567
  const result = await client.get(`security-policies/${ip_version}`);
1568
+ if (from_zone || to_zone) {
1569
+ const all = result.security_policies ?? [];
1570
+ const filtered = all.filter((entry) => {
1571
+ const policy = entry[ip_version];
1572
+ if (!policy) return false;
1573
+ if (from_zone && !matchesZone2(zoneName2(policy.from), from_zone)) return false;
1574
+ if (to_zone && !matchesZone2(zoneName2(policy.to), to_zone)) return false;
1575
+ return true;
1576
+ });
1577
+ const out = { security_policies: filtered, matched: filtered.length, total: all.length };
1578
+ return { content: [{ type: "text", text: JSON.stringify(out, null, 2) }] };
1579
+ }
1520
1580
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1521
1581
  } catch (e) {
1522
1582
  return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
@@ -1692,159 +1752,6 @@ function parseGeoLookup(ip, raw) {
1692
1752
  return parsed;
1693
1753
  }
1694
1754
  function registerGeoIpTools(server, registry) {
1695
- server.tool(
1696
- "list_geo_ip_policies",
1697
- "List all GeoIP filtering policies configured on the appliance.",
1698
- { device: import_zod9.z.string().optional() },
1699
- async ({ device }) => {
1700
- try {
1701
- const client = await registry.getClient(device);
1702
- const result = await client.get("geo-ip/policies");
1703
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1704
- } catch (e) {
1705
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1706
- }
1707
- }
1708
- );
1709
- server.tool(
1710
- "get_geo_ip_policy",
1711
- "Retrieve a GeoIP policy by name.",
1712
- { name: import_zod9.z.string(), device: import_zod9.z.string().optional() },
1713
- async ({ name, device }) => {
1714
- try {
1715
- const client = await registry.getClient(device);
1716
- const result = await client.get(`geo-ip/policies/name/${name}`);
1717
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1718
- } catch (e) {
1719
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1720
- }
1721
- }
1722
- );
1723
- server.tool(
1724
- "create_geo_ip_policy",
1725
- "Create a GeoIP filtering policy. block_countries/allow_countries: lists of ISO 3166-1 alpha-2 country codes (e.g. ['CN', 'RU', 'KP']). Changes are STAGED; call commit_config to apply.",
1726
- {
1727
- name: import_zod9.z.string(),
1728
- block_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
1729
- allow_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
1730
- log: import_zod9.z.boolean().optional().default(true),
1731
- device: import_zod9.z.string().optional()
1732
- },
1733
- async ({ name, block_countries, allow_countries, log, device }) => {
1734
- try {
1735
- const client = await registry.getClient(device);
1736
- const policy = { name, log };
1737
- if (block_countries && block_countries.length > 0) {
1738
- policy.block_countries = block_countries.map((c) => ({ country: c.toUpperCase() }));
1739
- }
1740
- if (allow_countries && allow_countries.length > 0) {
1741
- policy.allow_countries = allow_countries.map((c) => ({ country: c.toUpperCase() }));
1742
- }
1743
- const result = await client.post("geo-ip/policies", { geo_ip_policies: [policy] });
1744
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1745
- } catch (e) {
1746
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1747
- }
1748
- }
1749
- );
1750
- server.tool(
1751
- "update_geo_ip_policy",
1752
- "Update a GeoIP policy (GET-then-PUT). Only supplied fields are changed. Providing an empty list clears that list. Changes are STAGED; call commit_config to apply.",
1753
- {
1754
- name: import_zod9.z.string(),
1755
- block_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
1756
- allow_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
1757
- log: import_zod9.z.boolean().optional(),
1758
- device: import_zod9.z.string().optional()
1759
- },
1760
- async ({ name, block_countries, allow_countries, log, device }) => {
1761
- try {
1762
- const client = await registry.getClient(device);
1763
- const current = await client.get(`geo-ip/policies/name/${name}`);
1764
- const policies = current.geo_ip_policies;
1765
- const policy = policies?.[0] ?? {};
1766
- if (block_countries !== void 0) {
1767
- policy.block_countries = block_countries.map((c) => ({ country: c.toUpperCase() }));
1768
- }
1769
- if (allow_countries !== void 0) {
1770
- policy.allow_countries = allow_countries.map((c) => ({ country: c.toUpperCase() }));
1771
- }
1772
- if (log !== void 0) policy.log = log;
1773
- const result = await client.put(`geo-ip/policies/name/${name}`, { geo_ip_policies: [policy] });
1774
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1775
- } catch (e) {
1776
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1777
- }
1778
- }
1779
- );
1780
- server.tool(
1781
- "delete_geo_ip_policy",
1782
- "Delete a GeoIP policy by name. Changes are STAGED; call commit_config to apply.",
1783
- { name: import_zod9.z.string(), device: import_zod9.z.string().optional() },
1784
- async ({ name, device }) => {
1785
- try {
1786
- const client = await registry.getClient(device);
1787
- const result = await client.delete(`geo-ip/policies/name/${name}`);
1788
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1789
- } catch (e) {
1790
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1791
- }
1792
- }
1793
- );
1794
- server.tool(
1795
- "list_geo_ip_countries",
1796
- "Return all country codes and names available for GeoIP filtering.",
1797
- { device: import_zod9.z.string().optional() },
1798
- async ({ device }) => {
1799
- try {
1800
- const client = await registry.getClient(device);
1801
- const result = await client.get("geo-ip/countries");
1802
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1803
- } catch (e) {
1804
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1805
- }
1806
- }
1807
- );
1808
- server.tool(
1809
- "get_geo_ip_stats",
1810
- "Return GeoIP statistics \u2014 connection counts blocked/allowed by country.",
1811
- { device: import_zod9.z.string().optional() },
1812
- async ({ device }) => {
1813
- try {
1814
- const client = await registry.getClient(device);
1815
- const result = await client.get("geo-ip/statistics");
1816
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1817
- } catch (e) {
1818
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1819
- }
1820
- }
1821
- );
1822
- server.tool(
1823
- "assign_geo_ip_to_rule",
1824
- "Attach a GeoIP policy to an existing access rule without changing any other rule fields. Changes are STAGED; call commit_config to apply.",
1825
- {
1826
- rule_id: import_zod9.z.number(),
1827
- geo_ip_policy_name: import_zod9.z.string(),
1828
- ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
1829
- device: import_zod9.z.string().optional()
1830
- },
1831
- async ({ rule_id, geo_ip_policy_name, ip_version, device }) => {
1832
- try {
1833
- const client = await registry.getClient(device);
1834
- const current = await client.get(`access-rules/${ip_version}/${rule_id}`);
1835
- const rules = current.access_rules;
1836
- const rule = rules?.[0]?.[ip_version] ?? {};
1837
- if (!rule.security_profile) rule.security_profile = {};
1838
- rule.security_profile.geo_ip_policy = { name: geo_ip_policy_name };
1839
- const result = await client.put(`access-rules/${ip_version}/${rule_id}`, {
1840
- access_rules: [{ [ip_version]: rule }]
1841
- });
1842
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1843
- } catch (e) {
1844
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1845
- }
1846
- }
1847
- );
1848
1755
  server.tool(
1849
1756
  "lookup_ip_country",
1850
1757
  "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.",
@@ -1864,23 +1771,22 @@ function registerGeoIpTools(server, registry) {
1864
1771
 
1865
1772
  // src/tools/logs.ts
1866
1773
  var import_zod10 = require("zod");
1867
- function logPath(version, subpath) {
1868
- return version >= 8 ? `log/${subpath}` : `reporting/${subpath}`;
1869
- }
1870
- async function getLogsWithFallback(client, subpathV7, subpathV8, params) {
1871
- const isPrimary = client.version >= 8;
1872
- const primary = logPath(client.version, isPrimary ? subpathV8 : subpathV7);
1873
- const fallbackVersion = isPrimary ? 7 : 8;
1874
- const fallback = logPath(fallbackVersion, isPrimary ? subpathV7 : subpathV8);
1875
- try {
1876
- return await client.get(primary, params);
1877
- } catch (e) {
1878
- if (e instanceof APIError && e.status === 404) {
1879
- return await client.get(fallback, params);
1774
+ async function getLogsWithFallback(client, candidates, params) {
1775
+ let lastErr;
1776
+ for (const path of candidates) {
1777
+ try {
1778
+ return await client.get(path, params);
1779
+ } catch (e) {
1780
+ if (e instanceof APIError && (e.status === 404 || e.status === 400)) {
1781
+ lastErr = e;
1782
+ continue;
1783
+ }
1784
+ throw e;
1880
1785
  }
1881
- throw e;
1882
1786
  }
1787
+ throw lastErr;
1883
1788
  }
1789
+ var EVENT_LOG_PATHS = ["log/events", "reporting/log/events"];
1884
1790
  function registerLogTools(server, registry) {
1885
1791
  server.tool(
1886
1792
  "get_log_categories",
@@ -1889,12 +1795,15 @@ function registerLogTools(server, registry) {
1889
1795
  async ({ device }) => {
1890
1796
  try {
1891
1797
  const client = await registry.getClient(device);
1892
- const path = client.version >= 8 ? "log/categories" : "reporting/log/categories";
1893
1798
  try {
1894
- const result = await client.get(path);
1799
+ const result = await getLogsWithFallback(
1800
+ client,
1801
+ ["log/categories", "reporting/log/categories"],
1802
+ {}
1803
+ );
1895
1804
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1896
1805
  } catch (e) {
1897
- if (e instanceof APIError && e.status === 404) {
1806
+ if (e instanceof APIError && (e.status === 404 || e.status === 400)) {
1898
1807
  const fallback = {
1899
1808
  categories: [
1900
1809
  "network access",
@@ -1944,39 +1853,7 @@ function registerLogTools(server, registry) {
1944
1853
  if (end_time) params.end_time = end_time;
1945
1854
  if (source_ip) params.src_ip = source_ip;
1946
1855
  if (keyword) params.keyword = keyword;
1947
- const result = await getLogsWithFallback(client, "log", "events", params);
1948
- return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1949
- } catch (e) {
1950
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1951
- }
1952
- }
1953
- );
1954
- server.tool(
1955
- "get_traffic_logs",
1956
- "Retrieve traffic/connection logs. count: max entries. source_ip/destination_ip: filter by IP. destination_port: TCP/UDP port. protocol: e.g. 'TCP', 'UDP', 'ICMP'. action: 'allow' or 'deny'.",
1957
- {
1958
- count: import_zod10.z.number().optional().default(100),
1959
- source_ip: import_zod10.z.string().optional(),
1960
- destination_ip: import_zod10.z.string().optional(),
1961
- destination_port: import_zod10.z.number().optional(),
1962
- protocol: import_zod10.z.string().optional(),
1963
- action: import_zod10.z.enum(["allow", "deny"]).optional(),
1964
- start_time: import_zod10.z.string().optional(),
1965
- end_time: import_zod10.z.string().optional(),
1966
- device: import_zod10.z.string().optional()
1967
- },
1968
- async ({ count, source_ip, destination_ip, destination_port, protocol, action, start_time, end_time, device }) => {
1969
- try {
1970
- const client = await registry.getClient(device);
1971
- const params = { count };
1972
- if (source_ip) params.src_ip = source_ip;
1973
- if (destination_ip) params.dst_ip = destination_ip;
1974
- if (destination_port !== void 0) params.dst_port = destination_port;
1975
- if (protocol) params.protocol = protocol;
1976
- if (action) params.action = action;
1977
- if (start_time) params.start_time = start_time;
1978
- if (end_time) params.end_time = end_time;
1979
- const result = await getLogsWithFallback(client, "appflow/connections", "traffic", params);
1856
+ const result = await getLogsWithFallback(client, EVENT_LOG_PATHS, params);
1980
1857
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1981
1858
  } catch (e) {
1982
1859
  return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
@@ -1999,7 +1876,7 @@ function registerLogTools(server, registry) {
1999
1876
  const params = { count, keyword: query };
2000
1877
  if (start_time) params.start_time = start_time;
2001
1878
  if (end_time) params.end_time = end_time;
2002
- const result = await getLogsWithFallback(client, "log", "events", params);
1879
+ const result = await getLogsWithFallback(client, EVENT_LOG_PATHS, params);
2003
1880
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
2004
1881
  } catch (e) {
2005
1882
  return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
@@ -2008,7 +1885,7 @@ function registerLogTools(server, registry) {
2008
1885
  );
2009
1886
  server.tool(
2010
1887
  "get_threat_logs",
2011
- "Retrieve IPS and threat-detection log events. severity: 'critical', 'high', 'medium', or 'low'.",
1888
+ "Retrieve IPS and threat-detection log events (filters by IPS category). severity maps to SonicOS priority levels: 'critical'\u2192critical, 'high'\u2192error, 'medium'\u2192warning, 'low'\u2192notice.",
2012
1889
  {
2013
1890
  count: import_zod10.z.number().optional().default(50),
2014
1891
  severity: import_zod10.z.enum(["critical", "high", "medium", "low"]).optional(),
@@ -2019,11 +1896,138 @@ function registerLogTools(server, registry) {
2019
1896
  async ({ count, severity, start_time, end_time, device }) => {
2020
1897
  try {
2021
1898
  const client = await registry.getClient(device);
1899
+ const severityToPriority = {
1900
+ critical: "critical",
1901
+ high: "error",
1902
+ medium: "warning",
1903
+ low: "notice"
1904
+ };
2022
1905
  const params = { count, category: "IPS" };
2023
- if (severity) params.severity = severity;
1906
+ if (severity) params.priority = severityToPriority[severity];
2024
1907
  if (start_time) params.start_time = start_time;
2025
1908
  if (end_time) params.end_time = end_time;
2026
- const result = await getLogsWithFallback(client, "log", "events", params);
1909
+ const result = await getLogsWithFallback(client, EVENT_LOG_PATHS, params);
1910
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1911
+ } catch (e) {
1912
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1913
+ }
1914
+ }
1915
+ );
1916
+ }
1917
+
1918
+ // src/tools/zones.ts
1919
+ var import_zod11 = require("zod");
1920
+ function registerZoneTools(server, registry) {
1921
+ server.tool(
1922
+ "list_zones",
1923
+ "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.",
1924
+ { device: import_zod11.z.string().optional() },
1925
+ async ({ device }) => {
1926
+ try {
1927
+ const client = await registry.getClient(device);
1928
+ const result = await client.get("zones");
1929
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1930
+ } catch (e) {
1931
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1932
+ }
1933
+ }
1934
+ );
1935
+ server.tool(
1936
+ "get_zone",
1937
+ "Retrieve a single security zone by name.",
1938
+ { name: import_zod11.z.string(), device: import_zod11.z.string().optional() },
1939
+ async ({ name, device }) => {
1940
+ try {
1941
+ const client = await registry.getClient(device);
1942
+ const result = await client.get(`zones/name/${encodeURIComponent(name)}`);
1943
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1944
+ } catch (e) {
1945
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1946
+ }
1947
+ }
1948
+ );
1949
+ }
1950
+
1951
+ // src/tools/interfaces.ts
1952
+ var import_zod12 = require("zod");
1953
+ function registerInterfaceTools(server, registry) {
1954
+ server.tool(
1955
+ "list_interfaces",
1956
+ "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.",
1957
+ { device: import_zod12.z.string().optional() },
1958
+ async ({ device }) => {
1959
+ try {
1960
+ const client = await registry.getClient(device);
1961
+ const result = await client.get("interfaces/ipv4");
1962
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1963
+ } catch (e) {
1964
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1965
+ }
1966
+ }
1967
+ );
1968
+ server.tool(
1969
+ "get_interface",
1970
+ 'Retrieve a single IPv4 interface by name (e.g. "X0").',
1971
+ { name: import_zod12.z.string(), device: import_zod12.z.string().optional() },
1972
+ async ({ name, device }) => {
1973
+ try {
1974
+ const client = await registry.getClient(device);
1975
+ const result = await client.get(`interfaces/ipv4/name/${encodeURIComponent(name)}`);
1976
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1977
+ } catch (e) {
1978
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1979
+ }
1980
+ }
1981
+ );
1982
+ }
1983
+
1984
+ // src/tools/schedules.ts
1985
+ var import_zod13 = require("zod");
1986
+ function registerScheduleTools(server, registry) {
1987
+ server.tool(
1988
+ "list_schedules",
1989
+ '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.',
1990
+ { device: import_zod13.z.string().optional() },
1991
+ async ({ device }) => {
1992
+ try {
1993
+ const client = await registry.getClient(device);
1994
+ const result = await client.get("schedules");
1995
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
1996
+ } catch (e) {
1997
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
1998
+ }
1999
+ }
2000
+ );
2001
+ server.tool(
2002
+ "get_schedule",
2003
+ "Retrieve a single schedule object by name.",
2004
+ { name: import_zod13.z.string(), device: import_zod13.z.string().optional() },
2005
+ async ({ name, device }) => {
2006
+ try {
2007
+ const client = await registry.getClient(device);
2008
+ const result = await client.get(`schedules/name/${encodeURIComponent(name)}`);
2009
+ return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
2010
+ } catch (e) {
2011
+ return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
2012
+ }
2013
+ }
2014
+ );
2015
+ }
2016
+
2017
+ // src/tools/route-policies.ts
2018
+ var import_zod14 = require("zod");
2019
+ function registerRoutePolicyTools(server, registry) {
2020
+ server.tool(
2021
+ "list_route_policies",
2022
+ "List static/policy-based routes with their destination, gateway, interface, and metric. Useful for understanding how traffic is routed off the appliance.",
2023
+ {
2024
+ ip_version: import_zod14.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
2025
+ device: import_zod14.z.string().optional()
2026
+ },
2027
+ async ({ ip_version, device }) => {
2028
+ try {
2029
+ const client = await registry.getClient(device);
2030
+ const result = await client.get(`route-policies/${ip_version}`);
2027
2031
  return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
2028
2032
  } catch (e) {
2029
2033
  return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
@@ -2051,7 +2055,7 @@ async function main() {
2051
2055
  const registry = new DeviceRegistry(config.profiles);
2052
2056
  const server = new import_mcp.McpServer({
2053
2057
  name: "sonicwall-mcp-server",
2054
- version: "0.4.1",
2058
+ version: "0.5.1",
2055
2059
  instructions: `SonicWall NSA MCP server \u2014 full read/write access to SonicWall firewalls via the SonicOS REST API.
2056
2060
 
2057
2061
  ## Device targeting
@@ -2066,7 +2070,6 @@ All timestamp parameters (start_time, end_time in log tools) are in the applianc
2066
2070
  ## Log querying
2067
2071
  - Call get_log_categories first to discover valid category names for get_event_logs.
2068
2072
  - get_event_logs: general system/security events. Filter by category, priority, source_ip, or keyword.
2069
- - get_traffic_logs: connection/flow logs. Filter by source_ip, destination_ip, port, protocol, or action.
2070
2073
  - get_threat_logs: IPS and AV detections. Filter by severity.
2071
2074
  - search_logs: full-text keyword search across event logs \u2014 use when you have a specific IP, hostname, or error string.
2072
2075
  - Default count is 100. Increase for broader searches, but keep it reasonable to avoid large payloads.
@@ -2077,7 +2080,11 @@ All timestamp parameters (start_time, end_time in log tools) are in the applianc
2077
2080
  - 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.
2078
2081
  - 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.
2079
2082
  - Always call list_access_rules, list_nat_policies, or list_security_policies before modifying, to confirm current state and avoid duplicates.
2080
- - GeoIP policies block or allow traffic by country code (ISO 3166-1 alpha-2). Use list_geo_ip_policies to see current policies, list_geo_ip_countries for all available codes, and lookup_ip_country to identify which country an IP address belongs to.
2083
+ - 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.
2084
+ - 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.
2085
+
2086
+ ## Read-only API note
2087
+ The SonicOS REST API is configuration-focused. Connection/flow ("traffic") logs and GeoIP policy objects are not exposed as REST endpoints, so there are no tools for them.
2081
2088
 
2082
2089
  ## Concurrent sessions
2083
2090
  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.`
@@ -2092,6 +2099,10 @@ SonicOS allows only ONE concurrent API session per appliance. If a session error
2092
2099
  registerSecurityPolicyTools(server, registry);
2093
2100
  registerGeoIpTools(server, registry);
2094
2101
  registerLogTools(server, registry);
2102
+ registerZoneTools(server, registry);
2103
+ registerInterfaceTools(server, registry);
2104
+ registerScheduleTools(server, registry);
2105
+ registerRoutePolicyTools(server, registry);
2095
2106
  const transport = config.transport;
2096
2107
  if (transport === "stdio") {
2097
2108
  const t = new import_stdio.StdioServerTransport();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnetwork-nz/sonicwall-api-mcp-server",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "MCP server for SonicWall NSA appliance API — logs, CRUD objects, rules, NAT, GeoIP",
5
5
  "keywords": [
6
6
  "mcp",