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/package.json CHANGED
@@ -1,19 +1,31 @@
1
1
  {
2
2
  "name": "hcloud-mcp",
3
- "version": "0.1.1",
3
+ "version": "0.3.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",
7
+ "files": [
8
+ "dist",
9
+ "skills",
10
+ "run.js"
11
+ ],
7
12
  "bin": {
8
13
  "hcloud-mcp": "dist/index.js"
9
14
  },
10
15
  "scripts": {
11
- "build": "tsc",
16
+ "build": "rm -rf dist && tsc",
12
17
  "prepublishOnly": "npm run build",
13
18
  "start": "node dist/index.js",
14
19
  "dev": "tsc --watch",
15
20
  "test:api": "node scripts/test-list-api.mjs",
16
21
  "test:mcp": "node scripts/test-mcp-list.mjs",
22
+ "test:live": "node scripts/test-live-lifecycle.mjs",
23
+ "test:live:dns": "node scripts/test-live-dns.mjs",
24
+ "test:live:images": "node scripts/test-live-images.mjs",
25
+ "test:live:ops": "node scripts/test-live-server-ops.mjs",
26
+ "test:live:actions": "node scripts/test-live-action-gaps.mjs",
27
+ "test:live:certs": "node scripts/test-live-certificates.mjs",
28
+ "test:live:storage": "node scripts/test-live-storage-box.mjs",
17
29
  "audit:api": "cross-env DRY_RUN=1 node scripts/audit-api-shapes.mjs"
18
30
  },
19
31
  "keywords": [
@@ -23,7 +35,10 @@
23
35
  "model-context-protocol"
24
36
  ],
25
37
  "license": "MIT",
26
- "repository": "github:Xodus-CO/hcloud-mcp",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/Xodus-CO/hcloud-mcp.git"
41
+ },
27
42
  "homepage": "https://github.com/Xodus-CO/hcloud-mcp#readme",
28
43
  "bugs": "https://github.com/Xodus-CO/hcloud-mcp/issues",
29
44
  "dependencies": {
@@ -0,0 +1,94 @@
1
+ ---
2
+ name: hetzner-cloud
3
+ description: Use when provisioning, changing, recovering, or tearing down Hetzner resources through the hcloud-mcp tools (servers, networks, firewalls, load balancers, volumes, IPs, DNS, certificates, snapshots, Storage Boxes), 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
+ ## DNS
41
+ - **Zone and RRSet references:** refer to a zone by name (`example.com`) or by ID. RRSet `name` is relative to the zone: `@` is the apex, `www` is www.example.com. Use lowercase.
42
+ - **Record values** use zone-file syntax:
43
+ - TXT values must be quoted, e.g. `"\"v=spf1 -all\""`.
44
+ - MX values look like `"10 mail.example.com."`.
45
+ - A record pointing at a server: use the IP from `get_server`, at `public_net.ipv4.ip`.
46
+ - **Picking the right tool:**
47
+
48
+ | Task | Tool |
49
+ |---|---|
50
+ | Add a record | `add_rrset_records` (creates the RRSet if it's missing) |
51
+ | Replace all records | `set_rrset_records` |
52
+ | Drop one record | `remove_rrset_records` (removing the last record deletes the RRSet) |
53
+ | Change a record's comment | `update_rrset_records` |
54
+
55
+ - **Back up before bulk changes:** `export_zonefile`, then `import_zonefile`. Import replaces every RRSet in the zone. Never import a partial file.
56
+ - **A new zone answers nothing yet.** Tell the user to point the domain's nameservers at the registrar to `get_zone.authoritative_nameservers.assigned`.
57
+ - **Errors:** `protected` means `change_rrset_protection` or `change_zone_protection` is on; ask the user before turning it off. `incorrect_zone_mode` means you tried a record edit on a secondary zone.
58
+
59
+ ## Recovery, snapshots, protection
60
+ - **Before a risky change** (`rebuild_server`, `change_server_type`): power the server off → `create_snapshot` (wait for it to finish) → make the change. Find and clean up snapshots later with `list_snapshots`, since they bill per GB-month.
61
+ - **Locked out of a server:** first try `reset_root_password`, which needs the qemu guest agent; stock images have it. If that fails: `enable_rescue` → wait for the Action → `reset_server` → fix things from the rescue system. Rescue switches itself off after one boot. `request_console` gives a browser VNC URL that must be used within 60 seconds.
62
+ - **Secrets:** passwords and console URLs go to the user only. Never write them to files, labels, or later tool arguments.
63
+ - **Protection:** use `change_protection(resource, id, delete)`. On servers it also sets rebuild protection, because the API requires both to match. Only remove protection after the user confirms.
64
+ - **Backups:** `disable_server_backups` deletes every existing backup. To keep one, run `update_image type:"snapshot"` on it first.
65
+
66
+ ## Metrics
67
+ Call `get_server_metrics` or `get_load_balancer_metrics` with `last_minutes` and `include_values:false` to get the summary first. Pull the raw series only if something looks off. CPU is per vCPU: 200 means two full cores.
68
+
69
+ ## Certificates and load balancer HTTPS
70
+ - **Managed (Let's Encrypt):** the domain must be in a primary Hetzner DNS zone that is delegated to Hetzner. Steps: `create_zone` → user delegates it at the registrar → `create_certificate type:managed` → poll `get_action`. Hetzner renews it automatically.
71
+ - **Uploaded:** certificates never renew. To rotate, create the new cert, point the LB service at it via `update_load_balancer_service http.certificates`, then delete the old one. Check `used_by` before deleting any certificate.
72
+
73
+ ## Storage Boxes
74
+ - **Where they live:** `api.hetzner.com`, using the same token. Poll their actions with `get_storage_box_action`, and wait for the box's `status: active`.
75
+ - **Passwords:** 12–128 characters, with upper case, lower case, a digit and a special character. Generate a random one rather than inventing a memorable one. A password reset locks out existing clients.
76
+ - **Irreversible actions:** `rollback_storage_box_snapshot` discards newer snapshots and all data written since. `delete_storage_box` removes everything. Confirm first, and suggest `change_storage_box_protection`.
77
+
78
+ ## Labels and network changes
79
+ - **Labels:** every `update_*` replaces the whole label set. Read the current labels and merge.
80
+ - **Alias IPs:** `change_server_alias_ips` replaces the whole list. Send the existing IPs plus the new one.
81
+ - **Placement groups:** `add_server_to_placement_group` needs the server powered off. Removing works while it runs.
82
+ - **Network ranges:** `change_network_ip_range` can only widen the range (e.g. /16 → /15), and needs every member detached first.
83
+
84
+ ## Common mistakes
85
+ | Symptom | Cause and fix |
86
+ |---|---|
87
+ | `locked` or `conflict` | Another Action is still running on the resource. Wait for it, then retry |
88
+ | `must_be_unassigned` | Unassign the IP first, and wait for that Action |
89
+ | `invalid_input` on a firewall | A CIDR has host bits set |
90
+ | Server can't join the network | The subnet's `network_zone` doesn't match the server's location |
91
+ | `protected` | Delete protection is on. Ask the user before you change it |
92
+
93
+ ## Safety
94
+ Deletes, `rebuild_server` (wipes the disk), `import_zonefile`, `rollback_storage_box_snapshot`, `disable_server_backups`, `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.
@@ -1,45 +0,0 @@
1
- import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
- import { ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
3
- import { z } from "zod";
4
- import { zodToJsonSchema } from "zod-to-json-schema";
5
- export class McpServer {
6
- server;
7
- tools = new Map();
8
- constructor(info) {
9
- this.server = new Server(info, {
10
- capabilities: {
11
- tools: {},
12
- },
13
- });
14
- this.server.setRequestHandler(ListToolsRequestSchema, async () => {
15
- return {
16
- tools: Array.from(this.tools.entries()).map(([name, tool]) => ({
17
- name,
18
- description: tool.description,
19
- inputSchema: zodToJsonSchema(tool.parameters),
20
- })),
21
- };
22
- });
23
- this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
24
- const tool = this.tools.get(request.params.name);
25
- if (!tool) {
26
- throw new McpError(ErrorCode.MethodNotFound, `Tool not found: ${request.params.name}`);
27
- }
28
- const args = tool.parameters.safeParse(request.params.arguments);
29
- if (!args.success) {
30
- throw new McpError(ErrorCode.InvalidParams, `Invalid arguments: ${args.error.message}`);
31
- }
32
- return await tool.handler(args.data);
33
- });
34
- }
35
- tool(name, description, parameters, handler) {
36
- this.tools.set(name, {
37
- description,
38
- parameters: z.object(parameters),
39
- handler,
40
- });
41
- }
42
- async connect(transport) {
43
- return this.server.connect(transport);
44
- }
45
- }
@@ -1,160 +0,0 @@
1
- /**
2
- * Audit script: verify request body shapes for create_* tools match the Hetzner API.
3
- * Builds minimal valid payloads and calls the SDK.
4
- * With DRY_RUN=1: uses invalid token so requests fail with 401 (no resources created).
5
- * With real token: makes real API calls and may create resources.
6
- * Run from project root: node scripts/audit-api-shapes.mjs
7
- */
8
- import "dotenv/config";
9
- import {
10
- ServersService,
11
- LoadBalancersService,
12
- NetworksService,
13
- VolumesService,
14
- FloatingIPsService,
15
- SshKeysService,
16
- PlacementGroupsService,
17
- OpenAPI,
18
- } from "hetzner-sdk-ts";
19
-
20
- let token = process.env.HCLOUD_TOKEN;
21
- if (!token) {
22
- console.error("Error: HCLOUD_TOKEN environment variable is required");
23
- process.exit(1);
24
- }
25
- if (process.env.DRY_RUN === "1") {
26
- token = "invalid";
27
- console.log(
28
- "DRY_RUN=1: using invalid token (no resources will be created)\n",
29
- );
30
- }
31
- OpenAPI.TOKEN = token;
32
-
33
- function ok(name, err) {
34
- const msg = err?.message || String(err);
35
- if (msg.includes("Unauthorized") || msg.includes("401")) {
36
- console.log(
37
- `${name}: OK (request shape accepted, auth failed as expected or token invalid)`,
38
- );
39
- return true;
40
- }
41
- if (msg.includes("invalid") || msg.includes("400")) {
42
- console.error(`${name}: FAIL - API rejected payload:`, msg);
43
- return false;
44
- }
45
- console.error(`${name}: FAIL -`, msg);
46
- return false;
47
- }
48
-
49
- async function run() {
50
- let failed = 0;
51
-
52
- console.log("Auditing create_* request body shapes...\n");
53
-
54
- // create_server
55
- try {
56
- await ServersService.postServers({
57
- requestBody: {
58
- name: "audit-test-server",
59
- server_type: "cx11",
60
- image: "ubuntu-24.04",
61
- location: "fsn1",
62
- },
63
- });
64
- console.log("create_server: OK (request sent)");
65
- } catch (e) {
66
- if (!ok("create_server", e)) failed++;
67
- }
68
-
69
- // create_load_balancer
70
- try {
71
- await LoadBalancersService.postLoadBalancers({
72
- requestBody: {
73
- name: "audit-test-lb",
74
- load_balancer_type: "lb11",
75
- location: "fsn1",
76
- },
77
- });
78
- console.log("create_load_balancer: OK (request sent)");
79
- } catch (e) {
80
- if (!ok("create_load_balancer", e)) failed++;
81
- }
82
-
83
- // create_network
84
- try {
85
- await NetworksService.postNetworks({
86
- requestBody: {
87
- name: "audit-test-network",
88
- ip_range: "10.0.0.0/16",
89
- },
90
- });
91
- console.log("create_network: OK (request sent)");
92
- } catch (e) {
93
- if (!ok("create_network", e)) failed++;
94
- }
95
-
96
- // create_volume
97
- try {
98
- await VolumesService.postVolumes({
99
- requestBody: {
100
- name: "audit-test-volume",
101
- size: 10,
102
- location: "fsn1",
103
- },
104
- });
105
- console.log("create_volume: OK (request sent)");
106
- } catch (e) {
107
- if (!ok("create_volume", e)) failed++;
108
- }
109
-
110
- // create_floating_ip
111
- try {
112
- await FloatingIPsService.postFloatingIps({
113
- requestBody: {
114
- type: "ipv4",
115
- home_location: "fsn1",
116
- },
117
- });
118
- console.log("create_floating_ip: OK (request sent)");
119
- } catch (e) {
120
- if (!ok("create_floating_ip", e)) failed++;
121
- }
122
-
123
- // create_ssh_key
124
- try {
125
- await SshKeysService.postSshKeys({
126
- requestBody: {
127
- name: "audit-test-key",
128
- public_key:
129
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI audit-test-invalid-key",
130
- },
131
- });
132
- console.log("create_ssh_key: OK (request sent)");
133
- } catch (e) {
134
- if (!ok("create_ssh_key", e)) failed++;
135
- }
136
-
137
- // create_placement_group
138
- try {
139
- await PlacementGroupsService.postPlacementGroups({
140
- requestBody: {
141
- name: "audit-test-pg",
142
- type: "spread",
143
- },
144
- });
145
- console.log("create_placement_group: OK (request sent)");
146
- } catch (e) {
147
- if (!ok("create_placement_group", e)) failed++;
148
- }
149
-
150
- console.log("");
151
- if (failed > 0) {
152
- console.error(
153
- `${failed} audit(s) failed. Check payload shapes against SDK/API.`,
154
- );
155
- process.exit(1);
156
- }
157
- console.log("All create_* payload shapes accepted by API.");
158
- }
159
-
160
- run();
@@ -1,47 +0,0 @@
1
- /**
2
- * Test list_* API calls using the same Hetzner SDK as the MCP server.
3
- * Run from project root: node scripts/test-list-api.mjs
4
- * Uses HCLOUD_TOKEN from environment or .env.
5
- */
6
- import "dotenv/config";
7
- import {
8
- LocationsService,
9
- ServerTypesService,
10
- DatacentersService,
11
- OpenAPI,
12
- } from "hetzner-sdk-ts";
13
-
14
- const token = process.env.HCLOUD_TOKEN;
15
- if (!token) {
16
- console.error("Error: HCLOUD_TOKEN environment variable is required");
17
- process.exit(1);
18
- }
19
- OpenAPI.TOKEN = token;
20
-
21
- async function run() {
22
- console.log("Testing list_locations...");
23
- try {
24
- const r = await LocationsService.getLocations({});
25
- console.log("list_locations OK, count:", r.locations?.length ?? 0);
26
- } catch (e) {
27
- console.error("list_locations failed:", e.message || e);
28
- }
29
-
30
- console.log("Testing list_server_types...");
31
- try {
32
- const r = await ServerTypesService.getServerTypes({});
33
- console.log("list_server_types OK, count:", r.server_types?.length ?? 0);
34
- } catch (e) {
35
- console.error("list_server_types failed:", e.message || e);
36
- }
37
-
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
- }
46
-
47
- run();
@@ -1,62 +0,0 @@
1
- /**
2
- * Integration test: spawn the MCP server and call list_locations via the MCP client.
3
- * Run from project root: node scripts/test-mcp-list.mjs
4
- * Uses HCLOUD_TOKEN from environment or .env.
5
- */
6
- import "dotenv/config";
7
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
8
- import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
9
- import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
10
- import { fileURLToPath } from "url";
11
- import { dirname, join } from "path";
12
-
13
- const __dirname = dirname(fileURLToPath(import.meta.url));
14
- const projectRoot = join(__dirname, "..");
15
-
16
- const token = process.env.HCLOUD_TOKEN;
17
- if (!token) {
18
- console.error("Error: HCLOUD_TOKEN environment variable is required");
19
- process.exit(1);
20
- }
21
-
22
- const transport = new StdioClientTransport({
23
- command: "node",
24
- args: [join(projectRoot, "dist/index.js")],
25
- env: { ...process.env, HCLOUD_TOKEN: token },
26
- cwd: projectRoot,
27
- });
28
-
29
- const client = new Client(
30
- { name: "test-client", version: "1.0.0" },
31
- { capabilities: {} }
32
- );
33
-
34
- async function main() {
35
- console.log("Connecting to MCP server...");
36
- await client.connect(transport);
37
-
38
- console.log("Calling list_locations...");
39
- const result = await client.callTool(
40
- { name: "list_locations", arguments: {} },
41
- CallToolResultSchema
42
- );
43
- console.log("isError:", result.isError);
44
- if (result.content?.length) {
45
- for (const part of result.content) {
46
- if (part.type === "text") {
47
- const preview = part.text.slice(0, 500);
48
- console.log("content (preview):", preview + (part.text.length > 500 ? "..." : ""));
49
- }
50
- }
51
- } else {
52
- console.log("content:", result.content);
53
- }
54
-
55
- await client.close();
56
- process.exit(result.isError ? 1 : 0);
57
- }
58
-
59
- main().catch((err) => {
60
- console.error("Test failed:", err);
61
- process.exit(1);
62
- });