@solomonneas/adguard-mcp 0.2.0 → 0.3.2

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 CHANGED
@@ -1,10 +1,75 @@
1
- # adguard-mcp
1
+ <!-- content-guard: allow private-ipv4 file -->
2
+ <p align="center">
3
+ <img src="docs/assets/adguardctrl-social-preview.jpg" alt="adguardctrl banner" width="900">
4
+ </p>
2
5
 
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`.
6
+ <p align="center">
7
+ <a href="https://lidless.dev"><img src="docs/assets/marks/adguardctrl-circle.png" width="48" alt="Lidless Labs"></a>
8
+ </p>
9
+
10
+ <h1 align="center">adguardctrl</h1>
11
+
12
+ <p align="center">
13
+ <strong>An operator control CLI for AdGuard Home, with an MCP adapter for assistant workflows and back-compatible launchers.</strong>
14
+ </p>
15
+
16
+ <p align="center">
17
+ <a href="https://lidless.dev/adguard-mcp"><strong>Website</strong></a>
18
+ &nbsp;&middot;&nbsp;
19
+ <a href="#quickstart"><strong>Quickstart</strong></a>
20
+ </p>
21
+
22
+ <p align="center">
23
+ <img src="https://shieldcn.dev/github/ci/lidless-labs/adguardctrl.svg?branch=main&workflow=ci.yml" alt="CI status">
24
+ <img src="https://shieldcn.dev/npm/@solomonneas/adguard-mcp.svg" alt="npm version">
25
+ <img src="https://shieldcn.dev/badge/license-MIT-green.svg" alt="MIT license">
26
+ </p>
27
+
28
+ `adguardctrl` is an operator control CLI for AdGuard Home, the self-hosted DNS sinkhole. It gives shell, cron, CI, and assistant workflows one typed control surface for inspecting network-wide DNS filtering across one or more boxes. The npm package remains `@solomonneas/adguard-mcp` for compatibility and still ships the back-compatible `adguard-mcp` bin; new MCP launchers can start the adapter with `adguardctrl mcp`.
29
+
30
+ ## What it does
31
+
32
+ `adguardctrl` speaks the AdGuard Home API across one or more instances, plus optional AdGuardHome Sync status and control. The direct CLI is read-only today, covering server status, stats, the DNS query log, filter lists, named clients, DNS rewrites, DNS and TLS config, DHCP status, and a `check-host` lookup that shows exactly what AdGuard would do with a hostname.
33
+
34
+ For assistant clients, `adguardctrl mcp` starts the stdio MCP adapter used by Claude Desktop, Claude Code, Codex CLI, OpenClaw, Hermes, and other Model Context Protocol clients. That adapter keeps the original `adguard-mcp` tool surface and safety model: reads are open, writes require an explicit `confirm: true`, and destructive operations additionally require `destructive: true`, so an agent cannot disable filtering or wipe rules on a hallucinated call.
35
+
36
+ ## Quickstart
37
+
38
+ Install globally:
39
+
40
+ ```
41
+ npm install -g @solomonneas/adguard-mcp
42
+ ```
43
+
44
+ Or run via npx with no install:
45
+
46
+ ```
47
+ npx -y @solomonneas/adguard-mcp
48
+ ```
49
+
50
+ Then use `adguardctrl` from your shell, or wire the package into an MCP client. The minimal config for any client that speaks the standard `mcpServers` shape (Claude Desktop, Claude Code):
51
+
52
+ ```json
53
+ {
54
+ "mcpServers": {
55
+ "adguard": {
56
+ "command": "npx",
57
+ "args": ["-y", "@solomonneas/adguard-mcp"],
58
+ "env": {
59
+ "ADGUARD_PRIMARY_URL": "http://192.0.2.10",
60
+ "ADGUARD_PRIMARY_USERNAME": "admin",
61
+ "ADGUARD_PRIMARY_PASSWORD": "your-password"
62
+ }
63
+ }
64
+ }
65
+ }
66
+ ```
67
+
68
+ Once connected, ask your client to call `adguard_status` to confirm it can reach the box. Reads work immediately; writes need the `confirm: true` flag and destructive ops also need `destructive: true`.
4
69
 
5
70
  ## Tools
6
71
 
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`.
72
+ **Reads (14):** `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`, `adguard_sync_status`, `adguard_sync_health`, `adguard_sync_logs`.
8
73
 
9
74
  | Tool | Description |
10
75
  |---|---|
@@ -19,8 +84,11 @@ MCP server exposing AdGuard Home read/write tools across one or more instances.
19
84
  | `adguard_get_blocked_services` | Global blocked-services list + weekly schedule (`GET /control/blocked_services/get`). |
20
85
  | `adguard_get_dns_config` | DNS upstreams, bootstrap, cache, parallel resolution, blocking mode (`GET /control/dns_info`). |
21
86
  | `adguard_get_safesearch_settings` | SafeSearch enabled state + per-engine flags (`GET /control/safesearch/status`). |
87
+ | `adguard_sync_status` | AdGuardHome Sync origin/replica status (`GET /api/v1/status`). |
88
+ | `adguard_sync_health` | AdGuardHome Sync health check (`HEAD /healthz`). |
89
+ | `adguard_sync_logs` | AdGuardHome Sync in-memory logs (`GET /api/v1/logs`). |
22
90
 
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`.
91
+ **Safe writes (13, 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`, `adguard_sync_run`.
24
92
 
25
93
  | Tool | Description |
26
94
  |---|---|
@@ -36,8 +104,9 @@ MCP server exposing AdGuard Home read/write tools across one or more instances.
36
104
  | `adguard_set_blocked_services` | Set GLOBAL blocked services + optional weekly schedule; accepts HH:MM strings or ms (`PUT /control/blocked_services/update`). |
37
105
  | `adguard_toggle_safesearch` | Enable or disable SafeSearch globally with per-engine flags (`PUT /control/safesearch/settings`). |
38
106
  | `adguard_toggle_safebrowsing` | Enable or disable AGH SafeBrowsing (`POST /control/safebrowsing/enable` or `/disable`). |
107
+ | `adguard_sync_run` | Trigger AdGuardHome Sync immediately (`POST /api/v1/sync`). |
39
108
 
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`.
109
+ **Destructive (6, require `confirm: true` + `destructive: true`):** `adguard_replace_user_rules`, `adguard_toggle_protection`, `adguard_delete_client`, `adguard_clear_query_log`, `adguard_reset_stats`, `adguard_sync_clear_logs`.
41
110
 
42
111
  | Tool | Description |
43
112
  |---|---|
@@ -46,62 +115,79 @@ MCP server exposing AdGuard Home read/write tools across one or more instances.
46
115
  | `adguard_delete_client` | Remove a configured named client; per-client rules and stats are lost (`POST /control/clients/delete`). |
47
116
  | `adguard_clear_query_log` | Wipe the DNS query log (`POST /control/querylog_clear`). |
48
117
  | `adguard_reset_stats` | Zero the stats window (`POST /control/stats_reset`). |
118
+ | `adguard_sync_clear_logs` | Clear AdGuardHome Sync in-memory logs (`POST /api/v1/clear-logs`). |
49
119
 
50
120
  ## Configuration
51
121
 
52
122
  Set per-instance env vars. At least one instance is required.
53
123
 
54
124
  ```
55
- ADGUARD_PRIMARY_URL=http://192.168.1.10
125
+ ADGUARD_PRIMARY_URL=http://192.0.2.10
56
126
  ADGUARD_PRIMARY_USERNAME=admin
57
127
  ADGUARD_PRIMARY_PASSWORD=<password>
58
128
 
59
129
  # Optional second instance:
60
- ADGUARD_SECONDARY_URL=http://192.168.1.11
130
+ ADGUARD_SECONDARY_URL=http://192.0.2.11
61
131
  ADGUARD_SECONDARY_USERNAME=admin
62
132
  ADGUARD_SECONDARY_PASSWORD=<password>
63
133
 
64
134
  # Optional: which instance is default when a tool omits the `instance` arg:
65
135
  ADGUARD_DEFAULT_INSTANCE=primary
136
+
137
+ # Optional: per-request HTTP timeout in milliseconds (default 30000; minimum 1000):
138
+ ADGUARD_REQUEST_TIMEOUT_MS=30000
66
139
  ```
67
140
 
68
141
  Instance names are derived from the env-var middle segment (case-insensitive). Add `ADGUARD_LIVINGROOM_URL/USERNAME/PASSWORD` and the MCP picks it up on next start.
69
142
 
70
143
  Every tool accepts optional `instance: "<name>"` to address a non-default box.
71
144
 
72
- ## Install
145
+ AdGuardHome Sync is optional and uses a separate env prefix so it does not collide with AdGuard Home instance names:
73
146
 
74
147
  ```
75
- npm install -g @solomonneas/adguard-mcp
148
+ ADGUARDHOME_SYNC_URL=http://192.0.2.10:8080
149
+
150
+ # Optional, only when the Sync API is configured with Basic auth:
151
+ ADGUARDHOME_SYNC_USERNAME=sync
152
+ ADGUARDHOME_SYNC_PASSWORD=<password>
76
153
  ```
77
154
 
78
- Or run via npx:
155
+ `ADGUARD_SYNC_URL/USERNAME/PASSWORD` is also accepted as an alias and is reserved for the Sync server, not an AdGuard Home instance named `sync`.
79
156
 
80
- ```
81
- npx -y @solomonneas/adguard-mcp
157
+ If neither Sync URL env var is set, Sync tools remain listed but return a clear config error when called.
158
+
159
+ ## CLI
160
+
161
+ `adguardctrl` is the package's primary operator entry point for shells, cron, and CI. It shares the `AdGuardClient` / `AdGuardSyncClient` core with the MCP adapter and reads the same env config. It exposes only the Tier-1 read tools; writes stay in the MCP/plugin surface behind the tier gates.
162
+
163
+ ```bash
164
+ npx @solomonneas/adguard-mcp@latest status
165
+ # or, installed globally:
166
+ adguardctrl status
167
+ adguardctrl stats
168
+ adguardctrl querylog --limit 20 --blocked-only
169
+ adguardctrl check-host youtube.com --client kid-tablet
170
+ adguardctrl clients list
171
+ adguardctrl filters list
172
+ adguardctrl rewrites list
173
+ adguardctrl dns-config
174
+ adguardctrl tls status # private key is redacted
175
+ adguardctrl sync health # exit 1 if Sync is not healthy (cron-friendly)
176
+ adguardctrl status --json # raw JSON for piping
177
+ adguardctrl status --instance secondary
82
178
  ```
83
179
 
84
- ## Setup
180
+ Run `adguardctrl help` for the full command and flag list. `--instance <name>` targets a non-default AdGuard Home box; `--json` emits raw JSON instead of the concise human-readable summary. Exit codes: `0` success, `1` runtime error (backend unreachable / call failed, and `sync health` when not healthy), `2` usage error (unknown command/flag or bad value).
85
181
 
86
- ### Claude Desktop
182
+ ### Starting the MCP server
87
183
 
88
- `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
184
+ `adguardctrl mcp` (or the back-compat `adguard-mcp` bin) starts the stdio MCP adapter. If a launcher referenced the file path `dist/mcp-server.js` directly, it keeps working; new launchers can point at `dist/mcp-bin.js` (or `dist/cli.js mcp`). Launchers that use the `adguard-mcp` bin name need no change.
89
185
 
90
- ```json
91
- {
92
- "mcpServers": {
93
- "adguard": {
94
- "command": "npx",
95
- "args": ["-y", "@solomonneas/adguard-mcp"],
96
- "env": {
97
- "ADGUARD_PRIMARY_URL": "http://192.168.1.10",
98
- "ADGUARD_PRIMARY_USERNAME": "admin",
99
- "ADGUARD_PRIMARY_PASSWORD": "your-password"
100
- }
101
- }
102
- }
103
- }
104
- ```
186
+ ## Setup per client
187
+
188
+ ### Claude Desktop
189
+
190
+ `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows): use the `mcpServers` block from [Quickstart](#quickstart).
105
191
 
106
192
  ### Claude Code
107
193
 
@@ -140,7 +226,7 @@ mcp_servers:
140
226
  command: npx
141
227
  args: ["-y", "@solomonneas/adguard-mcp"]
142
228
  env:
143
- ADGUARD_PRIMARY_URL: http://192.168.1.10
229
+ ADGUARD_PRIMARY_URL: http://192.0.2.10
144
230
  ADGUARD_PRIMARY_USERNAME: admin
145
231
  ADGUARD_PRIMARY_PASSWORD: your-password
146
232
  ```
@@ -155,7 +241,7 @@ command = "npx"
155
241
  args = ["-y", "@solomonneas/adguard-mcp"]
156
242
 
157
243
  [mcp_servers.adguard.env]
158
- ADGUARD_PRIMARY_URL = "http://192.168.1.10"
244
+ ADGUARD_PRIMARY_URL = "http://192.0.2.10"
159
245
  ADGUARD_PRIMARY_USERNAME = "admin"
160
246
  ADGUARD_PRIMARY_PASSWORD = "your-password"
161
247
  ```
@@ -166,6 +252,133 @@ ADGUARD_PRIMARY_PASSWORD = "your-password"
166
252
  - Tier 2 writes require an explicit `confirm: true` arg; the JSON schema documents this on every write tool.
167
253
  - Tier 3 destructive ops additionally require `destructive: true`. The model cannot disable protection or overwrite the rules block from a hallucinated tool call.
168
254
 
255
+ ## Why not just give the agent the AdGuard Home API?
256
+
257
+ - **The raw AdGuard Home API has no agent-safety layer.** Every endpoint is one call away, including the ones that disable all blocking or wipe your rules. The MCP adapter keeps reads open and gates writes behind `confirm: true` and destructive ops behind `destructive: true`, so a hallucinated tool call cannot silently break your network.
258
+ - **`curl` or a generic HTTP MCP server** would mean the model hand-builds request bodies, handles Basic auth, and remembers which AdGuard quirk applies (the nested `{name, data}` client body, milliseconds-from-midnight schedules, the `PUT` vs `POST` split). `adguardctrl` and its MCP adapter encode those as typed commands and tools, so the caller picks an intent, not an HTTP shape.
259
+ - **A single-instance integration** does not match a real homelab. `adguardctrl` resolves any number of instances from env vars by name and lets commands or MCP tools target a non-default box with one `instance` arg, plus optional AdGuardHome Sync control alongside.
260
+ - **Clicking the web dashboard** works, but not from inside an assistant and not across several boxes at once. This is the same control surface, available to the agent you already have open.
261
+
262
+ ## What adguardctrl is not
263
+
264
+ `adguardctrl` is not a hosted service, a replacement for the AdGuard Home dashboard, or an autonomous network manager.
265
+
266
+ It does not:
267
+
268
+ - install or manage background services automatically
269
+ - store or proxy your DNS traffic
270
+ - make any write without an explicit `confirm: true` flag from the caller
271
+ - perform a destructive operation without `confirm: true` and `destructive: true` together
272
+ - talk to AdGuard's hosted DNS product; it targets self-hosted AdGuard Home instances you run
273
+
274
+ ## HTTP mode
275
+
276
+ Run one process shared by multiple MCP clients, alongside the existing stdio mode:
277
+
278
+ ```sh
279
+ node dist/mcp-server.js --http
280
+ # Also: adguardctrl mcp --http or adguard-mcp --http
281
+ ```
282
+
283
+ Configure the usual `ADGUARD_<NAME>_URL`, `_USERNAME`, and `_PASSWORD` variables
284
+ and optional AdGuardHome Sync credentials on the server. Generate a separate
285
+ HTTP token with `openssl rand -hex 32`.
286
+
287
+ | Variable | Default | Purpose |
288
+ | --- | --- | --- |
289
+ | `ADGUARD_MCP_HTTP_TOKEN` | Required | Independent bearer credential, at least 32 characters |
290
+ | `ADGUARD_MCP_HTTP_HOST` | IPv4 loopback | Listener bind address. Wildcards (`0.0.0.0`, `::`, `[::]`) are refused |
291
+ | `ADGUARD_MCP_HTTP_PORT` | `3111` | TCP port, or `0` for a free port |
292
+
293
+ Startup rejects a missing or blank token, or a token equal to any configured
294
+ AdGuard Home or Sync username, password, credential pair, Base64 credential
295
+ pair, Basic authorization value, or URL userinfo credential. Sync aliases are
296
+ resolved using the existing `ADGUARDHOME_SYNC_*` / `ADGUARD_SYNC_*` precedence.
297
+ Token comparisons use SHA-256 digests and constant-time comparison. The token is
298
+ registered with the secret redactor.
299
+
300
+ The resolved listener address is printed to stderr. `/mcp` accepts Streamable
301
+ HTTP POST, GET, and DELETE with bearer authentication on every request.
302
+ `GET /healthz` requires no token and returns only `{"status":"ok"}`.
303
+ Host and Origin checks run before authentication. Host must match the bound host
304
+ or a loopback alias. A supplied Origin must be an HTTP or HTTPS loopback origin.
305
+ The listener limits bodies to 1 MiB, request receipt to 30 seconds, headers to 10 seconds,
306
+ and sessions to 128. Sessions idle for 30 minutes expire on a minute timer.
307
+ Active POST requests prevent idle expiry. An open SSE channel alone does not.
308
+ SIGTERM and SIGINT close the sessions and listener. Clients must initialize again
309
+ after expiry or restart.
310
+
311
+ Each session owns a fresh MCP server, tool objects, and request handlers. Write
312
+ gates have no pending approvals or process-wide write-enable flag: every call
313
+ requires `confirm:true`, plus `destructive:true` for destructive tools. A confirmed
314
+ call cannot authorize a later call or another session. There are no deferred tool
315
+ sets, client caches, or shared rate limiters. Only the secret masking registry is
316
+ shared. All clients with the token share the configured upstream privileges and
317
+ can modify the same upstream resources. Session IDs route connections and do not
318
+ identify separate users.
319
+
320
+ Keep the default loopback binding for local clients. Remote access needs a
321
+ trusted TLS proxy or tunnel and network access controls. This listener provides
322
+ no TLS, OAuth, browser CORS access, or per-client upstream accounts. Preserve the
323
+ allowed Host header through a proxy. A wildcard bind does not allow arbitrary
324
+ Host headers.
325
+
326
+ ### Claude Code
327
+
328
+ Add an HTTP entry under `mcpServers` in the client configuration:
329
+
330
+ ```json
331
+ {
332
+ "mcpServers": {
333
+ "adguard": {
334
+ "type": "http",
335
+ "url": "http://localhost:3111/mcp",
336
+ "headersHelper": "/path/to/helper ADGUARD_MCP_HTTP_TOKEN"
337
+ }
338
+ }
339
+ }
340
+ ```
341
+
342
+ The executable helper reads the named environment variable and prints an
343
+ Authorization JSON object. For example:
344
+
345
+ ```js
346
+ #!/usr/bin/env node
347
+ const token = process.env[process.argv[2]];
348
+ if (!token) process.exit(1);
349
+ console.log(JSON.stringify({ Authorization: `Bearer ${token}` }));
350
+ ```
351
+
352
+ Provide `ADGUARD_MCP_HTTP_TOKEN` to the helper through the client environment.
353
+ Keep the token out of client configuration files and version control.
354
+
355
+ ### Codex
356
+
357
+ ```toml
358
+ [mcp_servers.adguard]
359
+ url = "http://localhost:3111/mcp"
360
+ bearer_token_env_var = "ADGUARD_MCP_HTTP_TOKEN"
361
+ ```
362
+
363
+ Export the token in the Codex process environment. The URL selects Streamable
364
+ HTTP, with the bearer token supplied from the named variable.
365
+
366
+ ### systemd user service
367
+
368
+ [Example unit](docs/systemd/adguard-mcp-http.service) uses an installation under
369
+ `/opt/adguardctrl`. Adjust its paths before installing it. Its EnvironmentFile is
370
+ `%h/.config/adguard-mcp/http.env`. Create that file with mode `0600`, containing
371
+ the server's upstream configuration and HTTP token. The unit uses
372
+ `NoNewPrivileges=true`, `PrivateTmp=true`, and `UMask=0077`.
373
+
169
374
  ## License
170
375
 
171
- MIT
376
+ MIT. See [LICENSE](LICENSE).
377
+
378
+ ---
379
+
380
+ <p align="center"><a href="https://lidless.dev">Part of <strong>Lidless Labs</strong></a> &middot; the eye does not close</p>
381
+
382
+ <p align="center"><sub><strong>Homelab:</strong> <a href="https://github.com/lidless-labs/proxmox-mcp">proxmox-mcp</a> &middot; <a href="https://github.com/lidless-labs/immichctrl">immichctrl</a> &middot; <a href="https://github.com/lidless-labs/jellyctrl">jellyctrl</a> &middot; <a href="https://github.com/lidless-labs/proxguard">proxguard</a></sub></p>
383
+
384
+ <p align="center"><sub><a href="https://lidless.dev">All tools</a> &middot; <a href="https://github.com/lidless-labs">Lidless Labs on GitHub</a></sub></p>