@solomonneas/adguard-mcp 0.2.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // mcp-server.ts
4
+ import { realpathSync } from "fs";
5
+ import { pathToFileURL } from "url";
4
6
  import { Buffer as Buffer2 } from "buffer";
5
7
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
6
8
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -35,6 +37,20 @@ var UnknownDefaultInstanceError = class extends Error {
35
37
  this.name = "UnknownDefaultInstanceError";
36
38
  }
37
39
  };
40
+ var NoSyncServerError = class extends Error {
41
+ constructor() {
42
+ super("No AdGuardHome Sync server configured. Set ADGUARDHOME_SYNC_URL or ADGUARD_SYNC_URL, and optionally matching USERNAME/PASSWORD.");
43
+ this.name = "NoSyncServerError";
44
+ }
45
+ };
46
+ var PartialSyncConfigError = class extends Error {
47
+ constructor(missing) {
48
+ super(
49
+ `Partial AdGuardHome Sync config: missing ${missing.join(", ")}. Set ADGUARDHOME_SYNC_URL or ADGUARD_SYNC_URL, and set USERNAME/PASSWORD together when the Sync API uses auth.`
50
+ );
51
+ this.name = "PartialSyncConfigError";
52
+ }
53
+ };
38
54
  function resolveInstances(env) {
39
55
  const instances = {};
40
56
  const candidateNames = /* @__PURE__ */ new Set();
@@ -42,6 +58,7 @@ function resolveInstances(env) {
42
58
  for (const key of Object.keys(env)) {
43
59
  const m = SUFFIX_RE.exec(key);
44
60
  if (!m) continue;
61
+ if (m[1] === "SYNC") continue;
45
62
  if (env[key] === void 0 || env[key] === "") continue;
46
63
  candidateNames.add(m[1]);
47
64
  }
@@ -70,12 +87,28 @@ function resolveInstances(env) {
70
87
  const defaultInstance = instances.primary ? "primary" : Object.keys(instances).sort()[0];
71
88
  return { instances, defaultInstance };
72
89
  }
73
- function getInstanceConfig(cfg2, name) {
74
- const resolved = (name ?? cfg2.defaultInstance).toLowerCase();
75
- const inst = cfg2.instances[resolved];
76
- if (!inst) throw new UnknownInstanceError(resolved, Object.keys(cfg2.instances));
90
+ function resolveSyncConfig(env) {
91
+ const url = env.ADGUARDHOME_SYNC_URL || env.ADGUARD_SYNC_URL;
92
+ const username = env.ADGUARDHOME_SYNC_USERNAME || env.ADGUARD_SYNC_USERNAME;
93
+ const password = env.ADGUARDHOME_SYNC_PASSWORD || env.ADGUARD_SYNC_PASSWORD;
94
+ const missing = [];
95
+ if (!url && (username || password)) missing.push("URL");
96
+ if (username && !password) missing.push("PASSWORD");
97
+ if (password && !username) missing.push("USERNAME");
98
+ if (missing.length > 0) throw new PartialSyncConfigError(missing);
99
+ if (!url) return void 0;
100
+ return username && password ? { url, username, password } : { url };
101
+ }
102
+ function getInstanceConfig(cfg, name) {
103
+ const resolved = (name ?? cfg.defaultInstance).toLowerCase();
104
+ const inst = cfg.instances[resolved];
105
+ if (!inst) throw new UnknownInstanceError(resolved, Object.keys(cfg.instances));
77
106
  return inst;
78
107
  }
108
+ function getSyncConfig(cfg) {
109
+ if (!cfg) throw new NoSyncServerError();
110
+ return cfg;
111
+ }
79
112
 
80
113
  // src/adguard-client.ts
81
114
  var AdGuardClientError = class extends Error {
@@ -93,9 +126,9 @@ var AdGuardUnreachableError = class extends Error {
93
126
  }
94
127
  };
95
128
  var AdGuardClient = class {
96
- constructor(cfg2, opts = {}) {
97
- this.cfg = cfg2;
98
- this.authHeader = "Basic " + Buffer.from(`${cfg2.username}:${cfg2.password}`).toString("base64");
129
+ constructor(cfg, opts = {}) {
130
+ this.cfg = cfg;
131
+ this.authHeader = "Basic " + Buffer.from(`${cfg.username}:${cfg.password}`).toString("base64");
99
132
  this.retryDelayMs = opts.retryDelayMs ?? 1e3;
100
133
  }
101
134
  cfg;
@@ -124,7 +157,7 @@ var AdGuardClient = class {
124
157
  const res = await fetch(url, { method, headers, body: bodyStr });
125
158
  if (res.status >= 200 && res.status < 300) {
126
159
  const text = await res.text();
127
- return text ? JSON.parse(text) : void 0;
160
+ return parseSuccessBody(text);
128
161
  }
129
162
  if (res.status >= 500) {
130
163
  lastErr = new AdGuardUnreachableError(`HTTP ${res.status}`);
@@ -147,10 +180,105 @@ var AdGuardClient = class {
147
180
  throw lastErr ?? new AdGuardUnreachableError("unknown");
148
181
  }
149
182
  };
183
+ function parseSuccessBody(text) {
184
+ if (!text) return void 0;
185
+ try {
186
+ return JSON.parse(text);
187
+ } catch {
188
+ return text;
189
+ }
190
+ }
150
191
  function sleep(ms) {
151
192
  return new Promise((r) => setTimeout(r, ms));
152
193
  }
153
194
 
195
+ // src/adguard-sync-client.ts
196
+ var AdGuardSyncClientError = class extends Error {
197
+ constructor(status, message) {
198
+ super(`AdGuardHome Sync ${status}: ${message}`);
199
+ this.status = status;
200
+ this.name = "AdGuardSyncClientError";
201
+ }
202
+ status;
203
+ };
204
+ var AdGuardSyncUnreachableError = class extends Error {
205
+ constructor(cause) {
206
+ super(`AdGuardHome Sync unreachable: ${cause}`);
207
+ this.name = "AdGuardSyncUnreachableError";
208
+ }
209
+ };
210
+ var AdGuardSyncClient = class {
211
+ constructor(cfg, opts = {}) {
212
+ this.cfg = cfg;
213
+ if (cfg.username && cfg.password) {
214
+ this.authHeader = "Basic " + Buffer.from(`${cfg.username}:${cfg.password}`).toString("base64");
215
+ }
216
+ this.retryDelayMs = opts.retryDelayMs ?? 1e3;
217
+ }
218
+ cfg;
219
+ authHeader;
220
+ retryDelayMs;
221
+ async get(path) {
222
+ return this.request("GET", path);
223
+ }
224
+ async post(path, body) {
225
+ return this.request("POST", path, body);
226
+ }
227
+ async head(path) {
228
+ await this.request("HEAD", path);
229
+ return { ok: true };
230
+ }
231
+ async request(method, path, body) {
232
+ const url = this.cfg.url.replace(/\/+$/, "") + path;
233
+ const headers = {};
234
+ if (this.authHeader) headers.authorization = this.authHeader;
235
+ let bodyStr;
236
+ if (body !== void 0) {
237
+ headers["content-type"] = "application/json";
238
+ bodyStr = JSON.stringify(body);
239
+ }
240
+ let lastErr;
241
+ for (let attempt = 0; attempt < 2; attempt++) {
242
+ try {
243
+ const res = await fetch(url, { method, headers, body: bodyStr });
244
+ if (res.status >= 200 && res.status < 300) {
245
+ if (method === "HEAD") return void 0;
246
+ const text = await res.text();
247
+ return parseSuccessBody2(text);
248
+ }
249
+ if (res.status >= 500) {
250
+ lastErr = new AdGuardSyncUnreachableError(`HTTP ${res.status}`);
251
+ if (attempt === 0) await sleep2(this.retryDelayMs);
252
+ continue;
253
+ }
254
+ const errText = await res.text();
255
+ let msg = errText;
256
+ try {
257
+ msg = JSON.parse(errText).message ?? errText;
258
+ } catch {
259
+ }
260
+ throw new AdGuardSyncClientError(res.status, msg);
261
+ } catch (e) {
262
+ if (e instanceof AdGuardSyncClientError) throw e;
263
+ lastErr = new AdGuardSyncUnreachableError(e.message);
264
+ if (attempt === 0) await sleep2(this.retryDelayMs);
265
+ }
266
+ }
267
+ throw lastErr ?? new AdGuardSyncUnreachableError("unknown");
268
+ }
269
+ };
270
+ function parseSuccessBody2(text) {
271
+ if (!text) return void 0;
272
+ try {
273
+ return JSON.parse(text);
274
+ } catch {
275
+ return text;
276
+ }
277
+ }
278
+ function sleep2(ms) {
279
+ return new Promise((r) => setTimeout(r, ms));
280
+ }
281
+
154
282
  // src/security.ts
155
283
  var SECRETS = /* @__PURE__ */ new Set();
156
284
  function registerSecret(s) {
@@ -220,7 +348,7 @@ function hhmmToMs(value) {
220
348
 
221
349
  // src/tools/adguard_status.ts
222
350
  var Schema = Type2.Object({ instance: InstanceArg }, { additionalProperties: false });
223
- function createAdguardStatusTool(getClient2) {
351
+ function createAdguardStatusTool(getClient) {
224
352
  return {
225
353
  name: "adguard_status",
226
354
  label: "adguard: status",
@@ -228,7 +356,7 @@ function createAdguardStatusTool(getClient2) {
228
356
  parameters: Schema,
229
357
  execute: async (_id, raw) => {
230
358
  const args = raw;
231
- const client = getClient2(args.instance);
359
+ const client = getClient(args.instance);
232
360
  const status = await client.get("/control/status");
233
361
  return jsonToolResult(status);
234
362
  }
@@ -238,7 +366,7 @@ function createAdguardStatusTool(getClient2) {
238
366
  // src/tools/adguard_stats.ts
239
367
  import { Type as Type3 } from "@sinclair/typebox";
240
368
  var Schema2 = Type3.Object({ instance: InstanceArg }, { additionalProperties: false });
241
- function createAdguardStatsTool(getClient2) {
369
+ function createAdguardStatsTool(getClient) {
242
370
  return {
243
371
  name: "adguard_stats",
244
372
  label: "adguard: stats",
@@ -246,7 +374,7 @@ function createAdguardStatsTool(getClient2) {
246
374
  parameters: Schema2,
247
375
  execute: async (_id, raw) => {
248
376
  const args = raw;
249
- const client = getClient2(args.instance);
377
+ const client = getClient(args.instance);
250
378
  const stats = await client.get("/control/stats");
251
379
  return jsonToolResult(stats);
252
380
  }
@@ -260,24 +388,47 @@ var Schema3 = Type4.Object({
260
388
  limit: Type4.Optional(Type4.Integer({ minimum: 1, maximum: 500, description: "Max entries to return. Default 50." })),
261
389
  client: Type4.Optional(Type4.String({ description: "Filter by client IP or hostname. AGH's querylog supports a single free-text `search` parameter; client/domain are combined (space-joined) when both passed." })),
262
390
  domain: Type4.Optional(Type4.String({ description: "Filter by domain. AGH's querylog supports a single free-text `search` parameter; client/domain are combined (space-joined) when both passed." })),
263
- blocked_only: Type4.Optional(Type4.Boolean({ description: "When true, only return blocked queries (AGH response_status=blocked)." }))
391
+ blocked_only: Type4.Optional(Type4.Boolean({ description: "When true, only return blocked queries using AGH's modern `reason` filter." })),
392
+ reasons: Type4.Optional(Type4.Array(Type4.Union([
393
+ Type4.Literal("NotFilteredNotFound"),
394
+ Type4.Literal("NotFilteredWhiteList"),
395
+ Type4.Literal("NotFilteredError"),
396
+ Type4.Literal("FilteredBlackList"),
397
+ Type4.Literal("FilteredSafeBrowsing"),
398
+ Type4.Literal("FilteredParental"),
399
+ Type4.Literal("FilteredInvalid"),
400
+ Type4.Literal("FilteredSafeSearch"),
401
+ Type4.Literal("FilteredBlockedService"),
402
+ Type4.Literal("Rewrite"),
403
+ Type4.Literal("RewriteEtcHosts"),
404
+ Type4.Literal("RewriteRule")
405
+ ]), { description: "Filter by one or more AGH FilteringReason values. Takes precedence over blocked_only." }))
264
406
  }, { additionalProperties: false });
265
- function createAdguardQueryLogTool(getClient2) {
407
+ var BLOCKED_REASONS = [
408
+ "FilteredBlackList",
409
+ "FilteredSafeBrowsing",
410
+ "FilteredParental",
411
+ "FilteredInvalid",
412
+ "FilteredSafeSearch",
413
+ "FilteredBlockedService"
414
+ ];
415
+ function createAdguardQueryLogTool(getClient) {
266
416
  return {
267
417
  name: "adguard_query_log",
268
418
  label: "adguard: query log",
269
- description: "Read recent DNS queries via GET /control/querylog. Filter by client, domain, blocked-only. client + domain are combined into AGH's single `search` param when both passed.",
419
+ description: "Read recent DNS queries via GET /control/querylog. Filter by client, domain, blocked-only, or specific FilteringReason values. client + domain are combined into AGH's single `search` param when both passed.",
270
420
  parameters: Schema3,
271
421
  execute: async (_id, raw) => {
272
422
  const args = raw;
273
423
  const params = new URLSearchParams();
274
424
  params.set("limit", String(args.limit ?? 50));
275
- if (args.blocked_only) params.set("response_status", "blocked");
425
+ const reasons = args.reasons && args.reasons.length > 0 ? args.reasons : args.blocked_only ? BLOCKED_REASONS : [];
426
+ for (const reason of reasons) params.append("reason", reason);
276
427
  const searchTerms = [];
277
428
  if (args.client) searchTerms.push(args.client);
278
429
  if (args.domain) searchTerms.push(args.domain);
279
430
  if (searchTerms.length > 0) params.set("search", searchTerms.join(" "));
280
- const client = getClient2(args.instance);
431
+ const client = getClient(args.instance);
281
432
  const log = await client.get(`/control/querylog?${params.toString()}`);
282
433
  return jsonToolResult(log);
283
434
  }
@@ -287,7 +438,7 @@ function createAdguardQueryLogTool(getClient2) {
287
438
  // src/tools/adguard_list_filter_lists.ts
288
439
  import { Type as Type5 } from "@sinclair/typebox";
289
440
  var Schema4 = Type5.Object({ instance: InstanceArg }, { additionalProperties: false });
290
- function createAdguardListFilterListsTool(getClient2) {
441
+ function createAdguardListFilterListsTool(getClient) {
291
442
  return {
292
443
  name: "adguard_list_filter_lists",
293
444
  label: "adguard: list filter lists",
@@ -295,7 +446,7 @@ function createAdguardListFilterListsTool(getClient2) {
295
446
  parameters: Schema4,
296
447
  execute: async (_id, raw) => {
297
448
  const args = raw;
298
- const client = getClient2(args.instance);
449
+ const client = getClient(args.instance);
299
450
  const status = await client.get("/control/filtering/status");
300
451
  return jsonToolResult(status);
301
452
  }
@@ -305,7 +456,7 @@ function createAdguardListFilterListsTool(getClient2) {
305
456
  // src/tools/adguard_list_user_rules.ts
306
457
  import { Type as Type6 } from "@sinclair/typebox";
307
458
  var Schema5 = Type6.Object({ instance: InstanceArg }, { additionalProperties: false });
308
- function createAdguardListUserRulesTool(getClient2) {
459
+ function createAdguardListUserRulesTool(getClient) {
309
460
  return {
310
461
  name: "adguard_list_user_rules",
311
462
  label: "adguard: list user rules",
@@ -313,7 +464,7 @@ function createAdguardListUserRulesTool(getClient2) {
313
464
  parameters: Schema5,
314
465
  execute: async (_id, raw) => {
315
466
  const args = raw;
316
- const client = getClient2(args.instance);
467
+ const client = getClient(args.instance);
317
468
  const status = await client.get("/control/filtering/status");
318
469
  return jsonToolResult({ rules: status.user_rules ?? [] });
319
470
  }
@@ -323,7 +474,7 @@ function createAdguardListUserRulesTool(getClient2) {
323
474
  // src/tools/adguard_list_clients.ts
324
475
  import { Type as Type7 } from "@sinclair/typebox";
325
476
  var Schema6 = Type7.Object({ instance: InstanceArg }, { additionalProperties: false });
326
- function createAdguardListClientsTool(getClient2) {
477
+ function createAdguardListClientsTool(getClient) {
327
478
  return {
328
479
  name: "adguard_list_clients",
329
480
  label: "adguard: list clients",
@@ -331,7 +482,7 @@ function createAdguardListClientsTool(getClient2) {
331
482
  parameters: Schema6,
332
483
  execute: async (_id, raw) => {
333
484
  const args = raw;
334
- const client = getClient2(args.instance);
485
+ const client = getClient(args.instance);
335
486
  const out = await client.get("/control/clients");
336
487
  return jsonToolResult(out);
337
488
  }
@@ -341,16 +492,16 @@ function createAdguardListClientsTool(getClient2) {
341
492
  // src/tools/adguard_list_blocked_services_catalog.ts
342
493
  import { Type as Type8 } from "@sinclair/typebox";
343
494
  var Schema7 = Type8.Object({ instance: InstanceArg }, { additionalProperties: false });
344
- function createAdguardListBlockedServicesCatalogTool(getClient2) {
495
+ function createAdguardListBlockedServicesCatalogTool(getClient) {
345
496
  return {
346
497
  name: "adguard_list_blocked_services_catalog",
347
498
  label: "adguard: blocked services catalog",
348
- description: "List the services AdGuard Home can block per-client (youtube, tiktok, instagram, etc) via GET /control/blocked_services/services.",
499
+ description: "List the services AdGuard Home can block per-client (youtube, tiktok, instagram, etc) via GET /control/blocked_services/all.",
349
500
  parameters: Schema7,
350
501
  execute: async (_id, raw) => {
351
502
  const args = raw;
352
- const client = getClient2(args.instance);
353
- const catalog = await client.get("/control/blocked_services/services");
503
+ const client = getClient(args.instance);
504
+ const catalog = await client.get("/control/blocked_services/all");
354
505
  return jsonToolResult(catalog);
355
506
  }
356
507
  };
@@ -388,7 +539,7 @@ var Schema8 = Type9.Object({
388
539
  confirm: Type9.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
389
540
  }, { additionalProperties: false });
390
541
  var NAME = "adguard_add_user_rule";
391
- function createAdguardAddUserRuleTool(getClient2) {
542
+ function createAdguardAddUserRuleTool(getClient) {
392
543
  return {
393
544
  name: NAME,
394
545
  label: "adguard: add user rule",
@@ -397,7 +548,7 @@ function createAdguardAddUserRuleTool(getClient2) {
397
548
  execute: async (_id, raw) => {
398
549
  assertConfirmedWrite(raw, NAME);
399
550
  const args = raw;
400
- const client = getClient2(args.instance);
551
+ const client = getClient(args.instance);
401
552
  const status = await client.get("/control/filtering/status");
402
553
  const existing = status.user_rules ?? [];
403
554
  if (existing.includes(args.rule)) {
@@ -418,7 +569,7 @@ var Schema9 = Type10.Object({
418
569
  confirm: Type10.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
419
570
  }, { additionalProperties: false });
420
571
  var NAME2 = "adguard_remove_user_rule";
421
- function createAdguardRemoveUserRuleTool(getClient2) {
572
+ function createAdguardRemoveUserRuleTool(getClient) {
422
573
  return {
423
574
  name: NAME2,
424
575
  label: "adguard: remove user rule",
@@ -427,7 +578,7 @@ function createAdguardRemoveUserRuleTool(getClient2) {
427
578
  execute: async (_id, raw) => {
428
579
  assertConfirmedWrite(raw, NAME2);
429
580
  const args = raw;
430
- const client = getClient2(args.instance);
581
+ const client = getClient(args.instance);
431
582
  const status = await client.get("/control/filtering/status");
432
583
  const existing = status.user_rules ?? [];
433
584
  if (!existing.includes(args.rule)) {
@@ -450,7 +601,7 @@ var Schema10 = Type11.Object({
450
601
  confirm: Type11.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
451
602
  }, { additionalProperties: false });
452
603
  var NAME3 = "adguard_add_filter_list";
453
- function createAdguardAddFilterListTool(getClient2) {
604
+ function createAdguardAddFilterListTool(getClient) {
454
605
  return {
455
606
  name: NAME3,
456
607
  label: "adguard: add filter list",
@@ -459,7 +610,7 @@ function createAdguardAddFilterListTool(getClient2) {
459
610
  execute: async (_id, raw) => {
460
611
  assertConfirmedWrite(raw, NAME3);
461
612
  const args = raw;
462
- const client = getClient2(args.instance);
613
+ const client = getClient(args.instance);
463
614
  await client.post("/control/filtering/add_url", { name: args.name, url: args.url, whitelist: args.whitelist ?? false });
464
615
  return jsonToolResult({ added: { name: args.name, url: args.url } });
465
616
  }
@@ -475,7 +626,7 @@ var Schema11 = Type12.Object({
475
626
  confirm: Type12.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
476
627
  }, { additionalProperties: false });
477
628
  var NAME4 = "adguard_remove_filter_list";
478
- function createAdguardRemoveFilterListTool(getClient2) {
629
+ function createAdguardRemoveFilterListTool(getClient) {
479
630
  return {
480
631
  name: NAME4,
481
632
  label: "adguard: remove filter list",
@@ -484,7 +635,7 @@ function createAdguardRemoveFilterListTool(getClient2) {
484
635
  execute: async (_id, raw) => {
485
636
  assertConfirmedWrite(raw, NAME4);
486
637
  const args = raw;
487
- const client = getClient2(args.instance);
638
+ const client = getClient(args.instance);
488
639
  await client.post("/control/filtering/remove_url", { url: args.url, whitelist: args.whitelist ?? false });
489
640
  return jsonToolResult({ removed: args.url });
490
641
  }
@@ -501,7 +652,7 @@ var Schema12 = Type13.Object({
501
652
  confirm: Type13.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
502
653
  }, { additionalProperties: false });
503
654
  var NAME5 = "adguard_toggle_filter_list";
504
- function createAdguardToggleFilterListTool(getClient2) {
655
+ function createAdguardToggleFilterListTool(getClient) {
505
656
  return {
506
657
  name: NAME5,
507
658
  label: "adguard: toggle filter list",
@@ -510,7 +661,7 @@ function createAdguardToggleFilterListTool(getClient2) {
510
661
  execute: async (_id, raw) => {
511
662
  assertConfirmedWrite(raw, NAME5);
512
663
  const args = raw;
513
- const client = getClient2(args.instance);
664
+ const client = getClient(args.instance);
514
665
  await client.post("/control/filtering/set_url", { url: args.url, whitelist: args.whitelist ?? false, data: { enabled: args.enabled } });
515
666
  return jsonToolResult({ url: args.url, enabled: args.enabled });
516
667
  }
@@ -526,7 +677,7 @@ var Schema13 = Type14.Object({
526
677
  confirm: Type14.Boolean({ description: "Must be true to write. Tier-2 safe-write gate." })
527
678
  }, { additionalProperties: false });
528
679
  var NAME6 = "adguard_set_client_blocked_services";
529
- function createAdguardSetClientBlockedServicesTool(getClient2) {
680
+ function createAdguardSetClientBlockedServicesTool(getClient) {
530
681
  return {
531
682
  name: NAME6,
532
683
  label: "adguard: set client blocked services",
@@ -535,7 +686,7 @@ function createAdguardSetClientBlockedServicesTool(getClient2) {
535
686
  execute: async (_id, raw) => {
536
687
  assertConfirmedWrite(raw, NAME6);
537
688
  const args = raw;
538
- const client = getClient2(args.instance);
689
+ const client = getClient(args.instance);
539
690
  const clients = await client.get("/control/clients");
540
691
  const existing = (clients.clients ?? []).find((c) => c.name === args.name);
541
692
  if (!existing) return jsonToolResult({ client: args.name, not_found: true });
@@ -555,7 +706,7 @@ var Schema14 = Type15.Object({
555
706
  destructive: Type15.Boolean({ description: "Must be true. Tier-3 destructive gate (overwrites existing rules)." })
556
707
  }, { additionalProperties: false });
557
708
  var NAME7 = "adguard_replace_user_rules";
558
- function createAdguardReplaceUserRulesTool(getClient2) {
709
+ function createAdguardReplaceUserRulesTool(getClient) {
559
710
  return {
560
711
  name: NAME7,
561
712
  label: "adguard: replace user rules",
@@ -564,7 +715,7 @@ function createAdguardReplaceUserRulesTool(getClient2) {
564
715
  execute: async (_id, raw) => {
565
716
  assertDestructive(raw, NAME7);
566
717
  const args = raw;
567
- const client = getClient2(args.instance);
718
+ const client = getClient(args.instance);
568
719
  await client.post("/control/filtering/set_rules", { rules: args.rules });
569
720
  return jsonToolResult({ rules_count: args.rules.length });
570
721
  }
@@ -580,7 +731,7 @@ var Schema15 = Type16.Object({
580
731
  destructive: Type16.Boolean({ description: "Must be true. Tier-3 destructive gate (toggling off removes all blocking)." })
581
732
  }, { additionalProperties: false });
582
733
  var NAME8 = "adguard_toggle_protection";
583
- function createAdguardToggleProtectionTool(getClient2) {
734
+ function createAdguardToggleProtectionTool(getClient) {
584
735
  return {
585
736
  name: NAME8,
586
737
  label: "adguard: toggle protection",
@@ -589,7 +740,7 @@ function createAdguardToggleProtectionTool(getClient2) {
589
740
  execute: async (_id, raw) => {
590
741
  assertDestructive(raw, NAME8);
591
742
  const args = raw;
592
- const client = getClient2(args.instance);
743
+ const client = getClient(args.instance);
593
744
  await client.post("/control/protection", { enabled: args.enabled });
594
745
  return jsonToolResult({ enabled: args.enabled });
595
746
  }
@@ -605,7 +756,7 @@ var Schema16 = Type17.Object({
605
756
  qtype: Type17.Optional(Type17.String({ description: "DNS query type (A, AAAA, HTTPS, MX...). Default: server-side default (A)." }))
606
757
  }, { additionalProperties: false });
607
758
  var NAME9 = "adguard_check_host";
608
- function createAdguardCheckHostTool(getClient2) {
759
+ function createAdguardCheckHostTool(getClient) {
609
760
  return {
610
761
  name: NAME9,
611
762
  label: "adguard: check host",
@@ -613,7 +764,7 @@ function createAdguardCheckHostTool(getClient2) {
613
764
  parameters: Schema16,
614
765
  execute: async (_id, raw) => {
615
766
  const args = raw;
616
- const client = getClient2(args.instance);
767
+ const client = getClient(args.instance);
617
768
  const params = new URLSearchParams({ name: args.host });
618
769
  if (args.client) params.set("client", args.client);
619
770
  if (args.qtype) params.set("qtype", args.qtype);
@@ -627,7 +778,7 @@ function createAdguardCheckHostTool(getClient2) {
627
778
  import { Type as Type18 } from "@sinclair/typebox";
628
779
  var Schema17 = Type18.Object({ instance: InstanceArg }, { additionalProperties: false });
629
780
  var NAME10 = "adguard_get_blocked_services";
630
- function createAdguardGetBlockedServicesTool(getClient2) {
781
+ function createAdguardGetBlockedServicesTool(getClient) {
631
782
  return {
632
783
  name: NAME10,
633
784
  label: "adguard: get blocked services",
@@ -635,7 +786,7 @@ function createAdguardGetBlockedServicesTool(getClient2) {
635
786
  parameters: Schema17,
636
787
  execute: async (_id, raw) => {
637
788
  const args = raw;
638
- const client = getClient2(args.instance);
789
+ const client = getClient(args.instance);
639
790
  const result = await client.get("/control/blocked_services/get");
640
791
  return jsonToolResult(result);
641
792
  }
@@ -646,7 +797,7 @@ function createAdguardGetBlockedServicesTool(getClient2) {
646
797
  import { Type as Type19 } from "@sinclair/typebox";
647
798
  var Schema18 = Type19.Object({ instance: InstanceArg }, { additionalProperties: false });
648
799
  var NAME11 = "adguard_get_dns_config";
649
- function createAdguardGetDnsConfigTool(getClient2) {
800
+ function createAdguardGetDnsConfigTool(getClient) {
650
801
  return {
651
802
  name: NAME11,
652
803
  label: "adguard: get DNS config",
@@ -654,7 +805,7 @@ function createAdguardGetDnsConfigTool(getClient2) {
654
805
  parameters: Schema18,
655
806
  execute: async (_id, raw) => {
656
807
  const args = raw;
657
- const client = getClient2(args.instance);
808
+ const client = getClient(args.instance);
658
809
  const result = await client.get("/control/dns_info");
659
810
  return jsonToolResult(result);
660
811
  }
@@ -665,7 +816,7 @@ function createAdguardGetDnsConfigTool(getClient2) {
665
816
  import { Type as Type20 } from "@sinclair/typebox";
666
817
  var Schema19 = Type20.Object({ instance: InstanceArg }, { additionalProperties: false });
667
818
  var NAME12 = "adguard_get_safesearch_settings";
668
- function createAdguardGetSafesearchSettingsTool(getClient2) {
819
+ function createAdguardGetSafesearchSettingsTool(getClient) {
669
820
  return {
670
821
  name: NAME12,
671
822
  label: "adguard: get safesearch settings",
@@ -673,7 +824,7 @@ function createAdguardGetSafesearchSettingsTool(getClient2) {
673
824
  parameters: Schema19,
674
825
  execute: async (_id, raw) => {
675
826
  const args = raw;
676
- const client = getClient2(args.instance);
827
+ const client = getClient(args.instance);
677
828
  const result = await client.get("/control/safesearch/status");
678
829
  return jsonToolResult(result);
679
830
  }
@@ -688,7 +839,7 @@ var Schema20 = Type21.Object({
688
839
  confirm: Type21.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
689
840
  }, { additionalProperties: false });
690
841
  var NAME13 = "adguard_refresh_filter_lists";
691
- function createAdguardRefreshFilterListsTool(getClient2) {
842
+ function createAdguardRefreshFilterListsTool(getClient) {
692
843
  return {
693
844
  name: NAME13,
694
845
  label: "adguard: refresh filter lists",
@@ -697,7 +848,7 @@ function createAdguardRefreshFilterListsTool(getClient2) {
697
848
  execute: async (_id, raw) => {
698
849
  assertConfirmedWrite(raw, NAME13);
699
850
  const args = raw;
700
- const client = getClient2(args.instance);
851
+ const client = getClient(args.instance);
701
852
  const result = await client.post("/control/filtering/refresh", { whitelist: args.whitelist === true });
702
853
  return jsonToolResult(result);
703
854
  }
@@ -755,7 +906,7 @@ var CLIENT_BODY_FIELDS = [
755
906
  "upstreams_cache_enabled",
756
907
  "upstreams_cache_size"
757
908
  ];
758
- function createAdguardAddClientTool(getClient2) {
909
+ function createAdguardAddClientTool(getClient) {
759
910
  return {
760
911
  name: NAME14,
761
912
  label: "adguard: add client",
@@ -767,7 +918,7 @@ function createAdguardAddClientTool(getClient2) {
767
918
  for (const k of CLIENT_BODY_FIELDS) {
768
919
  if (raw[k] !== void 0) body[k] = raw[k];
769
920
  }
770
- const client = getClient2(raw.instance);
921
+ const client = getClient(raw.instance);
771
922
  await client.post("/control/clients/add", body);
772
923
  return jsonToolResult({ added: true, name: body.name });
773
924
  }
@@ -783,7 +934,7 @@ var Schema22 = Type23.Object({
783
934
  confirm: Type23.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
784
935
  }, { additionalProperties: false });
785
936
  var NAME15 = "adguard_update_client";
786
- function createAdguardUpdateClientTool(getClient2) {
937
+ function createAdguardUpdateClientTool(getClient) {
787
938
  return {
788
939
  name: NAME15,
789
940
  label: "adguard: update client",
@@ -792,7 +943,7 @@ function createAdguardUpdateClientTool(getClient2) {
792
943
  execute: async (_id, raw) => {
793
944
  assertConfirmedWrite(raw, NAME15);
794
945
  const args = raw;
795
- const client = getClient2(args.instance);
946
+ const client = getClient(args.instance);
796
947
  await client.post("/control/clients/update", { name: args.name, data: args.data });
797
948
  return jsonToolResult({ updated: true, name: args.name });
798
949
  }
@@ -839,7 +990,7 @@ function normalizeSchedule(schedule) {
839
990
  }
840
991
  return out;
841
992
  }
842
- function createAdguardSetBlockedServicesTool(getClient2) {
993
+ function createAdguardSetBlockedServicesTool(getClient) {
843
994
  return {
844
995
  name: NAME16,
845
996
  label: "adguard: set blocked services",
@@ -848,7 +999,7 @@ function createAdguardSetBlockedServicesTool(getClient2) {
848
999
  execute: async (_id, raw) => {
849
1000
  assertConfirmedWrite(raw, NAME16);
850
1001
  const args = raw;
851
- const client = getClient2(args.instance);
1002
+ const client = getClient(args.instance);
852
1003
  const body = { ids: args.ids };
853
1004
  const normalized = normalizeSchedule(args.schedule);
854
1005
  if (normalized) body.schedule = normalized;
@@ -873,7 +1024,7 @@ var Schema24 = Type25.Object({
873
1024
  confirm: Type25.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
874
1025
  }, { additionalProperties: false });
875
1026
  var NAME17 = "adguard_toggle_safesearch";
876
- function createAdguardToggleSafesearchTool(getClient2) {
1027
+ function createAdguardToggleSafesearchTool(getClient) {
877
1028
  return {
878
1029
  name: NAME17,
879
1030
  label: "adguard: toggle safesearch",
@@ -890,7 +1041,7 @@ function createAdguardToggleSafesearchTool(getClient2) {
890
1041
  else if (args[e] !== void 0) body[e] = args[e];
891
1042
  else body[e] = true;
892
1043
  }
893
- const client = getClient2(args.instance);
1044
+ const client = getClient(args.instance);
894
1045
  await client.put("/control/safesearch/settings", body);
895
1046
  return jsonToolResult({ set: true, enabled });
896
1047
  }
@@ -905,7 +1056,7 @@ var Schema25 = Type26.Object({
905
1056
  confirm: Type26.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
906
1057
  }, { additionalProperties: false });
907
1058
  var NAME18 = "adguard_toggle_safebrowsing";
908
- function createAdguardToggleSafebrowsingTool(getClient2) {
1059
+ function createAdguardToggleSafebrowsingTool(getClient) {
909
1060
  return {
910
1061
  name: NAME18,
911
1062
  label: "adguard: toggle safebrowsing",
@@ -914,7 +1065,7 @@ function createAdguardToggleSafebrowsingTool(getClient2) {
914
1065
  execute: async (_id, raw) => {
915
1066
  assertConfirmedWrite(raw, NAME18);
916
1067
  const args = raw;
917
- const client = getClient2(args.instance);
1068
+ const client = getClient(args.instance);
918
1069
  const path = args.enabled ? "/control/safebrowsing/enable" : "/control/safebrowsing/disable";
919
1070
  await client.post(path, void 0);
920
1071
  return jsonToolResult({ set: true, enabled: args.enabled });
@@ -931,7 +1082,7 @@ var Schema26 = Type27.Object({
931
1082
  destructive: Type27.Boolean({ description: "Must be true. Tier-3 destructive gate (deleting a client drops per-client rules and stats)." })
932
1083
  }, { additionalProperties: false });
933
1084
  var NAME19 = "adguard_delete_client";
934
- function createAdguardDeleteClientTool(getClient2) {
1085
+ function createAdguardDeleteClientTool(getClient) {
935
1086
  return {
936
1087
  name: NAME19,
937
1088
  label: "adguard: delete client",
@@ -940,7 +1091,7 @@ function createAdguardDeleteClientTool(getClient2) {
940
1091
  execute: async (_id, raw) => {
941
1092
  assertDestructive(raw, NAME19);
942
1093
  const args = raw;
943
- const client = getClient2(args.instance);
1094
+ const client = getClient(args.instance);
944
1095
  await client.post("/control/clients/delete", { name: args.name });
945
1096
  return jsonToolResult({ deleted: true, name: args.name });
946
1097
  }
@@ -955,7 +1106,7 @@ var Schema27 = Type28.Object({
955
1106
  destructive: Type28.Boolean({ description: "Must be true. Tier-3 destructive gate (the query log is gone after this)." })
956
1107
  }, { additionalProperties: false });
957
1108
  var NAME20 = "adguard_clear_query_log";
958
- function createAdguardClearQueryLogTool(getClient2) {
1109
+ function createAdguardClearQueryLogTool(getClient) {
959
1110
  return {
960
1111
  name: NAME20,
961
1112
  label: "adguard: clear query log",
@@ -964,7 +1115,7 @@ function createAdguardClearQueryLogTool(getClient2) {
964
1115
  execute: async (_id, raw) => {
965
1116
  assertDestructive(raw, NAME20);
966
1117
  const args = raw;
967
- const client = getClient2(args.instance);
1118
+ const client = getClient(args.instance);
968
1119
  await client.post("/control/querylog_clear", void 0);
969
1120
  return jsonToolResult({ cleared: true });
970
1121
  }
@@ -979,7 +1130,7 @@ var Schema28 = Type29.Object({
979
1130
  destructive: Type29.Boolean({ description: "Must be true. Tier-3 destructive gate (stats history is zeroed)." })
980
1131
  }, { additionalProperties: false });
981
1132
  var NAME21 = "adguard_reset_stats";
982
- function createAdguardResetStatsTool(getClient2) {
1133
+ function createAdguardResetStatsTool(getClient) {
983
1134
  return {
984
1135
  name: NAME21,
985
1136
  label: "adguard: reset stats",
@@ -988,78 +1139,639 @@ function createAdguardResetStatsTool(getClient2) {
988
1139
  execute: async (_id, raw) => {
989
1140
  assertDestructive(raw, NAME21);
990
1141
  const args = raw;
991
- const client = getClient2(args.instance);
1142
+ const client = getClient(args.instance);
992
1143
  await client.post("/control/stats_reset", void 0);
993
1144
  return jsonToolResult({ reset: true });
994
1145
  }
995
1146
  };
996
1147
  }
997
1148
 
1149
+ // src/tools/adguard_list_rewrites.ts
1150
+ import { Type as Type30 } from "@sinclair/typebox";
1151
+ var Schema29 = Type30.Object({ instance: InstanceArg }, { additionalProperties: false });
1152
+ var NAME22 = "adguard_list_rewrites";
1153
+ function createAdguardListRewritesTool(getClient) {
1154
+ return {
1155
+ name: NAME22,
1156
+ label: "adguard: list rewrites",
1157
+ description: "List DNS rewrite rules via GET /control/rewrite/list.",
1158
+ parameters: Schema29,
1159
+ execute: async (_id, raw) => {
1160
+ const args = raw;
1161
+ const client = getClient(args.instance);
1162
+ const rewrites = await client.get("/control/rewrite/list");
1163
+ return jsonToolResult(rewrites);
1164
+ }
1165
+ };
1166
+ }
1167
+
1168
+ // src/tools/adguard_add_rewrite.ts
1169
+ import { Type as Type31 } from "@sinclair/typebox";
1170
+ var Schema30 = Type31.Object({
1171
+ instance: InstanceArg,
1172
+ domain: Type31.String({ description: "Domain name to rewrite, e.g. router.home.arpa." }),
1173
+ answer: Type31.String({ description: "A, AAAA, or CNAME answer value." }),
1174
+ enabled: Type31.Optional(Type31.Boolean({ description: "Whether the rewrite is enabled. Defaults to AGH's default true when omitted." })),
1175
+ confirm: Type31.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1176
+ }, { additionalProperties: false });
1177
+ var NAME23 = "adguard_add_rewrite";
1178
+ function createAdguardAddRewriteTool(getClient) {
1179
+ return {
1180
+ name: NAME23,
1181
+ label: "adguard: add rewrite",
1182
+ description: "Add a DNS rewrite rule via POST /control/rewrite/add. Tier-2 write; requires confirm:true.",
1183
+ parameters: Schema30,
1184
+ execute: async (_id, raw) => {
1185
+ assertConfirmedWrite(raw, NAME23);
1186
+ const args = raw;
1187
+ const body = { domain: args.domain, answer: args.answer };
1188
+ if (args.enabled !== void 0) body.enabled = args.enabled;
1189
+ const client = getClient(args.instance);
1190
+ await client.post("/control/rewrite/add", body);
1191
+ return jsonToolResult({ added: true, domain: args.domain, answer: args.answer });
1192
+ }
1193
+ };
1194
+ }
1195
+
1196
+ // src/tools/adguard_update_rewrite.ts
1197
+ import { Type as Type32 } from "@sinclair/typebox";
1198
+ var RewriteEntrySchema = Type32.Object({
1199
+ domain: Type32.String({ description: "Domain name." }),
1200
+ answer: Type32.String({ description: "A, AAAA, or CNAME answer value." }),
1201
+ enabled: Type32.Optional(Type32.Boolean({ description: "Whether this rewrite is enabled." }))
1202
+ }, { additionalProperties: false });
1203
+ var Schema31 = Type32.Object({
1204
+ instance: InstanceArg,
1205
+ target: RewriteEntrySchema,
1206
+ update: RewriteEntrySchema,
1207
+ confirm: Type32.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1208
+ }, { additionalProperties: false });
1209
+ var NAME24 = "adguard_update_rewrite";
1210
+ function createAdguardUpdateRewriteTool(getClient) {
1211
+ return {
1212
+ name: NAME24,
1213
+ label: "adguard: update rewrite",
1214
+ description: "Update a DNS rewrite rule via PUT /control/rewrite/update with {target, update}. Tier-2 write; requires confirm:true.",
1215
+ parameters: Schema31,
1216
+ execute: async (_id, raw) => {
1217
+ assertConfirmedWrite(raw, NAME24);
1218
+ const args = raw;
1219
+ const client = getClient(args.instance);
1220
+ await client.put("/control/rewrite/update", { target: args.target, update: args.update });
1221
+ return jsonToolResult({ updated: true, target: args.target, update: args.update });
1222
+ }
1223
+ };
1224
+ }
1225
+
1226
+ // src/tools/adguard_delete_rewrite.ts
1227
+ import { Type as Type33 } from "@sinclair/typebox";
1228
+ var Schema32 = Type33.Object({
1229
+ instance: InstanceArg,
1230
+ domain: Type33.String({ description: "Domain name of the rewrite to delete." }),
1231
+ answer: Type33.String({ description: "Answer value of the rewrite to delete." }),
1232
+ enabled: Type33.Optional(Type33.Boolean({ description: "Enabled state, when needed to identify the exact rewrite." })),
1233
+ confirm: Type33.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1234
+ }, { additionalProperties: false });
1235
+ var NAME25 = "adguard_delete_rewrite";
1236
+ function createAdguardDeleteRewriteTool(getClient) {
1237
+ return {
1238
+ name: NAME25,
1239
+ label: "adguard: delete rewrite",
1240
+ description: "Delete a DNS rewrite rule via POST /control/rewrite/delete. Tier-2 write; requires confirm:true.",
1241
+ parameters: Schema32,
1242
+ execute: async (_id, raw) => {
1243
+ assertConfirmedWrite(raw, NAME25);
1244
+ const args = raw;
1245
+ const body = { domain: args.domain, answer: args.answer };
1246
+ if (args.enabled !== void 0) body.enabled = args.enabled;
1247
+ const client = getClient(args.instance);
1248
+ await client.post("/control/rewrite/delete", body);
1249
+ return jsonToolResult({ deleted: true, domain: args.domain, answer: args.answer });
1250
+ }
1251
+ };
1252
+ }
1253
+
1254
+ // src/tools/adguard_get_rewrite_settings.ts
1255
+ import { Type as Type34 } from "@sinclair/typebox";
1256
+ var Schema33 = Type34.Object({ instance: InstanceArg }, { additionalProperties: false });
1257
+ var NAME26 = "adguard_get_rewrite_settings";
1258
+ function createAdguardGetRewriteSettingsTool(getClient) {
1259
+ return {
1260
+ name: NAME26,
1261
+ label: "adguard: get rewrite settings",
1262
+ description: "Get DNS rewrite enabled state via GET /control/rewrite/settings.",
1263
+ parameters: Schema33,
1264
+ execute: async (_id, raw) => {
1265
+ const args = raw;
1266
+ const client = getClient(args.instance);
1267
+ const settings = await client.get("/control/rewrite/settings");
1268
+ return jsonToolResult(settings);
1269
+ }
1270
+ };
1271
+ }
1272
+
1273
+ // src/tools/adguard_toggle_rewrites.ts
1274
+ import { Type as Type35 } from "@sinclair/typebox";
1275
+ var Schema34 = Type35.Object({
1276
+ instance: InstanceArg,
1277
+ enabled: Type35.Boolean({ description: "Target DNS rewrite enabled state." }),
1278
+ confirm: Type35.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1279
+ }, { additionalProperties: false });
1280
+ var NAME27 = "adguard_toggle_rewrites";
1281
+ function createAdguardToggleRewritesTool(getClient) {
1282
+ return {
1283
+ name: NAME27,
1284
+ label: "adguard: toggle rewrites",
1285
+ description: "Enable or disable DNS rewrites via PUT /control/rewrite/settings/update. Tier-2 write; requires confirm:true.",
1286
+ parameters: Schema34,
1287
+ execute: async (_id, raw) => {
1288
+ assertConfirmedWrite(raw, NAME27);
1289
+ const args = raw;
1290
+ const client = getClient(args.instance);
1291
+ await client.put("/control/rewrite/settings/update", { enabled: args.enabled });
1292
+ return jsonToolResult({ updated: true, enabled: args.enabled });
1293
+ }
1294
+ };
1295
+ }
1296
+
1297
+ // src/tools/adguard_get_access_list.ts
1298
+ import { Type as Type36 } from "@sinclair/typebox";
1299
+ var Schema35 = Type36.Object({ instance: InstanceArg }, { additionalProperties: false });
1300
+ var NAME28 = "adguard_get_access_list";
1301
+ function createAdguardGetAccessListTool(getClient) {
1302
+ return {
1303
+ name: NAME28,
1304
+ label: "adguard: get access list",
1305
+ description: "Get allowed clients, disallowed clients, and blocked hosts via GET /control/access/list.",
1306
+ parameters: Schema35,
1307
+ execute: async (_id, raw) => {
1308
+ const args = raw;
1309
+ const client = getClient(args.instance);
1310
+ const list = await client.get("/control/access/list");
1311
+ return jsonToolResult(list);
1312
+ }
1313
+ };
1314
+ }
1315
+
1316
+ // src/tools/adguard_set_access_list.ts
1317
+ import { Type as Type37 } from "@sinclair/typebox";
1318
+ var Schema36 = Type37.Object({
1319
+ instance: InstanceArg,
1320
+ allowed_clients: Type37.Array(Type37.String(), { description: "Allowlist of clients: IP addresses, CIDRs, or ClientIDs. Empty array disables the allowlist." }),
1321
+ disallowed_clients: Type37.Array(Type37.String(), { description: "Blocklist of clients: IP addresses, CIDRs, or ClientIDs." }),
1322
+ blocked_hosts: Type37.Array(Type37.String(), { description: "Blocklist of hostnames." }),
1323
+ confirm: Type37.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1324
+ }, { additionalProperties: false });
1325
+ var NAME29 = "adguard_set_access_list";
1326
+ function createAdguardSetAccessListTool(getClient) {
1327
+ return {
1328
+ name: NAME29,
1329
+ label: "adguard: set access list",
1330
+ description: "Replace allowed clients, disallowed clients, and blocked hosts via POST /control/access/set. Tier-2 write; requires confirm:true.",
1331
+ parameters: Schema36,
1332
+ execute: async (_id, raw) => {
1333
+ assertConfirmedWrite(raw, NAME29);
1334
+ const args = raw;
1335
+ const body = {
1336
+ allowed_clients: args.allowed_clients,
1337
+ disallowed_clients: args.disallowed_clients,
1338
+ blocked_hosts: args.blocked_hosts
1339
+ };
1340
+ const client = getClient(args.instance);
1341
+ await client.post("/control/access/set", body);
1342
+ return jsonToolResult({ updated: true, ...body });
1343
+ }
1344
+ };
1345
+ }
1346
+
1347
+ // src/tools/adguard_get_querylog_config.ts
1348
+ import { Type as Type38 } from "@sinclair/typebox";
1349
+ var Schema37 = Type38.Object({ instance: InstanceArg }, { additionalProperties: false });
1350
+ var NAME30 = "adguard_get_querylog_config";
1351
+ function createAdguardGetQuerylogConfigTool(getClient) {
1352
+ return {
1353
+ name: NAME30,
1354
+ label: "adguard: get query log config",
1355
+ description: "Get query log settings via GET /control/querylog/config.",
1356
+ parameters: Schema37,
1357
+ execute: async (_id, raw) => {
1358
+ const args = raw;
1359
+ const client = getClient(args.instance);
1360
+ const config = await client.get("/control/querylog/config");
1361
+ return jsonToolResult(config);
1362
+ }
1363
+ };
1364
+ }
1365
+
1366
+ // src/tools/adguard_update_querylog_config.ts
1367
+ import { Type as Type39 } from "@sinclair/typebox";
1368
+ var Schema38 = Type39.Object({
1369
+ instance: InstanceArg,
1370
+ config: Type39.Object({}, { additionalProperties: true, description: "Query log config body for PUT /control/querylog/config/update." }),
1371
+ confirm: Type39.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1372
+ }, { additionalProperties: false });
1373
+ var NAME31 = "adguard_update_querylog_config";
1374
+ function createAdguardUpdateQuerylogConfigTool(getClient) {
1375
+ return {
1376
+ name: NAME31,
1377
+ label: "adguard: update query log config",
1378
+ description: "Update query log settings via PUT /control/querylog/config/update. Pass the AGH config fields inside `config`. Tier-2 write; requires confirm:true.",
1379
+ parameters: Schema38,
1380
+ execute: async (_id, raw) => {
1381
+ assertConfirmedWrite(raw, NAME31);
1382
+ const args = raw;
1383
+ const client = getClient(args.instance);
1384
+ await client.put("/control/querylog/config/update", args.config);
1385
+ return jsonToolResult({ updated: true, config: args.config });
1386
+ }
1387
+ };
1388
+ }
1389
+
1390
+ // src/tools/adguard_get_stats_config.ts
1391
+ import { Type as Type40 } from "@sinclair/typebox";
1392
+ var Schema39 = Type40.Object({ instance: InstanceArg }, { additionalProperties: false });
1393
+ var NAME32 = "adguard_get_stats_config";
1394
+ function createAdguardGetStatsConfigTool(getClient) {
1395
+ return {
1396
+ name: NAME32,
1397
+ label: "adguard: get stats config",
1398
+ description: "Get statistics settings via GET /control/stats/config.",
1399
+ parameters: Schema39,
1400
+ execute: async (_id, raw) => {
1401
+ const args = raw;
1402
+ const client = getClient(args.instance);
1403
+ const config = await client.get("/control/stats/config");
1404
+ return jsonToolResult(config);
1405
+ }
1406
+ };
1407
+ }
1408
+
1409
+ // src/tools/adguard_update_stats_config.ts
1410
+ import { Type as Type41 } from "@sinclair/typebox";
1411
+ var Schema40 = Type41.Object({
1412
+ instance: InstanceArg,
1413
+ config: Type41.Object({}, { additionalProperties: true, description: "Stats config body for PUT /control/stats/config/update." }),
1414
+ confirm: Type41.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
1415
+ }, { additionalProperties: false });
1416
+ var NAME33 = "adguard_update_stats_config";
1417
+ function createAdguardUpdateStatsConfigTool(getClient) {
1418
+ return {
1419
+ name: NAME33,
1420
+ label: "adguard: update stats config",
1421
+ description: "Update statistics settings via PUT /control/stats/config/update. Pass the AGH config fields inside `config`. Tier-2 write; requires confirm:true.",
1422
+ parameters: Schema40,
1423
+ execute: async (_id, raw) => {
1424
+ assertConfirmedWrite(raw, NAME33);
1425
+ const args = raw;
1426
+ const client = getClient(args.instance);
1427
+ await client.put("/control/stats/config/update", args.config);
1428
+ return jsonToolResult({ updated: true, config: args.config });
1429
+ }
1430
+ };
1431
+ }
1432
+
1433
+ // src/tools/adguard_dhcp_status.ts
1434
+ import { Type as Type42 } from "@sinclair/typebox";
1435
+ var Schema41 = Type42.Object({ instance: InstanceArg }, { additionalProperties: false });
1436
+ var NAME34 = "adguard_dhcp_status";
1437
+ function createAdguardDhcpStatusTool(getClient) {
1438
+ return {
1439
+ name: NAME34,
1440
+ label: "adguard: dhcp status",
1441
+ description: "Get DHCP server settings, leases, and status via GET /control/dhcp/status.",
1442
+ parameters: Schema41,
1443
+ execute: async (_id, raw) => {
1444
+ const args = raw;
1445
+ const client = getClient(args.instance);
1446
+ const status = await client.get("/control/dhcp/status");
1447
+ return jsonToolResult(status);
1448
+ }
1449
+ };
1450
+ }
1451
+
1452
+ // src/tools/adguard_dhcp_interfaces.ts
1453
+ import { Type as Type43 } from "@sinclair/typebox";
1454
+ var Schema42 = Type43.Object({ instance: InstanceArg }, { additionalProperties: false });
1455
+ var NAME35 = "adguard_dhcp_interfaces";
1456
+ function createAdguardDhcpInterfacesTool(getClient) {
1457
+ return {
1458
+ name: NAME35,
1459
+ label: "adguard: dhcp interfaces",
1460
+ description: "List network interfaces available to the DHCP server via GET /control/dhcp/interfaces.",
1461
+ parameters: Schema42,
1462
+ execute: async (_id, raw) => {
1463
+ const args = raw;
1464
+ const client = getClient(args.instance);
1465
+ const interfaces = await client.get("/control/dhcp/interfaces");
1466
+ return jsonToolResult(interfaces);
1467
+ }
1468
+ };
1469
+ }
1470
+
1471
+ // src/tools/adguard_tls_status.ts
1472
+ import { Type as Type44 } from "@sinclair/typebox";
1473
+ var Schema43 = Type44.Object({ instance: InstanceArg }, { additionalProperties: false });
1474
+ var NAME36 = "adguard_tls_status";
1475
+ function createAdguardTlsStatusTool(getClient) {
1476
+ return {
1477
+ name: NAME36,
1478
+ label: "adguard: tls status",
1479
+ description: "Get TLS configuration and validation status via GET /control/tls/status. Private key values are redacted from tool output.",
1480
+ parameters: Schema43,
1481
+ execute: async (_id, raw) => {
1482
+ const args = raw;
1483
+ const client = getClient(args.instance);
1484
+ const status = await client.get("/control/tls/status");
1485
+ return jsonToolResult(redactTlsSecrets(status));
1486
+ }
1487
+ };
1488
+ }
1489
+ function redactTlsSecrets(value) {
1490
+ if (Array.isArray(value)) return value.map(redactTlsSecrets);
1491
+ if (!value || typeof value !== "object") return value;
1492
+ const out = {};
1493
+ for (const [key, entry] of Object.entries(value)) {
1494
+ out[key] = key === "private_key" ? "[REDACTED]" : redactTlsSecrets(entry);
1495
+ }
1496
+ return out;
1497
+ }
1498
+
1499
+ // src/tools/adguard_validate_tls_config.ts
1500
+ import { Type as Type45 } from "@sinclair/typebox";
1501
+ var Schema44 = Type45.Object({
1502
+ instance: InstanceArg,
1503
+ config: Type45.Object({}, { additionalProperties: true, description: "TLS config body for POST /control/tls/validate. May include certificate_chain/private_key or file paths." }),
1504
+ confirm: Type45.Boolean({ description: "Must be true. Tier-2 gate because TLS validation may include sensitive key material." })
1505
+ }, { additionalProperties: false });
1506
+ var NAME37 = "adguard_validate_tls_config";
1507
+ function createAdguardValidateTlsConfigTool(getClient) {
1508
+ return {
1509
+ name: NAME37,
1510
+ label: "adguard: validate tls config",
1511
+ description: "Validate a TLS config via POST /control/tls/validate without applying it. Tier-2 gated because the request can carry certificate/key material; private key values are redacted from tool output.",
1512
+ parameters: Schema44,
1513
+ execute: async (_id, raw) => {
1514
+ assertConfirmedWrite(raw, NAME37);
1515
+ const args = raw;
1516
+ const client = getClient(args.instance);
1517
+ const result = await client.post("/control/tls/validate", args.config);
1518
+ return jsonToolResult(redactTlsSecrets(result));
1519
+ }
1520
+ };
1521
+ }
1522
+
1523
+ // src/tools/adguard_test_upstream_dns.ts
1524
+ import { Type as Type46 } from "@sinclair/typebox";
1525
+ var Schema45 = Type46.Object({
1526
+ instance: InstanceArg,
1527
+ bootstrap_dns: Type46.Array(Type46.String(), { description: "Bootstrap DNS servers, port optional." }),
1528
+ upstream_dns: Type46.Array(Type46.String(), { description: "Upstream DNS servers to test, port optional." }),
1529
+ fallback_dns: Type46.Optional(Type46.Array(Type46.String(), { description: "Fallback DNS servers to test, port optional." })),
1530
+ private_upstream: Type46.Optional(Type46.Array(Type46.String(), { description: "Local PTR resolvers to test, port optional." })),
1531
+ confirm: Type46.Boolean({ description: "Must be true. Tier-2 gate because the AGH server will probe the provided upstreams." })
1532
+ }, { additionalProperties: false });
1533
+ var NAME38 = "adguard_test_upstream_dns";
1534
+ function createAdguardTestUpstreamDnsTool(getClient) {
1535
+ return {
1536
+ name: NAME38,
1537
+ label: "adguard: test upstream dns",
1538
+ description: "Test upstream DNS server configuration via POST /control/test_upstream_dns. Tier-2 gated because it causes the AGH server to probe the provided upstreams.",
1539
+ parameters: Schema45,
1540
+ execute: async (_id, raw) => {
1541
+ assertConfirmedWrite(raw, NAME38);
1542
+ const args = raw;
1543
+ const body = {
1544
+ bootstrap_dns: args.bootstrap_dns,
1545
+ upstream_dns: args.upstream_dns
1546
+ };
1547
+ if (args.fallback_dns !== void 0) body.fallback_dns = args.fallback_dns;
1548
+ if (args.private_upstream !== void 0) body.private_upstream = args.private_upstream;
1549
+ const client = getClient(args.instance);
1550
+ const result = await client.post("/control/test_upstream_dns", body);
1551
+ return jsonToolResult(result);
1552
+ }
1553
+ };
1554
+ }
1555
+
1556
+ // src/tools/adguard_sync_status.ts
1557
+ import { Type as Type47 } from "@sinclair/typebox";
1558
+ var Schema46 = Type47.Object({}, { additionalProperties: false });
1559
+ function createAdguardSyncStatusTool(getSyncClient) {
1560
+ return {
1561
+ name: "adguard_sync_status",
1562
+ label: "adguard sync: status",
1563
+ description: "Get AdGuardHome Sync origin/replica status via GET /api/v1/status.",
1564
+ parameters: Schema46,
1565
+ execute: async (_id, _raw) => {
1566
+ const client = getSyncClient();
1567
+ const status = await client.get("/api/v1/status");
1568
+ return jsonToolResult(status);
1569
+ }
1570
+ };
1571
+ }
1572
+
1573
+ // src/tools/adguard_sync_health.ts
1574
+ import { Type as Type48 } from "@sinclair/typebox";
1575
+ var Schema47 = Type48.Object({}, { additionalProperties: false });
1576
+ function createAdguardSyncHealthTool(getSyncClient) {
1577
+ return {
1578
+ name: "adguard_sync_health",
1579
+ label: "adguard sync: health",
1580
+ description: "Check AdGuardHome Sync health via HEAD /healthz. The endpoint is unauthenticated upstream and returns 2xx only when origin and replicas are healthy.",
1581
+ parameters: Schema47,
1582
+ execute: async (_id, _raw) => {
1583
+ const client = getSyncClient();
1584
+ const health = await client.head("/healthz");
1585
+ return jsonToolResult(health);
1586
+ }
1587
+ };
1588
+ }
1589
+
1590
+ // src/tools/adguard_sync_logs.ts
1591
+ import { Type as Type49 } from "@sinclair/typebox";
1592
+ var Schema48 = Type49.Object({}, { additionalProperties: false });
1593
+ function createAdguardSyncLogsTool(getSyncClient) {
1594
+ return {
1595
+ name: "adguard_sync_logs",
1596
+ label: "adguard sync: logs",
1597
+ description: "Read AdGuardHome Sync in-memory logs via GET /api/v1/logs.",
1598
+ parameters: Schema48,
1599
+ execute: async (_id, _raw) => {
1600
+ const client = getSyncClient();
1601
+ const logs = await client.get("/api/v1/logs");
1602
+ return jsonToolResult({ logs });
1603
+ }
1604
+ };
1605
+ }
1606
+
1607
+ // src/tools/adguard_sync_run.ts
1608
+ import { Type as Type50 } from "@sinclair/typebox";
1609
+ var Schema49 = Type50.Object({
1610
+ confirm: Type50.Boolean({ description: "Must be true. Tier-2 safe-write gate. Starts a sync from origin to replicas." })
1611
+ }, { additionalProperties: false });
1612
+ var NAME39 = "adguard_sync_run";
1613
+ function createAdguardSyncRunTool(getSyncClient) {
1614
+ return {
1615
+ name: NAME39,
1616
+ label: "adguard sync: run",
1617
+ description: "Trigger AdGuardHome Sync immediately via POST /api/v1/sync. Tier-2 write; requires confirm:true.",
1618
+ parameters: Schema49,
1619
+ execute: async (_id, raw) => {
1620
+ assertConfirmedWrite(raw, NAME39);
1621
+ const client = getSyncClient();
1622
+ await client.post("/api/v1/sync");
1623
+ return jsonToolResult({ started: true });
1624
+ }
1625
+ };
1626
+ }
1627
+
1628
+ // src/tools/adguard_sync_clear_logs.ts
1629
+ import { Type as Type51 } from "@sinclair/typebox";
1630
+ var Schema50 = Type51.Object({
1631
+ confirm: Type51.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
1632
+ destructive: Type51.Boolean({ description: "Must be true. Tier-3 destructive gate. Clears AdGuardHome Sync logs." })
1633
+ }, { additionalProperties: false });
1634
+ var NAME40 = "adguard_sync_clear_logs";
1635
+ function createAdguardSyncClearLogsTool(getSyncClient) {
1636
+ return {
1637
+ name: NAME40,
1638
+ label: "adguard sync: clear logs",
1639
+ description: "Clear AdGuardHome Sync in-memory logs via POST /api/v1/clear-logs. Tier-3 destructive; requires confirm:true and destructive:true.",
1640
+ parameters: Schema50,
1641
+ execute: async (_id, raw) => {
1642
+ assertDestructive(raw, NAME40);
1643
+ const client = getSyncClient();
1644
+ await client.post("/api/v1/clear-logs");
1645
+ return jsonToolResult({ cleared: true });
1646
+ }
1647
+ };
1648
+ }
1649
+
998
1650
  // src/tools/index.ts
999
- function buildAllTools(getClient2) {
1651
+ function buildAllTools(getClient, getSyncClient) {
1000
1652
  return [
1001
1653
  // Tier 1: reads
1002
- createAdguardStatusTool(getClient2),
1003
- createAdguardStatsTool(getClient2),
1004
- createAdguardQueryLogTool(getClient2),
1005
- createAdguardListFilterListsTool(getClient2),
1006
- createAdguardListUserRulesTool(getClient2),
1007
- createAdguardListClientsTool(getClient2),
1008
- createAdguardListBlockedServicesCatalogTool(getClient2),
1009
- createAdguardCheckHostTool(getClient2),
1010
- createAdguardGetBlockedServicesTool(getClient2),
1011
- createAdguardGetDnsConfigTool(getClient2),
1012
- createAdguardGetSafesearchSettingsTool(getClient2),
1654
+ createAdguardStatusTool(getClient),
1655
+ createAdguardStatsTool(getClient),
1656
+ createAdguardQueryLogTool(getClient),
1657
+ createAdguardListFilterListsTool(getClient),
1658
+ createAdguardListUserRulesTool(getClient),
1659
+ createAdguardListClientsTool(getClient),
1660
+ createAdguardListBlockedServicesCatalogTool(getClient),
1661
+ createAdguardCheckHostTool(getClient),
1662
+ createAdguardGetBlockedServicesTool(getClient),
1663
+ createAdguardGetDnsConfigTool(getClient),
1664
+ createAdguardGetSafesearchSettingsTool(getClient),
1665
+ createAdguardListRewritesTool(getClient),
1666
+ createAdguardGetRewriteSettingsTool(getClient),
1667
+ createAdguardGetAccessListTool(getClient),
1668
+ createAdguardGetQuerylogConfigTool(getClient),
1669
+ createAdguardGetStatsConfigTool(getClient),
1670
+ createAdguardDhcpStatusTool(getClient),
1671
+ createAdguardDhcpInterfacesTool(getClient),
1672
+ createAdguardTlsStatusTool(getClient),
1673
+ createAdguardSyncStatusTool(getSyncClient),
1674
+ createAdguardSyncHealthTool(getSyncClient),
1675
+ createAdguardSyncLogsTool(getSyncClient),
1013
1676
  // Tier 2: safe writes (confirm: true)
1014
- createAdguardAddUserRuleTool(getClient2),
1015
- createAdguardRemoveUserRuleTool(getClient2),
1016
- createAdguardAddFilterListTool(getClient2),
1017
- createAdguardRemoveFilterListTool(getClient2),
1018
- createAdguardToggleFilterListTool(getClient2),
1019
- createAdguardSetClientBlockedServicesTool(getClient2),
1020
- createAdguardRefreshFilterListsTool(getClient2),
1021
- createAdguardAddClientTool(getClient2),
1022
- createAdguardUpdateClientTool(getClient2),
1023
- createAdguardSetBlockedServicesTool(getClient2),
1024
- createAdguardToggleSafesearchTool(getClient2),
1025
- createAdguardToggleSafebrowsingTool(getClient2),
1677
+ createAdguardAddUserRuleTool(getClient),
1678
+ createAdguardRemoveUserRuleTool(getClient),
1679
+ createAdguardAddFilterListTool(getClient),
1680
+ createAdguardRemoveFilterListTool(getClient),
1681
+ createAdguardToggleFilterListTool(getClient),
1682
+ createAdguardSetClientBlockedServicesTool(getClient),
1683
+ createAdguardRefreshFilterListsTool(getClient),
1684
+ createAdguardAddClientTool(getClient),
1685
+ createAdguardUpdateClientTool(getClient),
1686
+ createAdguardSetBlockedServicesTool(getClient),
1687
+ createAdguardToggleSafesearchTool(getClient),
1688
+ createAdguardToggleSafebrowsingTool(getClient),
1689
+ createAdguardAddRewriteTool(getClient),
1690
+ createAdguardUpdateRewriteTool(getClient),
1691
+ createAdguardDeleteRewriteTool(getClient),
1692
+ createAdguardToggleRewritesTool(getClient),
1693
+ createAdguardSetAccessListTool(getClient),
1694
+ createAdguardUpdateQuerylogConfigTool(getClient),
1695
+ createAdguardUpdateStatsConfigTool(getClient),
1696
+ createAdguardValidateTlsConfigTool(getClient),
1697
+ createAdguardTestUpstreamDnsTool(getClient),
1698
+ createAdguardSyncRunTool(getSyncClient),
1026
1699
  // Tier 3: destructive (confirm: true + destructive: true)
1027
- createAdguardReplaceUserRulesTool(getClient2),
1028
- createAdguardToggleProtectionTool(getClient2),
1029
- createAdguardDeleteClientTool(getClient2),
1030
- createAdguardClearQueryLogTool(getClient2),
1031
- createAdguardResetStatsTool(getClient2)
1700
+ createAdguardReplaceUserRulesTool(getClient),
1701
+ createAdguardToggleProtectionTool(getClient),
1702
+ createAdguardDeleteClientTool(getClient),
1703
+ createAdguardClearQueryLogTool(getClient),
1704
+ createAdguardResetStatsTool(getClient),
1705
+ createAdguardSyncClearLogsTool(getSyncClient)
1032
1706
  ];
1033
1707
  }
1034
1708
 
1035
1709
  // mcp-server.ts
1036
- var cfg = resolveInstances(process.env);
1037
- for (const inst of Object.values(cfg.instances)) {
1038
- registerSecret(inst.password);
1039
- const basicValue = "Basic " + Buffer2.from(`${inst.username}:${inst.password}`).toString("base64");
1040
- registerSecret(basicValue);
1041
- }
1042
- var getClient = (name) => new AdGuardClient(getInstanceConfig(cfg, name));
1043
- var tools = buildAllTools(getClient);
1044
- var toolMap = new Map(tools.map((t) => [t.name, t]));
1045
- var server = new Server({ name: "adguard-mcp", version: "0.2.0" }, { capabilities: { tools: {} } });
1046
- server.setRequestHandler(ListToolsRequestSchema, async () => ({
1047
- tools: tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.parameters }))
1048
- }));
1049
- server.setRequestHandler(CallToolRequestSchema, async (req) => {
1050
- const t = toolMap.get(req.params.name);
1051
- if (!t) {
1052
- return { content: [{ type: "text", text: JSON.stringify({ error: `unknown tool: ${req.params.name}` }) }], isError: true };
1710
+ async function startServer() {
1711
+ const cfg = resolveInstances(process.env);
1712
+ for (const inst of Object.values(cfg.instances)) {
1713
+ registerSecret(inst.password);
1714
+ const basicValue = "Basic " + Buffer2.from(`${inst.username}:${inst.password}`).toString("base64");
1715
+ registerSecret(basicValue);
1053
1716
  }
1717
+ const syncCfg = resolveSyncConfig(process.env);
1718
+ if (syncCfg?.password) {
1719
+ registerSecret(syncCfg.password);
1720
+ if (syncCfg.username) {
1721
+ const basicValue = "Basic " + Buffer2.from(`${syncCfg.username}:${syncCfg.password}`).toString("base64");
1722
+ registerSecret(basicValue);
1723
+ }
1724
+ }
1725
+ const getClient = (name) => new AdGuardClient(getInstanceConfig(cfg, name));
1726
+ const getSyncClient = () => new AdGuardSyncClient(getSyncConfig(syncCfg));
1727
+ const tools = buildAllTools(getClient, getSyncClient);
1728
+ const toolMap = new Map(tools.map((t) => [t.name, t]));
1729
+ const server = new Server({ name: "adguard-mcp", version: "0.3.0" }, { capabilities: { tools: {} } });
1730
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
1731
+ tools: tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.parameters }))
1732
+ }));
1733
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
1734
+ const t = toolMap.get(req.params.name);
1735
+ if (!t) {
1736
+ return { content: [{ type: "text", text: JSON.stringify({ error: `unknown tool: ${req.params.name}` }) }], isError: true };
1737
+ }
1738
+ try {
1739
+ return await t.execute(req.params.name, req.params.arguments ?? {});
1740
+ } catch (e) {
1741
+ const msg = redact(e.message);
1742
+ return { content: [{ type: "text", text: JSON.stringify({ error: msg }) }], isError: true };
1743
+ }
1744
+ });
1745
+ const transport = new StdioServerTransport();
1746
+ const __send = transport.send.bind(transport);
1747
+ transport.send = (message) => {
1748
+ const listed = message?.result?.tools;
1749
+ if (Array.isArray(listed)) {
1750
+ for (const t of listed) {
1751
+ if (t?.inputSchema) delete t.inputSchema.$schema;
1752
+ if (t?.outputSchema) delete t.outputSchema.$schema;
1753
+ }
1754
+ }
1755
+ return __send(message);
1756
+ };
1757
+ await server.connect(transport);
1758
+ }
1759
+ var isEntrypoint = (() => {
1760
+ const arg = process.argv[1];
1761
+ if (typeof arg !== "string") return false;
1054
1762
  try {
1055
- return await t.execute(req.params.name, req.params.arguments ?? {});
1056
- } catch (e) {
1057
- const msg = redact(e.message);
1058
- return { content: [{ type: "text", text: JSON.stringify({ error: msg }) }], isError: true };
1763
+ return import.meta.url === pathToFileURL(realpathSync(arg)).href;
1764
+ } catch {
1765
+ return false;
1059
1766
  }
1060
- });
1061
- var transport = new StdioServerTransport();
1062
- await server.connect(transport);
1767
+ })();
1768
+ if (isEntrypoint) {
1769
+ startServer().catch((error) => {
1770
+ const msg = error instanceof Error ? error.message : String(error);
1771
+ console.error(`adguard-mcp fatal: ${msg}`);
1772
+ process.exit(1);
1773
+ });
1774
+ }
1063
1775
  export {
1064
- tools
1776
+ startServer
1065
1777
  };