hcloud-mcp 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dns-tools.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { hcloudRequest, seg } from "./hcloud-api.js";
3
- import { json, listAll, withToolError } from "./tool-helpers.js";
3
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
4
  const zoneRef = z.string().describe("Zone ID or name, e.g. example.com");
5
5
  const rrName = z
6
6
  .string()
@@ -27,26 +27,38 @@ const nameserver = z.object({
27
27
  const rrsetPath = (zone, name, type) => `/zones/${seg(zone)}/rrsets/${seg(name)}/${seg(type)}`;
28
28
  export function registerDnsTools(server) {
29
29
  // --- Zones ---
30
- server.tool("list_zones", "List DNS zones (all pages). Optional filters by name, mode, label selector", {
31
- name: z.string().optional(),
32
- mode: z.enum(["primary", "secondary"]).optional(),
33
- label_selector: labelSelector,
30
+ server.registerTool("list_zones", {
31
+ description: "List DNS zones (all pages). Optional filters by name, mode, label selector",
32
+ inputSchema: {
33
+ name: z.string().optional(),
34
+ mode: z.enum(["primary", "secondary"]).optional(),
35
+ label_selector: labelSelector,
36
+ },
37
+ annotations: READ_ONLY,
34
38
  }, async (args) => withToolError(async () => {
35
- const zones = await listAll((p) => hcloudRequest("GET", "/zones", { query: { ...args, page: p.page, per_page: p.perPage } }), "zones");
39
+ const zones = await listAll((p) => hcloudRequest("GET", "/zones", { query: { ...args, ...p } }), "zones");
36
40
  return json(zones);
37
41
  }));
38
- server.tool("get_zone", "Get a DNS zone (status, nameservers it is authoritative on, delegation status, record count)", { zone: zoneRef }, async ({ zone }) => withToolError(async () => json((await hcloudRequest("GET", `/zones/${seg(zone)}`)).zone)));
39
- server.tool("create_zone", 'Create a DNS zone. mode "primary" = Hetzner hosts the records (optionally seed with rrsets or a zonefile); "secondary" = Hetzner pulls from primary_nameservers via AXFR. Returns zone + Action. After creating, delegate the domain to the zone\'s authoritative_nameservers at your registrar', {
40
- name: z.string().describe("Domain name, e.g. example.com (no trailing dot)"),
41
- mode: z.enum(["primary", "secondary"]).default("primary"),
42
- ttl: ttl.optional().describe("Default TTL for records without their own TTL (default 3600)"),
43
- labels: labels.optional(),
44
- primary_nameservers: z.array(nameserver).optional().describe("Required for mode=secondary"),
45
- rrsets: z
46
- .array(z.object({ name: rrName, type: rrType, ttl: ttl.nullable().optional(), records, labels: labels.optional() }))
47
- .optional()
48
- .describe("Initial RRSets (primary only; mutually exclusive with zonefile)"),
49
- zonefile: z.string().optional().describe("BIND zone file to import (primary only; mutually exclusive with rrsets)"),
42
+ server.registerTool("get_zone", {
43
+ description: "Get a DNS zone (status, nameservers it is authoritative on, delegation status, record count)",
44
+ inputSchema: { zone: zoneRef },
45
+ annotations: READ_ONLY,
46
+ }, async ({ zone }) => withToolError(async () => json((await hcloudRequest("GET", `/zones/${seg(zone)}`)).zone)));
47
+ server.registerTool("create_zone", {
48
+ description: 'Create a DNS zone. mode "primary" = Hetzner hosts the records (optionally seed with rrsets or a zonefile); "secondary" = Hetzner pulls from primary_nameservers via AXFR. Returns zone + Action. After creating, delegate the domain to the zone\'s authoritative_nameservers at your registrar',
49
+ inputSchema: {
50
+ name: z.string().describe("Domain name, e.g. example.com (no trailing dot)"),
51
+ mode: z.enum(["primary", "secondary"]).default("primary"),
52
+ ttl: ttl.optional().describe("Default TTL for records without their own TTL (default 3600)"),
53
+ labels: labels.optional(),
54
+ primary_nameservers: z.array(nameserver).optional().describe("Required for mode=secondary"),
55
+ rrsets: z
56
+ .array(z.object({ name: rrName, type: rrType, ttl: ttl.nullable().optional(), records, labels: labels.optional() }))
57
+ .optional()
58
+ .describe("Initial RRSets (primary only; mutually exclusive with zonefile)"),
59
+ zonefile: z.string().optional().describe("BIND zone file to import (primary only; mutually exclusive with rrsets)"),
60
+ },
61
+ annotations: ADDITIVE,
50
62
  }, async (args) => withToolError(async () => {
51
63
  if (args.rrsets && args.zonefile)
52
64
  throw new Error("Provide rrsets OR zonefile, not both");
@@ -55,32 +67,104 @@ export function registerDnsTools(server) {
55
67
  }
56
68
  return json(await hcloudRequest("POST", "/zones", { body: args }));
57
69
  }));
58
- server.tool("update_zone", "Update a zone's labels (replaces all labels)", { zone: zoneRef, labels }, async ({ zone, labels }) => withToolError(async () => json((await hcloudRequest("PUT", `/zones/${seg(zone)}`, { body: { labels } })).zone)));
59
- server.tool("delete_zone", "Delete a DNS zone and ALL its records. Irreversible; confirm with the user first. Returns an Action", { zone: zoneRef }, async ({ zone }) => withToolError(async () => json(await hcloudRequest("DELETE", `/zones/${seg(zone)}`))));
60
- server.tool("export_zonefile", "Export a primary zone as a BIND zone file (good for backups or reviewing all records at once)", { zone: zoneRef }, async ({ zone }) => withToolError(async () => {
70
+ server.registerTool("update_zone", {
71
+ description: "Update a zone's labels (replaces all labels)",
72
+ inputSchema: { zone: zoneRef, labels },
73
+ annotations: ADDITIVE_IDEMPOTENT,
74
+ }, async ({ zone, labels }) => withToolError(async () => json((await hcloudRequest("PUT", `/zones/${seg(zone)}`, { body: { labels } })).zone)));
75
+ server.registerTool("delete_zone", {
76
+ description: "Delete a DNS zone and ALL its records. Irreversible; confirm with the user first. Returns an Action",
77
+ inputSchema: { zone: zoneRef },
78
+ annotations: DESTRUCTIVE_IDEMPOTENT,
79
+ }, async ({ zone }) => withToolError(async () => json(await hcloudRequest("DELETE", `/zones/${seg(zone)}`))));
80
+ server.registerTool("export_zonefile", {
81
+ description: "Export a primary zone as a BIND zone file (good for backups or reviewing all records at once)",
82
+ inputSchema: { zone: zoneRef },
83
+ annotations: READ_ONLY,
84
+ }, async ({ zone }) => withToolError(async () => {
61
85
  const res = await hcloudRequest("GET", `/zones/${seg(zone)}/zonefile`);
62
86
  return { content: [{ type: "text", text: res.zonefile ?? JSON.stringify(res, null, 2) }] };
63
87
  }));
64
- server.tool("import_zonefile", "Replace ALL records of a primary zone with a BIND zone file. Destructive for records not in the file; export_zonefile first as a backup. Returns an Action", { zone: zoneRef, zonefile: z.string() }, async ({ zone, zonefile }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/import_zonefile`, { body: { zonefile } }))));
65
- server.tool("change_zone_ttl", "Change a zone's default TTL (applies to RRSets without their own TTL). Returns an Action", { zone: zoneRef, ttl }, async ({ zone, ttl }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/change_ttl`, { body: { ttl } }))));
66
- server.tool("change_zone_primary_nameservers", "Set the primary nameservers a secondary zone transfers from (replaces the list). Returns an Action", { zone: zoneRef, primary_nameservers: z.array(nameserver).min(1) }, async ({ zone, primary_nameservers }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/change_primary_nameservers`, { body: { primary_nameservers } }))));
67
- server.tool("change_zone_protection", "Enable/disable delete protection on a zone. Returns an Action", { zone: zoneRef, delete: z.boolean() }, async ({ zone, delete: del }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/change_protection`, { body: { delete: del } }))));
88
+ server.registerTool("import_zonefile", {
89
+ description: "Replace ALL records of a primary zone with a BIND zone file. Destructive for records not in the file; export_zonefile first as a backup. Returns an Action",
90
+ inputSchema: { zone: zoneRef, zonefile: z.string() },
91
+ annotations: DESTRUCTIVE_IDEMPOTENT,
92
+ }, async ({ zone, zonefile }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/import_zonefile`, { body: { zonefile } }))));
93
+ server.registerTool("change_zone_ttl", {
94
+ description: "Change a zone's default TTL (applies to RRSets without their own TTL). Returns an Action",
95
+ inputSchema: { zone: zoneRef, ttl },
96
+ annotations: ADDITIVE_IDEMPOTENT,
97
+ }, async ({ zone, ttl }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/change_ttl`, { body: { ttl } }))));
98
+ server.registerTool("change_zone_primary_nameservers", {
99
+ description: "Set the primary nameservers a secondary zone transfers from (replaces the list). Returns an Action",
100
+ inputSchema: { zone: zoneRef, primary_nameservers: z.array(nameserver).min(1) },
101
+ annotations: DESTRUCTIVE_IDEMPOTENT,
102
+ }, async ({ zone, primary_nameservers }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/change_primary_nameservers`, { body: { primary_nameservers } }))));
103
+ server.registerTool("change_zone_protection", {
104
+ description: "Enable/disable delete protection on a zone. Returns an Action",
105
+ inputSchema: { zone: zoneRef, delete: z.boolean() },
106
+ annotations: DESTRUCTIVE_IDEMPOTENT,
107
+ }, async ({ zone, delete: del }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/actions/change_protection`, { body: { delete: del } }))));
68
108
  // --- RRSets ---
69
- server.tool("list_rrsets", "List record sets (RRSets) in a zone (all pages). Filter by name and/or type", { zone: zoneRef, name: z.string().optional(), type: rrType.optional(), label_selector: labelSelector }, async ({ zone, ...filters }) => withToolError(async () => {
70
- const rrsets = await listAll((p) => hcloudRequest("GET", `/zones/${seg(zone)}/rrsets`, { query: { ...filters, page: p.page, per_page: p.perPage } }), "rrsets");
109
+ server.registerTool("list_rrsets", {
110
+ description: "List record sets (RRSets) in a zone (all pages). Filter by name and/or type",
111
+ inputSchema: { zone: zoneRef, name: z.string().optional(), type: rrType.optional(), label_selector: labelSelector },
112
+ annotations: READ_ONLY,
113
+ }, async ({ zone, ...filters }) => withToolError(async () => {
114
+ const rrsets = await listAll((p) => hcloudRequest("GET", `/zones/${seg(zone)}/rrsets`, { query: { ...filters, ...p } }), "rrsets");
71
115
  return json(rrsets);
72
116
  }));
73
- server.tool("get_rrset", "Get one RRSet by name and type", { zone: zoneRef, name: rrName, type: rrType }, async ({ zone, name, type }) => withToolError(async () => json((await hcloudRequest("GET", rrsetPath(zone, name, type))).rrset)));
74
- server.tool("create_rrset", "Create an RRSet (all records sharing one name+type). Fails if it already exists; use add_rrset_records or set_rrset_records to change an existing one. Returns rrset + Action", { zone: zoneRef, name: rrName, type: rrType, records, ttl: ttl.nullable().optional().describe("Omit/null = zone default"), labels: labels.optional() }, async ({ zone, ...body }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/rrsets`, { body }))));
75
- server.tool("update_rrset", "Update an RRSet's labels (replaces all labels). To change records use set/add/remove_rrset_records", { zone: zoneRef, name: rrName, type: rrType, labels }, async ({ zone, name, type, labels }) => withToolError(async () => json((await hcloudRequest("PUT", rrsetPath(zone, name, type), { body: { labels } })).rrset)));
76
- server.tool("delete_rrset", "Delete an RRSet and all its records. Returns an Action", { zone: zoneRef, name: rrName, type: rrType }, async ({ zone, name, type }) => withToolError(async () => json(await hcloudRequest("DELETE", rrsetPath(zone, name, type)))));
77
- server.tool("set_rrset_records", "Replace all records of an RRSet with the given list. Returns an Action", { zone: zoneRef, name: rrName, type: rrType, records }, async ({ zone, name, type, records }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/set_records`, { body: { records } }))));
78
- server.tool("add_rrset_records", "Add records to an RRSet, creating the RRSet if it does not exist. Returns an Action", { zone: zoneRef, name: rrName, type: rrType, records, ttl: ttl.nullable().optional().describe("Used only if the RRSet is created") }, async ({ zone, name, type, records, ttl }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/add_records`, { body: { records, ttl } }))));
79
- server.tool("remove_rrset_records", "Remove specific records (matched by value) from an RRSet. Removing the last record deletes the RRSet. Returns an Action", { zone: zoneRef, name: rrName, type: rrType, records }, async ({ zone, name, type, records }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/remove_records`, { body: { records } }))));
80
- server.tool("update_rrset_records", "Update the comments of existing records (matched by value). Cannot change values; use set_rrset_records for that", {
81
- zone: zoneRef, name: rrName, type: rrType,
82
- records: z.array(z.object({ value: z.string(), comment: z.string() })).min(1),
117
+ server.registerTool("get_rrset", {
118
+ description: "Get one RRSet by name and type",
119
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType },
120
+ annotations: READ_ONLY,
121
+ }, async ({ zone, name, type }) => withToolError(async () => json((await hcloudRequest("GET", rrsetPath(zone, name, type))).rrset)));
122
+ server.registerTool("create_rrset", {
123
+ description: "Create an RRSet (all records sharing one name+type). Fails if it already exists; use add_rrset_records or set_rrset_records to change an existing one. Returns rrset + Action",
124
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, records, ttl: ttl.nullable().optional().describe("Omit/null = zone default"), labels: labels.optional() },
125
+ annotations: ADDITIVE,
126
+ }, async ({ zone, ...body }) => withToolError(async () => json(await hcloudRequest("POST", `/zones/${seg(zone)}/rrsets`, { body }))));
127
+ server.registerTool("update_rrset", {
128
+ description: "Update an RRSet's labels (replaces all labels). To change records use set/add/remove_rrset_records",
129
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, labels },
130
+ annotations: ADDITIVE_IDEMPOTENT,
131
+ }, async ({ zone, name, type, labels }) => withToolError(async () => json((await hcloudRequest("PUT", rrsetPath(zone, name, type), { body: { labels } })).rrset)));
132
+ server.registerTool("delete_rrset", {
133
+ description: "Delete an RRSet and all its records. Returns an Action",
134
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType },
135
+ annotations: DESTRUCTIVE_IDEMPOTENT,
136
+ }, async ({ zone, name, type }) => withToolError(async () => json(await hcloudRequest("DELETE", rrsetPath(zone, name, type)))));
137
+ server.registerTool("set_rrset_records", {
138
+ description: "Replace all records of an RRSet with the given list. Returns an Action",
139
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, records },
140
+ annotations: DESTRUCTIVE_IDEMPOTENT,
141
+ }, async ({ zone, name, type, records }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/set_records`, { body: { records } }))));
142
+ server.registerTool("add_rrset_records", {
143
+ description: "Add records to an RRSet, creating the RRSet if it does not exist. Returns an Action",
144
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, records, ttl: ttl.nullable().optional().describe("Used only if the RRSet is created") },
145
+ annotations: ADDITIVE_IDEMPOTENT,
146
+ }, async ({ zone, name, type, records, ttl }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/add_records`, { body: { records, ttl } }))));
147
+ server.registerTool("remove_rrset_records", {
148
+ description: "Remove specific records (matched by value) from an RRSet. Removing the last record deletes the RRSet. Returns an Action",
149
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, records },
150
+ annotations: DESTRUCTIVE_IDEMPOTENT,
151
+ }, async ({ zone, name, type, records }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/remove_records`, { body: { records } }))));
152
+ server.registerTool("update_rrset_records", {
153
+ description: "Update the comments of existing records (matched by value). Cannot change values; use set_rrset_records for that",
154
+ inputSchema: {
155
+ zone: zoneRef, name: rrName, type: rrType,
156
+ records: z.array(z.object({ value: z.string(), comment: z.string() })).min(1),
157
+ },
158
+ annotations: ADDITIVE_IDEMPOTENT,
83
159
  }, async ({ zone, name, type, records }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/update_records`, { body: { records } }))));
84
- server.tool("change_rrset_ttl", "Change an RRSet's TTL. ttl is required: a number of seconds, or null to fall back to the zone default. Returns an Action", { zone: zoneRef, name: rrName, type: rrType, ttl: ttl.nullable() }, async ({ zone, name, type, ttl }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/change_ttl`, { body: { ttl } }))));
85
- server.tool("change_rrset_protection", "Enable/disable change protection on an RRSet (protected RRSets cannot be modified or deleted). Returns an Action", { zone: zoneRef, name: rrName, type: rrType, change: z.boolean() }, async ({ zone, name, type, change }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/change_protection`, { body: { change } }))));
160
+ server.registerTool("change_rrset_ttl", {
161
+ description: "Change an RRSet's TTL. ttl is required: a number of seconds, or null to fall back to the zone default. Returns an Action",
162
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, ttl: ttl.nullable() },
163
+ annotations: ADDITIVE_IDEMPOTENT,
164
+ }, async ({ zone, name, type, ttl }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/change_ttl`, { body: { ttl } }))));
165
+ server.registerTool("change_rrset_protection", {
166
+ description: "Enable/disable change protection on an RRSet (protected RRSets cannot be modified or deleted). Returns an Action",
167
+ inputSchema: { zone: zoneRef, name: rrName, type: rrType, change: z.boolean() },
168
+ annotations: DESTRUCTIVE_IDEMPOTENT,
169
+ }, async ({ zone, name, type, change }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/change_protection`, { body: { change } }))));
86
170
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { hcloudRequest } from "./hcloud-api.js";
3
- import { json, listAll, withToolError } from "./tool-helpers.js";
3
+ import { ADDITIVE_IDEMPOTENT, DESTRUCTIVE, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
4
  const PTR_RESOURCES = {
5
5
  server: "servers",
6
6
  primary_ip: "primary_ips",
@@ -8,26 +8,38 @@ const PTR_RESOURCES = {
8
8
  load_balancer: "load_balancers",
9
9
  };
10
10
  export function registerExtraTools(server) {
11
- server.tool("change_dns_ptr", "Set or reset reverse DNS (PTR) for a public IP of a server, Primary IP, Floating IP, or load balancer. dns_ptr is always required: pass a hostname to set it, or null to reset it to the Hetzner default. Returns an Action", {
12
- resource: z.enum(["server", "primary_ip", "floating_ip", "load_balancer"]),
13
- id: z.number().describe("ID of the server / Primary IP / Floating IP / load balancer"),
14
- ip: z.string().describe("The public IP to set the PTR for (IPv4, or a single IPv6 address within the resource's /64)"),
15
- dns_ptr: z.string().nullable().describe("Hostname, e.g. mail.example.com; null resets to default"),
11
+ server.registerTool("change_dns_ptr", {
12
+ description: "Set or reset reverse DNS (PTR) for a public IP of a server, Primary IP, Floating IP, or load balancer. dns_ptr is always required: pass a hostname to set it, or null to reset it to the Hetzner default. Returns an Action",
13
+ inputSchema: {
14
+ resource: z.enum(["server", "primary_ip", "floating_ip", "load_balancer"]),
15
+ id: z.number().describe("ID of the server / Primary IP / Floating IP / load balancer"),
16
+ ip: z.string().describe("The public IP to set the PTR for (IPv4, or a single IPv6 address within the resource's /64)"),
17
+ dns_ptr: z.string().nullable().describe("Hostname, e.g. mail.example.com; null resets to default"),
18
+ },
19
+ annotations: ADDITIVE_IDEMPOTENT,
16
20
  }, async ({ resource, id, ip, dns_ptr }) => withToolError(async () => json(await hcloudRequest("POST", `/${PTR_RESOURCES[resource]}/${id}/actions/change_dns_ptr`, { body: { ip, dns_ptr } }))));
17
- server.tool("rebuild_server", "Reinstall a server from an image, WIPING ALL DATA on its disk (attached volumes are kept). The server keeps its ID and IPs. Optional user_data (cloud-init) overrides the original. Returns an Action and, for images that use one, a new root_password. Irreversible; confirm with the user first", {
18
- id: z.number().describe("Server ID"),
19
- image: z.string().describe("Image name or ID, e.g. ubuntu-24.04 (check list_images deprecation)"),
20
- user_data: z.string().optional().describe("Cloud-Init user data (max 32KiB)"),
21
+ server.registerTool("rebuild_server", {
22
+ description: "Reinstall a server from an image, WIPING ALL DATA on its disk (attached volumes are kept). The server keeps its ID and IPs. Optional user_data (cloud-init) overrides the original. Returns an Action and, for images that use one, a new root_password. Irreversible; confirm with the user first",
23
+ inputSchema: {
24
+ id: z.number().describe("Server ID"),
25
+ image: z.string().describe("Image name or ID, e.g. ubuntu-24.04 (check list_images deprecation)"),
26
+ user_data: z.string().optional().describe("Cloud-Init user data (max 32KiB)"),
27
+ },
28
+ annotations: DESTRUCTIVE,
21
29
  }, async ({ id, image, user_data }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/rebuild`, { body: { image, user_data } }))));
22
- server.tool("list_network_members", "List resources attached to a network (servers and load balancers) with their private IP, alias IPs, subnet and attachment status. All pages", {
23
- id: z.number().describe("Network ID"),
24
- // Each filter may be given multiple times (OR within a filter), per the API spec.
25
- type: z.array(z.enum(["server", "load_balancer"])).optional(),
26
- subnet: z.array(z.string()).optional().describe("Subnet IP ranges in CIDR, e.g. [\"10.0.1.0/24\"]"),
27
- status: z.array(z.enum(["ok", "attaching", "detaching", "updating", "error"])).optional()
28
- .describe("Attachment status (spec enum: ok, attaching, detaching, updating, error)"),
30
+ server.registerTool("list_network_members", {
31
+ description: "List resources attached to a network (servers and load balancers) with their private IP, alias IPs, subnet and attachment status. All pages",
32
+ inputSchema: {
33
+ id: z.number().describe("Network ID"),
34
+ // Each filter may be given multiple times (OR within a filter), per the API spec.
35
+ type: z.array(z.enum(["server", "load_balancer"])).optional(),
36
+ subnet: z.array(z.string()).optional().describe("Subnet IP ranges in CIDR, e.g. [\"10.0.1.0/24\"]"),
37
+ status: z.array(z.enum(["ok", "attaching", "detaching", "updating", "error"])).optional()
38
+ .describe("Attachment status (spec enum: ok, attaching, detaching, updating, error)"),
39
+ },
40
+ annotations: READ_ONLY,
29
41
  }, async ({ id, ...filters }) => withToolError(async () => {
30
- const members = await listAll((p) => hcloudRequest("GET", `/networks/${id}/members`, { query: { ...filters, page: p.page, per_page: p.perPage } }), "members");
42
+ const members = await listAll((p) => hcloudRequest("GET", `/networks/${id}/members`, { query: { ...filters, ...p } }), "members");
31
43
  return json(members);
32
44
  }));
33
45
  }
@@ -1,6 +1,5 @@
1
- // Minimal typed client for Hetzner Cloud API endpoints that hetzner-sdk-ts does not
2
- // cover (e.g. DNS zones / RRSets). Uses the same token as the SDK.
3
- import { OpenAPI } from "hetzner-sdk-ts";
1
+ // Minimal fetch client for the Hetzner Cloud API (and the Hetzner API for Storage Boxes).
2
+ // Reads the project token from HCLOUD_TOKEN (index.ts loads .env / exits if unset).
4
3
  // Cloud API (servers, networks, DNS, ...) and the Hetzner API (Storage Boxes) accept the same project token.
5
4
  export const CLOUD_API = "https://api.hetzner.cloud/v1";
6
5
  export const HETZNER_API = "https://api.hetzner.com/v1";
@@ -9,14 +8,16 @@ export class HcloudApiError extends Error {
9
8
  code;
10
9
  details;
11
10
  constructor(status, code, message, details) {
12
- super(`${code} (${status}): ${message}${details ? ` ${JSON.stringify(details)}` : ""}`);
11
+ // The API sends `details: {}` on most errors; only append details that carry something.
12
+ const hasDetails = details != null && (typeof details !== "object" || Object.keys(details).length > 0);
13
+ super(`${code} (${status}): ${message}${hasDetails ? ` ${JSON.stringify(details)}` : ""}`);
13
14
  this.status = status;
14
15
  this.code = code;
15
16
  this.details = details;
16
17
  }
17
18
  }
18
19
  function token() {
19
- const t = (typeof OpenAPI.TOKEN === "string" ? OpenAPI.TOKEN : undefined) ?? process.env.HCLOUD_TOKEN;
20
+ const t = process.env.HCLOUD_TOKEN;
20
21
  if (!t)
21
22
  throw new Error("HCLOUD_TOKEN is not set");
22
23
  return t;
@@ -41,7 +42,16 @@ export async function hcloudRequest(method, path, options = {}) {
41
42
  if (res.status === 204)
42
43
  return {};
43
44
  const text = await res.text();
44
- const data = text ? JSON.parse(text) : {};
45
+ let data = {};
46
+ try {
47
+ data = text ? JSON.parse(text) : {};
48
+ }
49
+ catch (e) {
50
+ // Non-JSON body (e.g. an HTML 502 from a proxy): report the HTTP status instead.
51
+ if (!res.ok)
52
+ throw new HcloudApiError(res.status, "http_error", res.statusText);
53
+ throw e;
54
+ }
45
55
  if (!res.ok) {
46
56
  const err = data?.error ?? {};
47
57
  throw new HcloudApiError(res.status, err.code ?? "http_error", err.message ?? res.statusText, err.details);
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { hcloudRequest } from "./hcloud-api.js";
3
- import { json, listAll, withToolError } from "./tool-helpers.js";
3
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
4
  const labelsSchema = z.record(z.string(), z.string());
5
5
  // Every resource whose spec has POST /{collection}/{id}/actions/change_protection.
6
6
  // Certificates have no change_protection action. DNS zones and RRSets are covered by
@@ -15,53 +15,85 @@ const PROTECTION_RESOURCES = {
15
15
  image: "images",
16
16
  };
17
17
  export function registerImageTools(server) {
18
- server.tool("create_snapshot", "Create an image from a server's disk. type snapshot (default) is independent of the server and survives its deletion; billed per GB-month. type backup needs backups enabled and is deleted with the server. Shut the server down first for a consistent disk. Returns the image (status creating) and an Action; the server is locked until it finishes", {
19
- id: z.number().describe("Server ID"),
20
- description: z.string().optional().describe("Image description (auto-generated if omitted)"),
21
- type: z.enum(["snapshot", "backup"]).optional().describe("Default snapshot"),
22
- labels: labelsSchema.optional(),
18
+ server.registerTool("create_snapshot", {
19
+ description: "Create an image from a server's disk. type snapshot (default) is independent of the server and survives its deletion; billed per GB-month. type backup needs backups enabled and is deleted with the server. Shut the server down first for a consistent disk. Returns the image (status creating) and an Action; the server is locked until it finishes",
20
+ inputSchema: {
21
+ id: z.number().describe("Server ID"),
22
+ description: z.string().optional().describe("Image description (auto-generated if omitted)"),
23
+ type: z.enum(["snapshot", "backup"]).optional().describe("Default snapshot"),
24
+ labels: labelsSchema.optional(),
25
+ },
26
+ annotations: ADDITIVE,
23
27
  }, async ({ id, description, type, labels }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/create_image`, {
24
28
  body: { type: type ?? "snapshot", description, labels },
25
29
  }))));
26
- server.tool("list_snapshots", "List images with filters (list_images has none): by default only snapshot and backup images. Filter by label_selector, bound_to (server IDs, backups only), status, architecture, name. All pages", {
27
- type: z.array(z.enum(["snapshot", "backup", "system", "app"])).optional()
28
- .describe("Image types; default [\"snapshot\", \"backup\"]"),
29
- bound_to: z.array(z.string()).optional().describe("Server IDs the backup images are bound to"),
30
- label_selector: z.string().optional().describe("e.g. env=prod"),
31
- status: z.array(z.enum(["available", "creating", "unavailable"])).optional(),
32
- architecture: z.enum(["x86", "arm"]).optional(),
33
- name: z.string().optional().describe("Exact name (system/app images have names; snapshots usually not)"),
34
- include_deprecated: z.boolean().optional(),
35
- sort: z.array(z.string()).optional().describe("e.g. [\"created:desc\"]; fields id, name, created"),
30
+ server.registerTool("list_snapshots", {
31
+ description: "List images with filters (list_images has none): by default only snapshot and backup images. Filter by label_selector, bound_to (server IDs, backups only), status, architecture, name. All pages",
32
+ inputSchema: {
33
+ type: z.array(z.enum(["snapshot", "backup", "system", "app"])).optional()
34
+ .describe("Image types; default [\"snapshot\", \"backup\"]"),
35
+ bound_to: z.array(z.string()).optional().describe("Server IDs the backup images are bound to"),
36
+ label_selector: z.string().optional().describe("e.g. env=prod"),
37
+ status: z.array(z.enum(["available", "creating", "unavailable"])).optional(),
38
+ architecture: z.enum(["x86", "arm"]).optional(),
39
+ name: z.string().optional().describe("Exact name (system/app images have names; snapshots usually not)"),
40
+ include_deprecated: z.boolean().optional(),
41
+ sort: z.array(z.string()).optional().describe("e.g. [\"created:desc\"]; fields id, name, created"),
42
+ },
43
+ annotations: READ_ONLY,
36
44
  }, async ({ type, ...filters }) => withToolError(async () => {
37
45
  const images = await listAll((p) => hcloudRequest("GET", "/images", {
38
- query: { type: type ?? ["snapshot", "backup"], ...filters, page: p.page, per_page: p.perPage },
46
+ query: { type: type ?? ["snapshot", "backup"], ...filters, ...p },
39
47
  }), "images");
40
48
  return json(images);
41
49
  }));
42
- server.tool("get_image", "Get an image by ID (type, status, image_size/disk_size in GB, created_from, bound_to, protection, labels)", { id: z.number().describe("Image ID") }, async ({ id }) => withToolError(async () => json(await hcloudRequest("GET", `/images/${id}`))));
43
- server.tool("update_image", "Update a snapshot or backup image: description, labels (REPLACES the whole label set), or type \"snapshot\" to convert a backup into a snapshot (it then survives server deletion and disabling backups). System/app images cannot be updated", {
44
- id: z.number().describe("Image ID"),
45
- description: z.string().optional(),
46
- type: z.literal("snapshot").optional().describe("Convert a backup image to a snapshot"),
47
- labels: labelsSchema.optional().describe("Replaces all existing labels"),
50
+ server.registerTool("get_image", {
51
+ description: "Get an image by ID (type, status, image_size/disk_size in GB, created_from, bound_to, protection, labels)",
52
+ inputSchema: { id: z.number().describe("Image ID") },
53
+ annotations: READ_ONLY,
54
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("GET", `/images/${id}`))));
55
+ server.registerTool("update_image", {
56
+ description: "Update a snapshot or backup image: description, labels (REPLACES the whole label set), or type \"snapshot\" to convert a backup into a snapshot (it then survives server deletion and disabling backups). System/app images cannot be updated",
57
+ inputSchema: {
58
+ id: z.number().describe("Image ID"),
59
+ description: z.string().optional(),
60
+ type: z.literal("snapshot").optional().describe("Convert a backup image to a snapshot"),
61
+ labels: labelsSchema.optional().describe("Replaces all existing labels"),
62
+ },
63
+ annotations: ADDITIVE_IDEMPOTENT,
48
64
  }, async ({ id, description, type, labels }) => withToolError(async () => {
49
65
  if (description === undefined && type === undefined && labels === undefined) {
50
66
  throw new Error("Pass at least one of description, type, labels");
51
67
  }
52
68
  return json(await hcloudRequest("PUT", `/images/${id}`, { body: { description, type, labels } }));
53
69
  }));
54
- server.tool("delete_image", "Delete a snapshot or backup image (system/app images cannot be deleted). Fails if delete protection is on. Irreversible; confirm with the user first", { id: z.number().describe("Image ID") }, async ({ id }) => withToolError(async () => {
70
+ server.registerTool("delete_image", {
71
+ description: "Delete a snapshot or backup image (system/app images cannot be deleted). Fails if delete protection is on. Irreversible; confirm with the user first",
72
+ inputSchema: { id: z.number().describe("Image ID") },
73
+ annotations: DESTRUCTIVE_IDEMPOTENT,
74
+ }, async ({ id }) => withToolError(async () => {
55
75
  await hcloudRequest("DELETE", `/images/${id}`);
56
76
  return json({ deleted: true, id });
57
77
  }));
58
- server.tool("enable_server_backups", "Enable automatic daily backups for a server: +20% of the server price, 7 rolling backup slots (list them with list_snapshots type [\"backup\"] and bound_to). Returns an Action", { id: z.number().describe("Server ID") }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/enable_backup`))));
59
- server.tool("disable_server_backups", "Disable automatic backups for a server. IMMEDIATELY DELETES ALL EXISTING BACKUPS of the server; convert any you need to snapshots first (update_image type snapshot). Confirm with the user first. Returns an Action", { id: z.number().describe("Server ID") }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/disable_backup`))));
60
- server.tool("change_protection", "Enable/disable protection on a server, volume, floating_ip, primary_ip, load_balancer, network or image (snapshot/backup). Protected resources cannot be deleted (servers: nor rebuilt). `delete` applies to all; `rebuild` only to servers, and the API currently requires a server's delete and rebuild to be equal, so passing just one for a server sets both. For DNS use change_zone_protection / change_rrset_protection; certificates have no protection. Returns an Action", {
61
- resource: z.enum(["server", "volume", "floating_ip", "primary_ip", "load_balancer", "network", "image"]),
62
- id: z.number().describe("Resource ID"),
63
- delete: z.boolean().optional().describe("Prevent deletion"),
64
- rebuild: z.boolean().optional().describe("Servers only: prevent rebuild"),
78
+ server.registerTool("enable_server_backups", {
79
+ description: "Enable automatic daily backups for a server: +20% of the server price, 7 rolling backup slots (list them with list_snapshots type [\"backup\"] and bound_to). Returns an Action",
80
+ inputSchema: { id: z.number().describe("Server ID") },
81
+ annotations: ADDITIVE_IDEMPOTENT,
82
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/enable_backup`))));
83
+ server.registerTool("disable_server_backups", {
84
+ description: "Disable automatic backups for a server. IMMEDIATELY DELETES ALL EXISTING BACKUPS of the server; convert any you need to snapshots first (update_image type snapshot). Confirm with the user first. Returns an Action",
85
+ inputSchema: { id: z.number().describe("Server ID") },
86
+ annotations: DESTRUCTIVE_IDEMPOTENT,
87
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/disable_backup`))));
88
+ server.registerTool("change_protection", {
89
+ description: "Enable/disable protection on a server, volume, floating_ip, primary_ip, load_balancer, network or image (snapshot/backup). Protected resources cannot be deleted (servers: nor rebuilt). `delete` applies to all; `rebuild` only to servers, and the API currently requires a server's delete and rebuild to be equal, so passing just one for a server sets both. For DNS use change_zone_protection / change_rrset_protection; certificates have no protection. Returns an Action",
90
+ inputSchema: {
91
+ resource: z.enum(["server", "volume", "floating_ip", "primary_ip", "load_balancer", "network", "image"]),
92
+ id: z.number().describe("Resource ID"),
93
+ delete: z.boolean().optional().describe("Prevent deletion"),
94
+ rebuild: z.boolean().optional().describe("Servers only: prevent rebuild"),
95
+ },
96
+ annotations: DESTRUCTIVE_IDEMPOTENT,
65
97
  }, async ({ resource, id, delete: del, rebuild }) => withToolError(async () => {
66
98
  let body;
67
99
  if (resource === "server") {
package/dist/index.js CHANGED
@@ -4,7 +4,6 @@ import { fileURLToPath } from "url";
4
4
  import { config as loadEnv } from "dotenv";
5
5
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
- import { OpenAPI } from "hetzner-sdk-ts";
8
7
  import { registerTools } from "./register-tools.js";
9
8
  import { registerDnsTools } from "./dns-tools.js";
10
9
  import { registerExtraTools } from "./extra-tools.js";
@@ -19,13 +18,11 @@ if (!process.env.HCLOUD_TOKEN) {
19
18
  const __dirname = dirname(fileURLToPath(import.meta.url));
20
19
  loadEnv({ path: join(__dirname, "..", ".env") });
21
20
  }
22
- const token = process.env.HCLOUD_TOKEN;
23
- if (!token) {
21
+ if (!process.env.HCLOUD_TOKEN) {
24
22
  console.error("Error: HCLOUD_TOKEN environment variable is required");
25
23
  process.exit(1);
26
24
  }
27
- OpenAPI.TOKEN = token;
28
- const server = new McpServer({ name: "hetzner-cloud", version: "0.3.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
25
+ const server = new McpServer({ name: "hetzner-cloud", version: "0.4.1" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
29
26
  // Tool groups. HCLOUD_TOOLSETS (comma-separated) limits which load, for clients with
30
27
  // tool-count limits; default is all. "core" is always loaded.
31
28
  const TOOLSETS = {