mcp-controld 0.1.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.
@@ -0,0 +1,425 @@
1
+ import { z } from "zod";
2
+ import { apiPath, defineTool, destructiveAnnotations, nonEmptyString, segment, subOrgInput, writeAnnotations, } from "./tools-shared.js";
3
+ const integer = z.number().int();
4
+ const doCode = integer.min(0).max(3).describe("Rule action: 0 block, 1 bypass, 2 spoof, 3 redirect.");
5
+ const binaryStatus = z.union([z.literal(0), z.literal(1)]);
6
+ const formScalar = z.union([z.string(), z.number(), z.boolean()]);
7
+ const rawFormBody = z.record(z.string().min(1), z.union([formScalar, z.array(formScalar)]));
8
+ // Documented at PUT /organizations and POST /organizations/suborg. Both take the
9
+ // same field set; only the required list differs.
10
+ const organizationInput = {
11
+ contact_email: nonEmptyString.describe("Primary contact email for the organization."),
12
+ twofa_req: binaryStatus.describe("Require 2FA for members: 0 no, 1 yes."),
13
+ stats_endpoint: nonEmptyString.describe("Storage region PK. See controld_list_catalog with catalog 'analytics_regions'."),
14
+ address: z.string().optional().describe("Physical address."),
15
+ website: z.string().optional().describe("Website URL."),
16
+ contact_name: z.string().optional().describe("Name of the responsible contact."),
17
+ contact_phone: z.string().optional().describe("Contact phone number."),
18
+ parent_profile: nonEmptyString.optional().describe("Global profile PK enforced on all created devices."),
19
+ };
20
+ const deviceCreateInput = {
21
+ name: nonEmptyString,
22
+ client_count: nonEmptyString,
23
+ profile_id: nonEmptyString,
24
+ icon: nonEmptyString,
25
+ profile_id2: nonEmptyString.optional(),
26
+ stats: integer.min(0).max(2).optional(),
27
+ legacy_ipv4_status: binaryStatus.optional(),
28
+ learn_ip: binaryStatus.optional(),
29
+ restricted: binaryStatus.optional(),
30
+ desc: z.string().optional(),
31
+ ddns_status: binaryStatus.optional(),
32
+ ddns_subdomain: nonEmptyString.optional(),
33
+ ddns_ext_status: binaryStatus.optional(),
34
+ ddns_ext_host: nonEmptyString.optional(),
35
+ remap_device_id: nonEmptyString.optional(),
36
+ remap_client_id: nonEmptyString.optional(),
37
+ };
38
+ const deviceUpdateInput = {
39
+ name: nonEmptyString.optional(),
40
+ client_count: nonEmptyString.optional(),
41
+ profile_id: nonEmptyString.optional(),
42
+ profile_id2: nonEmptyString.optional(),
43
+ stats: integer.min(0).max(2).optional(),
44
+ legacy_ipv4_status: binaryStatus.optional(),
45
+ learn_ip: binaryStatus.optional(),
46
+ restricted: binaryStatus.optional(),
47
+ bump_tls: binaryStatus.optional(),
48
+ desc: z.string().optional(),
49
+ ddns_status: binaryStatus.optional(),
50
+ ddns_subdomain: nonEmptyString.optional(),
51
+ ddns_ext_host: nonEmptyString.optional(),
52
+ ddns_ext_status: binaryStatus.optional(),
53
+ status: integer.min(0).max(3).optional(),
54
+ ctrld_custom_config: z.string().optional(),
55
+ };
56
+ export const writeTools = [
57
+ defineTool({
58
+ name: "controld_create_profile",
59
+ config: {
60
+ description: "Create a blank Control D profile or clone an existing profile.",
61
+ inputSchema: z.object({
62
+ name: nonEmptyString,
63
+ clone_profile_id: nonEmptyString.optional(),
64
+ ...subOrgInput,
65
+ }).strict(),
66
+ annotations: writeAnnotations,
67
+ },
68
+ handler: (client, { sub_org_id, ...value }) => client.request("/profiles", {
69
+ method: "POST",
70
+ body: { encoding: "form", value },
71
+ subOrgId: sub_org_id,
72
+ }),
73
+ }),
74
+ defineTool({
75
+ name: "controld_update_profile",
76
+ config: {
77
+ description: "Rename a Control D profile or change its disable-until timestamp.",
78
+ inputSchema: z.object({
79
+ profile_id: nonEmptyString,
80
+ name: nonEmptyString.optional(),
81
+ disable_ttl: integer.min(0).optional(),
82
+ ...subOrgInput,
83
+ }).strict(),
84
+ annotations: writeAnnotations,
85
+ },
86
+ handler: (client, { profile_id, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}`, {
87
+ method: "PUT",
88
+ body: { encoding: "form", value },
89
+ subOrgId: sub_org_id,
90
+ }),
91
+ }),
92
+ defineTool({
93
+ name: "controld_delete_profile",
94
+ config: {
95
+ description: "Delete a Control D profile. The docs say only orphaned profiles delete successfully.",
96
+ inputSchema: z.object({ profile_id: nonEmptyString, ...subOrgInput }).strict(),
97
+ annotations: destructiveAnnotations,
98
+ },
99
+ handler: (client, { profile_id, sub_org_id }) => client.request(`/profiles/${segment(profile_id)}`, { method: "DELETE", subOrgId: sub_org_id }),
100
+ }),
101
+ defineTool({
102
+ name: "controld_set_profile_option",
103
+ config: {
104
+ description: "Enable, disable, or set the value of a Control D profile option.",
105
+ inputSchema: z.object({
106
+ profile_id: nonEmptyString,
107
+ name: nonEmptyString,
108
+ status: binaryStatus,
109
+ value: z.string().optional(),
110
+ ...subOrgInput,
111
+ }).strict(),
112
+ annotations: writeAnnotations,
113
+ },
114
+ handler: (client, { profile_id, name, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/options/${segment(name)}`, {
115
+ method: "PUT",
116
+ body: { encoding: "form", value },
117
+ subOrgId: sub_org_id,
118
+ }),
119
+ }),
120
+ defineTool({
121
+ name: "controld_set_filters",
122
+ config: {
123
+ description: "Set enabled or disabled status for Control D profile filters in a batch.",
124
+ inputSchema: z.object({
125
+ profile_id: nonEmptyString,
126
+ filters: z.array(z.object({ filter: nonEmptyString, status: binaryStatus }).strict()).min(1),
127
+ ...subOrgInput,
128
+ }).strict(),
129
+ annotations: writeAnnotations,
130
+ },
131
+ handler: (client, { profile_id, filters, sub_org_id }) => client.request(`/profiles/${segment(profile_id)}/filters`, {
132
+ method: "PUT",
133
+ body: { encoding: "json", value: { filters } },
134
+ subOrgId: sub_org_id,
135
+ }),
136
+ }),
137
+ defineTool({
138
+ name: "controld_set_service_rule",
139
+ config: {
140
+ description: "Create or modify a service rule on a Control D profile.",
141
+ inputSchema: z.object({
142
+ profile_id: nonEmptyString,
143
+ service: nonEmptyString,
144
+ do: doCode,
145
+ status: binaryStatus,
146
+ via: nonEmptyString.optional(),
147
+ via_v6: nonEmptyString.optional(),
148
+ ...subOrgInput,
149
+ }).strict(),
150
+ annotations: writeAnnotations,
151
+ },
152
+ handler: (client, { profile_id, service, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/services/${segment(service)}`, {
153
+ method: "PUT",
154
+ body: { encoding: "form", value },
155
+ subOrgId: sub_org_id,
156
+ }),
157
+ }),
158
+ defineTool({
159
+ name: "controld_set_default_rule",
160
+ config: {
161
+ description: "Set the default rule for a Control D profile.",
162
+ inputSchema: z.object({
163
+ profile_id: nonEmptyString,
164
+ do: doCode,
165
+ status: binaryStatus,
166
+ via: nonEmptyString.optional(),
167
+ ...subOrgInput,
168
+ }).strict(),
169
+ annotations: writeAnnotations,
170
+ },
171
+ handler: (client, { profile_id, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/default`, {
172
+ method: "PUT",
173
+ body: { encoding: "form", value },
174
+ subOrgId: sub_org_id,
175
+ }),
176
+ }),
177
+ defineTool({
178
+ name: "controld_create_custom_rules",
179
+ config: {
180
+ description: "Create one or more custom rules on a Control D profile.",
181
+ inputSchema: z.object({
182
+ profile_id: nonEmptyString,
183
+ hostnames: z.array(nonEmptyString).min(1),
184
+ do: doCode,
185
+ status: binaryStatus,
186
+ via: nonEmptyString.optional(),
187
+ via_v6: nonEmptyString.optional(),
188
+ folder_id: z.union([nonEmptyString, integer.min(0)]).optional(),
189
+ ...subOrgInput,
190
+ }).strict(),
191
+ annotations: writeAnnotations,
192
+ },
193
+ handler: (client, { profile_id, folder_id, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/rules`, {
194
+ method: "POST",
195
+ body: { encoding: "form", value: { ...value, group: folder_id } },
196
+ subOrgId: sub_org_id,
197
+ }),
198
+ }),
199
+ defineTool({
200
+ name: "controld_update_custom_rules",
201
+ config: {
202
+ description: "Update existing custom rules on a Control D profile. Rules are selected by hostname; hostnames not listed are untouched (live-verified).",
203
+ inputSchema: z.object({
204
+ profile_id: nonEmptyString,
205
+ hostnames: z.array(nonEmptyString).min(1),
206
+ do: doCode,
207
+ status: binaryStatus,
208
+ via: nonEmptyString.optional(),
209
+ via_v6: nonEmptyString.optional(),
210
+ folder_id: z.union([nonEmptyString, integer.min(0)]).optional(),
211
+ ...subOrgInput,
212
+ }).strict(),
213
+ annotations: writeAnnotations,
214
+ },
215
+ handler: (client, { profile_id, folder_id, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/rules`, {
216
+ method: "PUT",
217
+ body: { encoding: "form", value: { ...value, group: folder_id } },
218
+ subOrgId: sub_org_id,
219
+ }),
220
+ }),
221
+ defineTool({
222
+ name: "controld_delete_custom_rule",
223
+ config: {
224
+ description: "Delete a custom hostname rule from a Control D profile.",
225
+ inputSchema: z.object({
226
+ profile_id: nonEmptyString,
227
+ hostname: nonEmptyString,
228
+ ...subOrgInput,
229
+ }).strict(),
230
+ annotations: destructiveAnnotations,
231
+ },
232
+ handler: (client, { profile_id, hostname, sub_org_id }) => client.request(`/profiles/${segment(profile_id)}/rules/${segment(hostname)}`, { method: "DELETE", subOrgId: sub_org_id }),
233
+ }),
234
+ defineTool({
235
+ name: "controld_create_rule_folder",
236
+ config: {
237
+ description: "Create a custom-rule folder and its inherited action.",
238
+ inputSchema: z.object({
239
+ profile_id: nonEmptyString,
240
+ name: nonEmptyString,
241
+ do: doCode,
242
+ status: binaryStatus,
243
+ via: nonEmptyString.optional(),
244
+ ...subOrgInput,
245
+ }).strict(),
246
+ annotations: writeAnnotations,
247
+ },
248
+ handler: (client, { profile_id, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/groups`, {
249
+ method: "POST",
250
+ body: { encoding: "form", value },
251
+ subOrgId: sub_org_id,
252
+ }),
253
+ }),
254
+ defineTool({
255
+ name: "controld_update_rule_folder",
256
+ config: {
257
+ description: "Modify a custom-rule folder and its inherited action.",
258
+ inputSchema: z.object({
259
+ profile_id: nonEmptyString,
260
+ folder: nonEmptyString,
261
+ do: doCode,
262
+ status: binaryStatus,
263
+ name: nonEmptyString.optional(),
264
+ via: nonEmptyString.optional(),
265
+ ...subOrgInput,
266
+ }).strict(),
267
+ annotations: writeAnnotations,
268
+ },
269
+ handler: (client, { profile_id, folder, sub_org_id, ...value }) => client.request(`/profiles/${segment(profile_id)}/groups/${segment(folder)}`, {
270
+ method: "PUT",
271
+ body: { encoding: "form", value },
272
+ subOrgId: sub_org_id,
273
+ }),
274
+ }),
275
+ defineTool({
276
+ name: "controld_delete_rule_folder",
277
+ config: {
278
+ description: "Delete a custom-rule folder AND every rule inside it (cascade, live-verified).",
279
+ inputSchema: z.object({
280
+ profile_id: nonEmptyString,
281
+ folder: z.union([nonEmptyString, integer.min(0)]),
282
+ ...subOrgInput,
283
+ }).strict(),
284
+ annotations: destructiveAnnotations,
285
+ },
286
+ handler: (client, { profile_id, folder, sub_org_id }) => client.request(`/profiles/${segment(profile_id)}/groups/${segment(folder)}`, { method: "DELETE", subOrgId: sub_org_id }),
287
+ }),
288
+ defineTool({
289
+ name: "controld_create_device",
290
+ config: {
291
+ description: "Create a Control D device and its DNS resolvers.",
292
+ inputSchema: z.object({ ...deviceCreateInput, ...subOrgInput }).strict(),
293
+ annotations: writeAnnotations,
294
+ },
295
+ handler: (client, { sub_org_id, ...value }) => client.request("/devices", {
296
+ method: "POST",
297
+ body: { encoding: "form", value },
298
+ subOrgId: sub_org_id,
299
+ }),
300
+ }),
301
+ defineTool({
302
+ name: "controld_update_device",
303
+ config: {
304
+ description: "Modify documented settings on a Control D device.",
305
+ inputSchema: z.object({
306
+ device_id: nonEmptyString,
307
+ ...deviceUpdateInput,
308
+ ...subOrgInput,
309
+ }).strict(),
310
+ annotations: writeAnnotations,
311
+ },
312
+ handler: (client, { device_id, sub_org_id, ...value }) => client.request(`/devices/${segment(device_id)}`, {
313
+ method: "PUT",
314
+ body: { encoding: "form", value },
315
+ subOrgId: sub_org_id,
316
+ }),
317
+ }),
318
+ defineTool({
319
+ name: "controld_delete_device",
320
+ config: {
321
+ description: "Delete a Control D device. This breaks DNS on devices using its resolvers.",
322
+ inputSchema: z.object({ device_id: nonEmptyString, ...subOrgInput }).strict(),
323
+ annotations: destructiveAnnotations,
324
+ },
325
+ handler: (client, { device_id, sub_org_id }) => client.request(`/devices/${segment(device_id)}`, { method: "DELETE", subOrgId: sub_org_id }),
326
+ }),
327
+ defineTool({
328
+ name: "controld_authorize_ips",
329
+ config: {
330
+ description: "Authorize IPv4 or IPv6 addresses to use a Control D device.",
331
+ inputSchema: z.object({
332
+ device_id: nonEmptyString,
333
+ ips: z.array(nonEmptyString).min(1),
334
+ ...subOrgInput,
335
+ }).strict(),
336
+ annotations: writeAnnotations,
337
+ },
338
+ handler: (client, { sub_org_id, ...value }) => client.request("/access", {
339
+ method: "POST",
340
+ body: { encoding: "form", value },
341
+ subOrgId: sub_org_id,
342
+ }),
343
+ }),
344
+ defineTool({
345
+ name: "controld_deauthorize_ips",
346
+ config: {
347
+ description: "Deauthorize IPv4 or IPv6 addresses from a Control D device.",
348
+ inputSchema: z.object({
349
+ device_id: nonEmptyString,
350
+ ips: z.array(nonEmptyString).min(1),
351
+ ...subOrgInput,
352
+ }).strict(),
353
+ annotations: destructiveAnnotations,
354
+ },
355
+ handler: (client, { sub_org_id, ...value }) => client.request("/access", {
356
+ method: "DELETE",
357
+ body: { encoding: "form", value },
358
+ subOrgId: sub_org_id,
359
+ }),
360
+ }),
361
+ defineTool({
362
+ name: "controld_create_suborg",
363
+ config: {
364
+ description: "Create a sub-organization. Organization accounts only.",
365
+ inputSchema: z.object({
366
+ name: nonEmptyString.describe("Organization name."),
367
+ ...organizationInput,
368
+ ...subOrgInput,
369
+ }).strict(),
370
+ annotations: writeAnnotations,
371
+ },
372
+ handler: (client, { sub_org_id, ...value }) => client.request("/organizations/suborg", {
373
+ method: "POST",
374
+ body: { encoding: "form", value },
375
+ subOrgId: sub_org_id,
376
+ }),
377
+ }),
378
+ defineTool({
379
+ name: "controld_update_organization",
380
+ config: {
381
+ description: "Modify an organization's contact and policy details. Organization accounts only. UNVERIFIED: Control D documents the fields but no identifier parameter, and does not say how the target organization is chosen, so this tool has not been confirmed against a live account. It may modify an organization other than the one you intend. Ask the user to confirm before calling it, and re-read the organization afterwards to check what changed.",
382
+ inputSchema: z.object({
383
+ name: nonEmptyString.optional().describe("Organization name."),
384
+ contact_email: nonEmptyString.optional().describe("Primary contact email for the organization."),
385
+ twofa_req: organizationInput.twofa_req.optional(),
386
+ stats_endpoint: nonEmptyString.optional().describe("Storage region PK. See controld_list_catalog with catalog 'analytics_regions'."),
387
+ address: organizationInput.address,
388
+ website: organizationInput.website,
389
+ contact_name: organizationInput.contact_name,
390
+ contact_phone: organizationInput.contact_phone,
391
+ parent_profile: organizationInput.parent_profile,
392
+ ...subOrgInput,
393
+ }).strict(),
394
+ annotations: writeAnnotations,
395
+ },
396
+ handler: (client, { sub_org_id, ...value }) => client.request("/organizations", {
397
+ method: "PUT",
398
+ body: { encoding: "form", value },
399
+ subOrgId: sub_org_id,
400
+ }),
401
+ }),
402
+ defineTool({
403
+ name: "controld_request_write",
404
+ config: {
405
+ description: "Escape hatch: send a mutating request to any Control D API path with the write token. Use only when no typed tool covers what you need, because nothing here validates the body against the endpoint. Prefer the named tools, which check their inputs.",
406
+ inputSchema: z.object({
407
+ method: z.enum(["POST", "PUT", "PATCH", "DELETE"]).describe("HTTP method."),
408
+ path: apiPath,
409
+ encoding: z.enum(["form", "json"]).default("form").describe("Body encoding. Control D documents form encoding for almost every write."),
410
+ body: z.record(z.string().min(1), z.unknown()).optional().describe("Request body fields. Form encoding accepts strings, numbers, booleans, and arrays of those."),
411
+ ...subOrgInput,
412
+ }).strict(),
413
+ annotations: destructiveAnnotations,
414
+ },
415
+ handler: (client, { method, path, encoding, body, sub_org_id }) => client.request(path, {
416
+ method,
417
+ subOrgId: sub_org_id,
418
+ body: body === undefined
419
+ ? undefined
420
+ : encoding === "json"
421
+ ? { encoding: "json", value: body }
422
+ : { encoding: "form", value: rawFormBody.parse(body) },
423
+ }),
424
+ }),
425
+ ];
package/dist/tools.js ADDED
@@ -0,0 +1,39 @@
1
+ import { redact } from "./client.js";
2
+ import { diagnosticsTools } from "./tools-diagnostics.js";
3
+ import { readTools } from "./tools-read.js";
4
+ import { writeTools } from "./tools-write.js";
5
+ import { textResult } from "./tools-shared.js";
6
+ function registerTool(server, client, tool) {
7
+ server.registerTool(tool.name, tool.config, async (args) => {
8
+ try {
9
+ return textResult(await tool.handler(client, args));
10
+ }
11
+ catch (error) {
12
+ const message = error instanceof Error ? error.message : String(error);
13
+ throw new Error(redact(message, [
14
+ process.env.CONTROLD_API_TOKEN,
15
+ process.env.CONTROLD_API_TOKEN_READ,
16
+ process.env.CONTROLD_API_TOKEN_WRITE,
17
+ ]));
18
+ }
19
+ });
20
+ }
21
+ export function registerTools(server, client, writesEnabled) {
22
+ for (const tool of [...readTools, ...diagnosticsTools]) {
23
+ if (tool.config.annotations.readOnlyHint !== true) {
24
+ throw new Error(`${tool.name} must be annotated read-only.`);
25
+ }
26
+ }
27
+ for (const tool of writeTools) {
28
+ if (tool.config.annotations.readOnlyHint === true) {
29
+ throw new Error(`${tool.name} must not be annotated read-only.`);
30
+ }
31
+ }
32
+ for (const tool of readTools)
33
+ registerTool(server, client, tool);
34
+ for (const tool of diagnosticsTools)
35
+ registerTool(server, client, tool);
36
+ if (writesEnabled)
37
+ for (const tool of writeTools)
38
+ registerTool(server, client, tool);
39
+ }
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "mcp-controld",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for the Control D API. Manage DNS profiles, filters, rules, and devices from any MCP client.",
5
+ "keywords": [
6
+ "mcp",
7
+ "mcp-server",
8
+ "model-context-protocol",
9
+ "controld",
10
+ "control-d",
11
+ "dns",
12
+ "dns-filtering",
13
+ "claude",
14
+ "ai"
15
+ ],
16
+ "homepage": "https://github.com/Fundryi/MCP-ControlD#readme",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/Fundryi/MCP-ControlD.git"
20
+ },
21
+ "bugs": {
22
+ "url": "https://github.com/Fundryi/MCP-ControlD/issues"
23
+ },
24
+ "author": "Fundryi",
25
+ "license": "MIT",
26
+ "type": "module",
27
+ "bin": {
28
+ "mcp-controld": "dist/index.js"
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "engines": {
34
+ "node": ">=22"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc -p tsconfig.json",
38
+ "prepare": "tsc -p tsconfig.json",
39
+ "test": "tsx --test"
40
+ },
41
+ "dependencies": {
42
+ "@modelcontextprotocol/sdk": "^1.30.0",
43
+ "zod": "^4.4.3"
44
+ },
45
+ "devDependencies": {
46
+ "@types/node": "^22.20.1",
47
+ "tsx": "^4.23.12",
48
+ "typescript": "^7.0.2"
49
+ }
50
+ }