hcloud-mcp 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -7
- package/dist/index.js +2 -1
- package/dist/instructions.js +13 -0
- package/dist/register-tools.js +71 -58
- package/package.json +2 -1
- package/scripts/test-list-api.mjs +0 -8
- package/scripts/test-live-lifecycle.mjs +187 -0
- package/skills/hetzner-cloud/SKILL.md +50 -0
package/README.md
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
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
4
|
|
|
5
5
|
- **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
6
|
- **Hetzner Cloud:** [Get started](https://hetzner.cloud/?ref=IAYKetqPnlq9) — new signups get €20 credit.
|
|
8
7
|
|
|
9
8
|
---
|
|
@@ -76,10 +75,40 @@ The server exposes Hetzner Cloud API operations as MCP tools:
|
|
|
76
75
|
| **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
76
|
| **SSH Keys** | `list_ssh_keys`, `create_ssh_key`, `update_ssh_key`, `delete_ssh_key` |
|
|
78
77
|
| **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`, `
|
|
78
|
+
| **Metadata & actions** | `list_locations`, `list_images`, `list_server_types`, `list_load_balancer_types`, `get_pricing`; `list_actions`, `get_action` (poll async operations) |
|
|
80
79
|
|
|
81
80
|
> **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
81
|
|
|
82
|
+
### Server instructions and agent skill
|
|
83
|
+
|
|
84
|
+
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`.
|
|
85
|
+
|
|
86
|
+
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.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Claude Code (personal skills)
|
|
90
|
+
mkdir -p ~/.claude/skills && cp -r skills/hetzner-cloud ~/.claude/skills/
|
|
91
|
+
# or from an npm install:
|
|
92
|
+
cp -r "$(npm root -g)/hcloud-mcp/skills/hetzner-cloud" ~/.claude/skills/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The skill is also included in the npm package.
|
|
96
|
+
|
|
97
|
+
## API compatibility
|
|
98
|
+
|
|
99
|
+
Updated in 0.2.0 for Hetzner Cloud API changes through November 2026 ([changelog](https://docs.hetzner.cloud/changelog)):
|
|
100
|
+
|
|
101
|
+
- `list_datacenters` is **removed**, because the endpoint now returns 410 Gone. Use `list_locations`.
|
|
102
|
+
- `create_server` no longer accepts `datacenter`, because the API removed it on 2026-07-01. Use `location`.
|
|
103
|
+
- `create_primary_ip` takes `location` instead of `datacenter`.
|
|
104
|
+
- `delete_load_balancer` now returns the deletion Action.
|
|
105
|
+
- `add_network_subnet` no longer offers the deprecated `server` type. Use `cloud`.
|
|
106
|
+
- List tools now return every page. Previously they silently stopped at the first 25 items.
|
|
107
|
+
- Floating IPs and Primary IPs must be unassigned before you delete them.
|
|
108
|
+
- `list_actions` requires `id`, because Hetzner removed project-wide action listing. Use `get_action` to poll.
|
|
109
|
+
|
|
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).
|
|
111
|
+
|
|
83
112
|
## Usage examples
|
|
84
113
|
|
|
85
114
|
With the MCP client connected, you can ask the agent to run tools using natural language.
|
|
@@ -87,8 +116,8 @@ With the MCP client connected, you can ask the agent to run tools using natural
|
|
|
87
116
|
### Simple
|
|
88
117
|
|
|
89
118
|
- _List my servers in Nuremberg_
|
|
90
|
-
- _Create
|
|
91
|
-
- _Create a
|
|
119
|
+
- _Create the cheapest available server in fsn1 with Ubuntu 24.04_
|
|
120
|
+
- _Create a small Ubuntu 24.04 server using my SSH key 'macbook'_
|
|
92
121
|
- _Attach a 10GB volume to web-01_
|
|
93
122
|
- _Set up a load balancer for my web servers_
|
|
94
123
|
- _List load balancer types_
|
|
@@ -99,9 +128,9 @@ With the MCP client connected, you can ask the agent to run tools using natural
|
|
|
99
128
|
|
|
100
129
|
- _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
130
|
- _Create a firewall for SSH and HTTP, attach to my web servers, then create a load balancer and add those servers as targets_
|
|
102
|
-
-
|
|
103
|
-
- _Create a Primary IP in ash
|
|
104
|
-
- _Create a 20GB volume and a
|
|
131
|
+
- _Get status of action 12345_
|
|
132
|
+
- _Create a Primary IP in ash, power off web-01, assign the IP, power back on_
|
|
133
|
+
- _Create a 20GB volume and a small server in nbg1, attach the volume to the server, and show me the device path_
|
|
105
134
|
- _Power off server 12345, change its type to cpx31, then power it back on_
|
|
106
135
|
- _Add server web-02 as a target to my load balancer prod-lb_
|
|
107
136
|
- _Tear down: detach/delete volumes, delete LB and firewall, unassign/delete floating IPs, delete servers web-01 and web-02_
|
|
@@ -112,6 +141,8 @@ With the MCP client connected, you can ask the agent to run tools using natural
|
|
|
112
141
|
| ----------------------- | ----------------------------------------------------------- |
|
|
113
142
|
| `src/index.ts` | Entry point, stdio transport, `HCLOUD_TOKEN` check |
|
|
114
143
|
| `src/register-tools.ts` | Tool definitions and Hetzner API calls (uses SDK McpServer) |
|
|
144
|
+
| `src/instructions.ts` | Server instructions sent to MCP clients at initialize |
|
|
145
|
+
| `skills/hetzner-cloud/` | Agent skill (SKILL.md) for driving this server safely |
|
|
115
146
|
|
|
116
147
|
**Scripts:**
|
|
117
148
|
|
|
@@ -122,6 +153,7 @@ npm run dev # watch and recompile
|
|
|
122
153
|
npm run test:api # test list_* Hetzner API calls (requires HCLOUD_TOKEN)
|
|
123
154
|
npm run test:mcp # integration test: MCP client calls list_locations (requires HCLOUD_TOKEN)
|
|
124
155
|
npm run audit:api # verify create_* request body shapes (DRY_RUN=1, no resources created)
|
|
156
|
+
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
157
|
```
|
|
126
158
|
|
|
127
159
|
## License
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ 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 { SERVER_INSTRUCTIONS } from "./instructions.js";
|
|
9
10
|
// Load .env from project root (parent of dist) so IDE-spawned server finds token when env isn't set
|
|
10
11
|
if (!process.env.HCLOUD_TOKEN) {
|
|
11
12
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -17,7 +18,7 @@ if (!token) {
|
|
|
17
18
|
process.exit(1);
|
|
18
19
|
}
|
|
19
20
|
OpenAPI.TOKEN = token;
|
|
20
|
-
const server = new McpServer({ name: "hetzner-cloud", version: "0.
|
|
21
|
+
const server = new McpServer({ name: "hetzner-cloud", version: "0.2.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS });
|
|
21
22
|
registerTools(server);
|
|
22
23
|
async function main() {
|
|
23
24
|
const transport = new StdioServerTransport();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Sent to MCP clients in the initialize response; most clients put it in the model's context.
|
|
2
|
+
// Keep it short and about how to use the tools, not a list of them.
|
|
3
|
+
export const SERVER_INSTRUCTIONS = `Hetzner Cloud API tools. Notes:
|
|
4
|
+
|
|
5
|
+
- Placement is by location (fsn1, nbg1, hel1, ash, hil, sin), not datacenter. Datacenters were removed from the API in 2026.
|
|
6
|
+
- Before create_server, call list_server_types. Each type has locations[] with available, recommended and deprecation. Pick a location where the type is available and not deprecated. Call list_images and skip any image whose deprecation is set.
|
|
7
|
+
- Most create, delete and action tools return an Action. They run asynchronously. Poll get_action until status is "success" or "error" before you start a step that depends on the result.
|
|
8
|
+
- Detach first, then delete. Floating IPs and Primary IPs must be unassigned before deletion (error must_be_unassigned). Assigning or unassigning a Primary IP requires the server to be powered off. Detach volumes and remove LB targets before you delete their servers.
|
|
9
|
+
- Firewall CIDRs must not have host bits set. Use 10.0.1.0/24, not 10.0.1.42/24. For a single host use /32 or /128.
|
|
10
|
+
- For private networks use subnet type "cloud". Type "server" is deprecated.
|
|
11
|
+
- List tools return all pages. In large projects, prefer get_* by ID when you already know it.
|
|
12
|
+
- Destructive tools (delete_*, reset_server, change_server_type, power_off_server) act immediately with no undo. Confirm with the user before using them on resources you did not create in this session.
|
|
13
|
+
- Pricing: get_pricing returns prices per location and server type, in EUR, with and without VAT.`;
|
package/dist/register-tools.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ServersService, LoadBalancersService, NetworksService, VolumesService, FirewallsService, FirewallActionsService, FloatingIPsService, SshKeysService, ImagesService, LocationsService, ServerTypesService, PlacementGroupsService, PrimaryIPsService, ServerActionsService, VolumeActionsService, FloatingIpActionsService, LoadBalancerActionsService, NetworkActionsService, PricingService, ActionsService, LoadBalancerTypesService,
|
|
1
|
+
import { ServersService, LoadBalancersService, NetworksService, VolumesService, FirewallsService, FirewallActionsService, FloatingIPsService, SshKeysService, ImagesService, LocationsService, ServerTypesService, PlacementGroupsService, PrimaryIPsService, ServerActionsService, VolumeActionsService, FloatingIpActionsService, LoadBalancerActionsService, NetworkActionsService, PricingService, ActionsService, LoadBalancerTypesService, PrimaryIpActionsService, } from "hetzner-sdk-ts";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
// Firewall rule: direction, protocol required; source_ips for 'in', destination_ips for 'out'; port for tcp/udp
|
|
4
4
|
const firewallRuleSchema = z.object({
|
|
5
5
|
direction: z.enum(["in", "out"]),
|
|
6
6
|
protocol: z.enum(["tcp", "udp", "icmp", "esp", "gre"]),
|
|
7
|
-
source_ips: z.array(z.string()).optional(),
|
|
8
|
-
destination_ips: z.array(z.string()).optional(),
|
|
7
|
+
source_ips: z.array(z.string()).optional().describe("CIDRs for direction=in; host bits must be zero (10.0.1.0/24, not 10.0.1.42/24; single host 192.0.2.2/32)"),
|
|
8
|
+
destination_ips: z.array(z.string()).optional().describe("CIDRs for direction=out; host bits must be zero"),
|
|
9
9
|
port: z.string().optional(),
|
|
10
10
|
description: z.string().nullable().optional(),
|
|
11
11
|
});
|
|
@@ -28,11 +28,25 @@ async function withToolError(run) {
|
|
|
28
28
|
return { content: [{ type: "text", text: `Error: ${formatError(error)}` }], isError: true };
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
// Hetzner list endpoints are paginated (default 25, max 50 per page). Follow
|
|
32
|
+
// meta.pagination.next_page so list tools return every item, not just page 1.
|
|
33
|
+
// (Link headers are deprecated by Hetzner; meta.pagination is the supported mechanism.)
|
|
34
|
+
async function listAll(fetchPage, key) {
|
|
35
|
+
const items = [];
|
|
36
|
+
let page = 1;
|
|
37
|
+
while (page != null) {
|
|
38
|
+
const response = await fetchPage({ page, perPage: 50 });
|
|
39
|
+
items.push(...(response?.[key] ?? []));
|
|
40
|
+
const next = response?.meta?.pagination?.next_page ?? null;
|
|
41
|
+
page = next != null && next > page ? next : null; // guard against non-advancing pagination
|
|
42
|
+
}
|
|
43
|
+
return items;
|
|
44
|
+
}
|
|
31
45
|
export function registerTools(server) {
|
|
32
46
|
// --- Servers ---
|
|
33
47
|
server.tool("list_servers", "List all servers", {}, async (_args, _extra) => withToolError(async () => {
|
|
34
|
-
const
|
|
35
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
48
|
+
const items = await listAll((p) => ServersService.getServers(p), "servers");
|
|
49
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
36
50
|
}));
|
|
37
51
|
server.tool("get_server", "Get a single server by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
38
52
|
const response = await ServersService.getServers1({ id });
|
|
@@ -42,8 +56,7 @@ export function registerTools(server) {
|
|
|
42
56
|
name: z.string(),
|
|
43
57
|
server_type: z.string(),
|
|
44
58
|
image: z.string(),
|
|
45
|
-
location: z.string().optional().describe("
|
|
46
|
-
datacenter: z.string().optional().describe("ID or name (omit if location set)"),
|
|
59
|
+
location: z.string().optional().describe("Location name or ID, e.g. fsn1, nbg1, hel1, ash, hil, sin. Check list_server_types locations[].available first"),
|
|
47
60
|
start_after_create: z.boolean().optional(),
|
|
48
61
|
ssh_keys: z.array(z.union([z.string(), z.number()])).optional().describe("List of SSH key names or IDs"),
|
|
49
62
|
firewalls: z.array(z.object({ firewall: z.number() })).optional(),
|
|
@@ -66,7 +79,6 @@ export function registerTools(server) {
|
|
|
66
79
|
server_type: args.server_type,
|
|
67
80
|
image: args.image,
|
|
68
81
|
location: args.location,
|
|
69
|
-
datacenter: args.datacenter,
|
|
70
82
|
start_after_create: args.start_after_create,
|
|
71
83
|
ssh_keys: args.ssh_keys?.map((k) => (typeof k === "number" ? String(k) : k)),
|
|
72
84
|
firewalls: args.firewalls,
|
|
@@ -164,8 +176,8 @@ export function registerTools(server) {
|
|
|
164
176
|
}));
|
|
165
177
|
// --- Load Balancers ---
|
|
166
178
|
server.tool("list_load_balancers", "List all load balancers", {}, async (_args, _extra) => withToolError(async () => {
|
|
167
|
-
const
|
|
168
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
179
|
+
const items = await listAll((p) => LoadBalancersService.getLoadBalancers(p), "load_balancers");
|
|
180
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
169
181
|
}));
|
|
170
182
|
server.tool("get_load_balancer", "Get a single load balancer by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
171
183
|
const response = await LoadBalancersService.getLoadBalancers1({ id });
|
|
@@ -190,9 +202,10 @@ export function registerTools(server) {
|
|
|
190
202
|
const response = await LoadBalancersService.postLoadBalancers({ requestBody });
|
|
191
203
|
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
192
204
|
}));
|
|
193
|
-
server.tool("delete_load_balancer", "Delete a load balancer", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
194
|
-
|
|
195
|
-
|
|
205
|
+
server.tool("delete_load_balancer", "Delete a load balancer. Returns a delete_load_balancer Action; poll get_action until it finishes", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
206
|
+
// Since 2026-10-05 this returns 201 + Action (previously 204 empty).
|
|
207
|
+
const response = await LoadBalancersService.deleteLoadBalancers({ id });
|
|
208
|
+
return { content: [{ type: "text", text: JSON.stringify(response ?? { deleted: true }, null, 2) }] };
|
|
196
209
|
}));
|
|
197
210
|
server.tool("update_load_balancer", "Update a load balancer (name, labels)", {
|
|
198
211
|
id: z.number(),
|
|
@@ -320,8 +333,8 @@ export function registerTools(server) {
|
|
|
320
333
|
}));
|
|
321
334
|
// --- Networks ---
|
|
322
335
|
server.tool("list_networks", "List all networks", {}, async (_args, _extra) => withToolError(async () => {
|
|
323
|
-
const
|
|
324
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
336
|
+
const items = await listAll((p) => NetworksService.getNetworks(p), "networks");
|
|
337
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
325
338
|
}));
|
|
326
339
|
server.tool("get_network", "Get a single network by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
327
340
|
const response = await NetworksService.getNetworks1({ id });
|
|
@@ -364,7 +377,8 @@ export function registerTools(server) {
|
|
|
364
377
|
}));
|
|
365
378
|
server.tool("add_network_subnet", "Add a subnet to a network (e.g. for private networking 10.0.0.0/16 in a zone)", {
|
|
366
379
|
id: z.number().describe("Network ID"),
|
|
367
|
-
|
|
380
|
+
// "server" type is deprecated (removal 2027-04-15) and equivalent to "cloud".
|
|
381
|
+
type: z.enum(["cloud", "vswitch"]),
|
|
368
382
|
network_zone: z.string().describe("Network zone, e.g. eu-central"),
|
|
369
383
|
ip_range: z.string().optional().describe("CIDR, e.g. 10.0.0.0/24; omit for auto /24"),
|
|
370
384
|
vswitch_id: z.number().optional().describe("Required if type is vswitch"),
|
|
@@ -387,8 +401,8 @@ export function registerTools(server) {
|
|
|
387
401
|
}));
|
|
388
402
|
// --- Volumes ---
|
|
389
403
|
server.tool("list_volumes", "List all volumes", {}, async (_args, _extra) => withToolError(async () => {
|
|
390
|
-
const
|
|
391
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
404
|
+
const items = await listAll((p) => VolumesService.getVolumes(p), "volumes");
|
|
405
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
392
406
|
}));
|
|
393
407
|
server.tool("get_volume", "Get a single volume by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
394
408
|
const response = await VolumesService.getVolumes1({ id });
|
|
@@ -447,8 +461,8 @@ export function registerTools(server) {
|
|
|
447
461
|
}));
|
|
448
462
|
// --- Firewalls ---
|
|
449
463
|
server.tool("list_firewalls", "List all firewalls", {}, async (_args, _extra) => withToolError(async () => {
|
|
450
|
-
const
|
|
451
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
464
|
+
const items = await listAll((p) => FirewallsService.getFirewalls(p), "firewalls");
|
|
465
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
452
466
|
}));
|
|
453
467
|
server.tool("get_firewall", "Get a single firewall by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
454
468
|
const response = await FirewallsService.getFirewalls1({ id });
|
|
@@ -510,8 +524,8 @@ export function registerTools(server) {
|
|
|
510
524
|
}));
|
|
511
525
|
// --- Floating IPs ---
|
|
512
526
|
server.tool("list_floating_ips", "List all floating IPs", {}, async (_args, _extra) => withToolError(async () => {
|
|
513
|
-
const
|
|
514
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
527
|
+
const items = await listAll((p) => FloatingIPsService.getFloatingIps(p), "floating_ips");
|
|
528
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
515
529
|
}));
|
|
516
530
|
server.tool("create_floating_ip", "Create a floating IP", {
|
|
517
531
|
type: z.enum(["ipv4", "ipv6"]),
|
|
@@ -555,34 +569,36 @@ export function registerTools(server) {
|
|
|
555
569
|
const response = await FloatingIpActionsService.postFloatingIpsActionsUnassign({ id });
|
|
556
570
|
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
557
571
|
}));
|
|
558
|
-
server.tool("delete_floating_ip", "Delete a floating IP (
|
|
572
|
+
server.tool("delete_floating_ip", "Delete a floating IP. Must be unassigned first (unassign_floating_ip), else fails with must_be_unassigned", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
559
573
|
await FloatingIPsService.deleteFloatingIps({ id });
|
|
560
574
|
return { content: [{ type: "text", text: "Floating IP deleted successfully" }] };
|
|
561
575
|
}));
|
|
562
576
|
// --- Primary IPs ---
|
|
563
|
-
server.tool("list_primary_ips", "List all Primary IPs (static IPs bound to a
|
|
564
|
-
const
|
|
565
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
577
|
+
server.tool("list_primary_ips", "List all Primary IPs (static IPs bound to a location, assignable to one server)", {}, async (_args, _extra) => withToolError(async () => {
|
|
578
|
+
const items = await listAll((p) => PrimaryIPsService.getPrimaryIps(p), "primary_ips");
|
|
579
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
566
580
|
}));
|
|
567
|
-
server.tool("create_primary_ip", "Create a Primary IP (
|
|
581
|
+
server.tool("create_primary_ip", "Create a Primary IP (location-scoped; server must be off to assign). Provide location OR assignee_id (server).", {
|
|
568
582
|
name: z.string(),
|
|
569
583
|
type: z.enum(["ipv4", "ipv6"]),
|
|
570
|
-
|
|
571
|
-
assignee_id: z.number().optional().describe("Server ID to assign to immediately (omit if
|
|
584
|
+
location: z.string().optional().describe("Location name or ID, e.g. fsn1 (omit if assignee_id set)"),
|
|
585
|
+
assignee_id: z.number().optional().describe("Server ID to assign to immediately (omit if location set)"),
|
|
572
586
|
auto_delete: z.boolean().optional(),
|
|
573
587
|
labels: z.record(z.string()).optional(),
|
|
574
588
|
}, async (args, _extra) => withToolError(async () => {
|
|
575
|
-
const
|
|
589
|
+
const hasLocation = args.location != null && args.location !== "";
|
|
576
590
|
const hasAssignee = args.assignee_id != null;
|
|
577
|
-
if (
|
|
578
|
-
throw new Error("Provide exactly one of
|
|
591
|
+
if (hasLocation === hasAssignee) {
|
|
592
|
+
throw new Error("Provide exactly one of location or assignee_id (mutually exclusive)");
|
|
579
593
|
}
|
|
594
|
+
// hetzner-sdk-ts 1.0.1 still models the removed `datacenter` field; the API
|
|
595
|
+
// (since 2026-07-01) takes `location`. The SDK passes the body through as JSON.
|
|
580
596
|
const requestBody = {
|
|
581
597
|
name: args.name,
|
|
582
598
|
type: args.type,
|
|
583
|
-
|
|
584
|
-
datacenter: args.datacenter,
|
|
599
|
+
location: args.location,
|
|
585
600
|
assignee_id: args.assignee_id,
|
|
601
|
+
...(hasAssignee ? { assignee_type: "server" } : {}),
|
|
586
602
|
auto_delete: args.auto_delete,
|
|
587
603
|
labels: args.labels,
|
|
588
604
|
};
|
|
@@ -604,7 +620,7 @@ export function registerTools(server) {
|
|
|
604
620
|
});
|
|
605
621
|
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
606
622
|
}));
|
|
607
|
-
server.tool("delete_primary_ip", "Delete a Primary IP
|
|
623
|
+
server.tool("delete_primary_ip", "Delete a Primary IP. Must be unassigned first (unassign_primary_ip, server powered off), else fails with must_be_unassigned", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
608
624
|
await PrimaryIPsService.deletePrimaryIps({ id });
|
|
609
625
|
return { content: [{ type: "text", text: "Primary IP deleted successfully" }] };
|
|
610
626
|
}));
|
|
@@ -624,17 +640,18 @@ export function registerTools(server) {
|
|
|
624
640
|
}));
|
|
625
641
|
// --- SSH Keys ---
|
|
626
642
|
server.tool("list_ssh_keys", "List all SSH keys", {}, async (_args, _extra) => withToolError(async () => {
|
|
627
|
-
const
|
|
628
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
643
|
+
const items = await listAll((p) => SshKeysService.getSshKeys(p), "ssh_keys");
|
|
644
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
629
645
|
}));
|
|
630
|
-
server.tool("create_ssh_key", "Create a new SSH key", {
|
|
646
|
+
server.tool("create_ssh_key", "Create a new SSH key (public_key is trimmed; the API rejects leading whitespace)", {
|
|
631
647
|
name: z.string(),
|
|
632
648
|
public_key: z.string(),
|
|
633
649
|
labels: z.record(z.string()).optional(),
|
|
634
650
|
}, async (args, _extra) => withToolError(async () => {
|
|
635
651
|
const requestBody = {
|
|
636
652
|
name: args.name,
|
|
637
|
-
|
|
653
|
+
// API rejects leading whitespace since 2026-04-22; pasted keys often carry it.
|
|
654
|
+
public_key: args.public_key.trim(),
|
|
638
655
|
labels: args.labels,
|
|
639
656
|
};
|
|
640
657
|
const response = await SshKeysService.postSshKeys({ requestBody });
|
|
@@ -657,27 +674,23 @@ export function registerTools(server) {
|
|
|
657
674
|
}));
|
|
658
675
|
// --- General Info ---
|
|
659
676
|
server.tool("list_locations", "List all locations", {}, async (_args, _extra) => withToolError(async () => {
|
|
660
|
-
const
|
|
661
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
677
|
+
const items = await listAll((p) => LocationsService.getLocations(p), "locations");
|
|
678
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
662
679
|
}));
|
|
663
|
-
server.tool("list_images", "List all images", {}, async (_args, _extra) => withToolError(async () => {
|
|
664
|
-
const
|
|
665
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
680
|
+
server.tool("list_images", "List all images (check each image's `deprecation` field; deprecated images can stop being usable for new servers)", {}, async (_args, _extra) => withToolError(async () => {
|
|
681
|
+
const items = await listAll((p) => ImagesService.getImages(p), "images");
|
|
682
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
666
683
|
}));
|
|
667
|
-
server.tool("list_server_types", "List all server types", {}, async (_args, _extra) => withToolError(async () => {
|
|
668
|
-
const
|
|
669
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
684
|
+
server.tool("list_server_types", "List all server types. Per-location availability is in locations[]: available, recommended, deprecation (top-level `deprecated` was removed)", {}, async (_args, _extra) => withToolError(async () => {
|
|
685
|
+
const items = await listAll((p) => ServerTypesService.getServerTypes(p), "server_types");
|
|
686
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
670
687
|
}));
|
|
671
|
-
server.tool("list_load_balancer_types", "List all load balancer types (for create_load_balancer load_balancer_type)", {}, async (_args, _extra) => withToolError(async () => {
|
|
672
|
-
const
|
|
673
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
674
|
-
}));
|
|
675
|
-
server.tool("list_datacenters", "List all datacenters (e.g. ash-dc1; where servers can be created)", {}, async (_args, _extra) => withToolError(async () => {
|
|
676
|
-
const response = await DatacentersService.getDatacenters({});
|
|
677
|
-
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
688
|
+
server.tool("list_load_balancer_types", "List all load balancer types (for create_load_balancer load_balancer_type; check `deprecation`)", {}, async (_args, _extra) => withToolError(async () => {
|
|
689
|
+
const items = await listAll((p) => LoadBalancerTypesService.getLoadBalancerTypes(p), "load_balancer_types");
|
|
690
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
678
691
|
}));
|
|
679
|
-
server.tool("list_actions", "
|
|
680
|
-
id: z.number().
|
|
692
|
+
server.tool("list_actions", "Get an action by ID with optional status filter. Hetzner no longer supports listing all actions in a project, so id is required. Prefer get_action", {
|
|
693
|
+
id: z.number().describe("Action ID (required by the API since 2025-01-30)"),
|
|
681
694
|
status: z.enum(["running", "success", "error"]).optional(),
|
|
682
695
|
sort: z
|
|
683
696
|
.enum([
|
|
@@ -708,8 +721,8 @@ export function registerTools(server) {
|
|
|
708
721
|
}));
|
|
709
722
|
// --- Placement Groups ---
|
|
710
723
|
server.tool("list_placement_groups", "List all placement groups", {}, async (_args, _extra) => withToolError(async () => {
|
|
711
|
-
const
|
|
712
|
-
return { content: [{ type: "text", text: JSON.stringify(
|
|
724
|
+
const items = await listAll((p) => PlacementGroupsService.getPlacementGroups(p), "placement_groups");
|
|
725
|
+
return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
|
|
713
726
|
}));
|
|
714
727
|
server.tool("create_placement_group", "Create a new placement group", {
|
|
715
728
|
name: z.string(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hcloud-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Standalone MCP server for Hetzner Cloud API — use with Cursor, Claude Desktop, CLI, or any MCP client",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"dev": "tsc --watch",
|
|
15
15
|
"test:api": "node scripts/test-list-api.mjs",
|
|
16
16
|
"test:mcp": "node scripts/test-mcp-list.mjs",
|
|
17
|
+
"test:live": "node scripts/test-live-lifecycle.mjs",
|
|
17
18
|
"audit:api": "cross-env DRY_RUN=1 node scripts/audit-api-shapes.mjs"
|
|
18
19
|
},
|
|
19
20
|
"keywords": [
|
|
@@ -7,7 +7,6 @@ import "dotenv/config";
|
|
|
7
7
|
import {
|
|
8
8
|
LocationsService,
|
|
9
9
|
ServerTypesService,
|
|
10
|
-
DatacentersService,
|
|
11
10
|
OpenAPI,
|
|
12
11
|
} from "hetzner-sdk-ts";
|
|
13
12
|
|
|
@@ -35,13 +34,6 @@ async function run() {
|
|
|
35
34
|
console.error("list_server_types failed:", e.message || e);
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
console.log("Testing list_datacenters...");
|
|
39
|
-
try {
|
|
40
|
-
const r = await DatacentersService.getDatacenters({});
|
|
41
|
-
console.log("list_datacenters OK, datacenters:", r.datacenters?.length ?? 0);
|
|
42
|
-
} catch (e) {
|
|
43
|
-
console.error("list_datacenters failed:", e.message || e);
|
|
44
|
-
}
|
|
45
37
|
}
|
|
46
38
|
|
|
47
39
|
run();
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Live lifecycle test: drives the built MCP server (dist/index.js) through a full
|
|
3
|
+
* create → modify → teardown cycle against the real Hetzner API.
|
|
4
|
+
*
|
|
5
|
+
* COSTS MONEY (a few cents; Hetzner bills hourly). Creates resources labeled
|
|
6
|
+
* hcloud-mcp-test=<run-id> and always cleans up only that run's resources via a REST safety net in `finally`.
|
|
7
|
+
*
|
|
8
|
+
* Usage: HCLOUD_TOKEN=... node scripts/test-live-lifecycle.mjs (npm run build first)
|
|
9
|
+
*/
|
|
10
|
+
import "dotenv/config";
|
|
11
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
12
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
13
|
+
|
|
14
|
+
const token = process.env.HCLOUD_TOKEN;
|
|
15
|
+
if (!token) { console.error("HCLOUD_TOKEN required"); process.exit(1); }
|
|
16
|
+
|
|
17
|
+
const suffix = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 6)}`;
|
|
18
|
+
// Unique per run so the safety-net cleanup only ever touches this run's resources.
|
|
19
|
+
const LABEL = { "hcloud-mcp-test": suffix };
|
|
20
|
+
const results = [];
|
|
21
|
+
const ok = (step, detail = "") => { results.push(["ok", step]); console.log(`ok ${step}${detail ? " — " + detail : ""}`); };
|
|
22
|
+
|
|
23
|
+
const client = new Client({ name: "live-test", version: "0" });
|
|
24
|
+
await client.connect(new StdioClientTransport({ command: "node", args: ["dist/index.js"], env: { ...process.env, HCLOUD_TOKEN: token } }));
|
|
25
|
+
|
|
26
|
+
async function call(name, args = {}) {
|
|
27
|
+
const r = await client.callTool({ name, arguments: args });
|
|
28
|
+
const text = r.content[0].text;
|
|
29
|
+
if (r.isError) throw new Error(`${name} failed: ${text}`);
|
|
30
|
+
try { return JSON.parse(text); } catch { return text; }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Collect every Action id in a response (action / actions / next_actions) and poll until done.
|
|
34
|
+
async function waitActions(resp, label) {
|
|
35
|
+
if (!resp || typeof resp !== "object") return;
|
|
36
|
+
const ids = [resp.action?.id, ...(resp.actions ?? []).map((a) => a.id), ...(resp.next_actions ?? []).map((a) => a.id)].filter(Boolean);
|
|
37
|
+
for (const id of ids) {
|
|
38
|
+
for (let i = 0; i < 120; i++) {
|
|
39
|
+
const r = await call("get_action", { id });
|
|
40
|
+
const a = r.action ?? r;
|
|
41
|
+
if (a.status === "success") break;
|
|
42
|
+
if (a.status === "error") throw new Error(`${label}: action ${id} error ${JSON.stringify(a.error)}`);
|
|
43
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
44
|
+
if (i === 119) throw new Error(`${label}: action ${id} timed out`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function rest(method, path, body) {
|
|
50
|
+
const r = await fetch(`https://api.hetzner.cloud/v1${path}`, {
|
|
51
|
+
method, headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
52
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
53
|
+
});
|
|
54
|
+
return r.status === 204 ? {} : r.json();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function safetyNetCleanup() {
|
|
58
|
+
const sel = `label_selector=${encodeURIComponent(`hcloud-mcp-test=${suffix}`)}`;
|
|
59
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
60
|
+
for (const lb of (await rest("GET", `/load_balancers?${sel}`)).load_balancers ?? []) await rest("DELETE", `/load_balancers/${lb.id}`);
|
|
61
|
+
for (const v of (await rest("GET", `/volumes?${sel}`)).volumes ?? []) { if (v.server) { await rest("POST", `/volumes/${v.id}/actions/detach`); await sleep(5000); } await rest("DELETE", `/volumes/${v.id}`); }
|
|
62
|
+
for (const f of (await rest("GET", `/floating_ips?${sel}`)).floating_ips ?? []) { if (f.server) { await rest("POST", `/floating_ips/${f.id}/actions/unassign`); await sleep(3000); } await rest("DELETE", `/floating_ips/${f.id}`); }
|
|
63
|
+
for (const s of (await rest("GET", `/servers?${sel}`)).servers ?? []) await rest("DELETE", `/servers/${s.id}`);
|
|
64
|
+
await sleep(10000);
|
|
65
|
+
for (const p of (await rest("GET", `/primary_ips?${sel}`)).primary_ips ?? []) { if (p.assignee_id) continue; await rest("DELETE", `/primary_ips/${p.id}`); }
|
|
66
|
+
for (const fw of (await rest("GET", `/firewalls?${sel}`)).firewalls ?? []) await rest("DELETE", `/firewalls/${fw.id}`);
|
|
67
|
+
for (const n of (await rest("GET", `/networks?${sel}`)).networks ?? []) await rest("DELETE", `/networks/${n.id}`);
|
|
68
|
+
const left = [];
|
|
69
|
+
for (const [path, key] of [["/servers", "servers"], ["/load_balancers", "load_balancers"], ["/volumes", "volumes"], ["/floating_ips", "floating_ips"], ["/primary_ips", "primary_ips"], ["/firewalls", "firewalls"], ["/networks", "networks"]]) {
|
|
70
|
+
const items = (await rest("GET", `${path}?${sel}`))[key] ?? [];
|
|
71
|
+
if (items.length) left.push(`${key}:${items.map((i) => i.id).join(",")}`);
|
|
72
|
+
}
|
|
73
|
+
return left;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let failed = null;
|
|
77
|
+
try {
|
|
78
|
+
// --- Pick location / type / image the way the skill says ---
|
|
79
|
+
const types = await call("list_server_types");
|
|
80
|
+
const pr = await call("get_pricing");
|
|
81
|
+
const pricing = pr.pricing ?? pr;
|
|
82
|
+
const priceOf = (typeName, loc) => {
|
|
83
|
+
const st = pricing.server_types.find((t) => t.name === typeName);
|
|
84
|
+
const p = st?.prices.find((x) => x.location === loc);
|
|
85
|
+
return p ? Number(p.price_hourly.gross) : Infinity;
|
|
86
|
+
};
|
|
87
|
+
const EU = ["fsn1", "nbg1", "hel1"];
|
|
88
|
+
let best = null;
|
|
89
|
+
for (const t of types) {
|
|
90
|
+
if (t.architecture !== "x86") continue;
|
|
91
|
+
for (const l of t.locations ?? []) {
|
|
92
|
+
if (!EU.includes(l.name) || !l.available || l.deprecation) continue;
|
|
93
|
+
const price = priceOf(t.name, l.name);
|
|
94
|
+
if (!best || price < best.price) best = { type: t.name, location: l.name, price };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!best) throw new Error("no available x86 type in EU");
|
|
98
|
+
const images = await call("list_images");
|
|
99
|
+
const image = images.find((i) => i.name === "ubuntu-24.04" && i.architecture === "x86" && !i.deprecation);
|
|
100
|
+
if (!image) throw new Error("ubuntu-24.04 x86 not found");
|
|
101
|
+
ok("select type/location/image", `${best.type} @ ${best.location} (€${best.price}/h), ${image.name}`);
|
|
102
|
+
|
|
103
|
+
// --- Network + subnet ---
|
|
104
|
+
const net = (await call("create_network", { name: `t-net-${suffix}`, ip_range: "10.77.0.0/16", labels: LABEL })).network;
|
|
105
|
+
await waitActions(await call("add_network_subnet", { id: net.id, type: "cloud", network_zone: "eu-central", ip_range: "10.77.1.0/24" }), "subnet");
|
|
106
|
+
ok("create_network + add_network_subnet(type=cloud)");
|
|
107
|
+
|
|
108
|
+
// --- Firewall with /32 CIDR ---
|
|
109
|
+
const fwResp = await call("create_firewall", {
|
|
110
|
+
name: `t-fw-${suffix}`, labels: LABEL,
|
|
111
|
+
rules: [{ direction: "in", protocol: "tcp", port: "22", source_ips: ["203.0.113.57/32"] }],
|
|
112
|
+
});
|
|
113
|
+
await waitActions(fwResp, "firewall");
|
|
114
|
+
const fw = fwResp.firewall;
|
|
115
|
+
ok("create_firewall");
|
|
116
|
+
|
|
117
|
+
// --- Server with location (no datacenter) ---
|
|
118
|
+
const srvResp = await call("create_server", {
|
|
119
|
+
name: `t-srv-${suffix}`, server_type: best.type, image: image.name, location: best.location,
|
|
120
|
+
networks: [net.id], firewalls: [{ firewall: fw.id }], labels: LABEL,
|
|
121
|
+
});
|
|
122
|
+
const srv = srvResp.server;
|
|
123
|
+
await waitActions(srvResp, "create_server");
|
|
124
|
+
const srvInfo = (await call("get_server", { id: srv.id }));
|
|
125
|
+
if (srvInfo.location?.name !== best.location) throw new Error(`server location mismatch: ${JSON.stringify(srvInfo.location)}`);
|
|
126
|
+
if ("datacenter" in srvInfo) console.log(" note: server response still includes datacenter");
|
|
127
|
+
ok("create_server(location)", `id ${srv.id}, location ${srvInfo.location.name}`);
|
|
128
|
+
|
|
129
|
+
// --- Primary IP: create by location, swap onto server ---
|
|
130
|
+
const pip = (await call("create_primary_ip", { name: `t-pip-${suffix}`, type: "ipv4", location: best.location, auto_delete: false, labels: LABEL })).primary_ip;
|
|
131
|
+
if (pip.assignee_type !== "unassigned") throw new Error(`expected assignee_type unassigned, got ${pip.assignee_type}`);
|
|
132
|
+
ok("create_primary_ip(location)", `assignee_type=${pip.assignee_type}`);
|
|
133
|
+
const oldPipId = srvInfo.public_net.ipv4.id;
|
|
134
|
+
await waitActions(await call("power_off_server", { id: srv.id }), "power_off");
|
|
135
|
+
await waitActions(await call("unassign_primary_ip", { id: oldPipId }), "unassign old pip");
|
|
136
|
+
await waitActions(await call("assign_primary_ip", { id: pip.id, server: srv.id }), "assign new pip");
|
|
137
|
+
await waitActions(await call("power_on_server", { id: srv.id }), "power_on");
|
|
138
|
+
await call("delete_primary_ip", { id: oldPipId });
|
|
139
|
+
const after = await call("get_server", { id: srv.id });
|
|
140
|
+
if (after.public_net.ipv4.id !== pip.id) throw new Error("primary ip swap did not stick");
|
|
141
|
+
ok("primary IP swap + delete old");
|
|
142
|
+
|
|
143
|
+
// --- Assigned IP delete must fail (must_be_unassigned) ---
|
|
144
|
+
try { await call("delete_primary_ip", { id: pip.id }); throw new Error("deleting assigned primary IP unexpectedly succeeded"); }
|
|
145
|
+
catch (e) { if (!/must_be_unassigned|assigned/i.test(String(e.message))) throw e; ok("delete assigned primary IP rejected", "must_be_unassigned"); }
|
|
146
|
+
|
|
147
|
+
// --- Volume attach/detach/delete ---
|
|
148
|
+
const volResp = await call("create_volume", { name: `t-vol-${suffix}`, size: 10, location: best.location, labels: LABEL });
|
|
149
|
+
await waitActions(volResp, "create_volume");
|
|
150
|
+
const vol = volResp.volume;
|
|
151
|
+
await waitActions(await call("attach_volume", { id: vol.id, server: srv.id }), "attach_volume");
|
|
152
|
+
await waitActions(await call("detach_volume", { id: vol.id }), "detach_volume");
|
|
153
|
+
await call("delete_volume", { id: vol.id });
|
|
154
|
+
ok("volume create/attach/detach/delete");
|
|
155
|
+
|
|
156
|
+
// --- Floating IP assign/unassign/delete ---
|
|
157
|
+
const fip = (await call("create_floating_ip", { type: "ipv4", home_location: best.location, labels: LABEL })).floating_ip;
|
|
158
|
+
await waitActions(await call("assign_floating_ip", { id: fip.id, server: srv.id }), "assign fip");
|
|
159
|
+
await waitActions(await call("unassign_floating_ip", { id: fip.id }), "unassign fip");
|
|
160
|
+
await call("delete_floating_ip", { id: fip.id });
|
|
161
|
+
ok("floating IP assign/unassign/delete");
|
|
162
|
+
|
|
163
|
+
// --- Load balancer: delete returns Action ---
|
|
164
|
+
const lbResp = await call("create_load_balancer", { name: `t-lb-${suffix}`, load_balancer_type: "lb11", location: best.location, labels: LABEL });
|
|
165
|
+
await waitActions(lbResp, "create_lb");
|
|
166
|
+
const delLb = await call("delete_load_balancer", { id: lbResp.load_balancer.id });
|
|
167
|
+
if (!delLb?.action?.id) throw new Error(`delete_load_balancer returned no action: ${JSON.stringify(delLb).slice(0, 200)}`);
|
|
168
|
+
await waitActions(delLb, "delete_lb");
|
|
169
|
+
ok("delete_load_balancer returns Action", `command=${delLb.action.command}`);
|
|
170
|
+
|
|
171
|
+
// --- Teardown in skill order ---
|
|
172
|
+
await waitActions(await call("delete_server", { id: srv.id }), "delete_server");
|
|
173
|
+
await call("unassign_primary_ip", { id: pip.id }).catch(() => {}); // already unassigned by server delete
|
|
174
|
+
await call("delete_primary_ip", { id: pip.id });
|
|
175
|
+
await call("delete_firewall", { id: fw.id });
|
|
176
|
+
await call("delete_network", { id: net.id });
|
|
177
|
+
ok("teardown via tools");
|
|
178
|
+
} catch (e) {
|
|
179
|
+
failed = e;
|
|
180
|
+
console.error(`FAIL ${e.message}`);
|
|
181
|
+
} finally {
|
|
182
|
+
await client.close().catch(() => {});
|
|
183
|
+
const left = await safetyNetCleanup();
|
|
184
|
+
console.log(left.length ? `LEFTOVER RESOURCES: ${left.join(" ")}` : `cleanup verified: no hcloud-mcp-test=${suffix} resources remain`);
|
|
185
|
+
console.log(`\n${results.length} steps passed${failed ? ", 1 failed" : ""}`);
|
|
186
|
+
process.exit(failed || left.length ? 1 : 0);
|
|
187
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hetzner-cloud
|
|
3
|
+
description: Use when provisioning, changing, or tearing down Hetzner Cloud resources through the hcloud-mcp tools (servers, networks, firewalls, load balancers, volumes, floating or primary IPs), or when a Hetzner call fails with must_be_unassigned, locked, invalid_input, or a 410.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Hetzner Cloud via hcloud-mcp
|
|
7
|
+
|
|
8
|
+
## Overview
|
|
9
|
+
Every mutating tool returns an **Action**, and Actions run asynchronously. Most failures come from starting the next step before the previous Action has finished, or from doing steps in the wrong order. Wait on each dependency, and follow the orders below.
|
|
10
|
+
|
|
11
|
+
## Waiting on an Action
|
|
12
|
+
After any create, delete, attach, detach, assign, unassign, or power call, read `action.id` from the response. Then call `get_action {id}` until `status` is `success`. If it is `error`, stop and report `action.error`. Only start a step that depends on that resource after `success`. Steps that don't depend on each other can run without waiting. If the response has no `action`, the call finished synchronously. `create_network` is one of these. If it has `actions` or `next_actions`, wait on each one.
|
|
13
|
+
|
|
14
|
+
## Argument shapes
|
|
15
|
+
| Tool | Shape |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `create_server` | `location` such as `fsn1`. Never `datacenter`, which was removed. `ssh_keys: ["name" or id]`, `networks: [netId]`, `firewalls: [{"firewall": fwId}]`, `volumes: [volId]` |
|
|
18
|
+
| `create_primary_ip` | Exactly one of `location` or `assignee_id` |
|
|
19
|
+
| `add_network_subnet` | `type: "cloud"`. `network_zone` must match the server's location: `eu-central` for fsn1, nbg1 and hel1; `us-east` for ash; `us-west` for hil; `ap-southeast` for sin |
|
|
20
|
+
| firewall rules | `{direction, protocol, port, source_ips}`. CIDRs must have zero host bits: `203.0.113.57/32`, not `/24`. If the user wrote `x.y.z.57/24`, ask whether they mean that one host (`/32`) or the whole range (`x.y.z.0/24`) |
|
|
21
|
+
| networks | `create_network` creates no subnet. Call `add_network_subnet` and wait for it to finish before you attach servers |
|
|
22
|
+
|
|
23
|
+
## Choosing a type and an image
|
|
24
|
+
Call `list_server_types` and pick a type whose `locations[]` entry for your location has `available: true` and `deprecation: null`. Call `list_images` and skip any image whose `deprecation` is set. The image's `architecture` must match the type's architecture (`x86` or `arm`). Use `get_pricing` to find the cheapest option in a location. Don't hardcode type names, because Hetzner retires them.
|
|
25
|
+
|
|
26
|
+
## Required orders
|
|
27
|
+
**Swap a Primary IP:** create the new IP in the same location → `shutdown_server` (wait for the Action) → `unassign_primary_ip` (wait) → `assign_primary_ip` (wait) → `power_on_server` → `delete_primary_ip` on the old IP. This takes the server offline, and the old address can't be recovered, so confirm with the user first. If `shutdown_server` doesn't finish within about 2 minutes, ask the user before you `power_off_server`.
|
|
28
|
+
|
|
29
|
+
**Teardown:**
|
|
30
|
+
1. `delete_load_balancer` (wait)
|
|
31
|
+
2. `unassign_floating_ip` (wait) → `delete_floating_ip`
|
|
32
|
+
3. `detach_volume` (wait) → `delete_volume`
|
|
33
|
+
4. `delete_server` (wait)
|
|
34
|
+
5. `delete_network`, `delete_firewall`, and unassigned primary IPs
|
|
35
|
+
|
|
36
|
+
Deleting an assigned IP fails with `must_be_unassigned`.
|
|
37
|
+
|
|
38
|
+
**Filtering by label:** no list tool takes a `label_selector`. Call the list tool for each resource type, including firewalls and primary IPs, then filter on `labels` yourself. List tools return every page.
|
|
39
|
+
|
|
40
|
+
## Common mistakes
|
|
41
|
+
| Symptom | Cause and fix |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `locked` or `conflict` | Another Action is still running on the resource. Wait for it, then retry |
|
|
44
|
+
| `must_be_unassigned` | Unassign the IP first, and wait for that Action |
|
|
45
|
+
| `invalid_input` on a firewall | A CIDR has host bits set |
|
|
46
|
+
| Server can't join the network | The subnet's `network_zone` doesn't match the server's location |
|
|
47
|
+
| `protected` | Delete protection is on. Ask the user before you change it |
|
|
48
|
+
|
|
49
|
+
## Safety
|
|
50
|
+
Deletes, `reset_server`, `power_off_server`, and `change_server_type` can't be undone. Before you run any of them, list exactly what will be affected and get the user's confirmation.
|