hcloud-mcp 0.1.1 → 0.3.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,9 +1,10 @@
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)
6
- - **Cursor Plugin:** [github.com/Xodus-CO/hetzner-mcp](https://github.com/Xodus-CO/hetzner-mcp) — install from the Cursor Plugin marketplace.
7
8
  - **Hetzner Cloud:** [Get started](https://hetzner.cloud/?ref=IAYKetqPnlq9) — new signups get €20 credit.
8
9
 
9
10
  ---
@@ -67,19 +68,72 @@ The server exposes Hetzner Cloud API operations as MCP tools:
67
68
 
68
69
  | Area | Tools |
69
70
  | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
70
- | **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` |
71
- | **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` |
72
- | **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` |
73
74
  | **Volumes** | `list_volumes`, `get_volume`, `create_volume`, `update_volume`, `delete_volume`; `attach_volume`, `detach_volume` |
74
75
  | **Firewalls** | `list_firewalls`, `get_firewall`, `create_firewall`, `update_firewall`, `delete_firewall`; `apply_firewall_to_resources`, `remove_firewall_from_resources`, `set_firewall_rules` |
75
76
  | **Floating IPs** | `list_floating_ips`, `create_floating_ip`, `update_floating_ip`, `delete_floating_ip`; `assign_floating_ip`, `unassign_floating_ip` |
76
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) |
77
78
  | **SSH Keys** | `list_ssh_keys`, `create_ssh_key`, `update_ssh_key`, `delete_ssh_key` |
78
79
  | **Placement Groups** | `list_placement_groups`, `create_placement_group`, `update_placement_group`, `delete_placement_group` |
79
- | **Metadata & actions** | `list_locations`, `list_images`, `list_server_types`, `list_load_balancer_types`, `list_datacenters`, `get_pricing`; `list_actions`, `get_action` (poll async operations) |
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*`) |
88
+ | **Metadata & actions** | `list_locations`, `list_images`, `list_server_types`, `list_load_balancer_types`, `get_pricing`; `list_actions`, `get_action` (poll async operations) |
80
89
 
81
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`.
82
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
+
107
+ ### Server instructions and agent skill
108
+
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`.
110
+
111
+ For deeper guidance, install the bundled skill **`hetzner-cloud`** (`skills/hetzner-cloud/SKILL.md`). It covers argument shapes, the required order for Primary IP swaps and teardowns, and fixes for common errors.
112
+
113
+ ```bash
114
+ # Claude Code (personal skills)
115
+ mkdir -p ~/.claude/skills && cp -r skills/hetzner-cloud ~/.claude/skills/
116
+ # or from an npm install:
117
+ cp -r "$(npm root -g)/hcloud-mcp/skills/hetzner-cloud" ~/.claude/skills/
118
+ ```
119
+
120
+ The skill is also included in the npm package.
121
+
122
+ ## API compatibility
123
+
124
+ Updated in 0.2.0 for Hetzner Cloud API changes through November 2026 ([changelog](https://docs.hetzner.cloud/changelog)):
125
+
126
+ - `list_datacenters` is **removed**, because the endpoint now returns 410 Gone. Use `list_locations`.
127
+ - `create_server` no longer accepts `datacenter`, because the API removed it on 2026-07-01. Use `location`.
128
+ - `create_primary_ip` takes `location` instead of `datacenter`.
129
+ - `delete_load_balancer` now returns the deletion Action.
130
+ - `add_network_subnet` no longer offers the deprecated `server` type. Use `cloud`.
131
+ - List tools now return every page. Previously they silently stopped at the first 25 items.
132
+ - Floating IPs and Primary IPs must be unassigned before you delete them.
133
+ - `list_actions` requires `id`, because Hetzner removed project-wide action listing. Use `get_action` to poll.
134
+
135
+ Hetzner Robot (dedicated servers) is not covered yet; see [#21](https://github.com/Xodus-CO/hcloud-mcp/issues/21).
136
+
83
137
  ## Usage examples
84
138
 
85
139
  With the MCP client connected, you can ask the agent to run tools using natural language.
@@ -87,21 +141,23 @@ With the MCP client connected, you can ask the agent to run tools using natural
87
141
  ### Simple
88
142
 
89
143
  - _List my servers in Nuremberg_
90
- - _Create a cx22 server with Ubuntu 24.04_
91
- - _Create a cx22 server with Ubuntu 24.04 using my SSH key 'macbook'_
144
+ - _Create the cheapest available server in fsn1 with Ubuntu 24.04_
145
+ - _Create a small Ubuntu 24.04 server using my SSH key 'macbook'_
92
146
  - _Attach a 10GB volume to web-01_
93
147
  - _Set up a load balancer for my web servers_
94
148
  - _List load balancer types_
95
149
  - _Show current pricing for cpx31 servers_
96
150
  - _Get status of action 12345_
151
+ - _Add an A record for www.example.com pointing to my web-01 server_
152
+ - _Export the zone file for example.com_
97
153
 
98
154
  ### Complex
99
155
 
100
156
  - _Create a private network 10.0.0.0/16 in eu-central, add a subnet, then create two servers in that zone (e.g. fsn1 and nbg1) and attach them_
101
157
  - _Create a firewall for SSH and HTTP, attach to my web servers, then create a load balancer and add those servers as targets_
102
- - _List running actions and get status of action 12345_
103
- - _Create a Primary IP in ash-dc1, power off web-01, assign the IP, power back on_
104
- - _Create a 20GB volume and a cx22 server in nbg1, attach the volume to the server, and show me the device path_
158
+ - _Get status of action 12345_
159
+ - _Create a Primary IP in ash, power off web-01, assign the IP, power back on_
160
+ - _Create a 20GB volume and a small server in nbg1, attach the volume to the server, and show me the device path_
105
161
  - _Power off server 12345, change its type to cpx31, then power it back on_
106
162
  - _Add server web-02 as a target to my load balancer prod-lb_
107
163
  - _Tear down: detach/delete volumes, delete LB and firewall, unassign/delete floating IPs, delete servers web-01 and web-02_
@@ -112,6 +168,16 @@ With the MCP client connected, you can ask the agent to run tools using natural
112
168
  | ----------------------- | ----------------------------------------------------------- |
113
169
  | `src/index.ts` | Entry point, stdio transport, `HCLOUD_TOKEN` check |
114
170
  | `src/register-tools.ts` | Tool definitions and Hetzner API calls (uses SDK McpServer) |
171
+ | `src/extra-tools.ts` | Newer Cloud API endpoints (reverse DNS, rebuild, network members) |
172
+ | `src/dns-tools.ts` | DNS zone/RRSet tools (direct API client, not in the SDK) |
173
+ | `src/hcloud-api.ts` | Minimal fetch client for endpoints hetzner-sdk-ts lacks |
174
+ | `src/action-gap-tools.ts` | Placement groups, alias IPs, LB network/type/algorithm/public interface, routes, ISOs |
175
+ | `src/image-tools.ts` | Snapshots, backups, image management, `change_protection` |
176
+ | `src/server-ops-tools.ts` | Rescue, console, root password, server/LB metrics |
177
+ | `src/certificate-tools.ts` | TLS certificates |
178
+ | `src/storage-box-tools.ts` | Storage Boxes (api.hetzner.com, same token) |
179
+ | `src/instructions.ts` | Server instructions sent to MCP clients at initialize |
180
+ | `skills/hetzner-cloud/` | Agent skill (SKILL.md) for driving this server safely |
115
181
 
116
182
  **Scripts:**
117
183
 
@@ -122,6 +188,13 @@ npm run dev # watch and recompile
122
188
  npm run test:api # test list_* Hetzner API calls (requires HCLOUD_TOKEN)
123
189
  npm run test:mcp # integration test: MCP client calls list_locations (requires HCLOUD_TOKEN)
124
190
  npm run audit:api # verify create_* request body shapes (DRY_RUN=1, no resources created)
191
+ npm run test:live:dns # DNS create→teardown on a throwaway zone (free)
192
+ npm run test:live:images # snapshots, backups, protection (costs cents)
193
+ npm run test:live:ops # rescue, console, root password, metrics (costs cents)
194
+ npm run test:live:actions # placement groups, alias IPs, LB/network actions, ISOs (costs cents)
195
+ npm run test:live:certs # uploaded self-signed certificate lifecycle (free)
196
+ npm run test:live:storage # Storage Box lifecycle on a new bx11 (fractions of a cent; never touches existing boxes)
197
+ 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)
125
198
  ```
126
199
 
127
200
  ## License
@@ -0,0 +1,66 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { 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.tool("add_server_to_placement_group", "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", {
8
+ id: z.number().describe("Server ID"),
9
+ placement_group: z.number().describe("Placement group ID"),
10
+ }, async ({ id, placement_group }) => action(`/servers/${id}/actions/add_to_placement_group`, { placement_group }));
11
+ server.tool("remove_server_from_placement_group", "Remove a server from its placement group. Returns an Action", { id: z.number().describe("Server ID") }, async ({ id }) => action(`/servers/${id}/actions/remove_from_placement_group`));
12
+ server.tool("change_server_alias_ips", "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", {
13
+ id: z.number().describe("Server ID"),
14
+ network: z.number().describe("ID of a network already attached to the server"),
15
+ alias_ips: z.array(z.string()).describe("Complete new list of alias IPs, e.g. [\"10.0.1.50\"]"),
16
+ }, async ({ id, network, alias_ips }) => action(`/servers/${id}/actions/change_alias_ips`, { network, alias_ips }));
17
+ // --- Load balancers ---
18
+ server.tool("attach_load_balancer_to_network", "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", {
19
+ id: z.number().describe("Load balancer ID"),
20
+ network: z.number().describe("Network ID"),
21
+ ip: z.string().optional().describe("Private IP to assign; auto-assigned if omitted"),
22
+ ip_range: z.string().optional().describe("Subnet ip_range (CIDR) to auto-assign the IP from, e.g. 10.0.1.0/24"),
23
+ }, async ({ id, network, ip, ip_range }) => action(`/load_balancers/${id}/actions/attach_to_network`, { network, ip, ip_range }));
24
+ server.tool("detach_load_balancer_from_network", "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", {
25
+ id: z.number().describe("Load balancer ID"),
26
+ network: z.number().describe("Network ID"),
27
+ }, async ({ id, network }) => action(`/load_balancers/${id}/actions/detach_from_network`, { network }));
28
+ server.tool("change_load_balancer_algorithm", "Change how a load balancer distributes new requests across targets. Returns an Action", {
29
+ id: z.number().describe("Load balancer ID"),
30
+ type: z.enum(["round_robin", "least_connections"]),
31
+ }, async ({ id, type }) => action(`/load_balancers/${id}/actions/change_algorithm`, { type }));
32
+ server.tool("change_load_balancer_type", "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", {
33
+ id: z.number().describe("Load balancer ID"),
34
+ load_balancer_type: z.string().describe("Type name or ID, e.g. lb11, lb21, lb31"),
35
+ }, async ({ id, load_balancer_type }) => action(`/load_balancers/${id}/actions/change_type`, { load_balancer_type }));
36
+ server.tool("enable_load_balancer_public_interface", "Enable a load balancer's public interface so it is reachable from the internet via its public IPs. Returns an Action", { id: z.number().describe("Load balancer ID") }, async ({ id }) => action(`/load_balancers/${id}/actions/enable_public_interface`));
37
+ server.tool("disable_load_balancer_public_interface", "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", { id: z.number().describe("Load balancer ID") }, async ({ id }) => action(`/load_balancers/${id}/actions/disable_public_interface`));
38
+ // --- Networks ---
39
+ server.tool("add_network_route", "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", {
40
+ id: z.number().describe("Network ID"),
41
+ destination: z.string().describe("Destination CIDR, e.g. 10.100.1.0/24 or 0.0.0.0/0"),
42
+ gateway: z.string().describe("Gateway IP inside the network, e.g. a server's private IP 10.0.1.2"),
43
+ }, async ({ id, destination, gateway }) => action(`/networks/${id}/actions/add_route`, { destination, gateway }));
44
+ server.tool("delete_network_route", "Delete a route from a network. destination and gateway must match the existing route exactly (see get_network routes). Returns an Action", {
45
+ id: z.number().describe("Network ID"),
46
+ destination: z.string().describe("Destination CIDR of the route"),
47
+ gateway: z.string().describe("Gateway IP of the route"),
48
+ }, async ({ id, destination, gateway }) => action(`/networks/${id}/actions/delete_route`, { destination, gateway }));
49
+ server.tool("change_network_ip_range", "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", {
50
+ id: z.number().describe("Network ID"),
51
+ ip_range: z.string().describe("New range in CIDR, same start IP as the current range, e.g. 10.0.0.0/15"),
52
+ }, async ({ id, ip_range }) => action(`/networks/${id}/actions/change_ip_range`, { ip_range }));
53
+ // --- ISOs ---
54
+ server.tool("list_isos", "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", {
55
+ name: z.string().optional().describe("Exact ISO name"),
56
+ architecture: z.enum(["x86", "arm"]).optional(),
57
+ include_architecture_wildcard: z.boolean().optional()
58
+ .describe("Also include ISOs with architecture null; only valid together with architecture"),
59
+ }, async (filters) => withToolError(async () => {
60
+ if (filters.include_architecture_wildcard !== undefined && !filters.architecture) {
61
+ throw new Error("include_architecture_wildcard requires architecture");
62
+ }
63
+ const isos = await listAll((p) => hcloudRequest("GET", "/isos", { query: { ...filters, page: p.page, per_page: p.perPage } }), "isos");
64
+ return json(isos);
65
+ }));
66
+ }
@@ -0,0 +1,65 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { 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.tool("list_certificates", "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)", {
14
+ name: z.string().optional().describe("Exact certificate name"),
15
+ label_selector: z.string().optional().describe("Label selector, e.g. env=prod"),
16
+ type: z.array(certType).optional().describe("Filter by type(s)"),
17
+ }, async (args) => withToolError(async () => {
18
+ const certs = await listAll((p) => hcloudRequest("GET", "/certificates", { query: { ...args, page: p.page, per_page: p.perPage } }), "certificates");
19
+ return json(certs);
20
+ }));
21
+ server.tool("get_certificate", "Get a TLS certificate: PEM chain (public), domain_names, validity window, fingerprint, used_by, and for managed certs status.issuance / status.renewal / status.error", { id: certId }, async ({ id }) => withToolError(async () => json((await hcloudRequest("GET", `/certificates/${id}`)).certificate)));
22
+ server.tool("create_certificate", "Create a TLS certificate. type \"uploaded\" (default): provide certificate (PEM, leaf first then chain) and private_key (PEM); " +
23
+ "supported keys RSA 2048/3072/4096 or ECDSA P-256/P-384; you must renew it yourself before not_valid_after. " +
24
+ "type \"managed\": provide domain_names; Hetzner requests and auto-renews a Let's Encrypt cert. " +
25
+ MANAGED_REQUIREMENTS +
26
+ ". Returns {certificate, action}: action tracks managed issuance (poll get_action), null for uploaded. " +
27
+ USAGE, {
28
+ name: z.string().describe("Unique name within the project"),
29
+ type: certType.default("uploaded"),
30
+ certificate: z.string().optional().describe("uploaded only: certificate + chain in PEM, each cert certifying the preceding one"),
31
+ private_key: z.string().optional().describe("uploaded only: private key in PEM. Sent to the API only; never returned"),
32
+ domain_names: z.array(z.string()).optional().describe('managed only: domains to include, e.g. ["example.com", "www.example.com"]'),
33
+ labels: labels.optional(),
34
+ }, async (args) => withToolError(async () => {
35
+ const { name, type, certificate, private_key, domain_names, labels } = args;
36
+ let body;
37
+ if (type === "uploaded") {
38
+ if (!certificate || !private_key)
39
+ throw new Error("type=uploaded requires both certificate and private_key (PEM)");
40
+ if (domain_names?.length)
41
+ throw new Error("domain_names is only valid for type=managed (uploaded certs take their domains from the PEM)");
42
+ body = { name, type, certificate, private_key, labels };
43
+ }
44
+ else {
45
+ if (!domain_names?.length)
46
+ throw new Error("type=managed requires a non-empty domain_names list");
47
+ if (certificate || private_key)
48
+ throw new Error("certificate/private_key are only valid for type=uploaded");
49
+ body = { name, type, domain_names, labels };
50
+ }
51
+ return json(await hcloudRequest("POST", "/certificates", { body }));
52
+ }));
53
+ server.tool("update_certificate", "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", { id: certId, name: z.string().optional(), labels: labels.optional() }, async ({ id, name, labels }) => withToolError(async () => {
54
+ if (name === undefined && labels === undefined)
55
+ throw new Error("Provide name and/or labels");
56
+ return json((await hcloudRequest("PUT", `/certificates/${id}`, { body: { name, labels } })).certificate);
57
+ }));
58
+ server.tool("delete_certificate", "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", { id: certId }, async ({ id }) => withToolError(async () => {
59
+ await hcloudRequest("DELETE", `/certificates/${id}`);
60
+ return json({ deleted: id });
61
+ }));
62
+ server.tool("retry_certificate", "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). " +
63
+ MANAGED_REQUIREMENTS +
64
+ ". Returns an Action (poll get_action)", { id: certId }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/certificates/${id}/actions/retry`))));
65
+ }
@@ -0,0 +1,86 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest, seg } from "./hcloud-api.js";
3
+ import { 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.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,
34
+ }, async (args) => withToolError(async () => {
35
+ const zones = await listAll((p) => hcloudRequest("GET", "/zones", { query: { ...args, page: p.page, per_page: p.perPage } }), "zones");
36
+ return json(zones);
37
+ }));
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)"),
50
+ }, async (args) => withToolError(async () => {
51
+ if (args.rrsets && args.zonefile)
52
+ throw new Error("Provide rrsets OR zonefile, not both");
53
+ if (args.mode === "secondary" && !args.primary_nameservers?.length) {
54
+ throw new Error("mode=secondary requires primary_nameservers");
55
+ }
56
+ return json(await hcloudRequest("POST", "/zones", { body: args }));
57
+ }));
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 () => {
61
+ const res = await hcloudRequest("GET", `/zones/${seg(zone)}/zonefile`);
62
+ return { content: [{ type: "text", text: res.zonefile ?? JSON.stringify(res, null, 2) }] };
63
+ }));
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 } }))));
68
+ // --- 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");
71
+ return json(rrsets);
72
+ }));
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),
83
+ }, 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 } }))));
86
+ }
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { 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.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"),
16
+ }, 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
+ }, 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)"),
29
+ }, 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");
31
+ return json(members);
32
+ }));
33
+ }
@@ -0,0 +1,52 @@
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";
4
+ // Cloud API (servers, networks, DNS, ...) and the Hetzner API (Storage Boxes) accept the same project token.
5
+ export const CLOUD_API = "https://api.hetzner.cloud/v1";
6
+ export const HETZNER_API = "https://api.hetzner.com/v1";
7
+ export class HcloudApiError extends Error {
8
+ status;
9
+ code;
10
+ details;
11
+ constructor(status, code, message, details) {
12
+ super(`${code} (${status}): ${message}${details ? ` ${JSON.stringify(details)}` : ""}`);
13
+ this.status = status;
14
+ this.code = code;
15
+ this.details = details;
16
+ }
17
+ }
18
+ function token() {
19
+ const t = (typeof OpenAPI.TOKEN === "string" ? OpenAPI.TOKEN : undefined) ?? process.env.HCLOUD_TOKEN;
20
+ if (!t)
21
+ throw new Error("HCLOUD_TOKEN is not set");
22
+ return t;
23
+ }
24
+ export async function hcloudRequest(method, path, options = {}) {
25
+ const url = new URL((options.baseUrl ?? CLOUD_API) + path);
26
+ for (const [k, raw] of Object.entries(options.query ?? {})) {
27
+ // Arrays become repeated params (?status=ok&status=error), as the API expects.
28
+ for (const v of Array.isArray(raw) ? raw : [raw]) {
29
+ if (v !== undefined && v !== null && v !== "")
30
+ url.searchParams.append(k, String(v));
31
+ }
32
+ }
33
+ const res = await fetch(url, {
34
+ method,
35
+ headers: {
36
+ Authorization: `Bearer ${token()}`,
37
+ ...(options.body !== undefined ? { "Content-Type": "application/json" } : {}),
38
+ },
39
+ body: options.body !== undefined ? JSON.stringify(options.body) : undefined,
40
+ });
41
+ if (res.status === 204)
42
+ return {};
43
+ const text = await res.text();
44
+ const data = text ? JSON.parse(text) : {};
45
+ if (!res.ok) {
46
+ const err = data?.error ?? {};
47
+ throw new HcloudApiError(res.status, err.code ?? "http_error", err.message ?? res.statusText, err.details);
48
+ }
49
+ return data;
50
+ }
51
+ /** Encode a path segment (zone names, RRSet names like "@" or "_acme-challenge"). */
52
+ export const seg = (value) => encodeURIComponent(String(value));
@@ -0,0 +1,85 @@
1
+ import { z } from "zod";
2
+ import { hcloudRequest } from "./hcloud-api.js";
3
+ import { json, listAll, withToolError } from "./tool-helpers.js";
4
+ const labelsSchema = z.record(z.string(), z.string());
5
+ // Every resource whose spec has POST /{collection}/{id}/actions/change_protection.
6
+ // Certificates have no change_protection action. DNS zones and RRSets are covered by
7
+ // change_zone_protection / change_rrset_protection in dns-tools.ts.
8
+ const PROTECTION_RESOURCES = {
9
+ server: "servers",
10
+ volume: "volumes",
11
+ floating_ip: "floating_ips",
12
+ primary_ip: "primary_ips",
13
+ load_balancer: "load_balancers",
14
+ network: "networks",
15
+ image: "images",
16
+ };
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(),
23
+ }, async ({ id, description, type, labels }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/create_image`, {
24
+ body: { type: type ?? "snapshot", description, labels },
25
+ }))));
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"),
36
+ }, async ({ type, ...filters }) => withToolError(async () => {
37
+ const images = await listAll((p) => hcloudRequest("GET", "/images", {
38
+ query: { type: type ?? ["snapshot", "backup"], ...filters, page: p.page, per_page: p.perPage },
39
+ }), "images");
40
+ return json(images);
41
+ }));
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"),
48
+ }, async ({ id, description, type, labels }) => withToolError(async () => {
49
+ if (description === undefined && type === undefined && labels === undefined) {
50
+ throw new Error("Pass at least one of description, type, labels");
51
+ }
52
+ return json(await hcloudRequest("PUT", `/images/${id}`, { body: { description, type, labels } }));
53
+ }));
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 () => {
55
+ await hcloudRequest("DELETE", `/images/${id}`);
56
+ return json({ deleted: true, id });
57
+ }));
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"),
65
+ }, async ({ resource, id, delete: del, rebuild }) => withToolError(async () => {
66
+ let body;
67
+ if (resource === "server") {
68
+ if (del === undefined && rebuild === undefined)
69
+ throw new Error("Pass delete and/or rebuild");
70
+ if (del !== undefined && rebuild !== undefined && del !== rebuild) {
71
+ throw new Error("For servers the API currently requires delete and rebuild to have the same value");
72
+ }
73
+ const value = (del ?? rebuild);
74
+ body = { delete: value, rebuild: value };
75
+ }
76
+ else {
77
+ if (rebuild !== undefined)
78
+ throw new Error(`rebuild protection only exists for servers, not ${resource}`);
79
+ if (del === undefined)
80
+ throw new Error("Pass delete (true or false)");
81
+ body = { delete: del };
82
+ }
83
+ return json(await hcloudRequest("POST", `/${PROTECTION_RESOURCES[resource]}/${id}/actions/change_protection`, { body }));
84
+ }));
85
+ }
package/dist/index.js CHANGED
@@ -6,6 +6,14 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
7
  import { OpenAPI } from "hetzner-sdk-ts";
8
8
  import { registerTools } from "./register-tools.js";
9
+ import { registerDnsTools } from "./dns-tools.js";
10
+ import { registerExtraTools } from "./extra-tools.js";
11
+ import { registerStorageBoxTools } from "./storage-box-tools.js";
12
+ import { registerCertificateTools } from "./certificate-tools.js";
13
+ import { registerImageTools } from "./image-tools.js";
14
+ import { registerServerOpsTools } from "./server-ops-tools.js";
15
+ import { registerActionGapTools } from "./action-gap-tools.js";
16
+ import { SERVER_INSTRUCTIONS } from "./instructions.js";
9
17
  // Load .env from project root (parent of dist) so IDE-spawned server finds token when env isn't set
10
18
  if (!process.env.HCLOUD_TOKEN) {
11
19
  const __dirname = dirname(fileURLToPath(import.meta.url));
@@ -17,8 +25,30 @@ if (!token) {
17
25
  process.exit(1);
18
26
  }
19
27
  OpenAPI.TOKEN = token;
20
- const server = new McpServer({ name: "hetzner-cloud", version: "0.1.0" }, { capabilities: { tools: {} } });
21
- registerTools(server);
28
+ const server = new McpServer({ name: "hetzner-cloud", version: "0.3.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
29
+ // Tool groups. HCLOUD_TOOLSETS (comma-separated) limits which load, for clients with
30
+ // tool-count limits; default is all. "core" is always loaded.
31
+ const TOOLSETS = {
32
+ core: [registerTools, registerExtraTools, registerActionGapTools],
33
+ dns: [registerDnsTools],
34
+ images: [registerImageTools],
35
+ ops: [registerServerOpsTools],
36
+ certificates: [registerCertificateTools],
37
+ storage_boxes: [registerStorageBoxTools],
38
+ };
39
+ const requested = (process.env.HCLOUD_TOOLSETS ?? "")
40
+ .split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
41
+ const unknown = requested.filter((t) => t !== "all" && !(t in TOOLSETS));
42
+ if (unknown.length) {
43
+ console.error(`Error: unknown HCLOUD_TOOLSETS ${unknown.join(", ")}. Valid: all, ${Object.keys(TOOLSETS).join(", ")}`);
44
+ process.exit(1);
45
+ }
46
+ const enabled = requested.length === 0 || requested.includes("all")
47
+ ? Object.keys(TOOLSETS)
48
+ : ["core", ...requested.filter((t) => t !== "core")];
49
+ for (const name of enabled)
50
+ for (const register of TOOLSETS[name])
51
+ register(server);
22
52
  async function main() {
23
53
  const transport = new StdioServerTransport();
24
54
  await server.connect(transport);