hcloud-mcp 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { hcloudRequest } from "./hcloud-api.js";
3
- import { json, withToolError } from "./tool-helpers.js";
3
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE, READ_ONLY, json, withToolError } from "./tool-helpers.js";
4
4
  // Hetzner keeps metrics for 30 days.
5
5
  const MAX_LAST_MINUTES = 30 * 24 * 60;
6
6
  /** Resolve start/end: explicit ISO-8601 pair, or now − last_minutes → now (default 60). */
@@ -69,23 +69,47 @@ async function getMetrics(path, type, args) {
69
69
  });
70
70
  }
71
71
  export function registerServerOpsTools(server) {
72
- server.tool("enable_rescue", "Enable the Hetzner Rescue System (minimal Linux for repair/reinstall) on a server. Does NOT reboot: rescue only takes effect at the next boot, so follow with reset_server (or reboot) once the Action succeeds. Rescue is disabled automatically when the server first boots into it, or if it is not used within 60 minutes. Returns an Action and root_password for the rescue system (valid once the Action succeeds; treat as a secret). Pass ssh_keys to log in by key instead", {
73
- id: z.number().describe("Server ID"),
74
- type: z.enum(["linux64"]).optional().describe("Rescue system type; only linux64 exists (default)"),
75
- ssh_keys: z.array(z.number()).optional().describe("SSH key IDs to inject into the rescue system"),
72
+ server.registerTool("enable_rescue", {
73
+ description: "Enable the Hetzner Rescue System (minimal Linux for repair/reinstall) on a server. Does NOT reboot: rescue only takes effect at the next boot, so follow with reset_server (or reboot) once the Action succeeds. Rescue is disabled automatically when the server first boots into it, or if it is not used within 60 minutes. Returns an Action and root_password for the rescue system (valid once the Action succeeds; treat as a secret). Pass ssh_keys to log in by key instead",
74
+ inputSchema: {
75
+ id: z.number().describe("Server ID"),
76
+ type: z.enum(["linux64"]).optional().describe("Rescue system type; only linux64 exists (default)"),
77
+ ssh_keys: z.array(z.number()).optional().describe("SSH key IDs to inject into the rescue system"),
78
+ },
79
+ annotations: ADDITIVE,
76
80
  }, async ({ id, type, ssh_keys }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/enable_rescue`, { body: { type, ssh_keys } }))));
77
- server.tool("disable_rescue", "Disable the Hetzner Rescue System so the server boots from its own disk next time. Does NOT reboot the server. Usually not needed: rescue disables itself after the first boot into it or after 60 minutes unused. Returns an Action", { id: z.number().describe("Server ID") }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/disable_rescue`))));
78
- server.tool("reset_root_password", "Generate and set a new root password on a server. Only works on Linux servers that are running (status 'running') AND have the qemu guest agent running; stock images may not ship it, in which case the API accepts the request but the Action ends in error. Returns an Action plus root_password, which is only in effect once the Action succeeds (poll get_action; treat it as a secret). Fallback if it fails: enable_rescue + reset_server, then change the password from the rescue system", { id: z.number().describe("Server ID") }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/reset_password`))));
79
- server.tool("request_console", "Request VNC-over-websocket console credentials (keyboard, monitor, mouse) for a server. Returns wss_url (contains a token) and a VNC password, plus an Action. The URL must be used to connect within 1 minute; request a new one after that. An already-open connection is not cut off by that timeout. Treat both values as secrets", { id: z.number().describe("Server ID") }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/request_console`))));
80
- server.tool("get_server_metrics", "Get server metrics (last 30 days only). Output starts with a per-series summary {points,min,avg,max,last}, then the raw time_series unless include_values=false. Series: cpu → cpu (percent, per vCPU: 100 = one full vCPU, so divide by vCPU count for overall usage); disk → disk.0.iops.read/write (iop/s), disk.0.bandwidth.read/write (bytes/s); network → network.0.pps.in/out (packets/s), network.0.bandwidth.in/out (bytes/s) on the public interface. Time range: pass start+end (ISO-8601), or omit both and use last_minutes (default 60)", {
81
- id: z.number().describe("Server ID"),
82
- type: z.array(z.enum(["cpu", "disk", "network"])).min(1).describe("Metric types, e.g. [\"cpu\"] or [\"cpu\",\"network\"]"),
83
- ...timeParams,
81
+ server.registerTool("disable_rescue", {
82
+ description: "Disable the Hetzner Rescue System so the server boots from its own disk next time. Does NOT reboot the server. Usually not needed: rescue disables itself after the first boot into it or after 60 minutes unused. Returns an Action",
83
+ inputSchema: { id: z.number().describe("Server ID") },
84
+ annotations: ADDITIVE_IDEMPOTENT,
85
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/disable_rescue`))));
86
+ server.registerTool("reset_root_password", {
87
+ description: "Generate and set a new root password on a server. Only works on Linux servers that are running (status 'running') AND have the qemu guest agent running; stock images may not ship it, in which case the API accepts the request but the Action ends in error. Returns an Action plus root_password, which is only in effect once the Action succeeds (poll get_action; treat it as a secret). Fallback if it fails: enable_rescue + reset_server, then change the password from the rescue system",
88
+ inputSchema: { id: z.number().describe("Server ID") },
89
+ annotations: DESTRUCTIVE,
90
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/reset_password`))));
91
+ server.registerTool("request_console", {
92
+ description: "Request VNC-over-websocket console credentials (keyboard, monitor, mouse) for a server. Returns wss_url (contains a token) and a VNC password, plus an Action. The URL must be used to connect within 1 minute; request a new one after that. An already-open connection is not cut off by that timeout. Treat both values as secrets",
93
+ inputSchema: { id: z.number().describe("Server ID") },
94
+ annotations: ADDITIVE,
95
+ }, async ({ id }) => withToolError(async () => json(await hcloudRequest("POST", `/servers/${id}/actions/request_console`))));
96
+ server.registerTool("get_server_metrics", {
97
+ description: "Get server metrics (last 30 days only). Output starts with a per-series summary {points,min,avg,max,last}, then the raw time_series unless include_values=false. Series: cpu → cpu (percent, per vCPU: 100 = one full vCPU, so divide by vCPU count for overall usage); disk → disk.0.iops.read/write (iop/s), disk.0.bandwidth.read/write (bytes/s); network → network.0.pps.in/out (packets/s), network.0.bandwidth.in/out (bytes/s) on the public interface. Time range: pass start+end (ISO-8601), or omit both and use last_minutes (default 60)",
98
+ inputSchema: {
99
+ id: z.number().describe("Server ID"),
100
+ type: z.array(z.enum(["cpu", "disk", "network"])).min(1).describe("Metric types, e.g. [\"cpu\"] or [\"cpu\",\"network\"]"),
101
+ ...timeParams,
102
+ },
103
+ annotations: READ_ONLY,
84
104
  }, async ({ id, type, ...rest }) => withToolError(() => getMetrics(`/servers/${id}/metrics`, type, rest)));
85
- server.tool("get_load_balancer_metrics", "Get load balancer metrics (last 30 days only). Output starts with a per-series summary {points,min,avg,max,last}, then the raw time_series unless include_values=false. Series: open_connections (number), connections_per_second, requests_per_second, bandwidth → bandwidth.in/bandwidth.out (bytes/s). Time range: pass start+end (ISO-8601), or omit both and use last_minutes (default 60)", {
86
- id: z.number().describe("Load balancer ID"),
87
- type: z.array(z.enum(["open_connections", "connections_per_second", "requests_per_second", "bandwidth"])).min(1)
88
- .describe("Metric types, e.g. [\"requests_per_second\",\"bandwidth\"]"),
89
- ...timeParams,
105
+ server.registerTool("get_load_balancer_metrics", {
106
+ description: "Get load balancer metrics (last 30 days only). Output starts with a per-series summary {points,min,avg,max,last}, then the raw time_series unless include_values=false. Series: open_connections (number), connections_per_second, requests_per_second, bandwidth → bandwidth.in/bandwidth.out (bytes/s). Time range: pass start+end (ISO-8601), or omit both and use last_minutes (default 60)",
107
+ inputSchema: {
108
+ id: z.number().describe("Load balancer ID"),
109
+ type: z.array(z.enum(["open_connections", "connections_per_second", "requests_per_second", "bandwidth"])).min(1)
110
+ .describe("Metric types, e.g. [\"requests_per_second\",\"bandwidth\"]"),
111
+ ...timeParams,
112
+ },
113
+ annotations: READ_ONLY,
90
114
  }, async ({ id, type, ...rest }) => withToolError(() => getMetrics(`/load_balancers/${id}/metrics`, type, rest)));
91
115
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { HETZNER_API, hcloudRequest } from "./hcloud-api.js";
3
- import { json, listAll, withToolError } from "./tool-helpers.js";
3
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, listAll, withToolError } from "./tool-helpers.js";
4
4
  // Every Storage Box request must go to api.hetzner.com, never api.hetzner.cloud.
5
5
  const sb = (method, path, opts = {}) => hcloudRequest(method, path, { ...opts, baseUrl: HETZNER_API });
6
6
  const boxPath = (id) => `/storage_boxes/${id}`;
@@ -44,88 +44,208 @@ const POLL = "Returns an Action; poll get_storage_box_action until status is suc
44
44
  const CONFIRM = "Irreversible; confirm with the user first";
45
45
  export function registerStorageBoxTools(server) {
46
46
  // --- Storage Box Types ---
47
- server.tool("list_storage_box_types", "List Storage Box Types (bx11, bx21, ...) with size, snapshot/subaccount limits and per-location hourly/monthly prices and setup fees", { name: z.string().optional() }, async (args) => withToolError(async () => json(await listAll((p) => sb("GET", "/storage_box_types", { query: { ...args, page: p.page, per_page: p.perPage } }), "storage_box_types"))));
48
- server.tool("get_storage_box_type", "Get a Storage Box Type by ID", { id: z.number().int().positive() }, async ({ id }) => withToolError(async () => json((await sb("GET", `/storage_box_types/${id}`)).storage_box_type)));
47
+ server.registerTool("list_storage_box_types", {
48
+ description: "List Storage Box Types (bx11, bx21, ...) with size, snapshot/subaccount limits and per-location hourly/monthly prices and setup fees",
49
+ inputSchema: { name: z.string().optional() },
50
+ annotations: READ_ONLY,
51
+ }, async (args) => withToolError(async () => json(await listAll((p) => sb("GET", "/storage_box_types", { query: { ...args, ...p } }), "storage_box_types"))));
52
+ server.registerTool("get_storage_box_type", {
53
+ description: "Get a Storage Box Type by ID",
54
+ inputSchema: { id: z.number().int().positive() },
55
+ annotations: READ_ONLY,
56
+ }, async ({ id }) => withToolError(async () => json((await sb("GET", `/storage_box_types/${id}`)).storage_box_type)));
49
57
  // --- Storage Boxes ---
50
- server.tool("list_storage_boxes", "List Storage Boxes (all pages). Optional filters by exact name and label selector", { name: z.string().optional(), label_selector: labelSelector, sort }, async (args) => withToolError(async () => json(await listAll((p) => sb("GET", "/storage_boxes", { query: { ...args, page: p.page, per_page: p.perPage } }), "storage_boxes"))));
51
- server.tool("get_storage_box", "Get a Storage Box: status (initializing/active/locked), type, location, username, server FQDN, access settings, snapshot plan, protection, disk usage stats. username/server/system are null while initializing", { id: boxId }, async ({ id }) => withToolError(async () => json((await sb("GET", boxPath(id))).storage_box)));
52
- server.tool("create_storage_box", `Create a Storage Box (billed hourly, capped at the monthly price; see list_storage_box_types for prices). ${POLL}; provisioning can take several minutes and username/server stay null until status is active`, {
53
- name: z.string().describe("Storage Box name"),
54
- location: z.string().describe("Location ID or name, e.g. fsn1, hel1 (see list_storage_box_types prices for availability)"),
55
- storage_box_type: z.string().describe("Storage Box Type ID or name, e.g. bx11"),
56
- password,
57
- labels: labels.optional(),
58
- ssh_keys: z.array(z.string()).optional().describe("SSH public keys in OpenSSH format to install"),
59
- access_settings: z.object(boxAccess).optional().describe("Initial access settings"),
58
+ server.registerTool("list_storage_boxes", {
59
+ description: "List Storage Boxes (all pages). Optional filters by exact name and label selector",
60
+ inputSchema: { name: z.string().optional(), label_selector: labelSelector, sort },
61
+ annotations: READ_ONLY,
62
+ }, async (args) => withToolError(async () => json(await listAll((p) => sb("GET", "/storage_boxes", { query: { ...args, ...p } }), "storage_boxes"))));
63
+ server.registerTool("get_storage_box", {
64
+ description: "Get a Storage Box: status (initializing/active/locked), type, location, username, server FQDN, access settings, snapshot plan, protection, disk usage stats. username/server/system are null while initializing",
65
+ inputSchema: { id: boxId },
66
+ annotations: READ_ONLY,
67
+ }, async ({ id }) => withToolError(async () => json((await sb("GET", boxPath(id))).storage_box)));
68
+ server.registerTool("create_storage_box", {
69
+ description: `Create a Storage Box (billed hourly, capped at the monthly price; see list_storage_box_types for prices). ${POLL}; provisioning can take several minutes and username/server stay null until status is active`,
70
+ inputSchema: {
71
+ name: z.string().describe("Storage Box name"),
72
+ location: z.string().describe("Location ID or name, e.g. fsn1, hel1 (see list_storage_box_types prices for availability)"),
73
+ storage_box_type: z.string().describe("Storage Box Type ID or name, e.g. bx11"),
74
+ password,
75
+ labels: labels.optional(),
76
+ ssh_keys: z.array(z.string()).optional().describe("SSH public keys in OpenSSH format to install"),
77
+ access_settings: z.object(boxAccess).optional().describe("Initial access settings"),
78
+ },
79
+ annotations: ADDITIVE,
60
80
  }, async (args) => withToolError(async () => {
61
81
  const res = await sb("POST", "/storage_boxes", { body: args });
62
82
  return json({ storage_box: res.storage_box, action: res.action });
63
83
  }));
64
- server.tool("update_storage_box", "Update a Storage Box's name and/or labels (labels replace the whole set)", { id: boxId, name: z.string().optional(), labels: labels.optional() }, async ({ id, ...body }) => withToolError(async () => json((await sb("PUT", boxPath(id), { body })).storage_box)));
65
- server.tool("delete_storage_box", `Delete a Storage Box and ALL its data, subaccounts and snapshots. ${CONFIRM}. Fails if delete protection is enabled. ${POLL}`, { id: boxId }, async ({ id }) => withToolError(async () => json(await sb("DELETE", boxPath(id)))));
66
- server.tool("list_storage_box_folders", "List folders in a Storage Box directory (not files). Box must be active", { id: boxId, path: z.string().optional().describe('Relative path to list (default: root)') }, async ({ id, path }) => withToolError(async () => json((await sb("GET", `${boxPath(id)}/folders`, { query: { path } })).folders)));
84
+ server.registerTool("update_storage_box", {
85
+ description: "Update a Storage Box's name and/or labels (labels replace the whole set)",
86
+ inputSchema: { id: boxId, name: z.string().optional(), labels: labels.optional() },
87
+ annotations: ADDITIVE_IDEMPOTENT,
88
+ }, async ({ id, ...body }) => withToolError(async () => json((await sb("PUT", boxPath(id), { body })).storage_box)));
89
+ server.registerTool("delete_storage_box", {
90
+ description: `Delete a Storage Box and ALL its data, subaccounts and snapshots. ${CONFIRM}. Fails if delete protection is enabled. ${POLL}`,
91
+ inputSchema: { id: boxId },
92
+ annotations: DESTRUCTIVE_IDEMPOTENT,
93
+ }, async ({ id }) => withToolError(async () => json(await sb("DELETE", boxPath(id)))));
94
+ server.registerTool("list_storage_box_folders", {
95
+ description: "List folders in a Storage Box directory (not files). Box must be active",
96
+ inputSchema: { id: boxId, path: z.string().optional().describe('Relative path to list (default: root)') },
97
+ annotations: READ_ONLY,
98
+ }, async ({ id, path }) => withToolError(async () => json((await sb("GET", `${boxPath(id)}/folders`, { query: { path } })).folders)));
67
99
  // --- Actions ---
68
- server.tool("get_storage_box_action", "Get a Storage Box Action by ID (create/delete/reset_password/snapshot/subaccount actions). This is the documented endpoint for Storage Box Actions (get_action currently also resolves them)", { id: z.number().int().positive().describe("Action ID") }, async ({ id }) => withToolError(async () => json((await sb("GET", `/storage_boxes/actions/${id}`)).action)));
69
- server.tool("list_storage_box_actions", "List Actions (all pages). With storage_box_id: actions for that box. Without: actions across all Storage Boxes (optionally filtered by id)", {
70
- storage_box_id: boxId.optional(),
71
- id: z.array(z.number().int().positive()).optional().describe("Filter by action IDs (Storage-Box-wide listing)"),
72
- status: actionStatus,
73
- sort,
100
+ server.registerTool("get_storage_box_action", {
101
+ description: "Get a Storage Box Action by ID (create/delete/reset_password/snapshot/subaccount actions). This is the documented endpoint for Storage Box Actions (get_action currently also resolves them)",
102
+ inputSchema: { id: z.number().int().positive().describe("Action ID") },
103
+ annotations: READ_ONLY,
104
+ }, async ({ id }) => withToolError(async () => json((await sb("GET", `/storage_boxes/actions/${id}`)).action)));
105
+ server.registerTool("list_storage_box_actions", {
106
+ description: "List Actions (all pages). With storage_box_id: actions for that box. Without: actions across all Storage Boxes (optionally filtered by id)",
107
+ inputSchema: {
108
+ storage_box_id: boxId.optional(),
109
+ id: z.array(z.number().int().positive()).optional().describe("Filter by action IDs (Storage-Box-wide listing)"),
110
+ status: actionStatus,
111
+ sort,
112
+ },
113
+ annotations: READ_ONLY,
74
114
  }, async ({ storage_box_id, ...query }) => withToolError(async () => {
75
115
  const path = storage_box_id ? `${boxPath(storage_box_id)}/actions` : "/storage_boxes/actions";
76
116
  if (storage_box_id && query.id)
77
117
  throw new Error("id filter is only supported without storage_box_id");
78
- return json(await listAll((p) => sb("GET", path, { query: { ...query, page: p.page, per_page: p.perPage } }), "actions"));
118
+ return json(await listAll((p) => sb("GET", path, { query: { ...query, ...p } }), "actions"));
79
119
  }));
80
- server.tool("change_storage_box_protection", `Enable/disable delete protection for a Storage Box. ${POLL}`, { id: boxId, delete: z.boolean().describe("Prevent deletion") }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/change_protection`, { body }))));
81
- server.tool("change_storage_box_type", `Upgrade/downgrade a Storage Box to another type (changes billing). Cannot downgrade below current usage. ${POLL}`, { id: boxId, storage_box_type: z.string().describe("Target Storage Box Type ID or name, e.g. bx21") }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/change_type`, { body }))));
82
- server.tool("reset_storage_box_password", `Set a new password for the Storage Box main account (existing clients using the old password lose access). ${POLL}`, { id: boxId, password }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/reset_password`, { body }))));
83
- server.tool("update_storage_box_access_settings", `Update the main account's access settings (partial: omitted fields are unchanged). ${POLL}`, { id: boxId, ...boxAccess }, async ({ id, ...body }) => withToolError(async () => {
120
+ server.registerTool("change_storage_box_protection", {
121
+ description: `Enable/disable delete protection for a Storage Box. ${POLL}`,
122
+ inputSchema: { id: boxId, delete: z.boolean().describe("Prevent deletion") },
123
+ annotations: DESTRUCTIVE_IDEMPOTENT,
124
+ }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/change_protection`, { body }))));
125
+ server.registerTool("change_storage_box_type", {
126
+ description: `Upgrade/downgrade a Storage Box to another type (changes billing). Cannot downgrade below current usage. ${POLL}`,
127
+ inputSchema: { id: boxId, storage_box_type: z.string().describe("Target Storage Box Type ID or name, e.g. bx21") },
128
+ annotations: DESTRUCTIVE_IDEMPOTENT,
129
+ }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/change_type`, { body }))));
130
+ server.registerTool("reset_storage_box_password", {
131
+ description: `Set a new password for the Storage Box main account (existing clients using the old password lose access). ${POLL}`,
132
+ inputSchema: { id: boxId, password },
133
+ annotations: DESTRUCTIVE_IDEMPOTENT,
134
+ }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/reset_password`, { body }))));
135
+ server.registerTool("update_storage_box_access_settings", {
136
+ description: `Update the main account's access settings (partial: omitted fields are unchanged). ${POLL}`,
137
+ inputSchema: { id: boxId, ...boxAccess },
138
+ annotations: DESTRUCTIVE_IDEMPOTENT,
139
+ }, async ({ id, ...body }) => withToolError(async () => {
84
140
  if (Object.keys(body).length === 0)
85
141
  throw new Error("Provide at least one access setting");
86
142
  return json(await sb("POST", `${boxPath(id)}/actions/update_access_settings`, { body }));
87
143
  }));
88
- server.tool("enable_storage_box_snapshot_plan", `Enable (or replace) the automatic snapshot plan. Runs at hour:minute UTC, optionally only on day_of_week (1=Mon..7=Sun) and/or day_of_month; null/omitted = every day. Oldest automatic snapshots beyond max_snapshots are deleted. ${POLL}`, {
89
- id: boxId,
90
- max_snapshots: z.number().int().min(1).describe("Snapshots to keep (<= the type's automatic_snapshot_limit)"),
91
- hour: z.number().int().min(0).max(23).describe("Hour (UTC)"),
92
- minute: z.number().int().min(0).max(59).describe("Minute (UTC)"),
93
- day_of_week: z.number().int().min(1).max(7).nullable().optional().describe("1=Monday..7=Sunday; null = every day"),
94
- day_of_month: z.number().int().min(1).max(31).nullable().optional().describe("Day of month; null = every day"),
144
+ server.registerTool("enable_storage_box_snapshot_plan", {
145
+ description: `Enable (or replace) the automatic snapshot plan. Runs at hour:minute UTC, optionally only on day_of_week (1=Mon..7=Sun) and/or day_of_month; null/omitted = every day. Oldest automatic snapshots beyond max_snapshots are deleted. ${POLL}`,
146
+ inputSchema: {
147
+ id: boxId,
148
+ max_snapshots: z.number().int().min(1).describe("Snapshots to keep (<= the type's automatic_snapshot_limit)"),
149
+ hour: z.number().int().min(0).max(23).describe("Hour (UTC)"),
150
+ minute: z.number().int().min(0).max(59).describe("Minute (UTC)"),
151
+ day_of_week: z.number().int().min(1).max(7).nullable().optional().describe("1=Monday..7=Sunday; null = every day"),
152
+ day_of_month: z.number().int().min(1).max(31).nullable().optional().describe("Day of month; null = every day"),
153
+ },
154
+ annotations: DESTRUCTIVE_IDEMPOTENT,
95
155
  }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/enable_snapshot_plan`, { body }))));
96
- server.tool("disable_storage_box_snapshot_plan", `Disable the automatic snapshot plan. Existing automatic snapshots are kept (delete them manually). ${POLL}`, { id: boxId }, async ({ id }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/disable_snapshot_plan`))));
97
- server.tool("rollback_storage_box_snapshot", `Roll a Storage Box back to a snapshot. Deletes all newer snapshots and ALL data written since the snapshot. ${CONFIRM}. ${POLL}`, { id: boxId, snapshot: z.string().describe("Snapshot ID or name") }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/rollback_snapshot`, { body }))));
156
+ server.registerTool("disable_storage_box_snapshot_plan", {
157
+ description: `Disable the automatic snapshot plan. Existing automatic snapshots are kept (delete them manually). ${POLL}`,
158
+ inputSchema: { id: boxId },
159
+ annotations: ADDITIVE_IDEMPOTENT,
160
+ }, async ({ id }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/disable_snapshot_plan`))));
161
+ server.registerTool("rollback_storage_box_snapshot", {
162
+ description: `Roll a Storage Box back to a snapshot. Deletes all newer snapshots and ALL data written since the snapshot. ${CONFIRM}. ${POLL}`,
163
+ inputSchema: { id: boxId, snapshot: z.string().describe("Snapshot ID or name") },
164
+ annotations: DESTRUCTIVE_IDEMPOTENT,
165
+ }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/actions/rollback_snapshot`, { body }))));
98
166
  // --- Subaccounts ---
99
- server.tool("list_storage_box_subaccounts", "List subaccounts of a Storage Box (username, home_directory, access settings, server FQDN)", { id: boxId, name: z.string().optional(), username: z.string().optional(), label_selector: labelSelector, sort }, async ({ id, ...query }) => withToolError(async () => json((await sb("GET", `${boxPath(id)}/subaccounts`, { query })).subaccounts)));
100
- server.tool("get_storage_box_subaccount", "Get a Storage Box subaccount", { id: boxId, subaccount_id: subaccountId }, async ({ id, subaccount_id }) => withToolError(async () => json((await sb("GET", subPath(id, subaccount_id))).subaccount)));
101
- server.tool("create_storage_box_subaccount", `Create a subaccount: a separate login restricted to home_directory inside the box (shares the box's quota). Username is assigned by Hetzner (<box-username>-subN). Returns {subaccount: {id, storage_box}, action}; ${POLL}, then get_storage_box_subaccount for details`, {
102
- id: boxId,
103
- home_directory: homeDirectory,
104
- password,
105
- name: z.string().optional().describe("Defaults to the generated username"),
106
- description: z.string().optional(),
107
- labels: labels.optional(),
108
- access_settings: z.object(subAccess).optional(),
167
+ server.registerTool("list_storage_box_subaccounts", {
168
+ description: "List subaccounts of a Storage Box (username, home_directory, access settings, server FQDN)",
169
+ inputSchema: { id: boxId, name: z.string().optional(), username: z.string().optional(), label_selector: labelSelector, sort },
170
+ annotations: READ_ONLY,
171
+ }, async ({ id, ...query }) => withToolError(async () => json((await sb("GET", `${boxPath(id)}/subaccounts`, { query })).subaccounts)));
172
+ server.registerTool("get_storage_box_subaccount", {
173
+ description: "Get a Storage Box subaccount",
174
+ inputSchema: { id: boxId, subaccount_id: subaccountId },
175
+ annotations: READ_ONLY,
176
+ }, async ({ id, subaccount_id }) => withToolError(async () => json((await sb("GET", subPath(id, subaccount_id))).subaccount)));
177
+ server.registerTool("create_storage_box_subaccount", {
178
+ description: `Create a subaccount: a separate login restricted to home_directory inside the box (shares the box's quota). Username is assigned by Hetzner (<box-username>-subN). Returns {subaccount: {id, storage_box}, action}; ${POLL}, then get_storage_box_subaccount for details`,
179
+ inputSchema: {
180
+ id: boxId,
181
+ home_directory: homeDirectory,
182
+ password,
183
+ name: z.string().optional().describe("Defaults to the generated username"),
184
+ description: z.string().optional(),
185
+ labels: labels.optional(),
186
+ access_settings: z.object(subAccess).optional(),
187
+ },
188
+ annotations: ADDITIVE,
109
189
  }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/subaccounts`, { body }))));
110
- server.tool("update_storage_box_subaccount", "Update a subaccount's name, description and/or labels (labels replace the whole set). Use change_storage_box_subaccount_home_directory / update_storage_box_subaccount_access_settings for those", {
111
- id: boxId,
112
- subaccount_id: subaccountId,
113
- name: z.string().optional(),
114
- description: z.string().optional(),
115
- labels: labels.optional(),
190
+ server.registerTool("update_storage_box_subaccount", {
191
+ description: "Update a subaccount's name, description and/or labels (labels replace the whole set). Use change_storage_box_subaccount_home_directory / update_storage_box_subaccount_access_settings for those",
192
+ inputSchema: {
193
+ id: boxId,
194
+ subaccount_id: subaccountId,
195
+ name: z.string().optional(),
196
+ description: z.string().optional(),
197
+ labels: labels.optional(),
198
+ },
199
+ annotations: ADDITIVE_IDEMPOTENT,
116
200
  }, async ({ id, subaccount_id, ...body }) => withToolError(async () => json((await sb("PUT", subPath(id, subaccount_id), { body })).subaccount)));
117
- server.tool("delete_storage_box_subaccount", `Delete a subaccount (its login stops working; files in its home directory remain in the main account). ${CONFIRM}. ${POLL}`, { id: boxId, subaccount_id: subaccountId }, async ({ id, subaccount_id }) => withToolError(async () => json(await sb("DELETE", subPath(id, subaccount_id)))));
118
- server.tool("change_storage_box_subaccount_home_directory", `Change a subaccount's home directory (created if missing). ${POLL}`, { id: boxId, subaccount_id: subaccountId, home_directory: homeDirectory }, async ({ id, subaccount_id, ...body }) => withToolError(async () => json(await sb("POST", `${subPath(id, subaccount_id)}/actions/change_home_directory`, { body }))));
119
- server.tool("reset_storage_box_subaccount_password", `Set a new password for a subaccount. ${POLL}`, { id: boxId, subaccount_id: subaccountId, password }, async ({ id, subaccount_id, ...body }) => withToolError(async () => json(await sb("POST", `${subPath(id, subaccount_id)}/actions/reset_subaccount_password`, { body }))));
120
- server.tool("update_storage_box_subaccount_access_settings", `Update a subaccount's access settings incl. readonly (partial: omitted fields are unchanged). ${POLL}`, { id: boxId, subaccount_id: subaccountId, ...subAccess }, async ({ id, subaccount_id, ...body }) => withToolError(async () => {
201
+ server.registerTool("delete_storage_box_subaccount", {
202
+ description: `Delete a subaccount (its login stops working; files in its home directory remain in the main account). ${CONFIRM}. ${POLL}`,
203
+ inputSchema: { id: boxId, subaccount_id: subaccountId },
204
+ annotations: DESTRUCTIVE_IDEMPOTENT,
205
+ }, async ({ id, subaccount_id }) => withToolError(async () => json(await sb("DELETE", subPath(id, subaccount_id)))));
206
+ server.registerTool("change_storage_box_subaccount_home_directory", {
207
+ description: `Change a subaccount's home directory (created if missing). ${POLL}`,
208
+ inputSchema: { id: boxId, subaccount_id: subaccountId, home_directory: homeDirectory },
209
+ annotations: ADDITIVE_IDEMPOTENT,
210
+ }, async ({ id, subaccount_id, ...body }) => withToolError(async () => json(await sb("POST", `${subPath(id, subaccount_id)}/actions/change_home_directory`, { body }))));
211
+ server.registerTool("reset_storage_box_subaccount_password", {
212
+ description: `Set a new password for a subaccount. ${POLL}`,
213
+ inputSchema: { id: boxId, subaccount_id: subaccountId, password },
214
+ annotations: DESTRUCTIVE_IDEMPOTENT,
215
+ }, async ({ id, subaccount_id, ...body }) => withToolError(async () => json(await sb("POST", `${subPath(id, subaccount_id)}/actions/reset_subaccount_password`, { body }))));
216
+ server.registerTool("update_storage_box_subaccount_access_settings", {
217
+ description: `Update a subaccount's access settings incl. readonly (partial: omitted fields are unchanged). ${POLL}`,
218
+ inputSchema: { id: boxId, subaccount_id: subaccountId, ...subAccess },
219
+ annotations: DESTRUCTIVE_IDEMPOTENT,
220
+ }, async ({ id, subaccount_id, ...body }) => withToolError(async () => {
121
221
  if (Object.keys(body).length === 0)
122
222
  throw new Error("Provide at least one access setting");
123
223
  return json(await sb("POST", `${subPath(id, subaccount_id)}/actions/update_access_settings`, { body }));
124
224
  }));
125
225
  // --- Snapshots ---
126
- server.tool("list_storage_box_snapshots", "List snapshots of a Storage Box (manual and automatic; is_automatic filters)", { id: boxId, name: z.string().optional(), label_selector: labelSelector, is_automatic: z.boolean().optional(), sort }, async ({ id, ...query }) => withToolError(async () => json((await sb("GET", `${boxPath(id)}/snapshots`, { query })).snapshots)));
127
- server.tool("get_storage_box_snapshot", "Get a Storage Box snapshot (name, description, size stats, is_automatic)", { id: boxId, snapshot_id: snapshotId }, async ({ id, snapshot_id }) => withToolError(async () => json((await sb("GET", snapPath(id, snapshot_id))).snapshot)));
128
- server.tool("create_storage_box_snapshot", `Create a manual snapshot (limited by the type's snapshot_limit). Returns {snapshot: {id, storage_box}, action}; ${POLL}, then get_storage_box_snapshot for details`, { id: boxId, description: z.string().optional(), labels: labels.optional() }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/snapshots`, { body }))));
129
- server.tool("update_storage_box_snapshot", "Update a snapshot's description and/or labels (labels replace the whole set)", { id: boxId, snapshot_id: snapshotId, description: z.string().optional(), labels: labels.optional() }, async ({ id, snapshot_id, ...body }) => withToolError(async () => json((await sb("PUT", snapPath(id, snapshot_id), { body })).snapshot)));
130
- server.tool("delete_storage_box_snapshot", `Delete a snapshot. ${CONFIRM}. ${POLL}`, { id: boxId, snapshot_id: snapshotId }, async ({ id, snapshot_id }) => withToolError(async () => json(await sb("DELETE", snapPath(id, snapshot_id)))));
226
+ server.registerTool("list_storage_box_snapshots", {
227
+ description: "List snapshots of a Storage Box (manual and automatic; is_automatic filters)",
228
+ inputSchema: { id: boxId, name: z.string().optional(), label_selector: labelSelector, is_automatic: z.boolean().optional(), sort },
229
+ annotations: READ_ONLY,
230
+ }, async ({ id, ...query }) => withToolError(async () => json((await sb("GET", `${boxPath(id)}/snapshots`, { query })).snapshots)));
231
+ server.registerTool("get_storage_box_snapshot", {
232
+ description: "Get a Storage Box snapshot (name, description, size stats, is_automatic)",
233
+ inputSchema: { id: boxId, snapshot_id: snapshotId },
234
+ annotations: READ_ONLY,
235
+ }, async ({ id, snapshot_id }) => withToolError(async () => json((await sb("GET", snapPath(id, snapshot_id))).snapshot)));
236
+ server.registerTool("create_storage_box_snapshot", {
237
+ description: `Create a manual snapshot (limited by the type's snapshot_limit). Returns {snapshot: {id, storage_box}, action}; ${POLL}, then get_storage_box_snapshot for details`,
238
+ inputSchema: { id: boxId, description: z.string().optional(), labels: labels.optional() },
239
+ annotations: ADDITIVE,
240
+ }, async ({ id, ...body }) => withToolError(async () => json(await sb("POST", `${boxPath(id)}/snapshots`, { body }))));
241
+ server.registerTool("update_storage_box_snapshot", {
242
+ description: "Update a snapshot's description and/or labels (labels replace the whole set)",
243
+ inputSchema: { id: boxId, snapshot_id: snapshotId, description: z.string().optional(), labels: labels.optional() },
244
+ annotations: ADDITIVE_IDEMPOTENT,
245
+ }, async ({ id, snapshot_id, ...body }) => withToolError(async () => json((await sb("PUT", snapPath(id, snapshot_id), { body })).snapshot)));
246
+ server.registerTool("delete_storage_box_snapshot", {
247
+ description: `Delete a snapshot. ${CONFIRM}. ${POLL}`,
248
+ inputSchema: { id: boxId, snapshot_id: snapshotId },
249
+ annotations: DESTRUCTIVE_IDEMPOTENT,
250
+ }, async ({ id, snapshot_id }) => withToolError(async () => json(await sb("DELETE", snapPath(id, snapshot_id)))));
131
251
  }
@@ -1,28 +1,19 @@
1
- // Shared helpers for tool modules.
2
- // hetzner-sdk-ts throws ApiError with the Hetzner error JSON in `body` and a vague
3
- // message ("Forbidden", "Generic Error: ..."). Surface the API's code/message instead,
4
- // matching HcloudApiError's format: "<code> (<status>): <message> <details>".
5
- export const formatError = (error) => {
6
- const e = error;
7
- if (e && e.name === "ApiError" && e.body != null) {
8
- let body = e.body;
9
- if (typeof body === "string") {
10
- try {
11
- body = JSON.parse(body);
12
- }
13
- catch { /* keep string */ }
14
- }
15
- const apiErr = body?.error;
16
- if (apiErr?.code) {
17
- const details = apiErr.details && Object.keys(apiErr.details).length ? ` ${JSON.stringify(apiErr.details)}` : "";
18
- return `${apiErr.code} (${e.status}): ${apiErr.message ?? ""}${details}`;
19
- }
20
- }
21
- if (error instanceof Error) {
22
- return error.message;
23
- }
24
- return String(error);
25
- };
1
+ // MCP tool annotations (hints for clients). Each tool picks one explicitly at registration.
2
+ // Every tool calls the external Hetzner API, so openWorldHint is always true. The spec
3
+ // defaults destructiveHint to true, so mutating tools always set it explicitly.
4
+ /** Reads only; changes nothing. */
5
+ export const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
6
+ /** Creates or triggers something new on each call; loses nothing. */
7
+ export const ADDITIVE = { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true };
8
+ /** Sets/attaches to a given value; repeating it has no further effect; loses nothing. */
9
+ export const ADDITIVE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
10
+ /** Can lose data or availability, and repeating it acts again (reboot, reset, rebuild). */
11
+ export const DESTRUCTIVE = { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true };
12
+ /** Can lose data or availability; repeating it has no further effect (deletes, detaches, replaces). */
13
+ export const DESTRUCTIVE_IDEMPOTENT = { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true };
14
+ // Errors from hcloudRequest are HcloudApiError, already formatted as
15
+ // "<code> (<status>): <message> <details>".
16
+ export const formatError = (error) => (error instanceof Error ? error.message : String(error));
26
17
  export async function withToolError(run) {
27
18
  try {
28
19
  return await run();
@@ -38,7 +29,7 @@ export async function listAll(fetchPage, key) {
38
29
  const items = [];
39
30
  let page = 1;
40
31
  while (page != null) {
41
- const response = await fetchPage({ page, perPage: 50 });
32
+ const response = await fetchPage({ page, per_page: 50 });
42
33
  items.push(...(response?.[key] ?? []));
43
34
  const next = response?.meta?.pagination?.next_page ?? null;
44
35
  page = next != null && next > page ? next : null; // guard against non-advancing pagination
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hcloud-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.4.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",
@@ -17,6 +17,7 @@
17
17
  "prepublishOnly": "npm run build",
18
18
  "start": "node dist/index.js",
19
19
  "dev": "tsc --watch",
20
+ "test:smoke": "node scripts/smoke-mcp.mjs",
20
21
  "test:api": "node scripts/test-list-api.mjs",
21
22
  "test:mcp": "node scripts/test-mcp-list.mjs",
22
23
  "test:live": "node scripts/test-live-lifecycle.mjs",
@@ -25,8 +26,7 @@
25
26
  "test:live:ops": "node scripts/test-live-server-ops.mjs",
26
27
  "test:live:actions": "node scripts/test-live-action-gaps.mjs",
27
28
  "test:live:certs": "node scripts/test-live-certificates.mjs",
28
- "test:live:storage": "node scripts/test-live-storage-box.mjs",
29
- "audit:api": "cross-env DRY_RUN=1 node scripts/audit-api-shapes.mjs"
29
+ "test:live:storage": "node scripts/test-live-storage-box.mjs"
30
30
  },
31
31
  "keywords": [
32
32
  "mcp",
@@ -44,13 +44,11 @@
44
44
  "dependencies": {
45
45
  "@modelcontextprotocol/sdk": "^1.26.0",
46
46
  "dotenv": "^17.3.1",
47
- "hetzner-sdk-ts": "^1.0.1",
48
47
  "zod": "^3.23.8",
49
48
  "zod-to-json-schema": "^3.25.1"
50
49
  },
51
50
  "devDependencies": {
52
51
  "@types/node": "^20.12.7",
53
- "cross-env": "^7.0.3",
54
52
  "typescript": "^5.4.5"
55
53
  }
56
54
  }
@@ -76,6 +76,8 @@ Call `get_server_metrics` or `get_load_balancer_metrics` with `last_minutes` and
76
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
77
 
78
78
  ## Labels and network changes
79
+ - **Stable LB address:** `create_primary_ip` in the LB's location → `create_load_balancer public_net:{ipv4:<id>}`. The IP can't be changed afterwards. Deleting the LB leaves the IP `unassigned`, ready for reuse.
80
+ - **Volumes:** see which server a volume is attached to in `assignee` (`{type:"server", id}`). The old `server` field disappears on 2027-10-27.
79
81
  - **Labels:** every `update_*` replaces the whole label set. Read the current labels and merge.
80
82
  - **Alias IPs:** `change_server_alias_ips` replaces the whole list. Send the existing IPs plus the new one.
81
83
  - **Placement groups:** `add_server_to_placement_group` needs the server powered off. Removing works while it runs.