@solomonneas/adguard-mcp 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -6
- package/dist/index.js +456 -15
- package/dist/mcp-server.js +460 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,51 @@
|
|
|
1
1
|
# adguard-mcp
|
|
2
2
|
|
|
3
|
-
MCP server exposing AdGuard Home read/write tools across one or more instances. Three-tier write gating: reads are open, writes require `confirm: true`, destructive ops require `confirm: true` + `destructive: true`.
|
|
3
|
+
MCP server exposing AdGuard Home read/write tools across one or more instances. 28 tools (11 reads / 12 safe-writes / 5 destructive). Three-tier write gating: reads are open, writes require `confirm: true`, destructive ops require `confirm: true` + `destructive: true`.
|
|
4
4
|
|
|
5
5
|
## Tools
|
|
6
6
|
|
|
7
|
-
**Reads (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
**Reads (11):** `adguard_status`, `adguard_stats`, `adguard_query_log`, `adguard_list_filter_lists`, `adguard_list_user_rules`, `adguard_list_clients`, `adguard_list_blocked_services_catalog`, `adguard_check_host`, `adguard_get_blocked_services`, `adguard_get_dns_config`, `adguard_get_safesearch_settings`.
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|---|---|
|
|
11
|
+
| `adguard_status` | Server status + protection state (`GET /control/status`). |
|
|
12
|
+
| `adguard_stats` | Stats window: top queries, blocked counts, clients (`GET /control/stats`). |
|
|
13
|
+
| `adguard_query_log` | DNS query log slice with filters (`GET /control/querylog`). |
|
|
14
|
+
| `adguard_list_filter_lists` | Subscribed blocklists + allowlists (`GET /control/filtering/status`). |
|
|
15
|
+
| `adguard_list_user_rules` | Custom user rules (`GET /control/filtering/status`). |
|
|
16
|
+
| `adguard_list_clients` | Configured named clients (`GET /control/clients`). |
|
|
17
|
+
| `adguard_list_blocked_services_catalog` | Available service IDs to block (`GET /control/blocked_services/services`). |
|
|
18
|
+
| `adguard_check_host` | Test what AGH would do with a hostname: filter decision, matched rules, CNAME chain, IPs (`GET /control/filtering/check_host`). |
|
|
19
|
+
| `adguard_get_blocked_services` | Global blocked-services list + weekly schedule (`GET /control/blocked_services/get`). |
|
|
20
|
+
| `adguard_get_dns_config` | DNS upstreams, bootstrap, cache, parallel resolution, blocking mode (`GET /control/dns_info`). |
|
|
21
|
+
| `adguard_get_safesearch_settings` | SafeSearch enabled state + per-engine flags (`GET /control/safesearch/status`). |
|
|
22
|
+
|
|
23
|
+
**Safe writes (12, require `confirm: true`):** `adguard_add_user_rule`, `adguard_remove_user_rule`, `adguard_add_filter_list`, `adguard_remove_filter_list`, `adguard_toggle_filter_list`, `adguard_set_client_blocked_services`, `adguard_refresh_filter_lists`, `adguard_add_client`, `adguard_update_client`, `adguard_set_blocked_services`, `adguard_toggle_safesearch`, `adguard_toggle_safebrowsing`.
|
|
24
|
+
|
|
25
|
+
| Tool | Description |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `adguard_add_user_rule` | Append a single user filter rule (`POST /control/filtering/set_rules`). |
|
|
28
|
+
| `adguard_remove_user_rule` | Remove a single user filter rule by exact match (`POST /control/filtering/set_rules`). |
|
|
29
|
+
| `adguard_add_filter_list` | Subscribe to a new blocklist or allowlist URL (`POST /control/filtering/add_url`). |
|
|
30
|
+
| `adguard_remove_filter_list` | Unsubscribe from a filter list by URL (`POST /control/filtering/remove_url`). |
|
|
31
|
+
| `adguard_toggle_filter_list` | Enable or disable a subscribed filter list (`POST /control/filtering/set_url`). |
|
|
32
|
+
| `adguard_set_client_blocked_services` | Set per-client blocked services + schedule (`POST /control/clients/update`). |
|
|
33
|
+
| `adguard_refresh_filter_lists` | Force refresh subscribed filter lists immediately (`POST /control/filtering/refresh`). |
|
|
34
|
+
| `adguard_add_client` | Register a new named client with per-client settings (`POST /control/clients/add`). |
|
|
35
|
+
| `adguard_update_client` | Full update for an existing named client; body is nested `{name, data}` (`POST /control/clients/update`). |
|
|
36
|
+
| `adguard_set_blocked_services` | Set GLOBAL blocked services + optional weekly schedule; accepts HH:MM strings or ms (`PUT /control/blocked_services/update`). |
|
|
37
|
+
| `adguard_toggle_safesearch` | Enable or disable SafeSearch globally with per-engine flags (`PUT /control/safesearch/settings`). |
|
|
38
|
+
| `adguard_toggle_safebrowsing` | Enable or disable AGH SafeBrowsing (`POST /control/safebrowsing/enable` or `/disable`). |
|
|
39
|
+
|
|
40
|
+
**Destructive (5, require `confirm: true` + `destructive: true`):** `adguard_replace_user_rules`, `adguard_toggle_protection`, `adguard_delete_client`, `adguard_clear_query_log`, `adguard_reset_stats`.
|
|
41
|
+
|
|
42
|
+
| Tool | Description |
|
|
43
|
+
|---|---|
|
|
44
|
+
| `adguard_replace_user_rules` | Wholesale replace the user rules block (`POST /control/filtering/set_rules`). |
|
|
45
|
+
| `adguard_toggle_protection` | Enable or disable global filtering; off stops ALL blocking (`POST /control/protection`). |
|
|
46
|
+
| `adguard_delete_client` | Remove a configured named client; per-client rules and stats are lost (`POST /control/clients/delete`). |
|
|
47
|
+
| `adguard_clear_query_log` | Wipe the DNS query log (`POST /control/querylog_clear`). |
|
|
48
|
+
| `adguard_reset_stats` | Zero the stats window (`POST /control/stats_reset`). |
|
|
12
49
|
|
|
13
50
|
## Configuration
|
|
14
51
|
|
package/dist/index.js
CHANGED
|
@@ -105,6 +105,9 @@ var AdGuardClient = class {
|
|
|
105
105
|
async post(path, body) {
|
|
106
106
|
return this.request("POST", path, body);
|
|
107
107
|
}
|
|
108
|
+
async put(path, body) {
|
|
109
|
+
return this.request("PUT", path, body);
|
|
110
|
+
}
|
|
108
111
|
async request(method, path, body) {
|
|
109
112
|
const url = this.cfg.url.replace(/\/+$/, "") + path;
|
|
110
113
|
const headers = { authorization: this.authHeader };
|
|
@@ -196,6 +199,22 @@ function jsonToolResult(payload) {
|
|
|
196
199
|
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
|
|
197
200
|
};
|
|
198
201
|
}
|
|
202
|
+
function hhmmToMs(value) {
|
|
203
|
+
if (typeof value === "number") {
|
|
204
|
+
if (!Number.isFinite(value)) throw new Error(`schedule time must be HH:MM or milliseconds, got: ${String(value)}`);
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
if (typeof value !== "string") {
|
|
208
|
+
throw new Error(`schedule time must be HH:MM string or milliseconds number, got: ${typeof value}`);
|
|
209
|
+
}
|
|
210
|
+
const m = /^(\d{1,2}):(\d{2})$/.exec(value);
|
|
211
|
+
if (!m) throw new Error(`schedule time must be HH:MM or milliseconds, got: ${value}`);
|
|
212
|
+
const h = Number(m[1]);
|
|
213
|
+
const mm = Number(m[2]);
|
|
214
|
+
if (mm > 59) throw new Error(`invalid HH:MM (minutes > 59): ${value}`);
|
|
215
|
+
if (h > 24 || h === 24 && mm > 0) throw new Error(`invalid HH:MM (max 24:00): ${value}`);
|
|
216
|
+
return (h * 60 + mm) * 60 * 1e3;
|
|
217
|
+
}
|
|
199
218
|
|
|
200
219
|
// src/tools/adguard_status.ts
|
|
201
220
|
var Schema = Type2.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
@@ -575,6 +594,442 @@ function createAdguardToggleProtectionTool(getClient) {
|
|
|
575
594
|
};
|
|
576
595
|
}
|
|
577
596
|
|
|
597
|
+
// src/tools/adguard_check_host.ts
|
|
598
|
+
import { Type as Type17 } from "@sinclair/typebox";
|
|
599
|
+
var Schema16 = Type17.Object({
|
|
600
|
+
instance: InstanceArg,
|
|
601
|
+
host: Type17.String({ description: "Hostname to test (e.g. 'youtube.com'). The lookup runs through AGH's filter pipeline as if the client queried it." }),
|
|
602
|
+
client: Type17.Optional(Type17.String({ description: "Optional client IP/ClientID/name to simulate the lookup against (per-client rules differ)." })),
|
|
603
|
+
qtype: Type17.Optional(Type17.String({ description: "DNS query type (A, AAAA, HTTPS, MX...). Default: server-side default (A)." }))
|
|
604
|
+
}, { additionalProperties: false });
|
|
605
|
+
var NAME9 = "adguard_check_host";
|
|
606
|
+
function createAdguardCheckHostTool(getClient) {
|
|
607
|
+
return {
|
|
608
|
+
name: NAME9,
|
|
609
|
+
label: "adguard: check host",
|
|
610
|
+
description: "Test what AGH would do with a hostname via GET /control/filtering/check_host. Returns the filter decision, matched rules, CNAME chain, and IPs.",
|
|
611
|
+
parameters: Schema16,
|
|
612
|
+
execute: async (_id, raw) => {
|
|
613
|
+
const args = raw;
|
|
614
|
+
const client = getClient(args.instance);
|
|
615
|
+
const params = new URLSearchParams({ name: args.host });
|
|
616
|
+
if (args.client) params.set("client", args.client);
|
|
617
|
+
if (args.qtype) params.set("qtype", args.qtype);
|
|
618
|
+
const result = await client.get(`/control/filtering/check_host?${params.toString()}`);
|
|
619
|
+
return jsonToolResult(result);
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/tools/adguard_get_blocked_services.ts
|
|
625
|
+
import { Type as Type18 } from "@sinclair/typebox";
|
|
626
|
+
var Schema17 = Type18.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
627
|
+
var NAME10 = "adguard_get_blocked_services";
|
|
628
|
+
function createAdguardGetBlockedServicesTool(getClient) {
|
|
629
|
+
return {
|
|
630
|
+
name: NAME10,
|
|
631
|
+
label: "adguard: get blocked services",
|
|
632
|
+
description: "Get the GLOBAL blocked-services list and weekly schedule via GET /control/blocked_services/get. Schedule day ranges are milliseconds-from-midnight.",
|
|
633
|
+
parameters: Schema17,
|
|
634
|
+
execute: async (_id, raw) => {
|
|
635
|
+
const args = raw;
|
|
636
|
+
const client = getClient(args.instance);
|
|
637
|
+
const result = await client.get("/control/blocked_services/get");
|
|
638
|
+
return jsonToolResult(result);
|
|
639
|
+
}
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// src/tools/adguard_get_dns_config.ts
|
|
644
|
+
import { Type as Type19 } from "@sinclair/typebox";
|
|
645
|
+
var Schema18 = Type19.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
646
|
+
var NAME11 = "adguard_get_dns_config";
|
|
647
|
+
function createAdguardGetDnsConfigTool(getClient) {
|
|
648
|
+
return {
|
|
649
|
+
name: NAME11,
|
|
650
|
+
label: "adguard: get DNS config",
|
|
651
|
+
description: "Get the DNS server config via GET /control/dns_info (upstreams, bootstrap, cache, parallel resolution, blocking mode, etc).",
|
|
652
|
+
parameters: Schema18,
|
|
653
|
+
execute: async (_id, raw) => {
|
|
654
|
+
const args = raw;
|
|
655
|
+
const client = getClient(args.instance);
|
|
656
|
+
const result = await client.get("/control/dns_info");
|
|
657
|
+
return jsonToolResult(result);
|
|
658
|
+
}
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
// src/tools/adguard_get_safesearch_settings.ts
|
|
663
|
+
import { Type as Type20 } from "@sinclair/typebox";
|
|
664
|
+
var Schema19 = Type20.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
665
|
+
var NAME12 = "adguard_get_safesearch_settings";
|
|
666
|
+
function createAdguardGetSafesearchSettingsTool(getClient) {
|
|
667
|
+
return {
|
|
668
|
+
name: NAME12,
|
|
669
|
+
label: "adguard: get safesearch settings",
|
|
670
|
+
description: "Get SafeSearch enabled state + per-engine flags via GET /control/safesearch/status.",
|
|
671
|
+
parameters: Schema19,
|
|
672
|
+
execute: async (_id, raw) => {
|
|
673
|
+
const args = raw;
|
|
674
|
+
const client = getClient(args.instance);
|
|
675
|
+
const result = await client.get("/control/safesearch/status");
|
|
676
|
+
return jsonToolResult(result);
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// src/tools/adguard_refresh_filter_lists.ts
|
|
682
|
+
import { Type as Type21 } from "@sinclair/typebox";
|
|
683
|
+
var Schema20 = Type21.Object({
|
|
684
|
+
instance: InstanceArg,
|
|
685
|
+
whitelist: Type21.Optional(Type21.Boolean({ description: "Refresh allowlist lists instead of blocklist lists. Default: false (refresh blocklists)." })),
|
|
686
|
+
confirm: Type21.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
687
|
+
}, { additionalProperties: false });
|
|
688
|
+
var NAME13 = "adguard_refresh_filter_lists";
|
|
689
|
+
function createAdguardRefreshFilterListsTool(getClient) {
|
|
690
|
+
return {
|
|
691
|
+
name: NAME13,
|
|
692
|
+
label: "adguard: refresh filter lists",
|
|
693
|
+
description: "Force refresh subscribed filter lists immediately via POST /control/filtering/refresh. Returns the number of lists updated. Tier-2 write; requires confirm:true.",
|
|
694
|
+
parameters: Schema20,
|
|
695
|
+
execute: async (_id, raw) => {
|
|
696
|
+
assertConfirmedWrite(raw, NAME13);
|
|
697
|
+
const args = raw;
|
|
698
|
+
const client = getClient(args.instance);
|
|
699
|
+
const result = await client.post("/control/filtering/refresh", { whitelist: args.whitelist === true });
|
|
700
|
+
return jsonToolResult(result);
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/tools/adguard_add_client.ts
|
|
706
|
+
import { Type as Type22 } from "@sinclair/typebox";
|
|
707
|
+
var SafeSearchSchema = Type22.Optional(Type22.Object({
|
|
708
|
+
enabled: Type22.Optional(Type22.Boolean()),
|
|
709
|
+
bing: Type22.Optional(Type22.Boolean()),
|
|
710
|
+
duckduckgo: Type22.Optional(Type22.Boolean()),
|
|
711
|
+
ecosia: Type22.Optional(Type22.Boolean()),
|
|
712
|
+
google: Type22.Optional(Type22.Boolean()),
|
|
713
|
+
pixabay: Type22.Optional(Type22.Boolean()),
|
|
714
|
+
yandex: Type22.Optional(Type22.Boolean()),
|
|
715
|
+
youtube: Type22.Optional(Type22.Boolean())
|
|
716
|
+
}, { additionalProperties: false }));
|
|
717
|
+
var Schema21 = Type22.Object({
|
|
718
|
+
instance: InstanceArg,
|
|
719
|
+
name: Type22.String({ description: "Client display name (must be unique on this instance)." }),
|
|
720
|
+
ids: Type22.Array(Type22.String(), { minItems: 1, description: "Identifier(s) for this client: IP, MAC, ClientID, or CIDR. At least one required." }),
|
|
721
|
+
use_global_settings: Type22.Optional(Type22.Boolean()),
|
|
722
|
+
filtering_enabled: Type22.Optional(Type22.Boolean()),
|
|
723
|
+
safebrowsing_enabled: Type22.Optional(Type22.Boolean()),
|
|
724
|
+
parental_enabled: Type22.Optional(Type22.Boolean()),
|
|
725
|
+
safe_search: SafeSearchSchema,
|
|
726
|
+
use_global_blocked_services: Type22.Optional(Type22.Boolean()),
|
|
727
|
+
blocked_services: Type22.Optional(Type22.Array(Type22.String())),
|
|
728
|
+
blocked_services_schedule: Type22.Optional(Type22.Object({}, { additionalProperties: true })),
|
|
729
|
+
upstreams: Type22.Optional(Type22.Array(Type22.String())),
|
|
730
|
+
tags: Type22.Optional(Type22.Array(Type22.String())),
|
|
731
|
+
ignore_querylog: Type22.Optional(Type22.Boolean()),
|
|
732
|
+
ignore_statistics: Type22.Optional(Type22.Boolean()),
|
|
733
|
+
upstreams_cache_enabled: Type22.Optional(Type22.Boolean()),
|
|
734
|
+
upstreams_cache_size: Type22.Optional(Type22.Number()),
|
|
735
|
+
confirm: Type22.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
736
|
+
}, { additionalProperties: false });
|
|
737
|
+
var NAME14 = "adguard_add_client";
|
|
738
|
+
var CLIENT_BODY_FIELDS = [
|
|
739
|
+
"name",
|
|
740
|
+
"ids",
|
|
741
|
+
"use_global_settings",
|
|
742
|
+
"filtering_enabled",
|
|
743
|
+
"safebrowsing_enabled",
|
|
744
|
+
"parental_enabled",
|
|
745
|
+
"safe_search",
|
|
746
|
+
"use_global_blocked_services",
|
|
747
|
+
"blocked_services",
|
|
748
|
+
"blocked_services_schedule",
|
|
749
|
+
"upstreams",
|
|
750
|
+
"tags",
|
|
751
|
+
"ignore_querylog",
|
|
752
|
+
"ignore_statistics",
|
|
753
|
+
"upstreams_cache_enabled",
|
|
754
|
+
"upstreams_cache_size"
|
|
755
|
+
];
|
|
756
|
+
function createAdguardAddClientTool(getClient) {
|
|
757
|
+
return {
|
|
758
|
+
name: NAME14,
|
|
759
|
+
label: "adguard: add client",
|
|
760
|
+
description: "Register a new named client via POST /control/clients/add. Tier-2 write; requires confirm:true.",
|
|
761
|
+
parameters: Schema21,
|
|
762
|
+
execute: async (_id, raw) => {
|
|
763
|
+
assertConfirmedWrite(raw, NAME14);
|
|
764
|
+
const body = {};
|
|
765
|
+
for (const k of CLIENT_BODY_FIELDS) {
|
|
766
|
+
if (raw[k] !== void 0) body[k] = raw[k];
|
|
767
|
+
}
|
|
768
|
+
const client = getClient(raw.instance);
|
|
769
|
+
await client.post("/control/clients/add", body);
|
|
770
|
+
return jsonToolResult({ added: true, name: body.name });
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// src/tools/adguard_update_client.ts
|
|
776
|
+
import { Type as Type23 } from "@sinclair/typebox";
|
|
777
|
+
var Schema22 = Type23.Object({
|
|
778
|
+
instance: InstanceArg,
|
|
779
|
+
name: Type23.String({ description: "Current name of the client to update (used to find the existing record)." }),
|
|
780
|
+
data: Type23.Object({}, { additionalProperties: true, description: "Full new Client object (AGH replaces the record; this is NOT a partial merge). Include name (new), ids, and any per-client settings to preserve." }),
|
|
781
|
+
confirm: Type23.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
782
|
+
}, { additionalProperties: false });
|
|
783
|
+
var NAME15 = "adguard_update_client";
|
|
784
|
+
function createAdguardUpdateClientTool(getClient) {
|
|
785
|
+
return {
|
|
786
|
+
name: NAME15,
|
|
787
|
+
label: "adguard: update client",
|
|
788
|
+
description: "Update an existing named client via POST /control/clients/update. Body is nested {name, data} where data replaces the full client record. Tier-2 write; requires confirm:true.",
|
|
789
|
+
parameters: Schema22,
|
|
790
|
+
execute: async (_id, raw) => {
|
|
791
|
+
assertConfirmedWrite(raw, NAME15);
|
|
792
|
+
const args = raw;
|
|
793
|
+
const client = getClient(args.instance);
|
|
794
|
+
await client.post("/control/clients/update", { name: args.name, data: args.data });
|
|
795
|
+
return jsonToolResult({ updated: true, name: args.name });
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// src/tools/adguard_set_blocked_services.ts
|
|
801
|
+
import { Type as Type24 } from "@sinclair/typebox";
|
|
802
|
+
var DayRange = Type24.Object({
|
|
803
|
+
start: Type24.Union([Type24.Number(), Type24.String()], { description: "Milliseconds from midnight (0-86400000) or HH:MM string." }),
|
|
804
|
+
end: Type24.Union([Type24.Number(), Type24.String()], { description: "Milliseconds from midnight (0-86400000) or HH:MM string." })
|
|
805
|
+
}, { additionalProperties: false });
|
|
806
|
+
var ScheduleSchema = Type24.Optional(Type24.Object({
|
|
807
|
+
time_zone: Type24.Optional(Type24.String()),
|
|
808
|
+
sun: Type24.Optional(DayRange),
|
|
809
|
+
mon: Type24.Optional(DayRange),
|
|
810
|
+
tue: Type24.Optional(DayRange),
|
|
811
|
+
wed: Type24.Optional(DayRange),
|
|
812
|
+
thu: Type24.Optional(DayRange),
|
|
813
|
+
fri: Type24.Optional(DayRange),
|
|
814
|
+
sat: Type24.Optional(DayRange)
|
|
815
|
+
}, { additionalProperties: false }));
|
|
816
|
+
var Schema23 = Type24.Object({
|
|
817
|
+
instance: InstanceArg,
|
|
818
|
+
ids: Type24.Array(Type24.String(), { description: "Service IDs from the catalog (youtube, instagram, tiktok, ...). Empty array clears global blocks." }),
|
|
819
|
+
schedule: ScheduleSchema,
|
|
820
|
+
confirm: Type24.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
821
|
+
}, { additionalProperties: false });
|
|
822
|
+
var NAME16 = "adguard_set_blocked_services";
|
|
823
|
+
function normalizeSchedule(schedule) {
|
|
824
|
+
if (!schedule) return void 0;
|
|
825
|
+
const out = {};
|
|
826
|
+
for (const [key, value] of Object.entries(schedule)) {
|
|
827
|
+
if (key === "time_zone") {
|
|
828
|
+
out[key] = value;
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (value && typeof value === "object" && "start" in value && "end" in value) {
|
|
832
|
+
const range = value;
|
|
833
|
+
out[key] = { start: hhmmToMs(range.start), end: hhmmToMs(range.end) };
|
|
834
|
+
} else {
|
|
835
|
+
out[key] = value;
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
return out;
|
|
839
|
+
}
|
|
840
|
+
function createAdguardSetBlockedServicesTool(getClient) {
|
|
841
|
+
return {
|
|
842
|
+
name: NAME16,
|
|
843
|
+
label: "adguard: set blocked services",
|
|
844
|
+
description: "Set the GLOBAL blocked-services list and optional weekly schedule via PUT /control/blocked_services/update. Accepts HH:MM strings or milliseconds for schedule times. Tier-2 write; requires confirm:true.",
|
|
845
|
+
parameters: Schema23,
|
|
846
|
+
execute: async (_id, raw) => {
|
|
847
|
+
assertConfirmedWrite(raw, NAME16);
|
|
848
|
+
const args = raw;
|
|
849
|
+
const client = getClient(args.instance);
|
|
850
|
+
const body = { ids: args.ids };
|
|
851
|
+
const normalized = normalizeSchedule(args.schedule);
|
|
852
|
+
if (normalized) body.schedule = normalized;
|
|
853
|
+
await client.put("/control/blocked_services/update", body);
|
|
854
|
+
return jsonToolResult({ set: true, count: args.ids.length });
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// src/tools/adguard_toggle_safesearch.ts
|
|
860
|
+
import { Type as Type25 } from "@sinclair/typebox";
|
|
861
|
+
var Schema24 = Type25.Object({
|
|
862
|
+
instance: InstanceArg,
|
|
863
|
+
enabled: Type25.Boolean({ description: "Target SafeSearch state globally." }),
|
|
864
|
+
bing: Type25.Optional(Type25.Boolean()),
|
|
865
|
+
duckduckgo: Type25.Optional(Type25.Boolean()),
|
|
866
|
+
ecosia: Type25.Optional(Type25.Boolean()),
|
|
867
|
+
google: Type25.Optional(Type25.Boolean()),
|
|
868
|
+
pixabay: Type25.Optional(Type25.Boolean()),
|
|
869
|
+
yandex: Type25.Optional(Type25.Boolean()),
|
|
870
|
+
youtube: Type25.Optional(Type25.Boolean()),
|
|
871
|
+
confirm: Type25.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
872
|
+
}, { additionalProperties: false });
|
|
873
|
+
var NAME17 = "adguard_toggle_safesearch";
|
|
874
|
+
function createAdguardToggleSafesearchTool(getClient) {
|
|
875
|
+
return {
|
|
876
|
+
name: NAME17,
|
|
877
|
+
label: "adguard: toggle safesearch",
|
|
878
|
+
description: "Enable or disable SafeSearch globally via PUT /control/safesearch/settings. Per-engine flags optional (default to all engines when enabling). Tier-2 write; requires confirm:true.",
|
|
879
|
+
parameters: Schema24,
|
|
880
|
+
execute: async (_id, raw) => {
|
|
881
|
+
assertConfirmedWrite(raw, NAME17);
|
|
882
|
+
const args = raw;
|
|
883
|
+
const enabled = args.enabled;
|
|
884
|
+
const engines = ["bing", "duckduckgo", "ecosia", "google", "pixabay", "yandex", "youtube"];
|
|
885
|
+
const body = { enabled };
|
|
886
|
+
for (const e of engines) {
|
|
887
|
+
if (!enabled) body[e] = false;
|
|
888
|
+
else if (args[e] !== void 0) body[e] = args[e];
|
|
889
|
+
else body[e] = true;
|
|
890
|
+
}
|
|
891
|
+
const client = getClient(args.instance);
|
|
892
|
+
await client.put("/control/safesearch/settings", body);
|
|
893
|
+
return jsonToolResult({ set: true, enabled });
|
|
894
|
+
}
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// src/tools/adguard_toggle_safebrowsing.ts
|
|
899
|
+
import { Type as Type26 } from "@sinclair/typebox";
|
|
900
|
+
var Schema25 = Type26.Object({
|
|
901
|
+
instance: InstanceArg,
|
|
902
|
+
enabled: Type26.Boolean({ description: "Target SafeBrowsing state." }),
|
|
903
|
+
confirm: Type26.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
904
|
+
}, { additionalProperties: false });
|
|
905
|
+
var NAME18 = "adguard_toggle_safebrowsing";
|
|
906
|
+
function createAdguardToggleSafebrowsingTool(getClient) {
|
|
907
|
+
return {
|
|
908
|
+
name: NAME18,
|
|
909
|
+
label: "adguard: toggle safebrowsing",
|
|
910
|
+
description: "Enable or disable AGH SafeBrowsing via POST /control/safebrowsing/enable or /disable. Tier-2 write; requires confirm:true.",
|
|
911
|
+
parameters: Schema25,
|
|
912
|
+
execute: async (_id, raw) => {
|
|
913
|
+
assertConfirmedWrite(raw, NAME18);
|
|
914
|
+
const args = raw;
|
|
915
|
+
const client = getClient(args.instance);
|
|
916
|
+
const path = args.enabled ? "/control/safebrowsing/enable" : "/control/safebrowsing/disable";
|
|
917
|
+
await client.post(path, void 0);
|
|
918
|
+
return jsonToolResult({ set: true, enabled: args.enabled });
|
|
919
|
+
}
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// src/tools/adguard_delete_client.ts
|
|
924
|
+
import { Type as Type27 } from "@sinclair/typebox";
|
|
925
|
+
var Schema26 = Type27.Object({
|
|
926
|
+
instance: InstanceArg,
|
|
927
|
+
name: Type27.String({ description: "Name of the configured client to remove." }),
|
|
928
|
+
confirm: Type27.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
|
|
929
|
+
destructive: Type27.Boolean({ description: "Must be true. Tier-3 destructive gate (deleting a client drops per-client rules and stats)." })
|
|
930
|
+
}, { additionalProperties: false });
|
|
931
|
+
var NAME19 = "adguard_delete_client";
|
|
932
|
+
function createAdguardDeleteClientTool(getClient) {
|
|
933
|
+
return {
|
|
934
|
+
name: NAME19,
|
|
935
|
+
label: "adguard: delete client",
|
|
936
|
+
description: "Remove a configured named client via POST /control/clients/delete. Tier-3 destructive; per-client rules and per-client filtering settings are lost. Requires confirm:true and destructive:true.",
|
|
937
|
+
parameters: Schema26,
|
|
938
|
+
execute: async (_id, raw) => {
|
|
939
|
+
assertDestructive(raw, NAME19);
|
|
940
|
+
const args = raw;
|
|
941
|
+
const client = getClient(args.instance);
|
|
942
|
+
await client.post("/control/clients/delete", { name: args.name });
|
|
943
|
+
return jsonToolResult({ deleted: true, name: args.name });
|
|
944
|
+
}
|
|
945
|
+
};
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/tools/adguard_clear_query_log.ts
|
|
949
|
+
import { Type as Type28 } from "@sinclair/typebox";
|
|
950
|
+
var Schema27 = Type28.Object({
|
|
951
|
+
instance: InstanceArg,
|
|
952
|
+
confirm: Type28.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
|
|
953
|
+
destructive: Type28.Boolean({ description: "Must be true. Tier-3 destructive gate (the query log is gone after this)." })
|
|
954
|
+
}, { additionalProperties: false });
|
|
955
|
+
var NAME20 = "adguard_clear_query_log";
|
|
956
|
+
function createAdguardClearQueryLogTool(getClient) {
|
|
957
|
+
return {
|
|
958
|
+
name: NAME20,
|
|
959
|
+
label: "adguard: clear query log",
|
|
960
|
+
description: "Wipe the AGH DNS query log via POST /control/querylog_clear (underscore endpoint). Tier-3 destructive; requires confirm:true and destructive:true.",
|
|
961
|
+
parameters: Schema27,
|
|
962
|
+
execute: async (_id, raw) => {
|
|
963
|
+
assertDestructive(raw, NAME20);
|
|
964
|
+
const args = raw;
|
|
965
|
+
const client = getClient(args.instance);
|
|
966
|
+
await client.post("/control/querylog_clear", void 0);
|
|
967
|
+
return jsonToolResult({ cleared: true });
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
// src/tools/adguard_reset_stats.ts
|
|
973
|
+
import { Type as Type29 } from "@sinclair/typebox";
|
|
974
|
+
var Schema28 = Type29.Object({
|
|
975
|
+
instance: InstanceArg,
|
|
976
|
+
confirm: Type29.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
|
|
977
|
+
destructive: Type29.Boolean({ description: "Must be true. Tier-3 destructive gate (stats history is zeroed)." })
|
|
978
|
+
}, { additionalProperties: false });
|
|
979
|
+
var NAME21 = "adguard_reset_stats";
|
|
980
|
+
function createAdguardResetStatsTool(getClient) {
|
|
981
|
+
return {
|
|
982
|
+
name: NAME21,
|
|
983
|
+
label: "adguard: reset stats",
|
|
984
|
+
description: "Zero out the AGH stats window via POST /control/stats_reset (underscore endpoint). Tier-3 destructive; requires confirm:true and destructive:true.",
|
|
985
|
+
parameters: Schema28,
|
|
986
|
+
execute: async (_id, raw) => {
|
|
987
|
+
assertDestructive(raw, NAME21);
|
|
988
|
+
const args = raw;
|
|
989
|
+
const client = getClient(args.instance);
|
|
990
|
+
await client.post("/control/stats_reset", void 0);
|
|
991
|
+
return jsonToolResult({ reset: true });
|
|
992
|
+
}
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// src/tools/index.ts
|
|
997
|
+
function buildAllTools(getClient) {
|
|
998
|
+
return [
|
|
999
|
+
// Tier 1: reads
|
|
1000
|
+
createAdguardStatusTool(getClient),
|
|
1001
|
+
createAdguardStatsTool(getClient),
|
|
1002
|
+
createAdguardQueryLogTool(getClient),
|
|
1003
|
+
createAdguardListFilterListsTool(getClient),
|
|
1004
|
+
createAdguardListUserRulesTool(getClient),
|
|
1005
|
+
createAdguardListClientsTool(getClient),
|
|
1006
|
+
createAdguardListBlockedServicesCatalogTool(getClient),
|
|
1007
|
+
createAdguardCheckHostTool(getClient),
|
|
1008
|
+
createAdguardGetBlockedServicesTool(getClient),
|
|
1009
|
+
createAdguardGetDnsConfigTool(getClient),
|
|
1010
|
+
createAdguardGetSafesearchSettingsTool(getClient),
|
|
1011
|
+
// Tier 2: safe writes (confirm: true)
|
|
1012
|
+
createAdguardAddUserRuleTool(getClient),
|
|
1013
|
+
createAdguardRemoveUserRuleTool(getClient),
|
|
1014
|
+
createAdguardAddFilterListTool(getClient),
|
|
1015
|
+
createAdguardRemoveFilterListTool(getClient),
|
|
1016
|
+
createAdguardToggleFilterListTool(getClient),
|
|
1017
|
+
createAdguardSetClientBlockedServicesTool(getClient),
|
|
1018
|
+
createAdguardRefreshFilterListsTool(getClient),
|
|
1019
|
+
createAdguardAddClientTool(getClient),
|
|
1020
|
+
createAdguardUpdateClientTool(getClient),
|
|
1021
|
+
createAdguardSetBlockedServicesTool(getClient),
|
|
1022
|
+
createAdguardToggleSafesearchTool(getClient),
|
|
1023
|
+
createAdguardToggleSafebrowsingTool(getClient),
|
|
1024
|
+
// Tier 3: destructive (confirm: true + destructive: true)
|
|
1025
|
+
createAdguardReplaceUserRulesTool(getClient),
|
|
1026
|
+
createAdguardToggleProtectionTool(getClient),
|
|
1027
|
+
createAdguardDeleteClientTool(getClient),
|
|
1028
|
+
createAdguardClearQueryLogTool(getClient),
|
|
1029
|
+
createAdguardResetStatsTool(getClient)
|
|
1030
|
+
];
|
|
1031
|
+
}
|
|
1032
|
+
|
|
578
1033
|
// index.ts
|
|
579
1034
|
function withRedactedErrors(tool) {
|
|
580
1035
|
const orig = tool.execute.bind(tool);
|
|
@@ -610,21 +1065,7 @@ var index_default = definePluginEntry({
|
|
|
610
1065
|
const cfg = resolveInstances(process.env);
|
|
611
1066
|
const getClient = makeFactory(cfg);
|
|
612
1067
|
const register = (t) => api.registerTool(withRedactedErrors(t));
|
|
613
|
-
|
|
614
|
-
register(createAdguardStatsTool(getClient));
|
|
615
|
-
register(createAdguardQueryLogTool(getClient));
|
|
616
|
-
register(createAdguardListFilterListsTool(getClient));
|
|
617
|
-
register(createAdguardListUserRulesTool(getClient));
|
|
618
|
-
register(createAdguardListClientsTool(getClient));
|
|
619
|
-
register(createAdguardListBlockedServicesCatalogTool(getClient));
|
|
620
|
-
register(createAdguardAddUserRuleTool(getClient));
|
|
621
|
-
register(createAdguardRemoveUserRuleTool(getClient));
|
|
622
|
-
register(createAdguardAddFilterListTool(getClient));
|
|
623
|
-
register(createAdguardRemoveFilterListTool(getClient));
|
|
624
|
-
register(createAdguardToggleFilterListTool(getClient));
|
|
625
|
-
register(createAdguardSetClientBlockedServicesTool(getClient));
|
|
626
|
-
register(createAdguardReplaceUserRulesTool(getClient));
|
|
627
|
-
register(createAdguardToggleProtectionTool(getClient));
|
|
1068
|
+
for (const t of buildAllTools(getClient)) register(t);
|
|
628
1069
|
}
|
|
629
1070
|
});
|
|
630
1071
|
export {
|
package/dist/mcp-server.js
CHANGED
|
@@ -107,6 +107,9 @@ var AdGuardClient = class {
|
|
|
107
107
|
async post(path, body) {
|
|
108
108
|
return this.request("POST", path, body);
|
|
109
109
|
}
|
|
110
|
+
async put(path, body) {
|
|
111
|
+
return this.request("PUT", path, body);
|
|
112
|
+
}
|
|
110
113
|
async request(method, path, body) {
|
|
111
114
|
const url = this.cfg.url.replace(/\/+$/, "") + path;
|
|
112
115
|
const headers = { authorization: this.authHeader };
|
|
@@ -198,6 +201,22 @@ function jsonToolResult(payload) {
|
|
|
198
201
|
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
|
|
199
202
|
};
|
|
200
203
|
}
|
|
204
|
+
function hhmmToMs(value) {
|
|
205
|
+
if (typeof value === "number") {
|
|
206
|
+
if (!Number.isFinite(value)) throw new Error(`schedule time must be HH:MM or milliseconds, got: ${String(value)}`);
|
|
207
|
+
return value;
|
|
208
|
+
}
|
|
209
|
+
if (typeof value !== "string") {
|
|
210
|
+
throw new Error(`schedule time must be HH:MM string or milliseconds number, got: ${typeof value}`);
|
|
211
|
+
}
|
|
212
|
+
const m = /^(\d{1,2}):(\d{2})$/.exec(value);
|
|
213
|
+
if (!m) throw new Error(`schedule time must be HH:MM or milliseconds, got: ${value}`);
|
|
214
|
+
const h = Number(m[1]);
|
|
215
|
+
const mm = Number(m[2]);
|
|
216
|
+
if (mm > 59) throw new Error(`invalid HH:MM (minutes > 59): ${value}`);
|
|
217
|
+
if (h > 24 || h === 24 && mm > 0) throw new Error(`invalid HH:MM (max 24:00): ${value}`);
|
|
218
|
+
return (h * 60 + mm) * 60 * 1e3;
|
|
219
|
+
}
|
|
201
220
|
|
|
202
221
|
// src/tools/adguard_status.ts
|
|
203
222
|
var Schema = Type2.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
@@ -577,6 +596,442 @@ function createAdguardToggleProtectionTool(getClient2) {
|
|
|
577
596
|
};
|
|
578
597
|
}
|
|
579
598
|
|
|
599
|
+
// src/tools/adguard_check_host.ts
|
|
600
|
+
import { Type as Type17 } from "@sinclair/typebox";
|
|
601
|
+
var Schema16 = Type17.Object({
|
|
602
|
+
instance: InstanceArg,
|
|
603
|
+
host: Type17.String({ description: "Hostname to test (e.g. 'youtube.com'). The lookup runs through AGH's filter pipeline as if the client queried it." }),
|
|
604
|
+
client: Type17.Optional(Type17.String({ description: "Optional client IP/ClientID/name to simulate the lookup against (per-client rules differ)." })),
|
|
605
|
+
qtype: Type17.Optional(Type17.String({ description: "DNS query type (A, AAAA, HTTPS, MX...). Default: server-side default (A)." }))
|
|
606
|
+
}, { additionalProperties: false });
|
|
607
|
+
var NAME9 = "adguard_check_host";
|
|
608
|
+
function createAdguardCheckHostTool(getClient2) {
|
|
609
|
+
return {
|
|
610
|
+
name: NAME9,
|
|
611
|
+
label: "adguard: check host",
|
|
612
|
+
description: "Test what AGH would do with a hostname via GET /control/filtering/check_host. Returns the filter decision, matched rules, CNAME chain, and IPs.",
|
|
613
|
+
parameters: Schema16,
|
|
614
|
+
execute: async (_id, raw) => {
|
|
615
|
+
const args = raw;
|
|
616
|
+
const client = getClient2(args.instance);
|
|
617
|
+
const params = new URLSearchParams({ name: args.host });
|
|
618
|
+
if (args.client) params.set("client", args.client);
|
|
619
|
+
if (args.qtype) params.set("qtype", args.qtype);
|
|
620
|
+
const result = await client.get(`/control/filtering/check_host?${params.toString()}`);
|
|
621
|
+
return jsonToolResult(result);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// src/tools/adguard_get_blocked_services.ts
|
|
627
|
+
import { Type as Type18 } from "@sinclair/typebox";
|
|
628
|
+
var Schema17 = Type18.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
629
|
+
var NAME10 = "adguard_get_blocked_services";
|
|
630
|
+
function createAdguardGetBlockedServicesTool(getClient2) {
|
|
631
|
+
return {
|
|
632
|
+
name: NAME10,
|
|
633
|
+
label: "adguard: get blocked services",
|
|
634
|
+
description: "Get the GLOBAL blocked-services list and weekly schedule via GET /control/blocked_services/get. Schedule day ranges are milliseconds-from-midnight.",
|
|
635
|
+
parameters: Schema17,
|
|
636
|
+
execute: async (_id, raw) => {
|
|
637
|
+
const args = raw;
|
|
638
|
+
const client = getClient2(args.instance);
|
|
639
|
+
const result = await client.get("/control/blocked_services/get");
|
|
640
|
+
return jsonToolResult(result);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// src/tools/adguard_get_dns_config.ts
|
|
646
|
+
import { Type as Type19 } from "@sinclair/typebox";
|
|
647
|
+
var Schema18 = Type19.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
648
|
+
var NAME11 = "adguard_get_dns_config";
|
|
649
|
+
function createAdguardGetDnsConfigTool(getClient2) {
|
|
650
|
+
return {
|
|
651
|
+
name: NAME11,
|
|
652
|
+
label: "adguard: get DNS config",
|
|
653
|
+
description: "Get the DNS server config via GET /control/dns_info (upstreams, bootstrap, cache, parallel resolution, blocking mode, etc).",
|
|
654
|
+
parameters: Schema18,
|
|
655
|
+
execute: async (_id, raw) => {
|
|
656
|
+
const args = raw;
|
|
657
|
+
const client = getClient2(args.instance);
|
|
658
|
+
const result = await client.get("/control/dns_info");
|
|
659
|
+
return jsonToolResult(result);
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/tools/adguard_get_safesearch_settings.ts
|
|
665
|
+
import { Type as Type20 } from "@sinclair/typebox";
|
|
666
|
+
var Schema19 = Type20.Object({ instance: InstanceArg }, { additionalProperties: false });
|
|
667
|
+
var NAME12 = "adguard_get_safesearch_settings";
|
|
668
|
+
function createAdguardGetSafesearchSettingsTool(getClient2) {
|
|
669
|
+
return {
|
|
670
|
+
name: NAME12,
|
|
671
|
+
label: "adguard: get safesearch settings",
|
|
672
|
+
description: "Get SafeSearch enabled state + per-engine flags via GET /control/safesearch/status.",
|
|
673
|
+
parameters: Schema19,
|
|
674
|
+
execute: async (_id, raw) => {
|
|
675
|
+
const args = raw;
|
|
676
|
+
const client = getClient2(args.instance);
|
|
677
|
+
const result = await client.get("/control/safesearch/status");
|
|
678
|
+
return jsonToolResult(result);
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
// src/tools/adguard_refresh_filter_lists.ts
|
|
684
|
+
import { Type as Type21 } from "@sinclair/typebox";
|
|
685
|
+
var Schema20 = Type21.Object({
|
|
686
|
+
instance: InstanceArg,
|
|
687
|
+
whitelist: Type21.Optional(Type21.Boolean({ description: "Refresh allowlist lists instead of blocklist lists. Default: false (refresh blocklists)." })),
|
|
688
|
+
confirm: Type21.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
689
|
+
}, { additionalProperties: false });
|
|
690
|
+
var NAME13 = "adguard_refresh_filter_lists";
|
|
691
|
+
function createAdguardRefreshFilterListsTool(getClient2) {
|
|
692
|
+
return {
|
|
693
|
+
name: NAME13,
|
|
694
|
+
label: "adguard: refresh filter lists",
|
|
695
|
+
description: "Force refresh subscribed filter lists immediately via POST /control/filtering/refresh. Returns the number of lists updated. Tier-2 write; requires confirm:true.",
|
|
696
|
+
parameters: Schema20,
|
|
697
|
+
execute: async (_id, raw) => {
|
|
698
|
+
assertConfirmedWrite(raw, NAME13);
|
|
699
|
+
const args = raw;
|
|
700
|
+
const client = getClient2(args.instance);
|
|
701
|
+
const result = await client.post("/control/filtering/refresh", { whitelist: args.whitelist === true });
|
|
702
|
+
return jsonToolResult(result);
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/tools/adguard_add_client.ts
|
|
708
|
+
import { Type as Type22 } from "@sinclair/typebox";
|
|
709
|
+
var SafeSearchSchema = Type22.Optional(Type22.Object({
|
|
710
|
+
enabled: Type22.Optional(Type22.Boolean()),
|
|
711
|
+
bing: Type22.Optional(Type22.Boolean()),
|
|
712
|
+
duckduckgo: Type22.Optional(Type22.Boolean()),
|
|
713
|
+
ecosia: Type22.Optional(Type22.Boolean()),
|
|
714
|
+
google: Type22.Optional(Type22.Boolean()),
|
|
715
|
+
pixabay: Type22.Optional(Type22.Boolean()),
|
|
716
|
+
yandex: Type22.Optional(Type22.Boolean()),
|
|
717
|
+
youtube: Type22.Optional(Type22.Boolean())
|
|
718
|
+
}, { additionalProperties: false }));
|
|
719
|
+
var Schema21 = Type22.Object({
|
|
720
|
+
instance: InstanceArg,
|
|
721
|
+
name: Type22.String({ description: "Client display name (must be unique on this instance)." }),
|
|
722
|
+
ids: Type22.Array(Type22.String(), { minItems: 1, description: "Identifier(s) for this client: IP, MAC, ClientID, or CIDR. At least one required." }),
|
|
723
|
+
use_global_settings: Type22.Optional(Type22.Boolean()),
|
|
724
|
+
filtering_enabled: Type22.Optional(Type22.Boolean()),
|
|
725
|
+
safebrowsing_enabled: Type22.Optional(Type22.Boolean()),
|
|
726
|
+
parental_enabled: Type22.Optional(Type22.Boolean()),
|
|
727
|
+
safe_search: SafeSearchSchema,
|
|
728
|
+
use_global_blocked_services: Type22.Optional(Type22.Boolean()),
|
|
729
|
+
blocked_services: Type22.Optional(Type22.Array(Type22.String())),
|
|
730
|
+
blocked_services_schedule: Type22.Optional(Type22.Object({}, { additionalProperties: true })),
|
|
731
|
+
upstreams: Type22.Optional(Type22.Array(Type22.String())),
|
|
732
|
+
tags: Type22.Optional(Type22.Array(Type22.String())),
|
|
733
|
+
ignore_querylog: Type22.Optional(Type22.Boolean()),
|
|
734
|
+
ignore_statistics: Type22.Optional(Type22.Boolean()),
|
|
735
|
+
upstreams_cache_enabled: Type22.Optional(Type22.Boolean()),
|
|
736
|
+
upstreams_cache_size: Type22.Optional(Type22.Number()),
|
|
737
|
+
confirm: Type22.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
738
|
+
}, { additionalProperties: false });
|
|
739
|
+
var NAME14 = "adguard_add_client";
|
|
740
|
+
var CLIENT_BODY_FIELDS = [
|
|
741
|
+
"name",
|
|
742
|
+
"ids",
|
|
743
|
+
"use_global_settings",
|
|
744
|
+
"filtering_enabled",
|
|
745
|
+
"safebrowsing_enabled",
|
|
746
|
+
"parental_enabled",
|
|
747
|
+
"safe_search",
|
|
748
|
+
"use_global_blocked_services",
|
|
749
|
+
"blocked_services",
|
|
750
|
+
"blocked_services_schedule",
|
|
751
|
+
"upstreams",
|
|
752
|
+
"tags",
|
|
753
|
+
"ignore_querylog",
|
|
754
|
+
"ignore_statistics",
|
|
755
|
+
"upstreams_cache_enabled",
|
|
756
|
+
"upstreams_cache_size"
|
|
757
|
+
];
|
|
758
|
+
function createAdguardAddClientTool(getClient2) {
|
|
759
|
+
return {
|
|
760
|
+
name: NAME14,
|
|
761
|
+
label: "adguard: add client",
|
|
762
|
+
description: "Register a new named client via POST /control/clients/add. Tier-2 write; requires confirm:true.",
|
|
763
|
+
parameters: Schema21,
|
|
764
|
+
execute: async (_id, raw) => {
|
|
765
|
+
assertConfirmedWrite(raw, NAME14);
|
|
766
|
+
const body = {};
|
|
767
|
+
for (const k of CLIENT_BODY_FIELDS) {
|
|
768
|
+
if (raw[k] !== void 0) body[k] = raw[k];
|
|
769
|
+
}
|
|
770
|
+
const client = getClient2(raw.instance);
|
|
771
|
+
await client.post("/control/clients/add", body);
|
|
772
|
+
return jsonToolResult({ added: true, name: body.name });
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
// src/tools/adguard_update_client.ts
|
|
778
|
+
import { Type as Type23 } from "@sinclair/typebox";
|
|
779
|
+
var Schema22 = Type23.Object({
|
|
780
|
+
instance: InstanceArg,
|
|
781
|
+
name: Type23.String({ description: "Current name of the client to update (used to find the existing record)." }),
|
|
782
|
+
data: Type23.Object({}, { additionalProperties: true, description: "Full new Client object (AGH replaces the record; this is NOT a partial merge). Include name (new), ids, and any per-client settings to preserve." }),
|
|
783
|
+
confirm: Type23.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
784
|
+
}, { additionalProperties: false });
|
|
785
|
+
var NAME15 = "adguard_update_client";
|
|
786
|
+
function createAdguardUpdateClientTool(getClient2) {
|
|
787
|
+
return {
|
|
788
|
+
name: NAME15,
|
|
789
|
+
label: "adguard: update client",
|
|
790
|
+
description: "Update an existing named client via POST /control/clients/update. Body is nested {name, data} where data replaces the full client record. Tier-2 write; requires confirm:true.",
|
|
791
|
+
parameters: Schema22,
|
|
792
|
+
execute: async (_id, raw) => {
|
|
793
|
+
assertConfirmedWrite(raw, NAME15);
|
|
794
|
+
const args = raw;
|
|
795
|
+
const client = getClient2(args.instance);
|
|
796
|
+
await client.post("/control/clients/update", { name: args.name, data: args.data });
|
|
797
|
+
return jsonToolResult({ updated: true, name: args.name });
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// src/tools/adguard_set_blocked_services.ts
|
|
803
|
+
import { Type as Type24 } from "@sinclair/typebox";
|
|
804
|
+
var DayRange = Type24.Object({
|
|
805
|
+
start: Type24.Union([Type24.Number(), Type24.String()], { description: "Milliseconds from midnight (0-86400000) or HH:MM string." }),
|
|
806
|
+
end: Type24.Union([Type24.Number(), Type24.String()], { description: "Milliseconds from midnight (0-86400000) or HH:MM string." })
|
|
807
|
+
}, { additionalProperties: false });
|
|
808
|
+
var ScheduleSchema = Type24.Optional(Type24.Object({
|
|
809
|
+
time_zone: Type24.Optional(Type24.String()),
|
|
810
|
+
sun: Type24.Optional(DayRange),
|
|
811
|
+
mon: Type24.Optional(DayRange),
|
|
812
|
+
tue: Type24.Optional(DayRange),
|
|
813
|
+
wed: Type24.Optional(DayRange),
|
|
814
|
+
thu: Type24.Optional(DayRange),
|
|
815
|
+
fri: Type24.Optional(DayRange),
|
|
816
|
+
sat: Type24.Optional(DayRange)
|
|
817
|
+
}, { additionalProperties: false }));
|
|
818
|
+
var Schema23 = Type24.Object({
|
|
819
|
+
instance: InstanceArg,
|
|
820
|
+
ids: Type24.Array(Type24.String(), { description: "Service IDs from the catalog (youtube, instagram, tiktok, ...). Empty array clears global blocks." }),
|
|
821
|
+
schedule: ScheduleSchema,
|
|
822
|
+
confirm: Type24.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
823
|
+
}, { additionalProperties: false });
|
|
824
|
+
var NAME16 = "adguard_set_blocked_services";
|
|
825
|
+
function normalizeSchedule(schedule) {
|
|
826
|
+
if (!schedule) return void 0;
|
|
827
|
+
const out = {};
|
|
828
|
+
for (const [key, value] of Object.entries(schedule)) {
|
|
829
|
+
if (key === "time_zone") {
|
|
830
|
+
out[key] = value;
|
|
831
|
+
continue;
|
|
832
|
+
}
|
|
833
|
+
if (value && typeof value === "object" && "start" in value && "end" in value) {
|
|
834
|
+
const range = value;
|
|
835
|
+
out[key] = { start: hhmmToMs(range.start), end: hhmmToMs(range.end) };
|
|
836
|
+
} else {
|
|
837
|
+
out[key] = value;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return out;
|
|
841
|
+
}
|
|
842
|
+
function createAdguardSetBlockedServicesTool(getClient2) {
|
|
843
|
+
return {
|
|
844
|
+
name: NAME16,
|
|
845
|
+
label: "adguard: set blocked services",
|
|
846
|
+
description: "Set the GLOBAL blocked-services list and optional weekly schedule via PUT /control/blocked_services/update. Accepts HH:MM strings or milliseconds for schedule times. Tier-2 write; requires confirm:true.",
|
|
847
|
+
parameters: Schema23,
|
|
848
|
+
execute: async (_id, raw) => {
|
|
849
|
+
assertConfirmedWrite(raw, NAME16);
|
|
850
|
+
const args = raw;
|
|
851
|
+
const client = getClient2(args.instance);
|
|
852
|
+
const body = { ids: args.ids };
|
|
853
|
+
const normalized = normalizeSchedule(args.schedule);
|
|
854
|
+
if (normalized) body.schedule = normalized;
|
|
855
|
+
await client.put("/control/blocked_services/update", body);
|
|
856
|
+
return jsonToolResult({ set: true, count: args.ids.length });
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/tools/adguard_toggle_safesearch.ts
|
|
862
|
+
import { Type as Type25 } from "@sinclair/typebox";
|
|
863
|
+
var Schema24 = Type25.Object({
|
|
864
|
+
instance: InstanceArg,
|
|
865
|
+
enabled: Type25.Boolean({ description: "Target SafeSearch state globally." }),
|
|
866
|
+
bing: Type25.Optional(Type25.Boolean()),
|
|
867
|
+
duckduckgo: Type25.Optional(Type25.Boolean()),
|
|
868
|
+
ecosia: Type25.Optional(Type25.Boolean()),
|
|
869
|
+
google: Type25.Optional(Type25.Boolean()),
|
|
870
|
+
pixabay: Type25.Optional(Type25.Boolean()),
|
|
871
|
+
yandex: Type25.Optional(Type25.Boolean()),
|
|
872
|
+
youtube: Type25.Optional(Type25.Boolean()),
|
|
873
|
+
confirm: Type25.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
874
|
+
}, { additionalProperties: false });
|
|
875
|
+
var NAME17 = "adguard_toggle_safesearch";
|
|
876
|
+
function createAdguardToggleSafesearchTool(getClient2) {
|
|
877
|
+
return {
|
|
878
|
+
name: NAME17,
|
|
879
|
+
label: "adguard: toggle safesearch",
|
|
880
|
+
description: "Enable or disable SafeSearch globally via PUT /control/safesearch/settings. Per-engine flags optional (default to all engines when enabling). Tier-2 write; requires confirm:true.",
|
|
881
|
+
parameters: Schema24,
|
|
882
|
+
execute: async (_id, raw) => {
|
|
883
|
+
assertConfirmedWrite(raw, NAME17);
|
|
884
|
+
const args = raw;
|
|
885
|
+
const enabled = args.enabled;
|
|
886
|
+
const engines = ["bing", "duckduckgo", "ecosia", "google", "pixabay", "yandex", "youtube"];
|
|
887
|
+
const body = { enabled };
|
|
888
|
+
for (const e of engines) {
|
|
889
|
+
if (!enabled) body[e] = false;
|
|
890
|
+
else if (args[e] !== void 0) body[e] = args[e];
|
|
891
|
+
else body[e] = true;
|
|
892
|
+
}
|
|
893
|
+
const client = getClient2(args.instance);
|
|
894
|
+
await client.put("/control/safesearch/settings", body);
|
|
895
|
+
return jsonToolResult({ set: true, enabled });
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// src/tools/adguard_toggle_safebrowsing.ts
|
|
901
|
+
import { Type as Type26 } from "@sinclair/typebox";
|
|
902
|
+
var Schema25 = Type26.Object({
|
|
903
|
+
instance: InstanceArg,
|
|
904
|
+
enabled: Type26.Boolean({ description: "Target SafeBrowsing state." }),
|
|
905
|
+
confirm: Type26.Boolean({ description: "Must be true. Tier-2 safe-write gate." })
|
|
906
|
+
}, { additionalProperties: false });
|
|
907
|
+
var NAME18 = "adguard_toggle_safebrowsing";
|
|
908
|
+
function createAdguardToggleSafebrowsingTool(getClient2) {
|
|
909
|
+
return {
|
|
910
|
+
name: NAME18,
|
|
911
|
+
label: "adguard: toggle safebrowsing",
|
|
912
|
+
description: "Enable or disable AGH SafeBrowsing via POST /control/safebrowsing/enable or /disable. Tier-2 write; requires confirm:true.",
|
|
913
|
+
parameters: Schema25,
|
|
914
|
+
execute: async (_id, raw) => {
|
|
915
|
+
assertConfirmedWrite(raw, NAME18);
|
|
916
|
+
const args = raw;
|
|
917
|
+
const client = getClient2(args.instance);
|
|
918
|
+
const path = args.enabled ? "/control/safebrowsing/enable" : "/control/safebrowsing/disable";
|
|
919
|
+
await client.post(path, void 0);
|
|
920
|
+
return jsonToolResult({ set: true, enabled: args.enabled });
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
// src/tools/adguard_delete_client.ts
|
|
926
|
+
import { Type as Type27 } from "@sinclair/typebox";
|
|
927
|
+
var Schema26 = Type27.Object({
|
|
928
|
+
instance: InstanceArg,
|
|
929
|
+
name: Type27.String({ description: "Name of the configured client to remove." }),
|
|
930
|
+
confirm: Type27.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
|
|
931
|
+
destructive: Type27.Boolean({ description: "Must be true. Tier-3 destructive gate (deleting a client drops per-client rules and stats)." })
|
|
932
|
+
}, { additionalProperties: false });
|
|
933
|
+
var NAME19 = "adguard_delete_client";
|
|
934
|
+
function createAdguardDeleteClientTool(getClient2) {
|
|
935
|
+
return {
|
|
936
|
+
name: NAME19,
|
|
937
|
+
label: "adguard: delete client",
|
|
938
|
+
description: "Remove a configured named client via POST /control/clients/delete. Tier-3 destructive; per-client rules and per-client filtering settings are lost. Requires confirm:true and destructive:true.",
|
|
939
|
+
parameters: Schema26,
|
|
940
|
+
execute: async (_id, raw) => {
|
|
941
|
+
assertDestructive(raw, NAME19);
|
|
942
|
+
const args = raw;
|
|
943
|
+
const client = getClient2(args.instance);
|
|
944
|
+
await client.post("/control/clients/delete", { name: args.name });
|
|
945
|
+
return jsonToolResult({ deleted: true, name: args.name });
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// src/tools/adguard_clear_query_log.ts
|
|
951
|
+
import { Type as Type28 } from "@sinclair/typebox";
|
|
952
|
+
var Schema27 = Type28.Object({
|
|
953
|
+
instance: InstanceArg,
|
|
954
|
+
confirm: Type28.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
|
|
955
|
+
destructive: Type28.Boolean({ description: "Must be true. Tier-3 destructive gate (the query log is gone after this)." })
|
|
956
|
+
}, { additionalProperties: false });
|
|
957
|
+
var NAME20 = "adguard_clear_query_log";
|
|
958
|
+
function createAdguardClearQueryLogTool(getClient2) {
|
|
959
|
+
return {
|
|
960
|
+
name: NAME20,
|
|
961
|
+
label: "adguard: clear query log",
|
|
962
|
+
description: "Wipe the AGH DNS query log via POST /control/querylog_clear (underscore endpoint). Tier-3 destructive; requires confirm:true and destructive:true.",
|
|
963
|
+
parameters: Schema27,
|
|
964
|
+
execute: async (_id, raw) => {
|
|
965
|
+
assertDestructive(raw, NAME20);
|
|
966
|
+
const args = raw;
|
|
967
|
+
const client = getClient2(args.instance);
|
|
968
|
+
await client.post("/control/querylog_clear", void 0);
|
|
969
|
+
return jsonToolResult({ cleared: true });
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
// src/tools/adguard_reset_stats.ts
|
|
975
|
+
import { Type as Type29 } from "@sinclair/typebox";
|
|
976
|
+
var Schema28 = Type29.Object({
|
|
977
|
+
instance: InstanceArg,
|
|
978
|
+
confirm: Type29.Boolean({ description: "Must be true. Tier-3 destructive gate." }),
|
|
979
|
+
destructive: Type29.Boolean({ description: "Must be true. Tier-3 destructive gate (stats history is zeroed)." })
|
|
980
|
+
}, { additionalProperties: false });
|
|
981
|
+
var NAME21 = "adguard_reset_stats";
|
|
982
|
+
function createAdguardResetStatsTool(getClient2) {
|
|
983
|
+
return {
|
|
984
|
+
name: NAME21,
|
|
985
|
+
label: "adguard: reset stats",
|
|
986
|
+
description: "Zero out the AGH stats window via POST /control/stats_reset (underscore endpoint). Tier-3 destructive; requires confirm:true and destructive:true.",
|
|
987
|
+
parameters: Schema28,
|
|
988
|
+
execute: async (_id, raw) => {
|
|
989
|
+
assertDestructive(raw, NAME21);
|
|
990
|
+
const args = raw;
|
|
991
|
+
const client = getClient2(args.instance);
|
|
992
|
+
await client.post("/control/stats_reset", void 0);
|
|
993
|
+
return jsonToolResult({ reset: true });
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// src/tools/index.ts
|
|
999
|
+
function buildAllTools(getClient2) {
|
|
1000
|
+
return [
|
|
1001
|
+
// 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),
|
|
1013
|
+
// 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),
|
|
1026
|
+
// Tier 3: destructive (confirm: true + destructive: true)
|
|
1027
|
+
createAdguardReplaceUserRulesTool(getClient2),
|
|
1028
|
+
createAdguardToggleProtectionTool(getClient2),
|
|
1029
|
+
createAdguardDeleteClientTool(getClient2),
|
|
1030
|
+
createAdguardClearQueryLogTool(getClient2),
|
|
1031
|
+
createAdguardResetStatsTool(getClient2)
|
|
1032
|
+
];
|
|
1033
|
+
}
|
|
1034
|
+
|
|
580
1035
|
// mcp-server.ts
|
|
581
1036
|
var cfg = resolveInstances(process.env);
|
|
582
1037
|
for (const inst of Object.values(cfg.instances)) {
|
|
@@ -585,25 +1040,9 @@ for (const inst of Object.values(cfg.instances)) {
|
|
|
585
1040
|
registerSecret(basicValue);
|
|
586
1041
|
}
|
|
587
1042
|
var getClient = (name) => new AdGuardClient(getInstanceConfig(cfg, name));
|
|
588
|
-
var tools =
|
|
589
|
-
createAdguardStatusTool(getClient),
|
|
590
|
-
createAdguardStatsTool(getClient),
|
|
591
|
-
createAdguardQueryLogTool(getClient),
|
|
592
|
-
createAdguardListFilterListsTool(getClient),
|
|
593
|
-
createAdguardListUserRulesTool(getClient),
|
|
594
|
-
createAdguardListClientsTool(getClient),
|
|
595
|
-
createAdguardListBlockedServicesCatalogTool(getClient),
|
|
596
|
-
createAdguardAddUserRuleTool(getClient),
|
|
597
|
-
createAdguardRemoveUserRuleTool(getClient),
|
|
598
|
-
createAdguardAddFilterListTool(getClient),
|
|
599
|
-
createAdguardRemoveFilterListTool(getClient),
|
|
600
|
-
createAdguardToggleFilterListTool(getClient),
|
|
601
|
-
createAdguardSetClientBlockedServicesTool(getClient),
|
|
602
|
-
createAdguardReplaceUserRulesTool(getClient),
|
|
603
|
-
createAdguardToggleProtectionTool(getClient)
|
|
604
|
-
];
|
|
1043
|
+
var tools = buildAllTools(getClient);
|
|
605
1044
|
var toolMap = new Map(tools.map((t) => [t.name, t]));
|
|
606
|
-
var server = new Server({ name: "adguard-mcp", version: "0.
|
|
1045
|
+
var server = new Server({ name: "adguard-mcp", version: "0.2.0" }, { capabilities: { tools: {} } });
|
|
607
1046
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
608
1047
|
tools: tools.map((t) => ({ name: t.name, description: t.description, inputSchema: t.parameters }))
|
|
609
1048
|
}));
|
|
@@ -621,3 +1060,6 @@ server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
|
621
1060
|
});
|
|
622
1061
|
var transport = new StdioServerTransport();
|
|
623
1062
|
await server.connect(transport);
|
|
1063
|
+
export {
|
|
1064
|
+
tools
|
|
1065
|
+
};
|