@teamnetwork-nz/sonicwall-api-mcp-server 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2083 -0
- package/package.json +51 -39
- package/bin/index.js +0 -63
package/dist/index.js
ADDED
|
@@ -0,0 +1,2083 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
28
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
29
|
+
|
|
30
|
+
// src/config.ts
|
|
31
|
+
var fs = __toESM(require("fs"));
|
|
32
|
+
function loadConfig() {
|
|
33
|
+
const devicesFile = process.env.SONICWALL_DEVICES_FILE;
|
|
34
|
+
let profiles = [];
|
|
35
|
+
if (devicesFile) {
|
|
36
|
+
const data = JSON.parse(fs.readFileSync(devicesFile, "utf8"));
|
|
37
|
+
if (!Array.isArray(data) || data.length === 0) {
|
|
38
|
+
throw new Error("SONICWALL_DEVICES_FILE must be a non-empty JSON array");
|
|
39
|
+
}
|
|
40
|
+
profiles = data.map((d) => ({
|
|
41
|
+
name: d.name,
|
|
42
|
+
host: d.host,
|
|
43
|
+
username: d.username,
|
|
44
|
+
password: d.password,
|
|
45
|
+
port: d.port ?? 443,
|
|
46
|
+
sslVerify: d.ssl_verify ?? true,
|
|
47
|
+
readOnly: d.read_only ?? true,
|
|
48
|
+
requestTimeout: d.request_timeout ?? 30
|
|
49
|
+
}));
|
|
50
|
+
} else {
|
|
51
|
+
const host = process.env.SONICWALL_HOST;
|
|
52
|
+
const username = process.env.SONICWALL_USERNAME;
|
|
53
|
+
const password = process.env.SONICWALL_PASSWORD;
|
|
54
|
+
if (!host || !username || !password) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"Set SONICWALL_HOST, SONICWALL_USERNAME, and SONICWALL_PASSWORD (or SONICWALL_DEVICES_FILE for multi-device)"
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
profiles = [{
|
|
60
|
+
name: process.env.SONICWALL_DEVICE_NAME ?? "default",
|
|
61
|
+
host,
|
|
62
|
+
username,
|
|
63
|
+
password,
|
|
64
|
+
port: parseInt(process.env.SONICWALL_PORT ?? "443", 10),
|
|
65
|
+
sslVerify: (process.env.SONICWALL_SSL_VERIFY ?? "true") !== "false",
|
|
66
|
+
readOnly: (process.env.SONICWALL_READ_ONLY ?? "true") !== "false",
|
|
67
|
+
requestTimeout: parseFloat(process.env.SONICWALL_REQUEST_TIMEOUT ?? "30")
|
|
68
|
+
}];
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
profiles,
|
|
72
|
+
transport: process.env.SONICWALL_TRANSPORT ?? "stdio",
|
|
73
|
+
ssePort: parseInt(process.env.SONICWALL_SSE_PORT ?? "8000", 10)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/auth.ts
|
|
78
|
+
var import_crypto = require("crypto");
|
|
79
|
+
var REAUTH_AFTER = 27e4;
|
|
80
|
+
var AuthenticationError = class extends Error {
|
|
81
|
+
constructor(message) {
|
|
82
|
+
super(message);
|
|
83
|
+
this.name = "AuthenticationError";
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var SessionConflictError = class extends Error {
|
|
87
|
+
constructor(message) {
|
|
88
|
+
super(message);
|
|
89
|
+
this.name = "SessionConflictError";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function md5(s) {
|
|
93
|
+
return (0, import_crypto.createHash)("md5").update(s).digest("hex");
|
|
94
|
+
}
|
|
95
|
+
function sha256(s) {
|
|
96
|
+
return (0, import_crypto.createHash)("sha256").update(s).digest("hex");
|
|
97
|
+
}
|
|
98
|
+
function parseDigestChallenge(header) {
|
|
99
|
+
const params = {};
|
|
100
|
+
for (const m of header.matchAll(/(\w+)="([^"]+)"/g)) {
|
|
101
|
+
params[m[1]] = m[2];
|
|
102
|
+
}
|
|
103
|
+
for (const m of header.matchAll(/(\w+)=([^",\s]+)/g)) {
|
|
104
|
+
if (!params[m[1]]) params[m[1]] = m[2];
|
|
105
|
+
}
|
|
106
|
+
return params;
|
|
107
|
+
}
|
|
108
|
+
function buildDigestHeader(method, uri, username, password, challenge) {
|
|
109
|
+
const { realm, nonce, qop } = challenge;
|
|
110
|
+
const algo = (challenge.algorithm ?? "MD5").toUpperCase();
|
|
111
|
+
const hash = algo === "SHA-256" ? sha256 : md5;
|
|
112
|
+
const nc = "00000001";
|
|
113
|
+
const cnonce = Math.random().toString(36).substring(2, 10);
|
|
114
|
+
const ha1 = hash(`${username}:${realm}:${password}`);
|
|
115
|
+
const ha2 = hash(`${method}:${uri}`);
|
|
116
|
+
const response = qop === "auth" ? hash(`${ha1}:${nonce}:${nc}:${cnonce}:auth:${ha2}`) : hash(`${ha1}:${nonce}:${ha2}`);
|
|
117
|
+
let h = `Digest username="${username}", realm="${realm}", nonce="${nonce}", uri="${uri}", response="${response}"`;
|
|
118
|
+
if (qop === "auth") h += `, qop=auth, nc=${nc}, cnonce="${cnonce}"`;
|
|
119
|
+
if (algo !== "MD5") h += `, algorithm=${algo}`;
|
|
120
|
+
return h;
|
|
121
|
+
}
|
|
122
|
+
var AuthManager = class {
|
|
123
|
+
constructor(username, password) {
|
|
124
|
+
this.username = username;
|
|
125
|
+
this.password = password;
|
|
126
|
+
}
|
|
127
|
+
username;
|
|
128
|
+
password;
|
|
129
|
+
token = null;
|
|
130
|
+
lastUsed = 0;
|
|
131
|
+
pending = null;
|
|
132
|
+
isStale() {
|
|
133
|
+
return !this.token || Date.now() - this.lastUsed > REAUTH_AFTER;
|
|
134
|
+
}
|
|
135
|
+
async ensureAuthenticated(baseUrl) {
|
|
136
|
+
if (!this.isStale()) {
|
|
137
|
+
this.lastUsed = Date.now();
|
|
138
|
+
return this.token;
|
|
139
|
+
}
|
|
140
|
+
if (!this.pending) {
|
|
141
|
+
this.pending = this._doLogin(baseUrl).finally(() => {
|
|
142
|
+
this.pending = null;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
await this.pending;
|
|
146
|
+
return this.token;
|
|
147
|
+
}
|
|
148
|
+
invalidate() {
|
|
149
|
+
this.token = null;
|
|
150
|
+
this.lastUsed = 0;
|
|
151
|
+
}
|
|
152
|
+
async logout(baseUrl) {
|
|
153
|
+
if (!this.token) return;
|
|
154
|
+
try {
|
|
155
|
+
const headers = { "Accept": "application/json" };
|
|
156
|
+
if (this.token !== "_cookie_session_") {
|
|
157
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
158
|
+
}
|
|
159
|
+
await fetch(`${baseUrl}/auth`, { method: "DELETE", headers });
|
|
160
|
+
} catch {
|
|
161
|
+
} finally {
|
|
162
|
+
this.token = null;
|
|
163
|
+
this.lastUsed = 0;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async _doLogin(baseUrl) {
|
|
167
|
+
const url = `${baseUrl}/auth`;
|
|
168
|
+
const path = new URL(url).pathname;
|
|
169
|
+
try {
|
|
170
|
+
const challenge = await this._getDigestChallenge(url);
|
|
171
|
+
if (challenge) {
|
|
172
|
+
const authHeader = buildDigestHeader("POST", path, this.username, this.password, challenge);
|
|
173
|
+
const resp2 = await fetch(url, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
headers: {
|
|
176
|
+
"Authorization": authHeader,
|
|
177
|
+
"Accept": "application/json",
|
|
178
|
+
"Content-Type": "application/json"
|
|
179
|
+
},
|
|
180
|
+
body: "{}"
|
|
181
|
+
});
|
|
182
|
+
if (resp2.status !== 401) {
|
|
183
|
+
await this._handleLoginResponse(resp2, url);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
} catch (e) {
|
|
188
|
+
if (e instanceof AuthenticationError || e instanceof SessionConflictError) throw e;
|
|
189
|
+
}
|
|
190
|
+
const basicCreds = Buffer.from(`${this.username}:${this.password}`).toString("base64");
|
|
191
|
+
let resp;
|
|
192
|
+
try {
|
|
193
|
+
resp = await fetch(url, {
|
|
194
|
+
method: "POST",
|
|
195
|
+
headers: {
|
|
196
|
+
"Authorization": `Basic ${basicCreds}`,
|
|
197
|
+
"Accept": "application/json",
|
|
198
|
+
"Content-Type": "application/json"
|
|
199
|
+
},
|
|
200
|
+
body: "{}"
|
|
201
|
+
});
|
|
202
|
+
} catch (e) {
|
|
203
|
+
throw new AuthenticationError(`Cannot connect to ${url}: ${e.message}`);
|
|
204
|
+
}
|
|
205
|
+
await this._handleLoginResponse(resp, url);
|
|
206
|
+
}
|
|
207
|
+
async _getDigestChallenge(url) {
|
|
208
|
+
let resp;
|
|
209
|
+
try {
|
|
210
|
+
resp = await fetch(url, {
|
|
211
|
+
method: "POST",
|
|
212
|
+
headers: { "Accept": "application/json", "Content-Type": "application/json" },
|
|
213
|
+
body: "{}"
|
|
214
|
+
});
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
if (resp.status !== 401) return null;
|
|
219
|
+
const wwwAuth = resp.headers.get("WWW-Authenticate") ?? "";
|
|
220
|
+
if (!wwwAuth.startsWith("Digest ")) return null;
|
|
221
|
+
return parseDigestChallenge(wwwAuth);
|
|
222
|
+
}
|
|
223
|
+
async _handleLoginResponse(resp, url) {
|
|
224
|
+
if (resp.status === 403) {
|
|
225
|
+
throw new SessionConflictError(
|
|
226
|
+
"Another admin session is currently active on this SonicWall appliance. Log out from the management UI or wait for the existing session to expire."
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
if (resp.status === 401) {
|
|
230
|
+
throw new AuthenticationError("Login rejected \u2014 check username and password.");
|
|
231
|
+
}
|
|
232
|
+
if (resp.status >= 400) {
|
|
233
|
+
const text = await resp.text().catch(() => "");
|
|
234
|
+
throw new AuthenticationError(`Login failed with HTTP ${resp.status}: ${text.slice(0, 200)}`);
|
|
235
|
+
}
|
|
236
|
+
let token = null;
|
|
237
|
+
try {
|
|
238
|
+
const body = await resp.json();
|
|
239
|
+
const status = body.status;
|
|
240
|
+
const info = status?.info;
|
|
241
|
+
if (Array.isArray(info) && info.length > 0) {
|
|
242
|
+
token = info[0].bearer_token ?? null;
|
|
243
|
+
} else if (info && typeof info === "object") {
|
|
244
|
+
token = info.bearer_token ?? null;
|
|
245
|
+
}
|
|
246
|
+
} catch {
|
|
247
|
+
}
|
|
248
|
+
this.token = token ?? "_cookie_session_";
|
|
249
|
+
this.lastUsed = Date.now();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
// src/client.ts
|
|
254
|
+
var WRITE_METHODS = /* @__PURE__ */ new Set(["POST", "PUT", "PATCH", "DELETE"]);
|
|
255
|
+
var ReadOnlyError = class extends Error {
|
|
256
|
+
constructor(method, path) {
|
|
257
|
+
super(
|
|
258
|
+
`${method} ${path} is a write operation but the server is in read-only mode. Set SONICWALL_READ_ONLY=false to enable write access.`
|
|
259
|
+
);
|
|
260
|
+
this.name = "ReadOnlyError";
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var APIError = class extends Error {
|
|
264
|
+
constructor(status, message, code) {
|
|
265
|
+
super(`HTTP ${status}: ${message}` + (code ? ` (code=${code})` : ""));
|
|
266
|
+
this.status = status;
|
|
267
|
+
this.code = code;
|
|
268
|
+
this.name = "APIError";
|
|
269
|
+
}
|
|
270
|
+
status;
|
|
271
|
+
code;
|
|
272
|
+
};
|
|
273
|
+
function sleep(ms) {
|
|
274
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
275
|
+
}
|
|
276
|
+
function isNetworkError(e) {
|
|
277
|
+
if (!(e instanceof Error)) return false;
|
|
278
|
+
return e.message.includes("fetch") || e.message.includes("network") || e.message.includes("connect") || e.message.includes("ECONNREFUSED") || e.message.includes("ETIMEDOUT") || e.message.includes("ENOTFOUND") || e.name === "TypeError";
|
|
279
|
+
}
|
|
280
|
+
async function fetchWithRetry(url, options, retries = 3) {
|
|
281
|
+
for (let i = 0; i < retries; i++) {
|
|
282
|
+
try {
|
|
283
|
+
return await fetch(url, options);
|
|
284
|
+
} catch (e) {
|
|
285
|
+
if (i === retries - 1 || !isNetworkError(e)) throw e;
|
|
286
|
+
await sleep(1e3 * Math.pow(2, i));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
throw new Error("unreachable");
|
|
290
|
+
}
|
|
291
|
+
var SonicWallClient = class {
|
|
292
|
+
constructor(profile) {
|
|
293
|
+
this.profile = profile;
|
|
294
|
+
this.auth = new AuthManager(profile.username, profile.password);
|
|
295
|
+
}
|
|
296
|
+
profile;
|
|
297
|
+
baseUrl = "";
|
|
298
|
+
version = 7;
|
|
299
|
+
auth;
|
|
300
|
+
async initialize() {
|
|
301
|
+
const { host, port } = this.profile;
|
|
302
|
+
const candidates = [
|
|
303
|
+
[`https://${host}:${port}/api/sonicos/v8`, 8],
|
|
304
|
+
[`https://${host}:${port}/api/sonicos`, 7]
|
|
305
|
+
];
|
|
306
|
+
for (const [base, version] of candidates) {
|
|
307
|
+
try {
|
|
308
|
+
const resp = await fetch(`${base}/system/status`, {
|
|
309
|
+
headers: { "Accept": "application/json" },
|
|
310
|
+
signal: AbortSignal.timeout(this.profile.requestTimeout * 1e3)
|
|
311
|
+
});
|
|
312
|
+
if (resp.status !== 404) {
|
|
313
|
+
this.baseUrl = base;
|
|
314
|
+
this.version = version;
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
} catch {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (!this.baseUrl) {
|
|
322
|
+
this.baseUrl = `https://${host}:${port}/api/sonicos`;
|
|
323
|
+
this.version = 7;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async close() {
|
|
327
|
+
await this.auth.logout(this.baseUrl);
|
|
328
|
+
}
|
|
329
|
+
async request(method, path, options) {
|
|
330
|
+
if (this.profile.readOnly && WRITE_METHODS.has(method.toUpperCase())) {
|
|
331
|
+
throw new ReadOnlyError(method.toUpperCase(), path);
|
|
332
|
+
}
|
|
333
|
+
let url = `${this.baseUrl}/${path.replace(/^\//, "")}`;
|
|
334
|
+
if (options?.params && Object.keys(options.params).length > 0) {
|
|
335
|
+
const qs = new URLSearchParams(
|
|
336
|
+
Object.entries(options.params).map(([k, v]) => [k, String(v)])
|
|
337
|
+
);
|
|
338
|
+
url += `?${qs}`;
|
|
339
|
+
}
|
|
340
|
+
const makeHeaders = async () => {
|
|
341
|
+
const token = await this.auth.ensureAuthenticated(this.baseUrl);
|
|
342
|
+
const headers2 = {
|
|
343
|
+
"Accept": "application/json",
|
|
344
|
+
"Content-Type": "application/json"
|
|
345
|
+
};
|
|
346
|
+
if (token && token !== "_cookie_session_") {
|
|
347
|
+
headers2["Authorization"] = `Bearer ${token}`;
|
|
348
|
+
}
|
|
349
|
+
return headers2;
|
|
350
|
+
};
|
|
351
|
+
let headers = await makeHeaders();
|
|
352
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
353
|
+
let resp;
|
|
354
|
+
try {
|
|
355
|
+
resp = await fetchWithRetry(url, {
|
|
356
|
+
method,
|
|
357
|
+
headers,
|
|
358
|
+
body: options?.body !== void 0 ? JSON.stringify(options.body) : void 0,
|
|
359
|
+
signal: AbortSignal.timeout(this.profile.requestTimeout * 1e3)
|
|
360
|
+
});
|
|
361
|
+
} catch (e) {
|
|
362
|
+
throw e;
|
|
363
|
+
}
|
|
364
|
+
if (resp.status === 401 && attempt === 0) {
|
|
365
|
+
this.auth.invalidate();
|
|
366
|
+
headers = await makeHeaders();
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
if (resp.status >= 400) {
|
|
370
|
+
await this._throwApiError(resp);
|
|
371
|
+
}
|
|
372
|
+
const text = await resp.text();
|
|
373
|
+
return text ? JSON.parse(text) : {};
|
|
374
|
+
}
|
|
375
|
+
throw new Error("unreachable");
|
|
376
|
+
}
|
|
377
|
+
async _throwApiError(resp) {
|
|
378
|
+
let msg;
|
|
379
|
+
let code;
|
|
380
|
+
try {
|
|
381
|
+
const body = await resp.json();
|
|
382
|
+
const status = body.status;
|
|
383
|
+
const info = status?.info;
|
|
384
|
+
if (Array.isArray(info) && info.length > 0) {
|
|
385
|
+
const i0 = info[0];
|
|
386
|
+
msg = i0.message ?? resp.statusText;
|
|
387
|
+
code = i0.code;
|
|
388
|
+
} else if (info && typeof info === "object") {
|
|
389
|
+
const i = info;
|
|
390
|
+
msg = i.message ?? resp.statusText;
|
|
391
|
+
code = i.code;
|
|
392
|
+
} else {
|
|
393
|
+
msg = resp.statusText;
|
|
394
|
+
}
|
|
395
|
+
} catch {
|
|
396
|
+
msg = (await resp.text().catch(() => "")).slice(0, 400) || resp.statusText;
|
|
397
|
+
}
|
|
398
|
+
throw new APIError(resp.status, msg, code);
|
|
399
|
+
}
|
|
400
|
+
get(path, params) {
|
|
401
|
+
return this.request("GET", path, { params });
|
|
402
|
+
}
|
|
403
|
+
post(path, body) {
|
|
404
|
+
return this.request("POST", path, { body });
|
|
405
|
+
}
|
|
406
|
+
put(path, body) {
|
|
407
|
+
return this.request("PUT", path, { body });
|
|
408
|
+
}
|
|
409
|
+
patch(path, body) {
|
|
410
|
+
return this.request("PATCH", path, { body });
|
|
411
|
+
}
|
|
412
|
+
delete(path) {
|
|
413
|
+
return this.request("DELETE", path);
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
// src/registry.ts
|
|
418
|
+
var DeviceRegistry = class {
|
|
419
|
+
constructor(profiles) {
|
|
420
|
+
this.profiles = profiles;
|
|
421
|
+
if (profiles.length === 0) {
|
|
422
|
+
throw new Error("At least one device profile must be configured.");
|
|
423
|
+
}
|
|
424
|
+
this.defaultDeviceName = profiles[0].name;
|
|
425
|
+
}
|
|
426
|
+
profiles;
|
|
427
|
+
clients = /* @__PURE__ */ new Map();
|
|
428
|
+
initPromises = /* @__PURE__ */ new Map();
|
|
429
|
+
defaultDeviceName;
|
|
430
|
+
names() {
|
|
431
|
+
return this.profiles.map((p) => p.name);
|
|
432
|
+
}
|
|
433
|
+
defaultName() {
|
|
434
|
+
return this.defaultDeviceName;
|
|
435
|
+
}
|
|
436
|
+
async getClient(name) {
|
|
437
|
+
const target = name ?? this.defaultDeviceName;
|
|
438
|
+
const profile = this.profiles.find((p) => p.name === target);
|
|
439
|
+
if (!profile) {
|
|
440
|
+
const available = this.profiles.map((p) => p.name).join(", ");
|
|
441
|
+
throw new Error(`Device '${target}' not found. Configured devices: ${available}`);
|
|
442
|
+
}
|
|
443
|
+
const existing = this.clients.get(target);
|
|
444
|
+
if (existing) return existing;
|
|
445
|
+
const inFlight = this.initPromises.get(target);
|
|
446
|
+
if (inFlight) return inFlight;
|
|
447
|
+
const promise = (async () => {
|
|
448
|
+
const client = new SonicWallClient(profile);
|
|
449
|
+
await client.initialize();
|
|
450
|
+
this.clients.set(target, client);
|
|
451
|
+
this.initPromises.delete(target);
|
|
452
|
+
return client;
|
|
453
|
+
})();
|
|
454
|
+
this.initPromises.set(target, promise);
|
|
455
|
+
return promise;
|
|
456
|
+
}
|
|
457
|
+
async closeAll() {
|
|
458
|
+
const clients = Array.from(this.clients.values());
|
|
459
|
+
this.clients.clear();
|
|
460
|
+
this.initPromises.clear();
|
|
461
|
+
await Promise.allSettled(clients.map((c) => c.close()));
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
|
|
465
|
+
// src/tools/system.ts
|
|
466
|
+
var import_zod = require("zod");
|
|
467
|
+
function registerSystemTools(server, registry) {
|
|
468
|
+
server.tool(
|
|
469
|
+
"list_devices",
|
|
470
|
+
"List all SonicWall devices configured in this server instance. Returns device names and which one is the default. Pass device='<name>' to any other tool to target a specific appliance.",
|
|
471
|
+
{},
|
|
472
|
+
async () => {
|
|
473
|
+
try {
|
|
474
|
+
const result = { devices: registry.names(), default: registry.defaultName() };
|
|
475
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
476
|
+
} catch (e) {
|
|
477
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
server.tool(
|
|
482
|
+
"get_system_status",
|
|
483
|
+
"Return device model, firmware version, serial number, and uptime.",
|
|
484
|
+
{ device: import_zod.z.string().optional() },
|
|
485
|
+
async ({ device }) => {
|
|
486
|
+
try {
|
|
487
|
+
const client = await registry.getClient(device);
|
|
488
|
+
const result = await client.get("system/status");
|
|
489
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
490
|
+
} catch (e) {
|
|
491
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
);
|
|
495
|
+
server.tool(
|
|
496
|
+
"commit_config",
|
|
497
|
+
"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.",
|
|
498
|
+
{ device: import_zod.z.string().optional() },
|
|
499
|
+
async ({ device }) => {
|
|
500
|
+
try {
|
|
501
|
+
const client = await registry.getClient(device);
|
|
502
|
+
const result = await client.post("config/pending");
|
|
503
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
504
|
+
} catch (e) {
|
|
505
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
);
|
|
509
|
+
server.tool(
|
|
510
|
+
"discard_config",
|
|
511
|
+
"Discard all staged configuration changes without applying them.",
|
|
512
|
+
{ device: import_zod.z.string().optional() },
|
|
513
|
+
async ({ device }) => {
|
|
514
|
+
try {
|
|
515
|
+
const client = await registry.getClient(device);
|
|
516
|
+
const result = await client.delete("config/pending");
|
|
517
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
518
|
+
} catch (e) {
|
|
519
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
server.tool(
|
|
524
|
+
"get_pending_config",
|
|
525
|
+
"Show configuration changes that have been staged but not yet committed.",
|
|
526
|
+
{ device: import_zod.z.string().optional() },
|
|
527
|
+
async ({ device }) => {
|
|
528
|
+
try {
|
|
529
|
+
const client = await registry.getClient(device);
|
|
530
|
+
const result = await client.get("config/pending");
|
|
531
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
532
|
+
} catch (e) {
|
|
533
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/tools/address-objects.ts
|
|
540
|
+
var import_zod2 = require("zod");
|
|
541
|
+
var ALL_TYPES = ["ipv4", "ipv6", "fqdn", "mac"];
|
|
542
|
+
function registerAddressObjectTools(server, registry) {
|
|
543
|
+
server.tool(
|
|
544
|
+
"list_address_objects",
|
|
545
|
+
"List address objects on the appliance. type: filter by 'ipv4', 'ipv6', 'fqdn', 'mac', or 'all' (default).",
|
|
546
|
+
{
|
|
547
|
+
type: import_zod2.z.enum(["ipv4", "ipv6", "fqdn", "mac", "all"]).optional().default("all"),
|
|
548
|
+
device: import_zod2.z.string().optional()
|
|
549
|
+
},
|
|
550
|
+
async ({ type, device }) => {
|
|
551
|
+
try {
|
|
552
|
+
const client = await registry.getClient(device);
|
|
553
|
+
let result;
|
|
554
|
+
if (type === "all") {
|
|
555
|
+
result = {};
|
|
556
|
+
for (const t of ALL_TYPES) {
|
|
557
|
+
try {
|
|
558
|
+
const data = await client.get(`address-objects/${t}`);
|
|
559
|
+
result[t] = data.address_objects ?? [];
|
|
560
|
+
} catch (e) {
|
|
561
|
+
if (e instanceof APIError) {
|
|
562
|
+
result[t] = [];
|
|
563
|
+
} else throw e;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
} else {
|
|
567
|
+
result = await client.get(`address-objects/${type}`);
|
|
568
|
+
}
|
|
569
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
570
|
+
} catch (e) {
|
|
571
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
);
|
|
575
|
+
server.tool(
|
|
576
|
+
"get_address_object",
|
|
577
|
+
"Retrieve a single address object by name and type.",
|
|
578
|
+
{
|
|
579
|
+
name: import_zod2.z.string(),
|
|
580
|
+
type: import_zod2.z.enum(["ipv4", "ipv6", "fqdn", "mac"]),
|
|
581
|
+
device: import_zod2.z.string().optional()
|
|
582
|
+
},
|
|
583
|
+
async ({ name, type, device }) => {
|
|
584
|
+
try {
|
|
585
|
+
const client = await registry.getClient(device);
|
|
586
|
+
const result = await client.get(`address-objects/${type}/name/${name}`);
|
|
587
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
588
|
+
} catch (e) {
|
|
589
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
);
|
|
593
|
+
server.tool(
|
|
594
|
+
"create_address_object_ipv4",
|
|
595
|
+
"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.",
|
|
596
|
+
{
|
|
597
|
+
name: import_zod2.z.string(),
|
|
598
|
+
zone: import_zod2.z.string(),
|
|
599
|
+
host: import_zod2.z.string().optional(),
|
|
600
|
+
network: import_zod2.z.string().optional(),
|
|
601
|
+
subnet_mask: import_zod2.z.string().optional(),
|
|
602
|
+
range_begin: import_zod2.z.string().optional(),
|
|
603
|
+
range_end: import_zod2.z.string().optional(),
|
|
604
|
+
device: import_zod2.z.string().optional()
|
|
605
|
+
},
|
|
606
|
+
async ({ name, zone, host, network, subnet_mask, range_begin, range_end, device }) => {
|
|
607
|
+
try {
|
|
608
|
+
const client = await registry.getClient(device);
|
|
609
|
+
const ipv4 = { name, zone };
|
|
610
|
+
if (host) {
|
|
611
|
+
ipv4.host = { ip: host };
|
|
612
|
+
} else if (network && subnet_mask) {
|
|
613
|
+
ipv4.network = { subnet: network, mask: subnet_mask };
|
|
614
|
+
} else if (range_begin && range_end) {
|
|
615
|
+
ipv4.range = { begin: range_begin, end: range_end };
|
|
616
|
+
} else {
|
|
617
|
+
return { content: [{ type: "text", text: "Error: Provide host, network+subnet_mask, or range_begin+range_end" }], isError: true };
|
|
618
|
+
}
|
|
619
|
+
const result = await client.post("address-objects/ipv4", { address_objects: [{ ipv4 }] });
|
|
620
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
621
|
+
} catch (e) {
|
|
622
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
);
|
|
626
|
+
server.tool(
|
|
627
|
+
"create_address_object_ipv6",
|
|
628
|
+
"Create an IPv6 address object. Provide either address (single IPv6) or network+prefix_length. Changes are STAGED; call commit_config to apply.",
|
|
629
|
+
{
|
|
630
|
+
name: import_zod2.z.string(),
|
|
631
|
+
zone: import_zod2.z.string(),
|
|
632
|
+
address: import_zod2.z.string().optional(),
|
|
633
|
+
network: import_zod2.z.string().optional(),
|
|
634
|
+
prefix_length: import_zod2.z.number().optional(),
|
|
635
|
+
device: import_zod2.z.string().optional()
|
|
636
|
+
},
|
|
637
|
+
async ({ name, zone, address, network, prefix_length, device }) => {
|
|
638
|
+
try {
|
|
639
|
+
const client = await registry.getClient(device);
|
|
640
|
+
const ipv6 = { name, zone };
|
|
641
|
+
if (address) {
|
|
642
|
+
ipv6.host = { ip: address };
|
|
643
|
+
} else if (network && prefix_length !== void 0) {
|
|
644
|
+
ipv6.network = { subnet: network, prefix_length };
|
|
645
|
+
} else {
|
|
646
|
+
return { content: [{ type: "text", text: "Error: Provide address or network+prefix_length" }], isError: true };
|
|
647
|
+
}
|
|
648
|
+
const result = await client.post("address-objects/ipv6", { address_objects: [{ ipv6 }] });
|
|
649
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
650
|
+
} catch (e) {
|
|
651
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
);
|
|
655
|
+
server.tool(
|
|
656
|
+
"create_address_object_fqdn",
|
|
657
|
+
"Create an FQDN address object. Changes are STAGED; call commit_config to apply.",
|
|
658
|
+
{
|
|
659
|
+
name: import_zod2.z.string(),
|
|
660
|
+
zone: import_zod2.z.string(),
|
|
661
|
+
domain: import_zod2.z.string(),
|
|
662
|
+
device: import_zod2.z.string().optional()
|
|
663
|
+
},
|
|
664
|
+
async ({ name, zone, domain, device }) => {
|
|
665
|
+
try {
|
|
666
|
+
const client = await registry.getClient(device);
|
|
667
|
+
const result = await client.post("address-objects/fqdn", {
|
|
668
|
+
address_objects: [{ fqdn: { name, zone, domain } }]
|
|
669
|
+
});
|
|
670
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
671
|
+
} catch (e) {
|
|
672
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
);
|
|
676
|
+
server.tool(
|
|
677
|
+
"update_address_object",
|
|
678
|
+
"Update an existing address object. Only supplied fields are changed (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
679
|
+
{
|
|
680
|
+
name: import_zod2.z.string(),
|
|
681
|
+
type: import_zod2.z.enum(["ipv4", "ipv6", "fqdn", "mac"]),
|
|
682
|
+
zone: import_zod2.z.string().optional(),
|
|
683
|
+
host: import_zod2.z.string().optional(),
|
|
684
|
+
network: import_zod2.z.string().optional(),
|
|
685
|
+
subnet_mask: import_zod2.z.string().optional(),
|
|
686
|
+
domain: import_zod2.z.string().optional(),
|
|
687
|
+
device: import_zod2.z.string().optional()
|
|
688
|
+
},
|
|
689
|
+
async ({ name, type, zone, host, network, subnet_mask, domain, device }) => {
|
|
690
|
+
try {
|
|
691
|
+
const client = await registry.getClient(device);
|
|
692
|
+
const current = await client.get(`address-objects/${type}/name/${name}`);
|
|
693
|
+
const objs = current.address_objects;
|
|
694
|
+
const obj = objs?.[0]?.[type] ?? {};
|
|
695
|
+
if (zone) obj.zone = zone;
|
|
696
|
+
if (host) obj.host = { ip: host };
|
|
697
|
+
if (network && subnet_mask) obj.network = { subnet: network, mask: subnet_mask };
|
|
698
|
+
if (domain) obj.domain = domain;
|
|
699
|
+
const result = await client.put(`address-objects/${type}/name/${name}`, {
|
|
700
|
+
address_objects: [{ [type]: obj }]
|
|
701
|
+
});
|
|
702
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
703
|
+
} catch (e) {
|
|
704
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
server.tool(
|
|
709
|
+
"delete_address_object",
|
|
710
|
+
"Delete an address object by name and type. Changes are STAGED; call commit_config to apply.",
|
|
711
|
+
{
|
|
712
|
+
name: import_zod2.z.string(),
|
|
713
|
+
type: import_zod2.z.enum(["ipv4", "ipv6", "fqdn", "mac"]),
|
|
714
|
+
device: import_zod2.z.string().optional()
|
|
715
|
+
},
|
|
716
|
+
async ({ name, type, device }) => {
|
|
717
|
+
try {
|
|
718
|
+
const client = await registry.getClient(device);
|
|
719
|
+
const result = await client.delete(`address-objects/${type}/name/${name}`);
|
|
720
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
721
|
+
} catch (e) {
|
|
722
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/tools/address-groups.ts
|
|
729
|
+
var import_zod3 = require("zod");
|
|
730
|
+
function registerAddressGroupTools(server, registry) {
|
|
731
|
+
server.tool(
|
|
732
|
+
"list_address_groups",
|
|
733
|
+
"List address groups on the appliance.",
|
|
734
|
+
{
|
|
735
|
+
type: import_zod3.z.enum(["ipv4", "ipv6", "all"]).optional().default("all"),
|
|
736
|
+
device: import_zod3.z.string().optional()
|
|
737
|
+
},
|
|
738
|
+
async ({ type, device }) => {
|
|
739
|
+
try {
|
|
740
|
+
const client = await registry.getClient(device);
|
|
741
|
+
let result;
|
|
742
|
+
if (type === "all") {
|
|
743
|
+
result = {};
|
|
744
|
+
for (const t of ["ipv4", "ipv6"]) {
|
|
745
|
+
try {
|
|
746
|
+
const data = await client.get(`address-groups/${t}`);
|
|
747
|
+
result[t] = data.address_groups ?? [];
|
|
748
|
+
} catch (e) {
|
|
749
|
+
if (e instanceof APIError) {
|
|
750
|
+
result[t] = [];
|
|
751
|
+
} else throw e;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
} else {
|
|
755
|
+
result = await client.get(`address-groups/${type}`);
|
|
756
|
+
}
|
|
757
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
758
|
+
} catch (e) {
|
|
759
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
);
|
|
763
|
+
server.tool(
|
|
764
|
+
"get_address_group",
|
|
765
|
+
"Retrieve a single address group by name.",
|
|
766
|
+
{
|
|
767
|
+
name: import_zod3.z.string(),
|
|
768
|
+
type: import_zod3.z.enum(["ipv4", "ipv6"]),
|
|
769
|
+
device: import_zod3.z.string().optional()
|
|
770
|
+
},
|
|
771
|
+
async ({ name, type, device }) => {
|
|
772
|
+
try {
|
|
773
|
+
const client = await registry.getClient(device);
|
|
774
|
+
const result = await client.get(`address-groups/${type}/name/${name}`);
|
|
775
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
776
|
+
} catch (e) {
|
|
777
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
);
|
|
781
|
+
server.tool(
|
|
782
|
+
"create_address_group",
|
|
783
|
+
"Create an address group with the given member object names. members: list of address object names. Changes are STAGED; call commit_config to apply.",
|
|
784
|
+
{
|
|
785
|
+
name: import_zod3.z.string(),
|
|
786
|
+
type: import_zod3.z.enum(["ipv4", "ipv6"]),
|
|
787
|
+
members: import_zod3.z.array(import_zod3.z.string()),
|
|
788
|
+
device: import_zod3.z.string().optional()
|
|
789
|
+
},
|
|
790
|
+
async ({ name, type, members, device }) => {
|
|
791
|
+
try {
|
|
792
|
+
const client = await registry.getClient(device);
|
|
793
|
+
const memberList = members.map((m) => ({ name: m }));
|
|
794
|
+
const result = await client.post(`address-groups/${type}`, {
|
|
795
|
+
address_groups: [{ address_group: { name, address_object: memberList } }]
|
|
796
|
+
});
|
|
797
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
798
|
+
} catch (e) {
|
|
799
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
);
|
|
803
|
+
server.tool(
|
|
804
|
+
"add_address_group_member",
|
|
805
|
+
"Add a member address object to an existing address group. Changes are STAGED; call commit_config to apply.",
|
|
806
|
+
{
|
|
807
|
+
group_name: import_zod3.z.string(),
|
|
808
|
+
type: import_zod3.z.enum(["ipv4", "ipv6"]),
|
|
809
|
+
member_name: import_zod3.z.string(),
|
|
810
|
+
device: import_zod3.z.string().optional()
|
|
811
|
+
},
|
|
812
|
+
async ({ group_name, type, member_name, device }) => {
|
|
813
|
+
try {
|
|
814
|
+
const client = await registry.getClient(device);
|
|
815
|
+
const current = await client.get(`address-groups/${type}/name/${group_name}`);
|
|
816
|
+
const groups = current.address_groups;
|
|
817
|
+
const grp = groups?.[0]?.address_group ?? {};
|
|
818
|
+
const members = grp.address_object ?? [];
|
|
819
|
+
if (!members.some((m) => m.name === member_name)) {
|
|
820
|
+
members.push({ name: member_name });
|
|
821
|
+
}
|
|
822
|
+
grp.address_object = members;
|
|
823
|
+
const result = await client.put(`address-groups/${type}/name/${group_name}`, {
|
|
824
|
+
address_groups: [{ address_group: grp }]
|
|
825
|
+
});
|
|
826
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
827
|
+
} catch (e) {
|
|
828
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
);
|
|
832
|
+
server.tool(
|
|
833
|
+
"remove_address_group_member",
|
|
834
|
+
"Remove a member address object from an address group. Changes are STAGED; call commit_config to apply.",
|
|
835
|
+
{
|
|
836
|
+
group_name: import_zod3.z.string(),
|
|
837
|
+
type: import_zod3.z.enum(["ipv4", "ipv6"]),
|
|
838
|
+
member_name: import_zod3.z.string(),
|
|
839
|
+
device: import_zod3.z.string().optional()
|
|
840
|
+
},
|
|
841
|
+
async ({ group_name, type, member_name, device }) => {
|
|
842
|
+
try {
|
|
843
|
+
const client = await registry.getClient(device);
|
|
844
|
+
const current = await client.get(`address-groups/${type}/name/${group_name}`);
|
|
845
|
+
const groups = current.address_groups;
|
|
846
|
+
const grp = groups?.[0]?.address_group ?? {};
|
|
847
|
+
const members = grp.address_object ?? [];
|
|
848
|
+
grp.address_object = members.filter((m) => m.name !== member_name);
|
|
849
|
+
const result = await client.put(`address-groups/${type}/name/${group_name}`, {
|
|
850
|
+
address_groups: [{ address_group: grp }]
|
|
851
|
+
});
|
|
852
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
853
|
+
} catch (e) {
|
|
854
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
);
|
|
858
|
+
server.tool(
|
|
859
|
+
"delete_address_group",
|
|
860
|
+
"Delete an address group by name. Changes are STAGED; call commit_config to apply.",
|
|
861
|
+
{
|
|
862
|
+
name: import_zod3.z.string(),
|
|
863
|
+
type: import_zod3.z.enum(["ipv4", "ipv6"]),
|
|
864
|
+
device: import_zod3.z.string().optional()
|
|
865
|
+
},
|
|
866
|
+
async ({ name, type, device }) => {
|
|
867
|
+
try {
|
|
868
|
+
const client = await registry.getClient(device);
|
|
869
|
+
const result = await client.delete(`address-groups/${type}/name/${name}`);
|
|
870
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
871
|
+
} catch (e) {
|
|
872
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
// src/tools/service-objects.ts
|
|
879
|
+
var import_zod4 = require("zod");
|
|
880
|
+
var PROTOCOLS = ["TCP", "UDP", "ICMP", "ICMPv6", "IGMP", "GRE", "ESP", "AH", "OTHER"];
|
|
881
|
+
function registerServiceObjectTools(server, registry) {
|
|
882
|
+
server.tool(
|
|
883
|
+
"list_service_objects",
|
|
884
|
+
"List all service objects on the appliance.",
|
|
885
|
+
{ device: import_zod4.z.string().optional() },
|
|
886
|
+
async ({ device }) => {
|
|
887
|
+
try {
|
|
888
|
+
const client = await registry.getClient(device);
|
|
889
|
+
const result = await client.get("service-objects");
|
|
890
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
891
|
+
} catch (e) {
|
|
892
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
);
|
|
896
|
+
server.tool(
|
|
897
|
+
"get_service_object",
|
|
898
|
+
"Retrieve a service object by name.",
|
|
899
|
+
{ name: import_zod4.z.string(), device: import_zod4.z.string().optional() },
|
|
900
|
+
async ({ name, device }) => {
|
|
901
|
+
try {
|
|
902
|
+
const client = await registry.getClient(device);
|
|
903
|
+
const result = await client.get(`service-objects/name/${name}`);
|
|
904
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
905
|
+
} catch (e) {
|
|
906
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
);
|
|
910
|
+
server.tool(
|
|
911
|
+
"create_service_object",
|
|
912
|
+
"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.",
|
|
913
|
+
{
|
|
914
|
+
name: import_zod4.z.string(),
|
|
915
|
+
protocol: import_zod4.z.enum(PROTOCOLS),
|
|
916
|
+
port_begin: import_zod4.z.number().optional(),
|
|
917
|
+
port_end: import_zod4.z.number().optional(),
|
|
918
|
+
icmp_type: import_zod4.z.number().optional(),
|
|
919
|
+
icmp_code: import_zod4.z.number().optional(),
|
|
920
|
+
device: import_zod4.z.string().optional()
|
|
921
|
+
},
|
|
922
|
+
async ({ name, protocol, port_begin, port_end, icmp_type, icmp_code, device }) => {
|
|
923
|
+
try {
|
|
924
|
+
const client = await registry.getClient(device);
|
|
925
|
+
const svc = { name, protocol: { protocol_type: protocol } };
|
|
926
|
+
const proto = svc.protocol;
|
|
927
|
+
if (protocol === "TCP" || protocol === "UDP") {
|
|
928
|
+
const key = protocol === "TCP" ? "tcp" : "udp";
|
|
929
|
+
proto[key] = { begin: port_begin, end: port_end ?? port_begin };
|
|
930
|
+
} else if (protocol === "ICMP" || protocol === "ICMPv6") {
|
|
931
|
+
const key = protocol === "ICMP" ? "icmp" : "icmpv6";
|
|
932
|
+
const icmp = { type: icmp_type };
|
|
933
|
+
if (icmp_code !== void 0) icmp.code = icmp_code;
|
|
934
|
+
proto[key] = icmp;
|
|
935
|
+
}
|
|
936
|
+
const result = await client.post("service-objects", { service_objects: [svc] });
|
|
937
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
938
|
+
} catch (e) {
|
|
939
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
);
|
|
943
|
+
server.tool(
|
|
944
|
+
"update_service_object",
|
|
945
|
+
"Update port or ICMP fields on an existing service object (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
946
|
+
{
|
|
947
|
+
name: import_zod4.z.string(),
|
|
948
|
+
port_begin: import_zod4.z.number().optional(),
|
|
949
|
+
port_end: import_zod4.z.number().optional(),
|
|
950
|
+
icmp_type: import_zod4.z.number().optional(),
|
|
951
|
+
icmp_code: import_zod4.z.number().optional(),
|
|
952
|
+
device: import_zod4.z.string().optional()
|
|
953
|
+
},
|
|
954
|
+
async ({ name, port_begin, port_end, icmp_type, icmp_code, device }) => {
|
|
955
|
+
try {
|
|
956
|
+
const client = await registry.getClient(device);
|
|
957
|
+
const current = await client.get(`service-objects/name/${name}`);
|
|
958
|
+
const svcs = current.service_objects;
|
|
959
|
+
const svc = svcs?.[0] ?? {};
|
|
960
|
+
const proto = svc.protocol ?? {};
|
|
961
|
+
if (port_begin !== void 0) {
|
|
962
|
+
for (const key of ["tcp", "udp"]) {
|
|
963
|
+
if (key in proto) {
|
|
964
|
+
const portObj = proto[key];
|
|
965
|
+
portObj.begin = port_begin;
|
|
966
|
+
portObj.end = port_end ?? port_begin;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
if (icmp_type !== void 0) {
|
|
971
|
+
for (const key of ["icmp", "icmpv6"]) {
|
|
972
|
+
if (key in proto) {
|
|
973
|
+
const icmpObj = proto[key];
|
|
974
|
+
icmpObj.type = icmp_type;
|
|
975
|
+
if (icmp_code !== void 0) icmpObj.code = icmp_code;
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
const result = await client.put(`service-objects/name/${name}`, { service_objects: [svc] });
|
|
980
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
981
|
+
} catch (e) {
|
|
982
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
);
|
|
986
|
+
server.tool(
|
|
987
|
+
"delete_service_object",
|
|
988
|
+
"Delete a service object by name. Changes are STAGED; call commit_config to apply.",
|
|
989
|
+
{ name: import_zod4.z.string(), device: import_zod4.z.string().optional() },
|
|
990
|
+
async ({ name, device }) => {
|
|
991
|
+
try {
|
|
992
|
+
const client = await registry.getClient(device);
|
|
993
|
+
const result = await client.delete(`service-objects/name/${name}`);
|
|
994
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
995
|
+
} catch (e) {
|
|
996
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// src/tools/service-groups.ts
|
|
1003
|
+
var import_zod5 = require("zod");
|
|
1004
|
+
function registerServiceGroupTools(server, registry) {
|
|
1005
|
+
server.tool(
|
|
1006
|
+
"list_service_groups",
|
|
1007
|
+
"List all service groups on the appliance.",
|
|
1008
|
+
{ device: import_zod5.z.string().optional() },
|
|
1009
|
+
async ({ device }) => {
|
|
1010
|
+
try {
|
|
1011
|
+
const client = await registry.getClient(device);
|
|
1012
|
+
const result = await client.get("service-groups");
|
|
1013
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1014
|
+
} catch (e) {
|
|
1015
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
);
|
|
1019
|
+
server.tool(
|
|
1020
|
+
"get_service_group",
|
|
1021
|
+
"Retrieve a service group by name.",
|
|
1022
|
+
{ name: import_zod5.z.string(), device: import_zod5.z.string().optional() },
|
|
1023
|
+
async ({ name, device }) => {
|
|
1024
|
+
try {
|
|
1025
|
+
const client = await registry.getClient(device);
|
|
1026
|
+
const result = await client.get(`service-groups/name/${name}`);
|
|
1027
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1028
|
+
} catch (e) {
|
|
1029
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
server.tool(
|
|
1034
|
+
"create_service_group",
|
|
1035
|
+
"Create a service group containing the given service object names. Changes are STAGED; call commit_config to apply.",
|
|
1036
|
+
{
|
|
1037
|
+
name: import_zod5.z.string(),
|
|
1038
|
+
members: import_zod5.z.array(import_zod5.z.string()),
|
|
1039
|
+
device: import_zod5.z.string().optional()
|
|
1040
|
+
},
|
|
1041
|
+
async ({ name, members, device }) => {
|
|
1042
|
+
try {
|
|
1043
|
+
const client = await registry.getClient(device);
|
|
1044
|
+
const result = await client.post("service-groups", {
|
|
1045
|
+
service_groups: [{ name, service_object: members.map((m) => ({ name: m })) }]
|
|
1046
|
+
});
|
|
1047
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1048
|
+
} catch (e) {
|
|
1049
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
);
|
|
1053
|
+
server.tool(
|
|
1054
|
+
"add_service_group_member",
|
|
1055
|
+
"Add a service object to an existing service group (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
1056
|
+
{
|
|
1057
|
+
group_name: import_zod5.z.string(),
|
|
1058
|
+
member_name: import_zod5.z.string(),
|
|
1059
|
+
device: import_zod5.z.string().optional()
|
|
1060
|
+
},
|
|
1061
|
+
async ({ group_name, member_name, device }) => {
|
|
1062
|
+
try {
|
|
1063
|
+
const client = await registry.getClient(device);
|
|
1064
|
+
const current = await client.get(`service-groups/name/${group_name}`);
|
|
1065
|
+
const groups = current.service_groups;
|
|
1066
|
+
const grp = groups?.[0] ?? {};
|
|
1067
|
+
const members = grp.service_object ?? [];
|
|
1068
|
+
if (!members.some((m) => m.name === member_name)) {
|
|
1069
|
+
members.push({ name: member_name });
|
|
1070
|
+
}
|
|
1071
|
+
grp.service_object = members;
|
|
1072
|
+
const result = await client.put(`service-groups/name/${group_name}`, { service_groups: [grp] });
|
|
1073
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1074
|
+
} catch (e) {
|
|
1075
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
);
|
|
1079
|
+
server.tool(
|
|
1080
|
+
"remove_service_group_member",
|
|
1081
|
+
"Remove a service object from a service group (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
1082
|
+
{
|
|
1083
|
+
group_name: import_zod5.z.string(),
|
|
1084
|
+
member_name: import_zod5.z.string(),
|
|
1085
|
+
device: import_zod5.z.string().optional()
|
|
1086
|
+
},
|
|
1087
|
+
async ({ group_name, member_name, device }) => {
|
|
1088
|
+
try {
|
|
1089
|
+
const client = await registry.getClient(device);
|
|
1090
|
+
const current = await client.get(`service-groups/name/${group_name}`);
|
|
1091
|
+
const groups = current.service_groups;
|
|
1092
|
+
const grp = groups?.[0] ?? {};
|
|
1093
|
+
const members = grp.service_object ?? [];
|
|
1094
|
+
grp.service_object = members.filter((m) => m.name !== member_name);
|
|
1095
|
+
const result = await client.put(`service-groups/name/${group_name}`, { service_groups: [grp] });
|
|
1096
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1097
|
+
} catch (e) {
|
|
1098
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
);
|
|
1102
|
+
server.tool(
|
|
1103
|
+
"delete_service_group",
|
|
1104
|
+
"Delete a service group by name. Changes are STAGED; call commit_config to apply.",
|
|
1105
|
+
{ name: import_zod5.z.string(), device: import_zod5.z.string().optional() },
|
|
1106
|
+
async ({ name, device }) => {
|
|
1107
|
+
try {
|
|
1108
|
+
const client = await registry.getClient(device);
|
|
1109
|
+
const result = await client.delete(`service-groups/name/${name}`);
|
|
1110
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1111
|
+
} catch (e) {
|
|
1112
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/tools/access-rules.ts
|
|
1119
|
+
var import_zod6 = require("zod");
|
|
1120
|
+
function registerAccessRuleTools(server, registry) {
|
|
1121
|
+
server.tool(
|
|
1122
|
+
"list_access_rules",
|
|
1123
|
+
"List firewall access rules, optionally filtered by source and/or destination zone.",
|
|
1124
|
+
{
|
|
1125
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1126
|
+
from_zone: import_zod6.z.string().optional(),
|
|
1127
|
+
to_zone: import_zod6.z.string().optional(),
|
|
1128
|
+
device: import_zod6.z.string().optional()
|
|
1129
|
+
},
|
|
1130
|
+
async ({ ip_version, from_zone, to_zone, device }) => {
|
|
1131
|
+
try {
|
|
1132
|
+
const client = await registry.getClient(device);
|
|
1133
|
+
const params = {};
|
|
1134
|
+
if (from_zone) params["from"] = from_zone;
|
|
1135
|
+
if (to_zone) params["to"] = to_zone;
|
|
1136
|
+
const result = await client.get(`access-rules/${ip_version}`, Object.keys(params).length ? params : void 0);
|
|
1137
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1138
|
+
} catch (e) {
|
|
1139
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
);
|
|
1143
|
+
server.tool(
|
|
1144
|
+
"get_access_rule",
|
|
1145
|
+
"Retrieve a single access rule by its numeric ID.",
|
|
1146
|
+
{
|
|
1147
|
+
rule_id: import_zod6.z.number(),
|
|
1148
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1149
|
+
device: import_zod6.z.string().optional()
|
|
1150
|
+
},
|
|
1151
|
+
async ({ rule_id, ip_version, device }) => {
|
|
1152
|
+
try {
|
|
1153
|
+
const client = await registry.getClient(device);
|
|
1154
|
+
const result = await client.get(`access-rules/${ip_version}/${rule_id}`);
|
|
1155
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1156
|
+
} catch (e) {
|
|
1157
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1158
|
+
}
|
|
1159
|
+
}
|
|
1160
|
+
);
|
|
1161
|
+
server.tool(
|
|
1162
|
+
"create_access_rule",
|
|
1163
|
+
"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.",
|
|
1164
|
+
{
|
|
1165
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]),
|
|
1166
|
+
name: import_zod6.z.string(),
|
|
1167
|
+
action: import_zod6.z.enum(["allow", "deny", "discard"]),
|
|
1168
|
+
from_zone: import_zod6.z.string(),
|
|
1169
|
+
to_zone: import_zod6.z.string(),
|
|
1170
|
+
source: import_zod6.z.string(),
|
|
1171
|
+
destination: import_zod6.z.string(),
|
|
1172
|
+
service: import_zod6.z.string(),
|
|
1173
|
+
enabled: import_zod6.z.boolean().optional().default(true),
|
|
1174
|
+
log: import_zod6.z.boolean().optional().default(true),
|
|
1175
|
+
priority: import_zod6.z.number().optional(),
|
|
1176
|
+
geo_ip_policy: import_zod6.z.string().optional(),
|
|
1177
|
+
comment: import_zod6.z.string().optional(),
|
|
1178
|
+
device: import_zod6.z.string().optional()
|
|
1179
|
+
},
|
|
1180
|
+
async ({ ip_version, name, action, from_zone, to_zone, source, destination, service, enabled, log, priority, geo_ip_policy, comment, device }) => {
|
|
1181
|
+
try {
|
|
1182
|
+
const client = await registry.getClient(device);
|
|
1183
|
+
const rule = {
|
|
1184
|
+
name,
|
|
1185
|
+
action,
|
|
1186
|
+
from: { zone: from_zone },
|
|
1187
|
+
to: { zone: to_zone },
|
|
1188
|
+
source: { address: { name: source } },
|
|
1189
|
+
destination: { address: { name: destination } },
|
|
1190
|
+
service: { name: service },
|
|
1191
|
+
enable: enabled,
|
|
1192
|
+
log
|
|
1193
|
+
};
|
|
1194
|
+
if (priority !== void 0) rule.priority = priority;
|
|
1195
|
+
if (comment) rule.comment = comment;
|
|
1196
|
+
if (geo_ip_policy) rule.security_profile = { geo_ip_policy: { name: geo_ip_policy } };
|
|
1197
|
+
const result = await client.post(`access-rules/${ip_version}`, {
|
|
1198
|
+
access_rules: [{ [ip_version]: rule }]
|
|
1199
|
+
});
|
|
1200
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1201
|
+
} catch (e) {
|
|
1202
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
);
|
|
1206
|
+
server.tool(
|
|
1207
|
+
"update_access_rule",
|
|
1208
|
+
"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.",
|
|
1209
|
+
{
|
|
1210
|
+
rule_id: import_zod6.z.number(),
|
|
1211
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1212
|
+
action: import_zod6.z.enum(["allow", "deny", "discard"]).optional(),
|
|
1213
|
+
source: import_zod6.z.string().optional(),
|
|
1214
|
+
destination: import_zod6.z.string().optional(),
|
|
1215
|
+
service: import_zod6.z.string().optional(),
|
|
1216
|
+
enabled: import_zod6.z.boolean().optional(),
|
|
1217
|
+
log: import_zod6.z.boolean().optional(),
|
|
1218
|
+
geo_ip_policy: import_zod6.z.string().optional(),
|
|
1219
|
+
comment: import_zod6.z.string().optional(),
|
|
1220
|
+
device: import_zod6.z.string().optional()
|
|
1221
|
+
},
|
|
1222
|
+
async ({ rule_id, ip_version, action, source, destination, service, enabled, log, geo_ip_policy, comment, device }) => {
|
|
1223
|
+
try {
|
|
1224
|
+
const client = await registry.getClient(device);
|
|
1225
|
+
const current = await client.get(`access-rules/${ip_version}/${rule_id}`);
|
|
1226
|
+
const rules = current.access_rules;
|
|
1227
|
+
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1228
|
+
if (action !== void 0) rule.action = action;
|
|
1229
|
+
if (source !== void 0) {
|
|
1230
|
+
if (!rule.source) rule.source = {};
|
|
1231
|
+
rule.source.address = { name: source };
|
|
1232
|
+
}
|
|
1233
|
+
if (destination !== void 0) {
|
|
1234
|
+
if (!rule.destination) rule.destination = {};
|
|
1235
|
+
rule.destination.address = { name: destination };
|
|
1236
|
+
}
|
|
1237
|
+
if (service !== void 0) rule.service = { name: service };
|
|
1238
|
+
if (enabled !== void 0) rule.enable = enabled;
|
|
1239
|
+
if (log !== void 0) rule.log = log;
|
|
1240
|
+
if (comment !== void 0) rule.comment = comment;
|
|
1241
|
+
if (geo_ip_policy !== void 0) {
|
|
1242
|
+
if (geo_ip_policy === "") {
|
|
1243
|
+
delete rule.security_profile;
|
|
1244
|
+
} else {
|
|
1245
|
+
rule.security_profile = { geo_ip_policy: { name: geo_ip_policy } };
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
const result = await client.put(`access-rules/${ip_version}/${rule_id}`, {
|
|
1249
|
+
access_rules: [{ [ip_version]: rule }]
|
|
1250
|
+
});
|
|
1251
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1252
|
+
} catch (e) {
|
|
1253
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
);
|
|
1257
|
+
server.tool(
|
|
1258
|
+
"delete_access_rule",
|
|
1259
|
+
"Delete an access rule by ID. Changes are STAGED; call commit_config to apply.",
|
|
1260
|
+
{
|
|
1261
|
+
rule_id: import_zod6.z.number(),
|
|
1262
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1263
|
+
device: import_zod6.z.string().optional()
|
|
1264
|
+
},
|
|
1265
|
+
async ({ rule_id, ip_version, device }) => {
|
|
1266
|
+
try {
|
|
1267
|
+
const client = await registry.getClient(device);
|
|
1268
|
+
const result = await client.delete(`access-rules/${ip_version}/${rule_id}`);
|
|
1269
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1270
|
+
} catch (e) {
|
|
1271
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
);
|
|
1275
|
+
server.tool(
|
|
1276
|
+
"enable_access_rule",
|
|
1277
|
+
"Enable a disabled access rule without modifying any other fields. Changes are STAGED; call commit_config to apply.",
|
|
1278
|
+
{
|
|
1279
|
+
rule_id: import_zod6.z.number(),
|
|
1280
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1281
|
+
device: import_zod6.z.string().optional()
|
|
1282
|
+
},
|
|
1283
|
+
async ({ rule_id, ip_version, device }) => {
|
|
1284
|
+
try {
|
|
1285
|
+
const client = await registry.getClient(device);
|
|
1286
|
+
const current = await client.get(`access-rules/${ip_version}/${rule_id}`);
|
|
1287
|
+
const rules = current.access_rules;
|
|
1288
|
+
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1289
|
+
rule.enable = true;
|
|
1290
|
+
const result = await client.put(`access-rules/${ip_version}/${rule_id}`, {
|
|
1291
|
+
access_rules: [{ [ip_version]: rule }]
|
|
1292
|
+
});
|
|
1293
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1294
|
+
} catch (e) {
|
|
1295
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
);
|
|
1299
|
+
server.tool(
|
|
1300
|
+
"disable_access_rule",
|
|
1301
|
+
"Disable an access rule without deleting it. Changes are STAGED; call commit_config to apply.",
|
|
1302
|
+
{
|
|
1303
|
+
rule_id: import_zod6.z.number(),
|
|
1304
|
+
ip_version: import_zod6.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1305
|
+
device: import_zod6.z.string().optional()
|
|
1306
|
+
},
|
|
1307
|
+
async ({ rule_id, ip_version, device }) => {
|
|
1308
|
+
try {
|
|
1309
|
+
const client = await registry.getClient(device);
|
|
1310
|
+
const current = await client.get(`access-rules/${ip_version}/${rule_id}`);
|
|
1311
|
+
const rules = current.access_rules;
|
|
1312
|
+
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1313
|
+
rule.enable = false;
|
|
1314
|
+
const result = await client.put(`access-rules/${ip_version}/${rule_id}`, {
|
|
1315
|
+
access_rules: [{ [ip_version]: rule }]
|
|
1316
|
+
});
|
|
1317
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1318
|
+
} catch (e) {
|
|
1319
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
// src/tools/nat-policies.ts
|
|
1326
|
+
var import_zod7 = require("zod");
|
|
1327
|
+
function setNameField(obj, key, value) {
|
|
1328
|
+
if (value !== void 0) obj[key] = { name: value };
|
|
1329
|
+
}
|
|
1330
|
+
function registerNatPolicyTools(server, registry) {
|
|
1331
|
+
server.tool(
|
|
1332
|
+
"list_nat_policies",
|
|
1333
|
+
"List all NAT policies.",
|
|
1334
|
+
{
|
|
1335
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1336
|
+
device: import_zod7.z.string().optional()
|
|
1337
|
+
},
|
|
1338
|
+
async ({ ip_version, device }) => {
|
|
1339
|
+
try {
|
|
1340
|
+
const client = await registry.getClient(device);
|
|
1341
|
+
const result = await client.get(`nat-policies/${ip_version}`);
|
|
1342
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1343
|
+
} catch (e) {
|
|
1344
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
);
|
|
1348
|
+
server.tool(
|
|
1349
|
+
"get_nat_policy",
|
|
1350
|
+
"Retrieve a NAT policy by its numeric ID.",
|
|
1351
|
+
{
|
|
1352
|
+
policy_id: import_zod7.z.number(),
|
|
1353
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1354
|
+
device: import_zod7.z.string().optional()
|
|
1355
|
+
},
|
|
1356
|
+
async ({ policy_id, ip_version, device }) => {
|
|
1357
|
+
try {
|
|
1358
|
+
const client = await registry.getClient(device);
|
|
1359
|
+
const result = await client.get(`nat-policies/${ip_version}/${policy_id}`);
|
|
1360
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1361
|
+
} catch (e) {
|
|
1362
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1363
|
+
}
|
|
1364
|
+
}
|
|
1365
|
+
);
|
|
1366
|
+
server.tool(
|
|
1367
|
+
"create_nat_policy",
|
|
1368
|
+
"Create a NAT policy. Use 'Original' for translated fields to mean no translation. Use 'Any' for interfaces to match all. Changes are STAGED; call commit_config to apply.",
|
|
1369
|
+
{
|
|
1370
|
+
name: import_zod7.z.string(),
|
|
1371
|
+
original_source: import_zod7.z.string(),
|
|
1372
|
+
translated_source: import_zod7.z.string(),
|
|
1373
|
+
original_destination: import_zod7.z.string(),
|
|
1374
|
+
translated_destination: import_zod7.z.string(),
|
|
1375
|
+
original_service: import_zod7.z.string(),
|
|
1376
|
+
translated_service: import_zod7.z.string(),
|
|
1377
|
+
inbound_interface: import_zod7.z.string().optional().default("Any"),
|
|
1378
|
+
outbound_interface: import_zod7.z.string().optional().default("Any"),
|
|
1379
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1380
|
+
enabled: import_zod7.z.boolean().optional().default(true),
|
|
1381
|
+
comment: import_zod7.z.string().optional(),
|
|
1382
|
+
device: import_zod7.z.string().optional()
|
|
1383
|
+
},
|
|
1384
|
+
async ({ name, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, ip_version, enabled, comment, device }) => {
|
|
1385
|
+
try {
|
|
1386
|
+
const client = await registry.getClient(device);
|
|
1387
|
+
const policy = {
|
|
1388
|
+
name,
|
|
1389
|
+
enable: enabled,
|
|
1390
|
+
original_source: { name: original_source },
|
|
1391
|
+
translated_source: { name: translated_source },
|
|
1392
|
+
original_destination: { name: original_destination },
|
|
1393
|
+
translated_destination: { name: translated_destination },
|
|
1394
|
+
original_service: { name: original_service },
|
|
1395
|
+
translated_service: { name: translated_service },
|
|
1396
|
+
inbound_interface: { name: inbound_interface },
|
|
1397
|
+
outbound_interface: { name: outbound_interface }
|
|
1398
|
+
};
|
|
1399
|
+
if (comment) policy.comment = comment;
|
|
1400
|
+
const result = await client.post(`nat-policies/${ip_version}`, {
|
|
1401
|
+
nat_policies: [{ [ip_version]: policy }]
|
|
1402
|
+
});
|
|
1403
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1404
|
+
} catch (e) {
|
|
1405
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
);
|
|
1409
|
+
server.tool(
|
|
1410
|
+
"update_nat_policy",
|
|
1411
|
+
"Update fields on an existing NAT policy (GET-then-PUT). Changes are STAGED; call commit_config to apply.",
|
|
1412
|
+
{
|
|
1413
|
+
policy_id: import_zod7.z.number(),
|
|
1414
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1415
|
+
original_source: import_zod7.z.string().optional(),
|
|
1416
|
+
translated_source: import_zod7.z.string().optional(),
|
|
1417
|
+
original_destination: import_zod7.z.string().optional(),
|
|
1418
|
+
translated_destination: import_zod7.z.string().optional(),
|
|
1419
|
+
original_service: import_zod7.z.string().optional(),
|
|
1420
|
+
translated_service: import_zod7.z.string().optional(),
|
|
1421
|
+
inbound_interface: import_zod7.z.string().optional(),
|
|
1422
|
+
outbound_interface: import_zod7.z.string().optional(),
|
|
1423
|
+
enabled: import_zod7.z.boolean().optional(),
|
|
1424
|
+
comment: import_zod7.z.string().optional(),
|
|
1425
|
+
device: import_zod7.z.string().optional()
|
|
1426
|
+
},
|
|
1427
|
+
async ({ policy_id, ip_version, original_source, translated_source, original_destination, translated_destination, original_service, translated_service, inbound_interface, outbound_interface, enabled, comment, device }) => {
|
|
1428
|
+
try {
|
|
1429
|
+
const client = await registry.getClient(device);
|
|
1430
|
+
const current = await client.get(`nat-policies/${ip_version}/${policy_id}`);
|
|
1431
|
+
const policies = current.nat_policies;
|
|
1432
|
+
const policy = policies?.[0]?.[ip_version] ?? {};
|
|
1433
|
+
setNameField(policy, "original_source", original_source);
|
|
1434
|
+
setNameField(policy, "translated_source", translated_source);
|
|
1435
|
+
setNameField(policy, "original_destination", original_destination);
|
|
1436
|
+
setNameField(policy, "translated_destination", translated_destination);
|
|
1437
|
+
setNameField(policy, "original_service", original_service);
|
|
1438
|
+
setNameField(policy, "translated_service", translated_service);
|
|
1439
|
+
setNameField(policy, "inbound_interface", inbound_interface);
|
|
1440
|
+
setNameField(policy, "outbound_interface", outbound_interface);
|
|
1441
|
+
if (enabled !== void 0) policy.enable = enabled;
|
|
1442
|
+
if (comment !== void 0) policy.comment = comment;
|
|
1443
|
+
const result = await client.put(`nat-policies/${ip_version}/${policy_id}`, {
|
|
1444
|
+
nat_policies: [{ [ip_version]: policy }]
|
|
1445
|
+
});
|
|
1446
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1447
|
+
} catch (e) {
|
|
1448
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
);
|
|
1452
|
+
server.tool(
|
|
1453
|
+
"delete_nat_policy",
|
|
1454
|
+
"Delete a NAT policy by ID. Changes are STAGED; call commit_config to apply.",
|
|
1455
|
+
{
|
|
1456
|
+
policy_id: import_zod7.z.number(),
|
|
1457
|
+
ip_version: import_zod7.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1458
|
+
device: import_zod7.z.string().optional()
|
|
1459
|
+
},
|
|
1460
|
+
async ({ policy_id, ip_version, device }) => {
|
|
1461
|
+
try {
|
|
1462
|
+
const client = await registry.getClient(device);
|
|
1463
|
+
const result = await client.delete(`nat-policies/${ip_version}/${policy_id}`);
|
|
1464
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1465
|
+
} catch (e) {
|
|
1466
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
);
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
// src/tools/security-policies.ts
|
|
1473
|
+
var import_zod8 = require("zod");
|
|
1474
|
+
function registerSecurityPolicyTools(server, registry) {
|
|
1475
|
+
server.tool(
|
|
1476
|
+
"list_security_policies",
|
|
1477
|
+
"List all security policies.",
|
|
1478
|
+
{
|
|
1479
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1480
|
+
device: import_zod8.z.string().optional()
|
|
1481
|
+
},
|
|
1482
|
+
async ({ ip_version, device }) => {
|
|
1483
|
+
try {
|
|
1484
|
+
const client = await registry.getClient(device);
|
|
1485
|
+
const result = await client.get(`security-policies/${ip_version}`);
|
|
1486
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1487
|
+
} catch (e) {
|
|
1488
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
);
|
|
1492
|
+
server.tool(
|
|
1493
|
+
"get_security_policy",
|
|
1494
|
+
"Retrieve a security policy by its numeric ID.",
|
|
1495
|
+
{
|
|
1496
|
+
policy_id: import_zod8.z.number(),
|
|
1497
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1498
|
+
device: import_zod8.z.string().optional()
|
|
1499
|
+
},
|
|
1500
|
+
async ({ policy_id, ip_version, device }) => {
|
|
1501
|
+
try {
|
|
1502
|
+
const client = await registry.getClient(device);
|
|
1503
|
+
const result = await client.get(`security-policies/${ip_version}/${policy_id}`);
|
|
1504
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1505
|
+
} catch (e) {
|
|
1506
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
);
|
|
1510
|
+
server.tool(
|
|
1511
|
+
"create_security_policy",
|
|
1512
|
+
"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.",
|
|
1513
|
+
{
|
|
1514
|
+
name: import_zod8.z.string(),
|
|
1515
|
+
source_zone: import_zod8.z.string(),
|
|
1516
|
+
destination_zone: import_zod8.z.string(),
|
|
1517
|
+
source_address: import_zod8.z.string(),
|
|
1518
|
+
destination_address: import_zod8.z.string(),
|
|
1519
|
+
service: import_zod8.z.string(),
|
|
1520
|
+
action: import_zod8.z.string(),
|
|
1521
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1522
|
+
users: import_zod8.z.array(import_zod8.z.string()).optional(),
|
|
1523
|
+
schedule: import_zod8.z.string().optional(),
|
|
1524
|
+
enabled: import_zod8.z.boolean().optional().default(true),
|
|
1525
|
+
log: import_zod8.z.boolean().optional().default(true),
|
|
1526
|
+
comment: import_zod8.z.string().optional(),
|
|
1527
|
+
device: import_zod8.z.string().optional()
|
|
1528
|
+
},
|
|
1529
|
+
async ({ name, source_zone, destination_zone, source_address, destination_address, service, action, ip_version, users, schedule, enabled, log, comment, device }) => {
|
|
1530
|
+
try {
|
|
1531
|
+
const client = await registry.getClient(device);
|
|
1532
|
+
const policy = {
|
|
1533
|
+
name,
|
|
1534
|
+
enable: enabled,
|
|
1535
|
+
log,
|
|
1536
|
+
from: { zone: source_zone },
|
|
1537
|
+
to: { zone: destination_zone },
|
|
1538
|
+
source: { address: { name: source_address } },
|
|
1539
|
+
destination: { address: { name: destination_address } },
|
|
1540
|
+
service: { name: service },
|
|
1541
|
+
action
|
|
1542
|
+
};
|
|
1543
|
+
if (users && users.length > 0) policy.users = users.map((u) => ({ name: u }));
|
|
1544
|
+
if (schedule) policy.schedule = { name: schedule };
|
|
1545
|
+
if (comment) policy.comment = comment;
|
|
1546
|
+
const result = await client.post(`security-policies/${ip_version}`, {
|
|
1547
|
+
security_policies: [{ [ip_version]: policy }]
|
|
1548
|
+
});
|
|
1549
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1550
|
+
} catch (e) {
|
|
1551
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
);
|
|
1555
|
+
server.tool(
|
|
1556
|
+
"update_security_policy",
|
|
1557
|
+
"Update fields on an existing security policy (GET-then-PUT). Only provided fields are changed. Changes are STAGED; call commit_config to apply.",
|
|
1558
|
+
{
|
|
1559
|
+
policy_id: import_zod8.z.number(),
|
|
1560
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1561
|
+
action: import_zod8.z.string().optional(),
|
|
1562
|
+
source_address: import_zod8.z.string().optional(),
|
|
1563
|
+
destination_address: import_zod8.z.string().optional(),
|
|
1564
|
+
service: import_zod8.z.string().optional(),
|
|
1565
|
+
enabled: import_zod8.z.boolean().optional(),
|
|
1566
|
+
log: import_zod8.z.boolean().optional(),
|
|
1567
|
+
comment: import_zod8.z.string().optional(),
|
|
1568
|
+
device: import_zod8.z.string().optional()
|
|
1569
|
+
},
|
|
1570
|
+
async ({ policy_id, ip_version, action, source_address, destination_address, service, enabled, log, comment, device }) => {
|
|
1571
|
+
try {
|
|
1572
|
+
const client = await registry.getClient(device);
|
|
1573
|
+
const current = await client.get(`security-policies/${ip_version}/${policy_id}`);
|
|
1574
|
+
const policies = current.security_policies;
|
|
1575
|
+
const policy = policies?.[0]?.[ip_version] ?? {};
|
|
1576
|
+
if (action !== void 0) policy.action = action;
|
|
1577
|
+
if (source_address !== void 0) {
|
|
1578
|
+
if (!policy.source) policy.source = {};
|
|
1579
|
+
policy.source.address = { name: source_address };
|
|
1580
|
+
}
|
|
1581
|
+
if (destination_address !== void 0) {
|
|
1582
|
+
if (!policy.destination) policy.destination = {};
|
|
1583
|
+
policy.destination.address = { name: destination_address };
|
|
1584
|
+
}
|
|
1585
|
+
if (service !== void 0) policy.service = { name: service };
|
|
1586
|
+
if (enabled !== void 0) policy.enable = enabled;
|
|
1587
|
+
if (log !== void 0) policy.log = log;
|
|
1588
|
+
if (comment !== void 0) policy.comment = comment;
|
|
1589
|
+
const result = await client.put(`security-policies/${ip_version}/${policy_id}`, {
|
|
1590
|
+
security_policies: [{ [ip_version]: policy }]
|
|
1591
|
+
});
|
|
1592
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1593
|
+
} catch (e) {
|
|
1594
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1597
|
+
);
|
|
1598
|
+
server.tool(
|
|
1599
|
+
"delete_security_policy",
|
|
1600
|
+
"Delete a security policy by ID. Changes are STAGED; call commit_config to apply.",
|
|
1601
|
+
{
|
|
1602
|
+
policy_id: import_zod8.z.number(),
|
|
1603
|
+
ip_version: import_zod8.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1604
|
+
device: import_zod8.z.string().optional()
|
|
1605
|
+
},
|
|
1606
|
+
async ({ policy_id, ip_version, device }) => {
|
|
1607
|
+
try {
|
|
1608
|
+
const client = await registry.getClient(device);
|
|
1609
|
+
const result = await client.delete(`security-policies/${ip_version}/${policy_id}`);
|
|
1610
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1611
|
+
} catch (e) {
|
|
1612
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
);
|
|
1616
|
+
}
|
|
1617
|
+
|
|
1618
|
+
// src/tools/geo-ip.ts
|
|
1619
|
+
var import_zod9 = require("zod");
|
|
1620
|
+
function parseGeoLookup(ip, raw) {
|
|
1621
|
+
const parsed = {
|
|
1622
|
+
ip,
|
|
1623
|
+
country: null,
|
|
1624
|
+
country_code: null,
|
|
1625
|
+
city: null,
|
|
1626
|
+
region: null,
|
|
1627
|
+
botnet: false
|
|
1628
|
+
};
|
|
1629
|
+
for (const rawLine of raw.split("\n")) {
|
|
1630
|
+
const line = rawLine.trim();
|
|
1631
|
+
const countryMatch = line.match(/[Cc]ountry\s*(?:[Cc]ode)?\s*:\s*(.+)/);
|
|
1632
|
+
if (countryMatch) {
|
|
1633
|
+
const val = countryMatch[1].trim();
|
|
1634
|
+
if (val.length === 2 && val === val.toUpperCase()) {
|
|
1635
|
+
parsed.country_code = val;
|
|
1636
|
+
} else {
|
|
1637
|
+
parsed.country = val;
|
|
1638
|
+
}
|
|
1639
|
+
continue;
|
|
1640
|
+
}
|
|
1641
|
+
const cityMatch = line.match(/[Cc]ity\s*:\s*(.+)/);
|
|
1642
|
+
if (cityMatch) {
|
|
1643
|
+
parsed.city = cityMatch[1].trim();
|
|
1644
|
+
continue;
|
|
1645
|
+
}
|
|
1646
|
+
const regionMatch = line.match(/[Rr]egion\s*:\s*(.+)/);
|
|
1647
|
+
if (regionMatch) {
|
|
1648
|
+
parsed.region = regionMatch[1].trim();
|
|
1649
|
+
continue;
|
|
1650
|
+
}
|
|
1651
|
+
if (/[Bb]otnet/.test(line) && /(?:yes|true|detected)/i.test(line)) {
|
|
1652
|
+
parsed.botnet = true;
|
|
1653
|
+
}
|
|
1654
|
+
}
|
|
1655
|
+
if (raw && parsed.country === null && parsed.country_code === null) {
|
|
1656
|
+
parsed.raw_output = raw;
|
|
1657
|
+
}
|
|
1658
|
+
return parsed;
|
|
1659
|
+
}
|
|
1660
|
+
function registerGeoIpTools(server, registry) {
|
|
1661
|
+
server.tool(
|
|
1662
|
+
"list_geo_ip_policies",
|
|
1663
|
+
"List all GeoIP filtering policies configured on the appliance.",
|
|
1664
|
+
{ device: import_zod9.z.string().optional() },
|
|
1665
|
+
async ({ device }) => {
|
|
1666
|
+
try {
|
|
1667
|
+
const client = await registry.getClient(device);
|
|
1668
|
+
const result = await client.get("geo-ip/policies");
|
|
1669
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1670
|
+
} catch (e) {
|
|
1671
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
);
|
|
1675
|
+
server.tool(
|
|
1676
|
+
"get_geo_ip_policy",
|
|
1677
|
+
"Retrieve a GeoIP policy by name.",
|
|
1678
|
+
{ name: import_zod9.z.string(), device: import_zod9.z.string().optional() },
|
|
1679
|
+
async ({ name, device }) => {
|
|
1680
|
+
try {
|
|
1681
|
+
const client = await registry.getClient(device);
|
|
1682
|
+
const result = await client.get(`geo-ip/policies/name/${name}`);
|
|
1683
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1684
|
+
} catch (e) {
|
|
1685
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
);
|
|
1689
|
+
server.tool(
|
|
1690
|
+
"create_geo_ip_policy",
|
|
1691
|
+
"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.",
|
|
1692
|
+
{
|
|
1693
|
+
name: import_zod9.z.string(),
|
|
1694
|
+
block_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
1695
|
+
allow_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
1696
|
+
log: import_zod9.z.boolean().optional().default(true),
|
|
1697
|
+
device: import_zod9.z.string().optional()
|
|
1698
|
+
},
|
|
1699
|
+
async ({ name, block_countries, allow_countries, log, device }) => {
|
|
1700
|
+
try {
|
|
1701
|
+
const client = await registry.getClient(device);
|
|
1702
|
+
const policy = { name, log };
|
|
1703
|
+
if (block_countries && block_countries.length > 0) {
|
|
1704
|
+
policy.block_countries = block_countries.map((c) => ({ country: c.toUpperCase() }));
|
|
1705
|
+
}
|
|
1706
|
+
if (allow_countries && allow_countries.length > 0) {
|
|
1707
|
+
policy.allow_countries = allow_countries.map((c) => ({ country: c.toUpperCase() }));
|
|
1708
|
+
}
|
|
1709
|
+
const result = await client.post("geo-ip/policies", { geo_ip_policies: [policy] });
|
|
1710
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1711
|
+
} catch (e) {
|
|
1712
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1715
|
+
);
|
|
1716
|
+
server.tool(
|
|
1717
|
+
"update_geo_ip_policy",
|
|
1718
|
+
"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.",
|
|
1719
|
+
{
|
|
1720
|
+
name: import_zod9.z.string(),
|
|
1721
|
+
block_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
1722
|
+
allow_countries: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
1723
|
+
log: import_zod9.z.boolean().optional(),
|
|
1724
|
+
device: import_zod9.z.string().optional()
|
|
1725
|
+
},
|
|
1726
|
+
async ({ name, block_countries, allow_countries, log, device }) => {
|
|
1727
|
+
try {
|
|
1728
|
+
const client = await registry.getClient(device);
|
|
1729
|
+
const current = await client.get(`geo-ip/policies/name/${name}`);
|
|
1730
|
+
const policies = current.geo_ip_policies;
|
|
1731
|
+
const policy = policies?.[0] ?? {};
|
|
1732
|
+
if (block_countries !== void 0) {
|
|
1733
|
+
policy.block_countries = block_countries.map((c) => ({ country: c.toUpperCase() }));
|
|
1734
|
+
}
|
|
1735
|
+
if (allow_countries !== void 0) {
|
|
1736
|
+
policy.allow_countries = allow_countries.map((c) => ({ country: c.toUpperCase() }));
|
|
1737
|
+
}
|
|
1738
|
+
if (log !== void 0) policy.log = log;
|
|
1739
|
+
const result = await client.put(`geo-ip/policies/name/${name}`, { geo_ip_policies: [policy] });
|
|
1740
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1741
|
+
} catch (e) {
|
|
1742
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
);
|
|
1746
|
+
server.tool(
|
|
1747
|
+
"delete_geo_ip_policy",
|
|
1748
|
+
"Delete a GeoIP policy by name. Changes are STAGED; call commit_config to apply.",
|
|
1749
|
+
{ name: import_zod9.z.string(), device: import_zod9.z.string().optional() },
|
|
1750
|
+
async ({ name, device }) => {
|
|
1751
|
+
try {
|
|
1752
|
+
const client = await registry.getClient(device);
|
|
1753
|
+
const result = await client.delete(`geo-ip/policies/name/${name}`);
|
|
1754
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1755
|
+
} catch (e) {
|
|
1756
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
);
|
|
1760
|
+
server.tool(
|
|
1761
|
+
"list_geo_ip_countries",
|
|
1762
|
+
"Return all country codes and names available for GeoIP filtering.",
|
|
1763
|
+
{ device: import_zod9.z.string().optional() },
|
|
1764
|
+
async ({ device }) => {
|
|
1765
|
+
try {
|
|
1766
|
+
const client = await registry.getClient(device);
|
|
1767
|
+
const result = await client.get("geo-ip/countries");
|
|
1768
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1769
|
+
} catch (e) {
|
|
1770
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
);
|
|
1774
|
+
server.tool(
|
|
1775
|
+
"get_geo_ip_stats",
|
|
1776
|
+
"Return GeoIP statistics \u2014 connection counts blocked/allowed by country.",
|
|
1777
|
+
{ device: import_zod9.z.string().optional() },
|
|
1778
|
+
async ({ device }) => {
|
|
1779
|
+
try {
|
|
1780
|
+
const client = await registry.getClient(device);
|
|
1781
|
+
const result = await client.get("geo-ip/statistics");
|
|
1782
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1783
|
+
} catch (e) {
|
|
1784
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1787
|
+
);
|
|
1788
|
+
server.tool(
|
|
1789
|
+
"assign_geo_ip_to_rule",
|
|
1790
|
+
"Attach a GeoIP policy to an existing access rule without changing any other rule fields. Changes are STAGED; call commit_config to apply.",
|
|
1791
|
+
{
|
|
1792
|
+
rule_id: import_zod9.z.number(),
|
|
1793
|
+
geo_ip_policy_name: import_zod9.z.string(),
|
|
1794
|
+
ip_version: import_zod9.z.enum(["ipv4", "ipv6"]).optional().default("ipv4"),
|
|
1795
|
+
device: import_zod9.z.string().optional()
|
|
1796
|
+
},
|
|
1797
|
+
async ({ rule_id, geo_ip_policy_name, ip_version, device }) => {
|
|
1798
|
+
try {
|
|
1799
|
+
const client = await registry.getClient(device);
|
|
1800
|
+
const current = await client.get(`access-rules/${ip_version}/${rule_id}`);
|
|
1801
|
+
const rules = current.access_rules;
|
|
1802
|
+
const rule = rules?.[0]?.[ip_version] ?? {};
|
|
1803
|
+
if (!rule.security_profile) rule.security_profile = {};
|
|
1804
|
+
rule.security_profile.geo_ip_policy = { name: geo_ip_policy_name };
|
|
1805
|
+
const result = await client.put(`access-rules/${ip_version}/${rule_id}`, {
|
|
1806
|
+
access_rules: [{ [ip_version]: rule }]
|
|
1807
|
+
});
|
|
1808
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1809
|
+
} catch (e) {
|
|
1810
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
);
|
|
1814
|
+
server.tool(
|
|
1815
|
+
"lookup_ip_country",
|
|
1816
|
+
"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.",
|
|
1817
|
+
{ ip: import_zod9.z.string(), device: import_zod9.z.string().optional() },
|
|
1818
|
+
async ({ ip, device }) => {
|
|
1819
|
+
try {
|
|
1820
|
+
const client = await registry.getClient(device);
|
|
1821
|
+
const result = await client.post("direct/cli", { cli_command: `diag geo-botnet-lookup ${ip}` });
|
|
1822
|
+
const raw = result.cli_output ?? result.output ?? JSON.stringify(result);
|
|
1823
|
+
return { content: [{ type: "text", text: JSON.stringify(parseGeoLookup(ip, raw), null, 2) }] };
|
|
1824
|
+
} catch (e) {
|
|
1825
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
);
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
// src/tools/logs.ts
|
|
1832
|
+
var import_zod10 = require("zod");
|
|
1833
|
+
function logPath(version, subpath) {
|
|
1834
|
+
return version >= 8 ? `log/${subpath}` : `reporting/${subpath}`;
|
|
1835
|
+
}
|
|
1836
|
+
async function getLogsWithFallback(client, subpathV7, subpathV8, params) {
|
|
1837
|
+
const isPrimary = client.version >= 8;
|
|
1838
|
+
const primary = logPath(client.version, isPrimary ? subpathV8 : subpathV7);
|
|
1839
|
+
const fallbackVersion = isPrimary ? 7 : 8;
|
|
1840
|
+
const fallback = logPath(fallbackVersion, isPrimary ? subpathV7 : subpathV8);
|
|
1841
|
+
try {
|
|
1842
|
+
return await client.get(primary, params);
|
|
1843
|
+
} catch (e) {
|
|
1844
|
+
if (e instanceof APIError && e.status === 404) {
|
|
1845
|
+
return await client.get(fallback, params);
|
|
1846
|
+
}
|
|
1847
|
+
throw e;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
function registerLogTools(server, registry) {
|
|
1851
|
+
server.tool(
|
|
1852
|
+
"get_log_categories",
|
|
1853
|
+
"Return the list of available log category names for use with get_event_logs.",
|
|
1854
|
+
{ device: import_zod10.z.string().optional() },
|
|
1855
|
+
async ({ device }) => {
|
|
1856
|
+
try {
|
|
1857
|
+
const client = await registry.getClient(device);
|
|
1858
|
+
const path = client.version >= 8 ? "log/categories" : "reporting/log/categories";
|
|
1859
|
+
try {
|
|
1860
|
+
const result = await client.get(path);
|
|
1861
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1862
|
+
} catch (e) {
|
|
1863
|
+
if (e instanceof APIError && e.status === 404) {
|
|
1864
|
+
const fallback = {
|
|
1865
|
+
categories: [
|
|
1866
|
+
"network access",
|
|
1867
|
+
"firewall",
|
|
1868
|
+
"vpn",
|
|
1869
|
+
"system",
|
|
1870
|
+
"security",
|
|
1871
|
+
"IPS",
|
|
1872
|
+
"anti-virus",
|
|
1873
|
+
"anti-spyware",
|
|
1874
|
+
"application control",
|
|
1875
|
+
"content filter",
|
|
1876
|
+
"decryption",
|
|
1877
|
+
"geoip",
|
|
1878
|
+
"authentication"
|
|
1879
|
+
]
|
|
1880
|
+
};
|
|
1881
|
+
return { content: [{ type: "text", text: JSON.stringify(fallback, null, 2) }] };
|
|
1882
|
+
}
|
|
1883
|
+
throw e;
|
|
1884
|
+
}
|
|
1885
|
+
} catch (e) {
|
|
1886
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
);
|
|
1890
|
+
server.tool(
|
|
1891
|
+
"get_event_logs",
|
|
1892
|
+
"Retrieve system/event logs from the appliance. count: max entries (default 100). category: e.g. 'network access', 'system', 'vpn'. priority: emergency/alert/critical/error/warning/notice/info/debug. start_time/end_time: ISO 8601. source_ip: filter by source IP. keyword: full-text search.",
|
|
1893
|
+
{
|
|
1894
|
+
count: import_zod10.z.number().optional().default(100),
|
|
1895
|
+
category: import_zod10.z.string().optional(),
|
|
1896
|
+
priority: import_zod10.z.enum(["emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"]).optional(),
|
|
1897
|
+
start_time: import_zod10.z.string().optional(),
|
|
1898
|
+
end_time: import_zod10.z.string().optional(),
|
|
1899
|
+
source_ip: import_zod10.z.string().optional(),
|
|
1900
|
+
keyword: import_zod10.z.string().optional(),
|
|
1901
|
+
device: import_zod10.z.string().optional()
|
|
1902
|
+
},
|
|
1903
|
+
async ({ count, category, priority, start_time, end_time, source_ip, keyword, device }) => {
|
|
1904
|
+
try {
|
|
1905
|
+
const client = await registry.getClient(device);
|
|
1906
|
+
const params = { count };
|
|
1907
|
+
if (category) params.category = category;
|
|
1908
|
+
if (priority) params.priority = priority;
|
|
1909
|
+
if (start_time) params.start_time = start_time;
|
|
1910
|
+
if (end_time) params.end_time = end_time;
|
|
1911
|
+
if (source_ip) params.src_ip = source_ip;
|
|
1912
|
+
if (keyword) params.keyword = keyword;
|
|
1913
|
+
const result = await getLogsWithFallback(client, "log", "events", params);
|
|
1914
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1915
|
+
} catch (e) {
|
|
1916
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
);
|
|
1920
|
+
server.tool(
|
|
1921
|
+
"get_traffic_logs",
|
|
1922
|
+
"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'.",
|
|
1923
|
+
{
|
|
1924
|
+
count: import_zod10.z.number().optional().default(100),
|
|
1925
|
+
source_ip: import_zod10.z.string().optional(),
|
|
1926
|
+
destination_ip: import_zod10.z.string().optional(),
|
|
1927
|
+
destination_port: import_zod10.z.number().optional(),
|
|
1928
|
+
protocol: import_zod10.z.string().optional(),
|
|
1929
|
+
action: import_zod10.z.enum(["allow", "deny"]).optional(),
|
|
1930
|
+
start_time: import_zod10.z.string().optional(),
|
|
1931
|
+
end_time: import_zod10.z.string().optional(),
|
|
1932
|
+
device: import_zod10.z.string().optional()
|
|
1933
|
+
},
|
|
1934
|
+
async ({ count, source_ip, destination_ip, destination_port, protocol, action, start_time, end_time, device }) => {
|
|
1935
|
+
try {
|
|
1936
|
+
const client = await registry.getClient(device);
|
|
1937
|
+
const params = { count };
|
|
1938
|
+
if (source_ip) params.src_ip = source_ip;
|
|
1939
|
+
if (destination_ip) params.dst_ip = destination_ip;
|
|
1940
|
+
if (destination_port !== void 0) params.dst_port = destination_port;
|
|
1941
|
+
if (protocol) params.protocol = protocol;
|
|
1942
|
+
if (action) params.action = action;
|
|
1943
|
+
if (start_time) params.start_time = start_time;
|
|
1944
|
+
if (end_time) params.end_time = end_time;
|
|
1945
|
+
const result = await getLogsWithFallback(client, "appflow/connections", "traffic", params);
|
|
1946
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1947
|
+
} catch (e) {
|
|
1948
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
);
|
|
1952
|
+
server.tool(
|
|
1953
|
+
"search_logs",
|
|
1954
|
+
"Full-text keyword search across event logs. query: text to search. count: max entries.",
|
|
1955
|
+
{
|
|
1956
|
+
query: import_zod10.z.string(),
|
|
1957
|
+
count: import_zod10.z.number().optional().default(200),
|
|
1958
|
+
start_time: import_zod10.z.string().optional(),
|
|
1959
|
+
end_time: import_zod10.z.string().optional(),
|
|
1960
|
+
device: import_zod10.z.string().optional()
|
|
1961
|
+
},
|
|
1962
|
+
async ({ query, count, start_time, end_time, device }) => {
|
|
1963
|
+
try {
|
|
1964
|
+
const client = await registry.getClient(device);
|
|
1965
|
+
const params = { count, keyword: query };
|
|
1966
|
+
if (start_time) params.start_time = start_time;
|
|
1967
|
+
if (end_time) params.end_time = end_time;
|
|
1968
|
+
const result = await getLogsWithFallback(client, "log", "events", params);
|
|
1969
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1970
|
+
} catch (e) {
|
|
1971
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
);
|
|
1975
|
+
server.tool(
|
|
1976
|
+
"get_threat_logs",
|
|
1977
|
+
"Retrieve IPS and threat-detection log events. severity: 'critical', 'high', 'medium', or 'low'.",
|
|
1978
|
+
{
|
|
1979
|
+
count: import_zod10.z.number().optional().default(50),
|
|
1980
|
+
severity: import_zod10.z.enum(["critical", "high", "medium", "low"]).optional(),
|
|
1981
|
+
start_time: import_zod10.z.string().optional(),
|
|
1982
|
+
end_time: import_zod10.z.string().optional(),
|
|
1983
|
+
device: import_zod10.z.string().optional()
|
|
1984
|
+
},
|
|
1985
|
+
async ({ count, severity, start_time, end_time, device }) => {
|
|
1986
|
+
try {
|
|
1987
|
+
const client = await registry.getClient(device);
|
|
1988
|
+
const params = { count, category: "IPS" };
|
|
1989
|
+
if (severity) params.severity = severity;
|
|
1990
|
+
if (start_time) params.start_time = start_time;
|
|
1991
|
+
if (end_time) params.end_time = end_time;
|
|
1992
|
+
const result = await getLogsWithFallback(client, "log", "events", params);
|
|
1993
|
+
return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
|
|
1994
|
+
} catch (e) {
|
|
1995
|
+
return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
|
|
2001
|
+
// src/index.ts
|
|
2002
|
+
async function main() {
|
|
2003
|
+
let config;
|
|
2004
|
+
try {
|
|
2005
|
+
config = loadConfig();
|
|
2006
|
+
} catch (e) {
|
|
2007
|
+
process.stderr.write(`sonicwall-mcp: configuration error: ${e.message}
|
|
2008
|
+
`);
|
|
2009
|
+
process.exit(1);
|
|
2010
|
+
}
|
|
2011
|
+
if (config.profiles.some((p) => !p.sslVerify)) {
|
|
2012
|
+
process.stderr.write(
|
|
2013
|
+
"sonicwall-mcp: WARNING \u2014 SSL verification disabled (SONICWALL_SSL_VERIFY=false). This setting is global and affects all connections in this process.\n"
|
|
2014
|
+
);
|
|
2015
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
2016
|
+
}
|
|
2017
|
+
const registry = new DeviceRegistry(config.profiles);
|
|
2018
|
+
const server = new import_mcp.McpServer({
|
|
2019
|
+
name: "sonicwall-mcp-server",
|
|
2020
|
+
version: "0.4.0",
|
|
2021
|
+
instructions: `SonicWall NSA MCP server \u2014 full read/write access to SonicWall firewalls via the SonicOS REST API.
|
|
2022
|
+
|
|
2023
|
+
## Device targeting
|
|
2024
|
+
Use list_devices to discover available appliances and their names. Pass device='<name>' to target a specific appliance; omit it to use the primary/default device.
|
|
2025
|
+
|
|
2026
|
+
## Staged configuration
|
|
2027
|
+
IMPORTANT: All create/update/delete operations are STAGED and do not take effect until you call commit_config. Call discard_config to abandon staged changes. Always commit after completing a related set of changes, or discard if the user changes their mind. Never leave uncommitted changes unless the user explicitly asks to review before committing.
|
|
2028
|
+
|
|
2029
|
+
## Datetime handling
|
|
2030
|
+
All timestamp parameters (start_time, end_time in log tools) are in the appliance's LOCAL timezone \u2014 SonicWall stores and filters logs using its own configured clock. Do not convert to UTC. Pass wall-clock time as the user states it, e.g. '2025-04-01T00:00:00'. Log timestamps in responses are also in the appliance's local timezone.
|
|
2031
|
+
|
|
2032
|
+
## Log querying
|
|
2033
|
+
- Call get_log_categories first to discover valid category names for get_event_logs.
|
|
2034
|
+
- get_event_logs: general system/security events. Filter by category, priority, source_ip, or keyword.
|
|
2035
|
+
- get_traffic_logs: connection/flow logs. Filter by source_ip, destination_ip, port, protocol, or action.
|
|
2036
|
+
- get_threat_logs: IPS and AV detections. Filter by severity.
|
|
2037
|
+
- search_logs: full-text keyword search across event logs \u2014 use when you have a specific IP, hostname, or error string.
|
|
2038
|
+
- Default count is 100. Increase for broader searches, but keep it reasonable to avoid large payloads.
|
|
2039
|
+
|
|
2040
|
+
## Object and rule management
|
|
2041
|
+
- Address objects (IPv4/IPv6/FQDN/MAC) and groups are the building blocks of access rules and NAT policies. Use list_address_objects / list_address_groups to discover existing objects before creating rules.
|
|
2042
|
+
- Service objects define protocol/port combinations. Use list_service_objects and list_service_groups to discover available services before referencing them in rules.
|
|
2043
|
+
- 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.
|
|
2044
|
+
- 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.
|
|
2045
|
+
- Always call list_access_rules, list_nat_policies, or list_security_policies before modifying, to confirm current state and avoid duplicates.
|
|
2046
|
+
- 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.
|
|
2047
|
+
|
|
2048
|
+
## Concurrent sessions
|
|
2049
|
+
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.`
|
|
2050
|
+
});
|
|
2051
|
+
registerSystemTools(server, registry);
|
|
2052
|
+
registerAddressObjectTools(server, registry);
|
|
2053
|
+
registerAddressGroupTools(server, registry);
|
|
2054
|
+
registerServiceObjectTools(server, registry);
|
|
2055
|
+
registerServiceGroupTools(server, registry);
|
|
2056
|
+
registerAccessRuleTools(server, registry);
|
|
2057
|
+
registerNatPolicyTools(server, registry);
|
|
2058
|
+
registerSecurityPolicyTools(server, registry);
|
|
2059
|
+
registerGeoIpTools(server, registry);
|
|
2060
|
+
registerLogTools(server, registry);
|
|
2061
|
+
const transport = config.transport;
|
|
2062
|
+
if (transport === "stdio") {
|
|
2063
|
+
const t = new import_stdio.StdioServerTransport();
|
|
2064
|
+
await server.connect(t);
|
|
2065
|
+
} else {
|
|
2066
|
+
process.stderr.write(
|
|
2067
|
+
`sonicwall-mcp: transport '${transport}' is not yet supported in the TypeScript version. Use stdio.
|
|
2068
|
+
`
|
|
2069
|
+
);
|
|
2070
|
+
process.exit(1);
|
|
2071
|
+
}
|
|
2072
|
+
const shutdown = async () => {
|
|
2073
|
+
await registry.closeAll();
|
|
2074
|
+
process.exit(0);
|
|
2075
|
+
};
|
|
2076
|
+
process.on("SIGINT", shutdown);
|
|
2077
|
+
process.on("SIGTERM", shutdown);
|
|
2078
|
+
}
|
|
2079
|
+
main().catch((e) => {
|
|
2080
|
+
process.stderr.write(`sonicwall-mcp: fatal: ${e.message}
|
|
2081
|
+
`);
|
|
2082
|
+
process.exit(1);
|
|
2083
|
+
});
|