hcloud-mcp 0.2.0 → 0.4.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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # HCloud MCP
2
2
 
3
+ [![Hcloud MCP server](https://mcprush.com/badge/hcloud-mcp/card.svg)](https://mcprush.com/to/hcloud-mcp?ref=badge)
4
+
3
5
  Standalone **MCP (Model Context Protocol) server** for the [Hetzner Cloud API](https://docs.hetzner.cloud/). Use it with any MCP client: Cursor, Claude Desktop, CLI tools, [smithery.ai](https://smithery.ai), or custom agents.
4
6
 
5
7
  - **Repository:** [github.com/Xodus-CO/hcloud-mcp](https://github.com/Xodus-CO/hcloud-mcp)
@@ -66,19 +68,42 @@ The server exposes Hetzner Cloud API operations as MCP tools:
66
68
 
67
69
  | Area | Tools |
68
70
  | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
69
- | **Servers** | `list_servers`, `get_server`, `create_server`, `delete_server`, `update_server`, `change_server_type`; power: `power_on_server`, `power_off_server`, `reboot_server`, `shutdown_server`, `reset_server`; `attach_iso`, `detach_iso`; `attach_server_to_network`, `detach_server_from_network` |
70
- | **Load Balancers** | `list_load_balancers`, `get_load_balancer`, `create_load_balancer`, `update_load_balancer`, `delete_load_balancer`; `add_load_balancer_target`, `remove_load_balancer_target`; `add_load_balancer_service`, `update_load_balancer_service`, `delete_load_balancer_service`; `list_load_balancer_types` |
71
- | **Networks** | `list_networks`, `get_network`, `create_network`, `update_network`, `delete_network`; `add_network_subnet`, `delete_network_subnet` |
71
+ | **Servers** | `list_servers`, `get_server`, `create_server`, `delete_server`, `update_server`, `change_server_type`; power: `power_on_server`, `power_off_server`, `reboot_server`, `shutdown_server`, `reset_server`; `attach_iso`, `detach_iso`; `attach_server_to_network`, `detach_server_from_network`; `rebuild_server`; reverse DNS: `change_dns_ptr` (also Primary/Floating IPs, LBs) |
72
+ | **Load Balancers** | `list_load_balancers`, `get_load_balancer`, `create_load_balancer`, `update_load_balancer`, `delete_load_balancer`; `add_load_balancer_target`, `remove_load_balancer_target`; `add_load_balancer_service`, `update_load_balancer_service`, `delete_load_balancer_service`; `list_load_balancer_types` (`http.timeout_idle` on update) |
73
+ | **Networks** | `list_networks`, `get_network`, `create_network`, `update_network`, `delete_network`; `add_network_subnet`, `delete_network_subnet`; `list_network_members` |
72
74
  | **Volumes** | `list_volumes`, `get_volume`, `create_volume`, `update_volume`, `delete_volume`; `attach_volume`, `detach_volume` |
73
75
  | **Firewalls** | `list_firewalls`, `get_firewall`, `create_firewall`, `update_firewall`, `delete_firewall`; `apply_firewall_to_resources`, `remove_firewall_from_resources`, `set_firewall_rules` |
74
76
  | **Floating IPs** | `list_floating_ips`, `create_floating_ip`, `update_floating_ip`, `delete_floating_ip`; `assign_floating_ip`, `unassign_floating_ip` |
75
77
  | **Primary IPs** | `list_primary_ips`, `create_primary_ip`, `get_primary_ip`, `update_primary_ip`, `delete_primary_ip`; `assign_primary_ip`, `unassign_primary_ip` (server must be off) |
76
78
  | **SSH Keys** | `list_ssh_keys`, `create_ssh_key`, `update_ssh_key`, `delete_ssh_key` |
77
79
  | **Placement Groups** | `list_placement_groups`, `create_placement_group`, `update_placement_group`, `delete_placement_group` |
80
+ | **DNS** | `list_zones`, `get_zone`, `create_zone`, `update_zone`, `delete_zone`; `export_zonefile`, `import_zonefile`; `change_zone_ttl`, `change_zone_primary_nameservers`, `change_zone_protection`; `list_rrsets`, `get_rrset`, `create_rrset`, `update_rrset`, `delete_rrset`; `set_rrset_records`, `add_rrset_records`, `remove_rrset_records`, `update_rrset_records`, `change_rrset_ttl`, `change_rrset_protection` |
81
+ | **Snapshots & backups** | `create_snapshot`, `list_snapshots`, `get_image`, `update_image`, `delete_image`; `enable_server_backups`, `disable_server_backups` |
82
+ | **Protection** | `change_protection` (servers, volumes, floating/primary IPs, LBs, networks, images) |
83
+ | **Rescue & console** | `enable_rescue`, `disable_rescue`, `reset_root_password`, `request_console` |
84
+ | **Metrics** | `get_server_metrics`, `get_load_balancer_metrics` (with min/avg/max summary; `last_minutes` shortcut) |
85
+ | **More actions** | `add_server_to_placement_group`, `remove_server_from_placement_group`, `change_server_alias_ips`; `attach_load_balancer_to_network`, `detach_load_balancer_from_network`, `change_load_balancer_algorithm`, `change_load_balancer_type`, `enable_load_balancer_public_interface`, `disable_load_balancer_public_interface`; `add_network_route`, `delete_network_route`, `change_network_ip_range`; `list_isos` |
86
+ | **Certificates** | `list_certificates`, `get_certificate`, `create_certificate` (uploaded or managed Let's Encrypt), `update_certificate`, `delete_certificate`, `retry_certificate` |
87
+ | **Storage Boxes** | boxes: `list_storage_boxes`, `get_storage_box`, `create_storage_box`, `update_storage_box`, `delete_storage_box`, `list_storage_box_folders`, `list_storage_box_types`, `get_storage_box_type`; actions: `change_storage_box_type`, `change_storage_box_protection`, `reset_storage_box_password`, `update_storage_box_access_settings`, `enable_storage_box_snapshot_plan`, `disable_storage_box_snapshot_plan`, `rollback_storage_box_snapshot`, `list_storage_box_actions`, `get_storage_box_action`; subaccounts (`*_storage_box_subaccount*`) and snapshots (`*_storage_box_snapshot*`) |
78
88
  | **Metadata & actions** | `list_locations`, `list_images`, `list_server_types`, `list_load_balancer_types`, `get_pricing`; `list_actions`, `get_action` (poll async operations) |
79
89
 
80
90
  > **Note:** Subnets (not networks) are scoped to a `network_zone` (e.g., `eu-central`). Each Subnet has a `network_zone`; all Subnets within a Network share the same `network_zone`. Servers must be created in locations that match the Subnet's `network_zone`, so resources in the Network are constrained by the shared subnet `network_zone`.
81
91
 
92
+ ### Limiting tools (`HCLOUD_TOOLSETS`)
93
+
94
+ The server exposes about 160 tools. Some MCP clients cap the total number of tools, or slow down with very many. Set `HCLOUD_TOOLSETS` to load only the groups you need. The `core` group is always loaded.
95
+
96
+ | Toolset | Contents |
97
+ |---|---|
98
+ | `core` | Servers, networks, firewalls, volumes, LBs, IPs, SSH keys, placement groups, reverse DNS, metadata, and extra actions |
99
+ | `dns` | DNS zones and RRSets |
100
+ | `images` | Snapshots, backups, image management, `change_protection` |
101
+ | `ops` | Rescue, console, root password, metrics |
102
+ | `certificates` | TLS certificates |
103
+ | `storage_boxes` | Storage Boxes, subaccounts, snapshots |
104
+
105
+ Example: `"env": { "HCLOUD_TOKEN": "...", "HCLOUD_TOOLSETS": "dns,images" }`. If you leave it unset, or set it to `all`, everything loads.
106
+
82
107
  ### Server instructions and agent skill
83
108
 
84
109
  The server sends **instructions** to the client when it connects. Most MCP clients add them to the model's context. They cover using locations instead of datacenters, polling Actions, the order to detach resources before deleting them, firewall CIDR rules, and deprecation checks. See `src/instructions.ts`.
@@ -103,11 +128,12 @@ Updated in 0.2.0 for Hetzner Cloud API changes through November 2026 ([changelog
103
128
  - `create_primary_ip` takes `location` instead of `datacenter`.
104
129
  - `delete_load_balancer` now returns the deletion Action.
105
130
  - `add_network_subnet` no longer offers the deprecated `server` type. Use `cloud`.
131
+ - **0.3.1:** `create_volume` and `attach_volume` send `assignee: {type: "server", id}` instead of the deprecated `server` field, which the API removes on 2027-10-27. Tool inputs are unchanged. Read `assignee` in volume responses.
106
132
  - List tools now return every page. Previously they silently stopped at the first 25 items.
107
133
  - Floating IPs and Primary IPs must be unassigned before you delete them.
108
134
  - `list_actions` requires `id`, because Hetzner removed project-wide action listing. Use `get_action` to poll.
109
135
 
110
- New API features that aren't wrapped yet, such as DNS zones, Storage Boxes, network members, and LB Primary IPs, are tracked in [issues](https://github.com/Xodus-CO/hcloud-mcp/issues).
136
+ Hetzner Robot (dedicated servers) is not covered yet; see [#21](https://github.com/Xodus-CO/hcloud-mcp/issues/21).
111
137
 
112
138
  ## Usage examples
113
139
 
@@ -123,6 +149,8 @@ With the MCP client connected, you can ask the agent to run tools using natural
123
149
  - _List load balancer types_
124
150
  - _Show current pricing for cpx31 servers_
125
151
  - _Get status of action 12345_
152
+ - _Add an A record for www.example.com pointing to my web-01 server_
153
+ - _Export the zone file for example.com_
126
154
 
127
155
  ### Complex
128
156
 
@@ -140,7 +168,15 @@ With the MCP client connected, you can ask the agent to run tools using natural
140
168
  | File | Purpose |
141
169
  | ----------------------- | ----------------------------------------------------------- |
142
170
  | `src/index.ts` | Entry point, stdio transport, `HCLOUD_TOKEN` check |
143
- | `src/register-tools.ts` | Tool definitions and Hetzner API calls (uses SDK McpServer) |
171
+ | `src/register-tools.ts` | Core tools: servers, LBs, networks, volumes, firewalls, IPs, SSH keys, info |
172
+ | `src/extra-tools.ts` | Newer Cloud API endpoints (reverse DNS, rebuild, network members) |
173
+ | `src/dns-tools.ts` | DNS zone/RRSet tools |
174
+ | `src/hcloud-api.ts` | Minimal fetch client for the Hetzner APIs (no SDK dependency) |
175
+ | `src/action-gap-tools.ts` | Placement groups, alias IPs, LB network/type/algorithm/public interface, routes, ISOs |
176
+ | `src/image-tools.ts` | Snapshots, backups, image management, `change_protection` |
177
+ | `src/server-ops-tools.ts` | Rescue, console, root password, server/LB metrics |
178
+ | `src/certificate-tools.ts` | TLS certificates |
179
+ | `src/storage-box-tools.ts` | Storage Boxes (api.hetzner.com, same token) |
144
180
  | `src/instructions.ts` | Server instructions sent to MCP clients at initialize |
145
181
  | `skills/hetzner-cloud/` | Agent skill (SKILL.md) for driving this server safely |
146
182
 
@@ -150,9 +186,15 @@ With the MCP client connected, you can ask the agent to run tools using natural
150
186
  npm run build # compile
151
187
  npm run start # run (requires HCLOUD_TOKEN)
152
188
  npm run dev # watch and recompile
153
- npm run test:api # test list_* Hetzner API calls (requires HCLOUD_TOKEN)
189
+ npm run test:smoke # offline: server starts, tools register, toolsets work (runs in CI)
190
+ npm run test:api # read-only checks of the API client: pagination, error format (requires HCLOUD_TOKEN, run build first)
154
191
  npm run test:mcp # integration test: MCP client calls list_locations (requires HCLOUD_TOKEN)
155
- npm run audit:api # verify create_* request body shapes (DRY_RUN=1, no resources created)
192
+ npm run test:live:dns # DNS create→teardown on a throwaway zone (free)
193
+ npm run test:live:images # snapshots, backups, protection (costs cents)
194
+ npm run test:live:ops # rescue, console, root password, metrics (costs cents)
195
+ npm run test:live:actions # placement groups, alias IPs, LB/network actions, ISOs (costs cents)
196
+ npm run test:live:certs # uploaded self-signed certificate lifecycle (free)
197
+ npm run test:live:storage # Storage Box lifecycle on a new bx11 (fractions of a cent; never touches existing boxes)
156
198
  npm run test:live # full create→teardown cycle via MCP (COSTS a few cents; resources get a unique per-run hcloud-mcp-test label, auto-cleaned)
157
199
  ```
158
200
 
@@ -0,0 +1,118 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { ADDITIVE_IDEMPOTENT, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
+ const action = (path, body) => withToolError(async () => json(await hcloudRequest("POST", path, { body: body ?? {} })));
5
+ export function registerActionGapTools(server) {
6
+ // --- Servers ---
7
+ server.registerTool("add_server_to_placement_group", {
8
+ description: "Add a server to a placement group. The server must be powered off (422 server_not_stopped) and not already in a placement group (422 already_in_placement_group). Returns an Action",
9
+ inputSchema: {
10
+ id: z.number().describe("Server ID"),
11
+ placement_group: z.number().describe("Placement group ID"),
12
+ },
13
+ annotations: ADDITIVE_IDEMPOTENT,
14
+ }, async ({ id, placement_group }) => action(`/servers/${id}/actions/add_to_placement_group`, { placement_group }));
15
+ server.registerTool("remove_server_from_placement_group", {
16
+ description: "Remove a server from its placement group. Returns an Action",
17
+ inputSchema: { id: z.number().describe("Server ID") },
18
+ annotations: DESTRUCTIVE_IDEMPOTENT,
19
+ }, async ({ id }) => action(`/servers/${id}/actions/remove_from_placement_group`));
20
+ server.registerTool("change_server_alias_ips", {
21
+ description: "Set the alias IPs of a server on a network it is already attached to. REPLACES the existing alias list for that network: to add one, pass the current alias_ips (get_server private_net) plus the new IP; pass [] to remove all. Returns an Action",
22
+ inputSchema: {
23
+ id: z.number().describe("Server ID"),
24
+ network: z.number().describe("ID of a network already attached to the server"),
25
+ alias_ips: z.array(z.string()).describe("Complete new list of alias IPs, e.g. [\"10.0.1.50\"]"),
26
+ },
27
+ annotations: DESTRUCTIVE_IDEMPOTENT,
28
+ }, async ({ id, network, alias_ips }) => action(`/servers/${id}/actions/change_alias_ips`, { network, alias_ips }));
29
+ // --- Load balancers ---
30
+ server.registerTool("attach_load_balancer_to_network", {
31
+ description: "Attach a load balancer to a network (one network per load balancer). Optionally request a specific private ip, or ip_range to auto-assign from a specific subnet; ip must lie within ip_range if both are given. Returns an Action",
32
+ inputSchema: {
33
+ id: z.number().describe("Load balancer ID"),
34
+ network: z.number().describe("Network ID"),
35
+ ip: z.string().optional().describe("Private IP to assign; auto-assigned if omitted"),
36
+ ip_range: z.string().optional().describe("Subnet ip_range (CIDR) to auto-assign the IP from, e.g. 10.0.1.0/24"),
37
+ },
38
+ annotations: ADDITIVE_IDEMPOTENT,
39
+ }, async ({ id, network, ip, ip_range }) => action(`/load_balancers/${id}/actions/attach_to_network`, { network, ip, ip_range }));
40
+ server.registerTool("detach_load_balancer_from_network", {
41
+ description: "Detach a load balancer from a network. Re-enable the public interface first if it was disabled, or the load balancer becomes unreachable. Returns an Action",
42
+ inputSchema: {
43
+ id: z.number().describe("Load balancer ID"),
44
+ network: z.number().describe("Network ID"),
45
+ },
46
+ annotations: DESTRUCTIVE_IDEMPOTENT,
47
+ }, async ({ id, network }) => action(`/load_balancers/${id}/actions/detach_from_network`, { network }));
48
+ server.registerTool("change_load_balancer_algorithm", {
49
+ description: "Change how a load balancer distributes new requests across targets. Returns an Action",
50
+ inputSchema: {
51
+ id: z.number().describe("Load balancer ID"),
52
+ type: z.enum(["round_robin", "least_connections"]),
53
+ },
54
+ annotations: ADDITIVE_IDEMPOTENT,
55
+ }, async ({ id, type }) => action(`/load_balancers/${id}/actions/change_algorithm`, { type }));
56
+ server.registerTool("change_load_balancer_type", {
57
+ description: "Change a load balancer's type (max services / targets / connections; price changes accordingly — check get_pricing). Fails with invalid_load_balancer_type if the current config exceeds the new type's limits. Returns an Action",
58
+ inputSchema: {
59
+ id: z.number().describe("Load balancer ID"),
60
+ load_balancer_type: z.string().describe("Type name or ID, e.g. lb11, lb21, lb31"),
61
+ },
62
+ annotations: DESTRUCTIVE_IDEMPOTENT,
63
+ }, async ({ id, load_balancer_type }) => action(`/load_balancers/${id}/actions/change_type`, { load_balancer_type }));
64
+ server.registerTool("enable_load_balancer_public_interface", {
65
+ description: "Enable a load balancer's public interface so it is reachable from the internet via its public IPs. Returns an Action",
66
+ inputSchema: { id: z.number().describe("Load balancer ID") },
67
+ annotations: ADDITIVE_IDEMPOTENT,
68
+ }, async ({ id }) => action(`/load_balancers/${id}/actions/enable_public_interface`));
69
+ server.registerTool("disable_load_balancer_public_interface", {
70
+ description: "Disable a load balancer's public interface (private-network only). Requires the load balancer to be attached to a network (load_balancer_not_attached_to_network) and all targets to use_private_ip (targets_without_use_private_ip). Returns an Action",
71
+ inputSchema: { id: z.number().describe("Load balancer ID") },
72
+ annotations: DESTRUCTIVE_IDEMPOTENT,
73
+ }, async ({ id }) => action(`/load_balancers/${id}/actions/disable_public_interface`));
74
+ // --- Networks ---
75
+ server.registerTool("add_network_route", {
76
+ description: "Add a route to a network: traffic for destination is sent to gateway. destination must be an RFC1918 range or 0.0.0.0/0 and must not overlap subnets or other routes; gateway must be an IP inside the network (not its first IP, not 172.31.1.1). Returns an Action",
77
+ inputSchema: {
78
+ id: z.number().describe("Network ID"),
79
+ destination: z.string().describe("Destination CIDR, e.g. 10.100.1.0/24 or 0.0.0.0/0"),
80
+ gateway: z.string().describe("Gateway IP inside the network, e.g. a server's private IP 10.0.1.2"),
81
+ },
82
+ annotations: ADDITIVE_IDEMPOTENT,
83
+ }, async ({ id, destination, gateway }) => action(`/networks/${id}/actions/add_route`, { destination, gateway }));
84
+ server.registerTool("delete_network_route", {
85
+ description: "Delete a route from a network. destination and gateway must match the existing route exactly (see get_network routes). Returns an Action",
86
+ inputSchema: {
87
+ id: z.number().describe("Network ID"),
88
+ destination: z.string().describe("Destination CIDR of the route"),
89
+ gateway: z.string().describe("Gateway IP of the route"),
90
+ },
91
+ annotations: DESTRUCTIVE_IDEMPOTENT,
92
+ }, async ({ id, destination, gateway }) => action(`/networks/${id}/actions/delete_route`, { destination, gateway }));
93
+ server.registerTool("change_network_ip_range", {
94
+ description: "Change a network's IP range. Can only be extended by shortening the netmask with the same base address (10.0.0.0/16 -> 10.0.0.0/15), never shrunk. The network must have NO attached servers or load balancers (detach them first). Returns an Action",
95
+ inputSchema: {
96
+ id: z.number().describe("Network ID"),
97
+ ip_range: z.string().describe("New range in CIDR, same start IP as the current range, e.g. 10.0.0.0/15"),
98
+ },
99
+ annotations: ADDITIVE_IDEMPOTENT,
100
+ }, async ({ id, ip_range }) => action(`/networks/${id}/actions/change_ip_range`, { ip_range }));
101
+ // --- ISOs ---
102
+ server.registerTool("list_isos", {
103
+ description: "List ISOs available to attach_iso (public and private). name is an exact match. architecture filters x86/arm; include_architecture_wildcard (requires architecture) also includes ISOs with no architecture. Check deprecation before use. All pages",
104
+ inputSchema: {
105
+ name: z.string().optional().describe("Exact ISO name"),
106
+ architecture: z.enum(["x86", "arm"]).optional(),
107
+ include_architecture_wildcard: z.boolean().optional()
108
+ .describe("Also include ISOs with architecture null; only valid together with architecture"),
109
+ },
110
+ annotations: READ_ONLY,
111
+ }, async (filters) => withToolError(async () => {
112
+ if (filters.include_architecture_wildcard !== undefined && !filters.architecture) {
113
+ throw new Error("include_architecture_wildcard requires architecture");
114
+ }
115
+ const isos = await listAll((p) => hcloudRequest("GET", "/isos", { query: { ...filters, ...p } }), "isos");
116
+ return json(isos);
117
+ }));
118
+ }
@@ -0,0 +1,89 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
+ const certId = z.number().int().describe("Certificate ID");
5
+ const certType = z.enum(["uploaded", "managed"]);
6
+ const labels = z.record(z.string());
7
+ const MANAGED_REQUIREMENTS = "Managed (Let's Encrypt) certificates are validated via DNS: every domain must be in a PRIMARY Hetzner DNS zone (create_zone) " +
8
+ "that is delegated to Hetzner's nameservers at the registrar, and any CAA record must allow Let's Encrypt. " +
9
+ "Typical failures: dns_zone_not_found, dns_zone_is_secondary_zone, could_not_verify_domain_delegated_to_zone, " +
10
+ "caa_record_does_not_allow_ca, ca_dns_validation_failed, Let's Encrypt rate limits";
11
+ const USAGE = "Certificates are referenced by ID in Load Balancer HTTPS services: http.certificates in add_load_balancer_service / update_load_balancer_service";
12
+ export function registerCertificateTools(server) {
13
+ server.registerTool("list_certificates", {
14
+ description: "List TLS certificates (all pages). Optional filters: name, label_selector, type. Each includes domain_names, not_valid_after, fingerprint, managed status and used_by (load balancers using it)",
15
+ inputSchema: {
16
+ name: z.string().optional().describe("Exact certificate name"),
17
+ label_selector: z.string().optional().describe("Label selector, e.g. env=prod"),
18
+ type: z.array(certType).optional().describe("Filter by type(s)"),
19
+ },
20
+ annotations: READ_ONLY,
21
+ }, async (args) => withToolError(async () => {
22
+ const certs = await listAll((p) => hcloudRequest("GET", "/certificates", { query: { ...args, ...p } }), "certificates");
23
+ return json(certs);
24
+ }));
25
+ server.registerTool("get_certificate", {
26
+ description: "Get a TLS certificate: PEM chain (public), domain_names, validity window, fingerprint, used_by, and for managed certs status.issuance / status.renewal / status.error",
27
+ inputSchema: { id: certId },
28
+ annotations: READ_ONLY,
29
+ }, async ({ id }) => withToolError(async () => json((await hcloudRequest("GET", `/certificates/${id}`)).certificate)));
30
+ server.registerTool("create_certificate", {
31
+ description: "Create a TLS certificate. type \"uploaded\" (default): provide certificate (PEM, leaf first then chain) and private_key (PEM); " +
32
+ "supported keys RSA 2048/3072/4096 or ECDSA P-256/P-384; you must renew it yourself before not_valid_after. " +
33
+ "type \"managed\": provide domain_names; Hetzner requests and auto-renews a Let's Encrypt cert. " +
34
+ MANAGED_REQUIREMENTS +
35
+ ". Returns {certificate, action}: action tracks managed issuance (poll get_action), null for uploaded. " +
36
+ USAGE,
37
+ inputSchema: {
38
+ name: z.string().describe("Unique name within the project"),
39
+ type: certType.default("uploaded"),
40
+ certificate: z.string().optional().describe("uploaded only: certificate + chain in PEM, each cert certifying the preceding one"),
41
+ private_key: z.string().optional().describe("uploaded only: private key in PEM. Sent to the API only; never returned"),
42
+ domain_names: z.array(z.string()).optional().describe('managed only: domains to include, e.g. ["example.com", "www.example.com"]'),
43
+ labels: labels.optional(),
44
+ },
45
+ annotations: ADDITIVE,
46
+ }, async (args) => withToolError(async () => {
47
+ const { name, type, certificate, private_key, domain_names, labels } = args;
48
+ let body;
49
+ if (type === "uploaded") {
50
+ if (!certificate || !private_key)
51
+ throw new Error("type=uploaded requires both certificate and private_key (PEM)");
52
+ if (domain_names?.length)
53
+ throw new Error("domain_names is only valid for type=managed (uploaded certs take their domains from the PEM)");
54
+ body = { name, type, certificate, private_key, labels };
55
+ }
56
+ else {
57
+ if (!domain_names?.length)
58
+ throw new Error("type=managed requires a non-empty domain_names list");
59
+ if (certificate || private_key)
60
+ throw new Error("certificate/private_key are only valid for type=uploaded");
61
+ body = { name, type, domain_names, labels };
62
+ }
63
+ return json(await hcloudRequest("POST", "/certificates", { body }));
64
+ }));
65
+ server.registerTool("update_certificate", {
66
+ description: "Rename a certificate and/or replace its labels (labels overwrite the whole set). The certificate content cannot be changed; to rotate an uploaded cert, create a new one, point the load balancer service at it, then delete the old one",
67
+ inputSchema: { id: certId, name: z.string().optional(), labels: labels.optional() },
68
+ annotations: ADDITIVE_IDEMPOTENT,
69
+ }, async ({ id, name, labels }) => withToolError(async () => {
70
+ if (name === undefined && labels === undefined)
71
+ throw new Error("Provide name and/or labels");
72
+ return json((await hcloudRequest("PUT", `/certificates/${id}`, { body: { name, labels } })).certificate);
73
+ }));
74
+ server.registerTool("delete_certificate", {
75
+ description: "Delete a certificate. Irreversible; confirm with the user first. Check used_by (get_certificate) first: load balancer HTTPS services referencing it should be switched to another certificate",
76
+ inputSchema: { id: certId },
77
+ annotations: DESTRUCTIVE_IDEMPOTENT,
78
+ }, async ({ id }) => withToolError(async () => {
79
+ await hcloudRequest("DELETE", `/certificates/${id}`);
80
+ return json({ deleted: id });
81
+ }));
82
+ server.registerTool("retry_certificate", {
83
+ description: "Retry a failed issuance or renewal of a managed certificate (only when status.issuance or status.renewal is \"failed\"; see status.error for the cause and fix it first). " +
84
+ MANAGED_REQUIREMENTS +
85
+ ". Returns an Action (poll get_action)",
86
+ inputSchema: { id: certId },
87
+ annotations: ADDITIVE,
88
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/certificates/${id}/actions/retry`))));
89
+ }
@@ -0,0 +1,170 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest, seg } from "./hcloud-api.js";
3
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
+ const zoneRef = z.string().describe("Zone ID or name, e.g. example.com");
5
+ const rrName = z
6
+ .string()
7
+ .describe('Record name relative to the zone: "@" for the apex, "www", "_acme-challenge", etc. Lowercase.');
8
+ const rrType = z.enum([
9
+ "A", "AAAA", "CAA", "CNAME", "DS", "HINFO", "HTTPS", "MX", "NS", "PTR", "RP", "SOA", "SRV", "SVCB", "TLSA", "TXT",
10
+ ]);
11
+ const record = z.object({
12
+ value: z
13
+ .string()
14
+ .describe('Record value in zone-file syntax. TXT values must be quoted, e.g. "\\"v=spf1 -all\\"". MX: "10 mail.example.com."'),
15
+ comment: z.string().optional(),
16
+ });
17
+ const records = z.array(record).min(1);
18
+ const ttl = z.number().int().describe("TTL in seconds");
19
+ const labels = z.record(z.string());
20
+ const labelSelector = z.string().optional().describe("Label selector, e.g. env=prod");
21
+ const nameserver = z.object({
22
+ address: z.string().describe("IPv4 or IPv6 of the primary nameserver"),
23
+ port: z.number().int().optional().describe("Default 53"),
24
+ tsig_key: z.string().optional(),
25
+ tsig_algorithm: z.string().optional().describe("e.g. hmac-sha256"),
26
+ });
27
+ const rrsetPath = (zone, name, type) => `/zones/${seg(zone)}/rrsets/${seg(name)}/${seg(type)}`;
28
+ export function registerDnsTools(server) {
29
+ // --- Zones ---
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,
38
+ }, async (args) => withToolError(async () => {
39
+ const zones = await listAll((p) => hcloudRequest("GET", "/zones", { query: { ...args, ...p } }), "zones");
40
+ return json(zones);
41
+ }));
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,
62
+ }, async (args) => withToolError(async () => {
63
+ if (args.rrsets && args.zonefile)
64
+ throw new Error("Provide rrsets OR zonefile, not both");
65
+ if (args.mode === "secondary" && !args.primary_nameservers?.length) {
66
+ throw new Error("mode=secondary requires primary_nameservers");
67
+ }
68
+ return json(await hcloudRequest("POST", "/zones", { body: args }));
69
+ }));
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 () => {
85
+ const res = await hcloudRequest("GET", `/zones/${seg(zone)}/zonefile`);
86
+ return { content: [{ type: "text", text: res.zonefile ?? JSON.stringify(res, null, 2) }] };
87
+ }));
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 } }))));
108
+ // --- 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");
115
+ return json(rrsets);
116
+ }));
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,
159
+ }, async ({ zone, name, type, records }) => withToolError(async () => json(await hcloudRequest("POST", `${rrsetPath(zone, name, type)}/actions/update_records`, { body: { records } }))));
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 } }))));
170
+ }
@@ -0,0 +1,45 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { ADDITIVE_IDEMPOTENT, DESTRUCTIVE, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
+ const PTR_RESOURCES = {
5
+ server: "servers",
6
+ primary_ip: "primary_ips",
7
+ floating_ip: "floating_ips",
8
+ load_balancer: "load_balancers",
9
+ };
10
+ export function registerExtraTools(server) {
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,
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 } }))));
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,
29
+ }, async ({ id, image, user_data }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/rebuild`, { body: { image, user_data } }))));
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,
41
+ }, async ({ id, ...filters }) => withToolError(async () => {
42
+ const members = await listAll((p) => hcloudRequest("GET", `/networks/${id}/members`, { query: { ...filters, ...p } }), "members");
43
+ return json(members);
44
+ }));
45
+ }
@@ -0,0 +1,62 @@
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).
3
+ // Cloud API (servers, networks, DNS, ...) and the Hetzner API (Storage Boxes) accept the same project token.
4
+ export const CLOUD_API = "https://api.hetzner.cloud/v1";
5
+ export const HETZNER_API = "https://api.hetzner.com/v1";
6
+ export class HcloudApiError extends Error {
7
+ status;
8
+ code;
9
+ details;
10
+ constructor(status, code, message, 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)}` : ""}`);
14
+ this.status = status;
15
+ this.code = code;
16
+ this.details = details;
17
+ }
18
+ }
19
+ function token() {
20
+ const t = process.env.HCLOUD_TOKEN;
21
+ if (!t)
22
+ throw new Error("HCLOUD_TOKEN is not set");
23
+ return t;
24
+ }
25
+ export async function hcloudRequest(method, path, options = {}) {
26
+ const url = new URL((options.baseUrl ?? CLOUD_API) + path);
27
+ for (const [k, raw] of Object.entries(options.query ?? {})) {
28
+ // Arrays become repeated params (?status=ok&status=error), as the API expects.
29
+ for (const v of Array.isArray(raw) ? raw : [raw]) {
30
+ if (v !== undefined && v !== null && v !== "")
31
+ url.searchParams.append(k, String(v));
32
+ }
33
+ }
34
+ const res = await fetch(url, {
35
+ method,
36
+ headers: {
37
+ Authorization: `Bearer ${token()}`,
38
+ ...(options.body !== undefined ? { "Content-Type": "application/json" } : {}),
39
+ },
40
+ body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
41
+ });
42
+ if (res.status === 204)
43
+ return {};
44
+ const text = await res.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
+ }
55
+ if (!res.ok) {
56
+ const err = data?.error ?? {};
57
+ throw new HcloudApiError(res.status, err.code ?? "http_error", err.message ?? res.statusText, err.details);
58
+ }
59
+ return data;
60
+ }
61
+ /** Encode a path segment (zone names, RRSet names like "@" or "_acme-challenge"). */
62
+ export const seg = (value) => encodeURIComponent(String(value));