mcp-controld 0.1.0 → 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 +67 -3
- package/dist/client.js +9 -4
- package/dist/index.js +18 -7
- package/dist/tools-diagnostics.js +1 -1
- package/dist/tools-read.js +16 -17
- package/dist/tools.js +9 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -48,10 +48,60 @@ Everything comes from environment variables, supplied by your MCP client. The se
|
|
|
48
48
|
|
|
49
49
|
Splitting the tokens is the point: reads keep using a read-scoped credential even on a server that can write, so a read tool cannot mutate anything even if something goes wrong upstream of it.
|
|
50
50
|
|
|
51
|
+
### Every option, shown
|
|
52
|
+
|
|
53
|
+
This is the full `env` block with every variable set. Copy the lines you want and delete the rest. Nothing here is required except the first.
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
"env": {
|
|
57
|
+
"CONTROLD_API_TOKEN_READ": "YOUR_API_TOKEN",
|
|
58
|
+
"CONTROLD_API_TOKEN_WRITE": "YOUR_API_TOKEN",
|
|
59
|
+
"CONTROLD_ORG_ID": "1234567890",
|
|
60
|
+
"CONTROLD_API_BASE_URL": "https://api.controld.com"
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The same thing in TOML, for Codex CLI:
|
|
65
|
+
|
|
66
|
+
```toml
|
|
67
|
+
[mcp_servers.controld.env]
|
|
68
|
+
CONTROLD_API_TOKEN_READ = "YOUR_API_TOKEN"
|
|
69
|
+
CONTROLD_API_TOKEN_WRITE = "YOUR_API_TOKEN"
|
|
70
|
+
CONTROLD_ORG_ID = "1234567890"
|
|
71
|
+
CONTROLD_API_BASE_URL = "https://api.controld.com"
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
And on the Claude Code command line:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
claude mcp add controld \
|
|
78
|
+
-e CONTROLD_API_TOKEN_READ=YOUR_API_TOKEN \
|
|
79
|
+
-e CONTROLD_API_TOKEN_WRITE=YOUR_API_TOKEN \
|
|
80
|
+
-e CONTROLD_ORG_ID=1234567890 \
|
|
81
|
+
-- npx -y mcp-controld
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Do not copy that block whole. Each optional line has a reason to leave it out:
|
|
85
|
+
|
|
86
|
+
- **`CONTROLD_API_TOKEN_WRITE`** turns on 21 tools that can change your DNS. Leave it out until you want that.
|
|
87
|
+
- **`CONTROLD_ORG_ID`** only applies to organization accounts. It sends an org header on every request, and a personal account rejects it.
|
|
88
|
+
- **`CONTROLD_API_BASE_URL`** is shown set to its own default, so including it changes nothing. It is there so you know the format if you ever need to point at a proxy.
|
|
89
|
+
|
|
90
|
+
Using the older single token instead of the pair looks like this:
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
"env": {
|
|
94
|
+
"CONTROLD_API_TOKEN": "YOUR_API_TOKEN",
|
|
95
|
+
"CONTROLD_ENABLE_WRITES": "1"
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
51
99
|
## Setup
|
|
52
100
|
|
|
53
101
|
There is nothing to install and no setup command to run. Point your MCP client at `npx mcp-controld` and it fetches and starts the server for you.
|
|
54
102
|
|
|
103
|
+
Every example below sets up **read-only** access, using one token. That is the safe default and it cannot change anything in your account. For the version with every option filled in, see [every option, shown](#every-option-shown) above.
|
|
104
|
+
|
|
55
105
|
### Claude Code
|
|
56
106
|
|
|
57
107
|
```sh
|
|
@@ -123,7 +173,9 @@ npm install
|
|
|
123
173
|
|
|
124
174
|
## Turning on write tools
|
|
125
175
|
|
|
126
|
-
|
|
176
|
+
There are two tokens, not one. The read token is required and signs every GET. The write token is optional and signs everything that changes your account. Keeping them separate means a read tool cannot mutate anything, even on a server that is allowed to write.
|
|
177
|
+
|
|
178
|
+
Create a second, write-scoped token in the Control D dashboard, then add it alongside the first:
|
|
127
179
|
|
|
128
180
|
```json
|
|
129
181
|
"env": {
|
|
@@ -134,6 +186,16 @@ Add a write token. That is the whole switch:
|
|
|
134
186
|
|
|
135
187
|
With no write token the write tools do not exist. Your client cannot list them and a prompt cannot call them, so a bad prompt cannot change your DNS setup.
|
|
136
188
|
|
|
189
|
+
## Protocol support
|
|
190
|
+
|
|
191
|
+
The server speaks MCP 2026-07-28 and every older revision from 2024-10-07 to 2025-11-25, on the same command. Your client picks the revision when it connects. There is nothing to configure.
|
|
192
|
+
|
|
193
|
+
On connect the server sends short instructions: start with `controld_list_profiles`, then `controld_get_profile_config` with section `all`.
|
|
194
|
+
|
|
195
|
+
A failed tool call returns a normal result with `isError: true` and a short plain-text message. When Control D rejects a request, the message is Control D's own text followed by the HTTP status and the Control D error code, for example `This profile does not exist (HTTP 404, code 40401)`. A bad argument gets an input validation message that names the argument. Tokens never appear in that text. Calling a tool name that does not exist is rejected with JSON-RPC error -32602.
|
|
196
|
+
|
|
197
|
+
Every tool carries MCP annotations. The 13 read and diagnostic tools have `readOnlyHint: true`. Write tools have `readOnlyHint: false`. The delete tools, `controld_deauthorize_ips`, and `controld_request_write` also have `destructiveHint: true`.
|
|
198
|
+
|
|
137
199
|
## Tool reference
|
|
138
200
|
|
|
139
201
|
Profile, device, access, and log tools accept an optional `sub_org_id` when you are acting on a sub-organization.
|
|
@@ -209,7 +271,7 @@ The two escape hatches, `controld_request_read` and `controld_request_write`, ex
|
|
|
209
271
|
- Paths are host-relative and validated. A path such as `//example.com/x` cannot retarget the request at another host. The CSV export checks the hostname before attaching credentials, so the token only ever goes to Control D or to a host you configured yourself in `CONTROLD_API_BASE_URL`.
|
|
210
272
|
- Tool output is capped at 1 MiB, with a truncation notice, so a huge response cannot flood your client's context.
|
|
211
273
|
- Every request has a timeout, so a hung API call cannot stall your session. Only GET is ever retried. A write is never replayed, because a failure can arrive after the change already took effect.
|
|
212
|
-
-
|
|
274
|
+
- Every published version is built from source and gated on the full test suite at publish time, so a release cannot contain a stale build or a failing test.
|
|
213
275
|
|
|
214
276
|
Found a security problem? See [SECURITY.md](SECURITY.md).
|
|
215
277
|
|
|
@@ -221,7 +283,9 @@ Found a security problem? See [SECURITY.md](SECURITY.md).
|
|
|
221
283
|
|
|
222
284
|
**A write fails with a permission error.** The token in `CONTROLD_API_TOKEN_WRITE` is read-scoped. The server cannot tell the two apart, so Control D rejects it at request time instead. Create a write token in the dashboard.
|
|
223
285
|
|
|
224
|
-
**Organization tools return an error.** Personal accounts have no organization. Those endpoints only work on org accounts.
|
|
286
|
+
**Organization tools return an error.** Personal accounts have no organization. Those endpoints only work on org accounts, and on a personal account they fail with a 404 (code 40401).
|
|
287
|
+
|
|
288
|
+
**`This token does not have access to this endpoint (HTTP 403, code 40301)`.** Control D sends this for a path that does not exist, too, not only for a token without access. If you called `controld_request_read` or `controld_request_write`, check the path first. The same token still works for any path that exists.
|
|
225
289
|
|
|
226
290
|
## Development
|
|
227
291
|
|
package/dist/client.js
CHANGED
|
@@ -241,10 +241,15 @@ export function createControlDClient(options = {}) {
|
|
|
241
241
|
const message = typeof apiError?.message === "string"
|
|
242
242
|
? apiError.message
|
|
243
243
|
: "Control D API request failed.";
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
244
|
+
const code = typeof apiError?.code === "string" || typeof apiError?.code === "number"
|
|
245
|
+
? apiError.code
|
|
246
|
+
: undefined;
|
|
247
|
+
// Status and code in the text: Control D answers an unknown path with
|
|
248
|
+
// 403 / 40301 "no access", which reads like a token problem without them.
|
|
249
|
+
const detail = code === undefined ? `HTTP ${response.status}` : `HTTP ${response.status}, code ${code}`;
|
|
250
|
+
const error = new Error(`${message} (${detail})`);
|
|
251
|
+
if (code !== undefined)
|
|
252
|
+
error.code = code;
|
|
248
253
|
throw error;
|
|
249
254
|
}
|
|
250
255
|
if (!response.ok)
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
4
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
5
|
+
import { createControlDClient, redact, resolveConfig } from "./client.js";
|
|
6
|
+
import { INSTRUCTIONS, registerTools } from "./tools.js";
|
|
7
|
+
// package.json ships in the npm tarball, so `npm version` is the only place to bump.
|
|
8
|
+
const { version } = createRequire(import.meta.url)("../package.json");
|
|
6
9
|
let config;
|
|
7
10
|
let client;
|
|
8
11
|
try {
|
|
@@ -14,6 +17,14 @@ catch (error) {
|
|
|
14
17
|
console.error(error instanceof Error ? error.message : String(error));
|
|
15
18
|
process.exit(1);
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
// serveStdio may build more than one server per process (a probe it throws
|
|
21
|
+
// away, then the real one), so keep state at module level, not on the server.
|
|
22
|
+
function buildServer() {
|
|
23
|
+
const server = new McpServer({ name: "mcp-controld", version }, { instructions: INSTRUCTIONS });
|
|
24
|
+
registerTools(server, client, config.writeToken !== undefined);
|
|
25
|
+
return server;
|
|
26
|
+
}
|
|
27
|
+
// Serves protocol 2026-07-28 and the 2024-10-07 to 2025-11-25 revisions.
|
|
28
|
+
serveStdio(buildServer, {
|
|
29
|
+
onerror: (error) => console.error(`mcp-controld transport error: ${redact(error.message, [config.readToken, config.writeToken])}`),
|
|
30
|
+
});
|
|
@@ -30,7 +30,7 @@ export const diagnosticsTools = [
|
|
|
30
30
|
defineTool({
|
|
31
31
|
name: "controld_export_dns_query_logs",
|
|
32
32
|
config: {
|
|
33
|
-
description: "
|
|
33
|
+
description: "Export DNS query logs as CSV for a bounded time window. Requires Full Analytics on the device. Works on personal and organization accounts.",
|
|
34
34
|
inputSchema: z.object({
|
|
35
35
|
analytics_endpoint_id: analyticsEndpointId.optional().describe("Analytics instance endpoint ID, not a hostname or URL. Omitted: auto-discovered from the account's stats_endpoint."),
|
|
36
36
|
start_time: rfc3339.describe("RFC 3339 start timestamp."),
|
package/dist/tools-read.js
CHANGED
|
@@ -22,22 +22,21 @@ const profileConfigInput = z.object({
|
|
|
22
22
|
folder_id: nonEmptyString.optional().describe("Rule folder ID. Used only when section is rules; omit or pass 0 for the root folder."),
|
|
23
23
|
...subOrgInput,
|
|
24
24
|
}).strict();
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
]);
|
|
25
|
+
// One flat object, not a union: a top-level oneOf leaves hosts and models with
|
|
26
|
+
// no `properties` to read. The refine keeps the union's rules.
|
|
27
|
+
const catalogInput = z.object({
|
|
28
|
+
catalog: z.enum([
|
|
29
|
+
"profile_options",
|
|
30
|
+
"device_types",
|
|
31
|
+
"service_categories",
|
|
32
|
+
"services",
|
|
33
|
+
"proxies",
|
|
34
|
+
"analytics_levels",
|
|
35
|
+
"analytics_regions",
|
|
36
|
+
]).describe("Catalog to list. 'services' also needs category."),
|
|
37
|
+
category: nonEmptyString.optional()
|
|
38
|
+
.describe("Service category ID from the service_categories catalog. Required with catalog 'services', not allowed otherwise."),
|
|
39
|
+
}).strict().refine((input) => (input.catalog === "services") === (input.category !== undefined), { message: "category is required with catalog 'services' and not allowed with any other catalog.", path: ["category"] });
|
|
41
40
|
export const readTools = [
|
|
42
41
|
defineTool({
|
|
43
42
|
name: "controld_list_profiles",
|
|
@@ -84,7 +83,7 @@ export const readTools = [
|
|
|
84
83
|
},
|
|
85
84
|
handler: (client, input) => {
|
|
86
85
|
const path = input.catalog === "services"
|
|
87
|
-
? `/services/categories/${segment(input.category)}`
|
|
86
|
+
? `/services/categories/${segment(input.category ?? "")}`
|
|
88
87
|
: {
|
|
89
88
|
profile_options: "/profiles/options",
|
|
90
89
|
device_types: "/devices/types",
|
package/dist/tools.js
CHANGED
|
@@ -3,6 +3,15 @@ import { diagnosticsTools } from "./tools-diagnostics.js";
|
|
|
3
3
|
import { readTools } from "./tools-read.js";
|
|
4
4
|
import { writeTools } from "./tools-write.js";
|
|
5
5
|
import { textResult } from "./tools-shared.js";
|
|
6
|
+
/** Sent to the client on connect. Keep every claim here true to the code below. */
|
|
7
|
+
export const INSTRUCTIONS = [
|
|
8
|
+
"Control D DNS management. Start with controld_list_profiles, then controld_get_profile_config with section \"all\" for one profile.",
|
|
9
|
+
"Every tool with readOnlyHint true only reads. Write tools exist only when the server has a write credential.",
|
|
10
|
+
"A failed call returns isError true and a short plain-text message. Control D failures end with the HTTP status and Control D code, for example \"(HTTP 404, code 40401)\".",
|
|
11
|
+
"HTTP 403 code 40301 \"This token does not have access to this endpoint\" can also mean the path does not exist. Check the path before you blame the token.",
|
|
12
|
+
"Organization tools fail on a personal account. That is expected, not a token problem.",
|
|
13
|
+
"controld_request_read and controld_request_write are escape hatches for undocumented paths. Use a named tool first.",
|
|
14
|
+
].join("\n");
|
|
6
15
|
function registerTool(server, client, tool) {
|
|
7
16
|
server.registerTool(tool.name, tool.config, async (args) => {
|
|
8
17
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-controld",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "MCP server for the Control D API. Manage DNS profiles, filters, rules, and devices from any MCP client.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mcp",
|
|
@@ -36,13 +36,15 @@
|
|
|
36
36
|
"scripts": {
|
|
37
37
|
"build": "tsc -p tsconfig.json",
|
|
38
38
|
"prepare": "tsc -p tsconfig.json",
|
|
39
|
+
"prepublishOnly": "npm test",
|
|
39
40
|
"test": "tsx --test"
|
|
40
41
|
},
|
|
41
42
|
"dependencies": {
|
|
42
|
-
"@modelcontextprotocol/
|
|
43
|
+
"@modelcontextprotocol/server": "^2.1.0",
|
|
43
44
|
"zod": "^4.4.3"
|
|
44
45
|
},
|
|
45
46
|
"devDependencies": {
|
|
47
|
+
"@modelcontextprotocol/client": "^2.1.0",
|
|
46
48
|
"@types/node": "^22.20.1",
|
|
47
49
|
"tsx": "^4.23.12",
|
|
48
50
|
"typescript": "^7.0.2"
|