hcloud-mcp 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
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
1
  import { z } from "zod";
2
+ import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, listAll, withToolError } from "./tool-helpers.js";
3
+ import { hcloudRequest } from "./hcloud-api.js";
3
4
  // Firewall rule: direction, protocol required; source_ips for 'in', destination_ips for 'out'; port for tcp/udp
4
5
  const firewallRuleSchema = z.object({
5
6
  direction: z.enum(["in", "out"]),
@@ -14,65 +15,49 @@ const firewallApplyToSchema = z.object({
14
15
  server: z.object({ id: z.number() }).optional(),
15
16
  label_selector: z.object({ selector: z.string() }).optional(),
16
17
  });
17
- const formatError = (error) => {
18
- if (error instanceof Error) {
19
- return error.message;
20
- }
21
- return String(error);
22
- };
23
- async function withToolError(run) {
24
- try {
25
- return await run();
26
- }
27
- catch (error) {
28
- return { content: [{ type: "text", text: `Error: ${formatError(error)}` }], isError: true };
29
- }
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
- }
45
18
  export function registerTools(server) {
46
19
  // --- Servers ---
47
- server.tool("list_servers", "List all servers", {}, async (_args, _extra) => withToolError(async () => {
48
- const items = await listAll((p) => ServersService.getServers(p), "servers");
20
+ server.registerTool("list_servers", {
21
+ description: "List all servers",
22
+ inputSchema: {},
23
+ annotations: READ_ONLY,
24
+ }, async (_args, _extra) => withToolError(async () => {
25
+ const items = await listAll((p) => hcloudRequest("GET", "/servers", { query: p }), "servers");
49
26
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
50
27
  }));
51
- server.tool("get_server", "Get a single server by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
52
- const response = await ServersService.getServers1({ id });
28
+ server.registerTool("get_server", {
29
+ description: "Get a single server by ID",
30
+ inputSchema: { id: z.number() },
31
+ annotations: READ_ONLY,
32
+ }, async ({ id }, _extra) => withToolError(async () => {
33
+ const response = await hcloudRequest("GET", `/servers/${id}`);
53
34
  return { content: [{ type: "text", text: JSON.stringify(response.server, null, 2) }] };
54
35
  }));
55
- server.tool("create_server", "Create a new server", {
56
- name: z.string(),
57
- server_type: z.string(),
58
- image: z.string(),
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"),
60
- start_after_create: z.boolean().optional(),
61
- ssh_keys: z.array(z.union([z.string(), z.number()])).optional().describe("List of SSH key names or IDs"),
62
- firewalls: z.array(z.object({ firewall: z.number() })).optional(),
63
- networks: z.array(z.number()).optional(),
64
- placement_group: z.number().optional().describe("ID of placement group"),
65
- public_net: z
66
- .object({
67
- enable_ipv4: z.boolean().optional(),
68
- enable_ipv6: z.boolean().optional(),
69
- ipv4: z.number().nullable().optional(),
70
- ipv6: z.number().nullable().optional(),
71
- })
72
- .optional(),
73
- user_data: z.string().optional().describe("Cloud-Init user data (max 32KiB)"),
74
- volumes: z.array(z.number()).optional().describe("Volume IDs to attach at creation"),
75
- labels: z.record(z.string()).optional(),
36
+ server.registerTool("create_server", {
37
+ description: "Create a new server",
38
+ inputSchema: {
39
+ name: z.string(),
40
+ server_type: z.string(),
41
+ image: z.string(),
42
+ location: z.string().optional().describe("Location name or ID, e.g. fsn1, nbg1, hel1, ash, hil, sin. Check list_server_types locations[].available first"),
43
+ start_after_create: z.boolean().optional(),
44
+ ssh_keys: z.array(z.union([z.string(), z.number()])).optional().describe("List of SSH key names or IDs"),
45
+ firewalls: z.array(z.object({ firewall: z.number() })).optional(),
46
+ networks: z.array(z.number()).optional(),
47
+ placement_group: z.number().optional().describe("ID of placement group"),
48
+ public_net: z
49
+ .object({
50
+ enable_ipv4: z.boolean().optional(),
51
+ enable_ipv6: z.boolean().optional(),
52
+ ipv4: z.number().nullable().optional(),
53
+ ipv6: z.number().nullable().optional(),
54
+ })
55
+ .optional(),
56
+ user_data: z.string().optional().describe("Cloud-Init user data (max 32KiB)"),
57
+ volumes: z.array(z.number()).optional().describe("Volume IDs to attach at creation"),
58
+ labels: z.record(z.string()).optional(),
59
+ },
60
+ annotations: ADDITIVE,
76
61
  }, async (args, _extra) => withToolError(async () => {
77
62
  const requestBody = {
78
63
  name: args.name,
@@ -89,266 +74,363 @@ export function registerTools(server) {
89
74
  volumes: args.volumes,
90
75
  labels: args.labels,
91
76
  };
92
- const response = await ServersService.postServers({ requestBody });
77
+ const response = await hcloudRequest("POST", "/servers", { body: requestBody });
93
78
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
94
79
  }));
95
- server.tool("delete_server", "Delete a server", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
96
- const response = await ServersService.deleteServers({ id });
80
+ server.registerTool("delete_server", {
81
+ description: "Delete a server",
82
+ inputSchema: { id: z.number() },
83
+ annotations: DESTRUCTIVE_IDEMPOTENT,
84
+ }, async ({ id }, _extra) => withToolError(async () => {
85
+ const response = await hcloudRequest("DELETE", `/servers/${id}`);
97
86
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
98
87
  }));
99
- server.tool("change_server_type", "Change the type of a server (scales resources). Server must be powered off.", {
100
- id: z.number(),
101
- server_type: z.string().describe("New server type (e.g. cx22)"),
102
- upgrade_disk: z.boolean().default(true).describe("Whether to upgrade disk size. If true, cannot downgrade later."),
88
+ server.registerTool("change_server_type", {
89
+ description: "Change the type of a server (scales resources). Server must be powered off.",
90
+ inputSchema: {
91
+ id: z.number(),
92
+ server_type: z.string().describe("New server type (e.g. cx22)"),
93
+ upgrade_disk: z.boolean().default(true).describe("Whether to upgrade disk size. If true, cannot downgrade later."),
94
+ },
95
+ annotations: DESTRUCTIVE_IDEMPOTENT,
103
96
  }, async ({ id, server_type, upgrade_disk }, _extra) => withToolError(async () => {
104
- const response = await ServerActionsService.postServersActionsChangeType({
105
- id,
106
- requestBody: { server_type, upgrade_disk }
107
- });
97
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/change_type`, { body: { server_type, upgrade_disk } });
108
98
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
109
99
  }));
110
- server.tool("power_on_server", "Power on a server", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
111
- const response = await ServerActionsService.postServersActionsPoweron({ id });
100
+ server.registerTool("power_on_server", {
101
+ description: "Power on a server",
102
+ inputSchema: { id: z.number() },
103
+ annotations: ADDITIVE_IDEMPOTENT,
104
+ }, async ({ id }, _extra) => withToolError(async () => {
105
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/poweron`);
112
106
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
113
107
  }));
114
- server.tool("power_off_server", "Power off a server (hard)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
115
- const response = await ServerActionsService.postServersActionsPoweroff({ id });
108
+ server.registerTool("power_off_server", {
109
+ description: "Power off a server (hard)",
110
+ inputSchema: { id: z.number() },
111
+ annotations: DESTRUCTIVE_IDEMPOTENT,
112
+ }, async ({ id }, _extra) => withToolError(async () => {
113
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/poweroff`);
116
114
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
117
115
  }));
118
- server.tool("reboot_server", "Reboot a server (soft)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
119
- const response = await ServerActionsService.postServersActionsReboot({ id });
116
+ server.registerTool("reboot_server", {
117
+ description: "Reboot a server (soft)",
118
+ inputSchema: { id: z.number() },
119
+ annotations: DESTRUCTIVE,
120
+ }, async ({ id }, _extra) => withToolError(async () => {
121
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/reboot`);
120
122
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
121
123
  }));
122
- server.tool("shutdown_server", "Shutdown a server (soft)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
123
- const response = await ServerActionsService.postServersActionsShutdown({ id });
124
+ server.registerTool("shutdown_server", {
125
+ description: "Shutdown a server (soft)",
126
+ inputSchema: { id: z.number() },
127
+ annotations: DESTRUCTIVE_IDEMPOTENT,
128
+ }, async ({ id }, _extra) => withToolError(async () => {
129
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/shutdown`);
124
130
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
125
131
  }));
126
- server.tool("reset_server", "Reset a server (hard)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
127
- const response = await ServerActionsService.postServersActionsReset({ id });
132
+ server.registerTool("reset_server", {
133
+ description: "Reset a server (hard)",
134
+ inputSchema: { id: z.number() },
135
+ annotations: DESTRUCTIVE,
136
+ }, async ({ id }, _extra) => withToolError(async () => {
137
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/reset`);
128
138
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
129
139
  }));
130
- server.tool("update_server", "Update a server (name, labels)", {
131
- id: z.number(),
132
- name: z.string().optional(),
133
- labels: z.record(z.string()).optional(),
140
+ server.registerTool("update_server", {
141
+ description: "Update a server (name, labels)",
142
+ inputSchema: {
143
+ id: z.number(),
144
+ name: z.string().optional(),
145
+ labels: z.record(z.string()).optional(),
146
+ },
147
+ annotations: ADDITIVE_IDEMPOTENT,
134
148
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
135
- const response = await ServersService.putServers({
136
- id,
137
- requestBody: { name, labels }
138
- });
149
+ const response = await hcloudRequest("PUT", `/servers/${id}`, { body: { name, labels } });
139
150
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
140
151
  }));
141
- server.tool("attach_iso", "Attach an ISO to a server", {
142
- id: z.number(),
143
- iso: z.string().describe("ID or name of the ISO"),
152
+ server.registerTool("attach_iso", {
153
+ description: "Attach an ISO to a server",
154
+ inputSchema: {
155
+ id: z.number(),
156
+ iso: z.string().describe("ID or name of the ISO"),
157
+ },
158
+ annotations: ADDITIVE_IDEMPOTENT,
144
159
  }, async ({ id, iso }, _extra) => withToolError(async () => {
145
- const response = await ServerActionsService.postServersActionsAttachIso({
146
- id,
147
- requestBody: { iso }
148
- });
149
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
150
- }));
151
- server.tool("detach_iso", "Detach an ISO from a server", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
152
- const response = await ServerActionsService.postServersActionsDetachIso({ id });
153
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
154
- }));
155
- server.tool("attach_server_to_network", "Attach a server to a network", {
156
- id: z.number(),
157
- network: z.number().describe("ID of the network"),
158
- ip: z.string().optional().describe("IP to request, otherwise auto-assigned"),
159
- alias_ips: z.array(z.string()).optional(),
160
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/attach_iso`, { body: { iso } });
161
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
162
+ }));
163
+ server.registerTool("detach_iso", {
164
+ description: "Detach an ISO from a server",
165
+ inputSchema: { id: z.number() },
166
+ annotations: DESTRUCTIVE_IDEMPOTENT,
167
+ }, async ({ id }, _extra) => withToolError(async () => {
168
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/detach_iso`);
169
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
170
+ }));
171
+ server.registerTool("attach_server_to_network", {
172
+ description: "Attach a server to a network",
173
+ inputSchema: {
174
+ id: z.number(),
175
+ network: z.number().describe("ID of the network"),
176
+ ip: z.string().optional().describe("IP to request, otherwise auto-assigned"),
177
+ alias_ips: z.array(z.string()).optional(),
178
+ },
179
+ annotations: ADDITIVE_IDEMPOTENT,
160
180
  }, async ({ id, network, ip, alias_ips }, _extra) => withToolError(async () => {
161
- const response = await ServerActionsService.postServersActionsAttachToNetwork({
162
- id,
163
- requestBody: { network, ip, alias_ips }
164
- });
181
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/attach_to_network`, { body: { network, ip, alias_ips } });
165
182
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
166
183
  }));
167
- server.tool("detach_server_from_network", "Detach a server from a network", {
168
- id: z.number(),
169
- network: z.number().describe("ID of the network"),
184
+ server.registerTool("detach_server_from_network", {
185
+ description: "Detach a server from a network",
186
+ inputSchema: {
187
+ id: z.number(),
188
+ network: z.number().describe("ID of the network"),
189
+ },
190
+ annotations: DESTRUCTIVE_IDEMPOTENT,
170
191
  }, async ({ id, network }, _extra) => withToolError(async () => {
171
- const response = await ServerActionsService.postServersActionsDetachFromNetwork({
172
- id,
173
- requestBody: { network }
174
- });
192
+ const response = await hcloudRequest("POST", `/servers/${id}/actions/detach_from_network`, { body: { network } });
175
193
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
176
194
  }));
177
195
  // --- Load Balancers ---
178
- server.tool("list_load_balancers", "List all load balancers", {}, async (_args, _extra) => withToolError(async () => {
179
- const items = await listAll((p) => LoadBalancersService.getLoadBalancers(p), "load_balancers");
196
+ server.registerTool("list_load_balancers", {
197
+ description: "List all load balancers",
198
+ inputSchema: {},
199
+ annotations: READ_ONLY,
200
+ }, async (_args, _extra) => withToolError(async () => {
201
+ const items = await listAll((p) => hcloudRequest("GET", "/load_balancers", { query: p }), "load_balancers");
180
202
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
181
203
  }));
182
- server.tool("get_load_balancer", "Get a single load balancer by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
183
- const response = await LoadBalancersService.getLoadBalancers1({ id });
204
+ server.registerTool("get_load_balancer", {
205
+ description: "Get a single load balancer by ID",
206
+ inputSchema: { id: z.number() },
207
+ annotations: READ_ONLY,
208
+ }, async ({ id }, _extra) => withToolError(async () => {
209
+ const response = await hcloudRequest("GET", `/load_balancers/${id}`);
184
210
  return { content: [{ type: "text", text: JSON.stringify(response.load_balancer, null, 2) }] };
185
211
  }));
186
- server.tool("create_load_balancer", "Create a new load balancer", {
187
- name: z.string(),
188
- algorithm: z.object({ type: z.enum(["round_robin", "least_connections"]) }).optional(),
189
- location: z.string(),
190
- load_balancer_type: z.string(),
191
- network_zone: z.string().optional(),
192
- labels: z.record(z.string()).optional(),
212
+ server.registerTool("create_load_balancer", {
213
+ description: "Create a load balancer in a location or network_zone. Optionally attach existing Primary IPs (public_net), join a private network, and define services/targets in one call. Returns load_balancer + Action. Primary IPs on an LB cannot be changed after creation and stay assigned for its lifetime",
214
+ inputSchema: {
215
+ name: z.string(),
216
+ load_balancer_type: z.string().describe("e.g. lb11 (see list_load_balancer_types)"),
217
+ location: z.string().optional().describe("Location name, e.g. fsn1. With public_net, pass the Primary IPs' location; a mismatch fails with primary_ip_location_mismatch"),
218
+ network_zone: z.string().optional().describe("e.g. eu-central; alternative to location"),
219
+ algorithm: z.object({ type: z.enum(["round_robin", "least_connections"]) }).optional(),
220
+ public_interface: z.boolean().optional().describe("Default true. false = private-only; then also pass network"),
221
+ public_net: z
222
+ .object({
223
+ ipv4: z.number().nullable().optional().describe("ID of an unassigned IPv4 Primary IP in the same location"),
224
+ ipv6: z.number().nullable().optional().describe("ID of an unassigned IPv6 Primary IP in the same location"),
225
+ })
226
+ .optional()
227
+ .describe("Use existing Primary IPs instead of auto-allocated addresses (only with the public interface enabled)"),
228
+ network: z.number().optional().describe("Private network ID to attach on creation"),
229
+ services: z
230
+ .array(z.object({
231
+ protocol: z.enum(["tcp", "http", "https"]),
232
+ listen_port: z.number().optional(),
233
+ destination_port: z.number().optional(),
234
+ proxyprotocol: z.boolean().default(false),
235
+ health_check: z.record(z.unknown()).optional().describe("Same shape as add_load_balancer_service.health_check"),
236
+ http: z.record(z.unknown()).optional().describe("Same shape as update_load_balancer_service.http (certificates, redirect_http, sticky_sessions, timeout_idle, ...)"),
237
+ }))
238
+ .optional(),
239
+ targets: z
240
+ .array(z.object({
241
+ type: z.enum(["server", "label_selector", "ip"]),
242
+ server: z.object({ id: z.number() }).optional(),
243
+ label_selector: z.object({ selector: z.string() }).optional(),
244
+ ip: z.object({ ip: z.string() }).optional(),
245
+ use_private_ip: z.boolean().optional(),
246
+ }))
247
+ .optional(),
248
+ labels: z.record(z.string()).optional(),
249
+ },
250
+ annotations: ADDITIVE,
193
251
  }, async (args, _extra) => withToolError(async () => {
194
- const requestBody = {
195
- name: args.name,
196
- load_balancer_type: args.load_balancer_type,
197
- location: args.location,
198
- algorithm: args.algorithm,
199
- network_zone: args.network_zone,
200
- labels: args.labels,
201
- };
202
- const response = await LoadBalancersService.postLoadBalancers({ requestBody });
252
+ const hasLocation = args.location != null && args.location !== "";
253
+ const hasZone = args.network_zone != null && args.network_zone !== "";
254
+ if (!hasLocation && !hasZone)
255
+ throw new Error("Provide location or network_zone");
256
+ if (args.public_net && args.public_interface === false) {
257
+ throw new Error("public_net requires the public interface (public_interface must not be false)");
258
+ }
259
+ const response = await hcloudRequest("POST", "/load_balancers", { body: args });
203
260
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
204
261
  }));
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 () => {
262
+ server.registerTool("delete_load_balancer", {
263
+ description: "Delete a load balancer. Returns a delete_load_balancer Action; poll get_action until it finishes",
264
+ inputSchema: { id: z.number() },
265
+ annotations: DESTRUCTIVE_IDEMPOTENT,
266
+ }, async ({ id }, _extra) => withToolError(async () => {
206
267
  // 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) }] };
209
- }));
210
- server.tool("update_load_balancer", "Update a load balancer (name, labels)", {
211
- id: z.number(),
212
- name: z.string().optional(),
213
- labels: z.record(z.string()).optional(),
268
+ const response = await hcloudRequest("DELETE", `/load_balancers/${id}`);
269
+ // hcloudRequest returns {} for a 204 (the pre-2026-10-05 empty response).
270
+ const deleted = Object.keys(response).length ? response : { deleted: true };
271
+ return { content: [{ type: "text", text: JSON.stringify(deleted, null, 2) }] };
272
+ }));
273
+ server.registerTool("update_load_balancer", {
274
+ description: "Update a load balancer (name, labels)",
275
+ inputSchema: {
276
+ id: z.number(),
277
+ name: z.string().optional(),
278
+ labels: z.record(z.string()).optional(),
279
+ },
280
+ annotations: ADDITIVE_IDEMPOTENT,
214
281
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
215
- const response = await LoadBalancersService.putLoadBalancers({
216
- id,
217
- requestBody: { name, labels }
218
- });
219
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
220
- }));
221
- server.tool("add_load_balancer_target", "Add a target to a load balancer", {
222
- id: z.number(),
223
- type: z.enum(["server", "label_selector", "ip"]),
224
- server: z.object({ id: z.number() }).optional(),
225
- label_selector: z.object({ selector: z.string() }).optional(),
226
- ip: z.object({ ip: z.string() }).optional(),
227
- use_private_ip: z.boolean().optional(),
282
+ const response = await hcloudRequest("PUT", `/load_balancers/${id}`, { body: { name, labels } });
283
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
284
+ }));
285
+ server.registerTool("add_load_balancer_target", {
286
+ description: "Add a target to a load balancer",
287
+ inputSchema: {
288
+ id: z.number(),
289
+ type: z.enum(["server", "label_selector", "ip"]),
290
+ server: z.object({ id: z.number() }).optional(),
291
+ label_selector: z.object({ selector: z.string() }).optional(),
292
+ ip: z.object({ ip: z.string() }).optional(),
293
+ use_private_ip: z.boolean().optional(),
294
+ },
295
+ annotations: ADDITIVE_IDEMPOTENT,
228
296
  }, async ({ id, type, server, label_selector, ip, use_private_ip }, _extra) => withToolError(async () => {
229
- const response = await LoadBalancerActionsService.postLoadBalancersActionsAddTarget({
230
- id,
231
- requestBody: { type, server, label_selector, ip, use_private_ip }
232
- });
233
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
234
- }));
235
- server.tool("remove_load_balancer_target", "Remove a target from a load balancer", {
236
- id: z.number(),
237
- type: z.enum(["server", "label_selector", "ip"]),
238
- server: z.object({ id: z.number() }).optional(),
239
- label_selector: z.object({ selector: z.string() }).optional(),
240
- ip: z.object({ ip: z.string() }).optional(),
297
+ const response = await hcloudRequest("POST", `/load_balancers/${id}/actions/add_target`, { body: { type, server, label_selector, ip, use_private_ip } });
298
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
299
+ }));
300
+ server.registerTool("remove_load_balancer_target", {
301
+ description: "Remove a target from a load balancer",
302
+ inputSchema: {
303
+ id: z.number(),
304
+ type: z.enum(["server", "label_selector", "ip"]),
305
+ server: z.object({ id: z.number() }).optional(),
306
+ label_selector: z.object({ selector: z.string() }).optional(),
307
+ ip: z.object({ ip: z.string() }).optional(),
308
+ },
309
+ annotations: DESTRUCTIVE_IDEMPOTENT,
241
310
  }, async ({ id, type, server, label_selector, ip }, _extra) => withToolError(async () => {
242
- const response = await LoadBalancerActionsService.postLoadBalancersActionsRemoveTarget({
243
- id,
244
- requestBody: { type, server, label_selector, ip }
245
- });
246
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
247
- }));
248
- server.tool("add_load_balancer_service", "Add a service to a load balancer", {
249
- id: z.number(),
250
- protocol: z.enum(["tcp", "http", "https"]),
251
- listen_port: z.number(),
252
- destination_port: z.number(),
253
- proxyprotocol: z.boolean(),
254
- health_check: z.object({
255
- protocol: z.enum(["tcp", "http"]),
256
- port: z.number(),
257
- interval: z.number(),
258
- timeout: z.number(),
259
- retries: z.number(),
311
+ const response = await hcloudRequest("POST", `/load_balancers/${id}/actions/remove_target`, { body: { type, server, label_selector, ip } });
312
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
313
+ }));
314
+ server.registerTool("add_load_balancer_service", {
315
+ description: "Add a service to a load balancer",
316
+ inputSchema: {
317
+ id: z.number(),
318
+ protocol: z.enum(["tcp", "http", "https"]),
319
+ listen_port: z.number(),
320
+ destination_port: z.number(),
321
+ proxyprotocol: z.boolean(),
322
+ health_check: z.object({
323
+ protocol: z.enum(["tcp", "http"]),
324
+ port: z.number(),
325
+ interval: z.number(),
326
+ timeout: z.number(),
327
+ retries: z.number(),
328
+ http: z.object({
329
+ domain: z.string().nullable().optional(),
330
+ path: z.string().optional(),
331
+ response: z.string().optional(),
332
+ status_codes: z.array(z.string()).optional(),
333
+ tls: z.boolean().optional(),
334
+ }).optional(),
335
+ }).optional(),
260
336
  http: z.object({
261
- domain: z.string().nullable().optional(),
262
- path: z.string().optional(),
263
- response: z.string().optional(),
264
- status_codes: z.array(z.string()).optional(),
265
- tls: z.boolean().optional(),
337
+ cookie_name: z.string().optional(),
338
+ cookie_lifetime: z.number().optional(),
339
+ certificates: z.array(z.number()).optional(),
340
+ redirect_http: z.boolean().optional(),
341
+ sticky_sessions: z.boolean().optional(),
266
342
  }).optional(),
267
- }).optional(),
268
- http: z.object({
269
- cookie_name: z.string().optional(),
270
- cookie_lifetime: z.number().optional(),
271
- certificates: z.array(z.number()).optional(),
272
- redirect_http: z.boolean().optional(),
273
- sticky_sessions: z.boolean().optional(),
274
- }).optional(),
343
+ },
344
+ annotations: ADDITIVE_IDEMPOTENT,
275
345
  }, async (args, _extra) => withToolError(async () => {
276
346
  const { id, ...body } = args;
277
- const response = await LoadBalancerActionsService.postLoadBalancersActionsAddService({
278
- id,
279
- requestBody: body
280
- });
347
+ const response = await hcloudRequest("POST", `/load_balancers/${id}/actions/add_service`, { body });
281
348
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
282
349
  }));
283
- server.tool("delete_load_balancer_service", "Delete a service from a load balancer", {
284
- id: z.number(),
285
- listen_port: z.number(),
350
+ server.registerTool("delete_load_balancer_service", {
351
+ description: "Delete a service from a load balancer",
352
+ inputSchema: {
353
+ id: z.number(),
354
+ listen_port: z.number(),
355
+ },
356
+ annotations: DESTRUCTIVE_IDEMPOTENT,
286
357
  }, async ({ id, listen_port }, _extra) => withToolError(async () => {
287
- const response = await LoadBalancerActionsService.postLoadBalancersActionsDeleteService({
288
- id,
289
- requestBody: { listen_port }
290
- });
291
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
292
- }));
293
- server.tool("update_load_balancer_service", "Update a load balancer service (listen_port identifies the service)", {
294
- id: z.number().describe("Load balancer ID"),
295
- listen_port: z.number().describe("Listen port of the service to update"),
296
- destination_port: z.number().optional(),
297
- protocol: z.enum(["tcp", "http", "https"]).optional(),
298
- proxyprotocol: z.boolean().optional(),
299
- health_check: z
300
- .object({
301
- protocol: z.enum(["tcp", "http"]),
302
- port: z.number(),
303
- interval: z.number(),
304
- timeout: z.number(),
305
- retries: z.number(),
358
+ const response = await hcloudRequest("POST", `/load_balancers/${id}/actions/delete_service`, { body: { listen_port } });
359
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
360
+ }));
361
+ server.registerTool("update_load_balancer_service", {
362
+ description: "Update a load balancer service (listen_port identifies the service)",
363
+ inputSchema: {
364
+ id: z.number().describe("Load balancer ID"),
365
+ listen_port: z.number().describe("Listen port of the service to update"),
366
+ destination_port: z.number().optional(),
367
+ protocol: z.enum(["tcp", "http", "https"]).optional(),
368
+ proxyprotocol: z.boolean().optional(),
369
+ health_check: z
370
+ .object({
371
+ protocol: z.enum(["tcp", "http"]),
372
+ port: z.number(),
373
+ interval: z.number(),
374
+ timeout: z.number(),
375
+ retries: z.number(),
376
+ http: z
377
+ .object({
378
+ domain: z.string().nullable().optional(),
379
+ path: z.string().optional(),
380
+ response: z.string().optional(),
381
+ status_codes: z.array(z.string()).optional(),
382
+ tls: z.boolean().optional(),
383
+ })
384
+ .optional(),
385
+ })
386
+ .optional(),
306
387
  http: z
307
388
  .object({
308
- domain: z.string().nullable().optional(),
309
- path: z.string().optional(),
310
- response: z.string().optional(),
311
- status_codes: z.array(z.string()).optional(),
312
- tls: z.boolean().optional(),
389
+ cookie_name: z.string().optional(),
390
+ cookie_lifetime: z.number().optional(),
391
+ certificates: z.array(z.number()).optional(),
392
+ redirect_http: z.boolean().optional(),
393
+ sticky_sessions: z.boolean().optional(),
394
+ timeout_idle: z.number().int().min(30).max(300).optional().describe("Idle timeout in seconds (30-300, default 50)"),
313
395
  })
314
396
  .optional(),
315
- })
316
- .optional(),
317
- http: z
318
- .object({
319
- cookie_name: z.string().optional(),
320
- cookie_lifetime: z.number().optional(),
321
- certificates: z.array(z.number()).optional(),
322
- redirect_http: z.boolean().optional(),
323
- sticky_sessions: z.boolean().optional(),
324
- })
325
- .optional(),
397
+ },
398
+ annotations: ADDITIVE_IDEMPOTENT,
326
399
  }, async (args, _extra) => withToolError(async () => {
327
400
  const { id, listen_port, ...body } = args;
328
- const response = await LoadBalancerActionsService.postLoadBalancersActionsUpdateService({
329
- id,
330
- requestBody: { listen_port, ...body }
331
- });
401
+ const response = await hcloudRequest("POST", `/load_balancers/${id}/actions/update_service`, { body: { listen_port, ...body } });
332
402
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
333
403
  }));
334
404
  // --- Networks ---
335
- server.tool("list_networks", "List all networks", {}, async (_args, _extra) => withToolError(async () => {
336
- const items = await listAll((p) => NetworksService.getNetworks(p), "networks");
405
+ server.registerTool("list_networks", {
406
+ description: "List all networks",
407
+ inputSchema: {},
408
+ annotations: READ_ONLY,
409
+ }, async (_args, _extra) => withToolError(async () => {
410
+ const items = await listAll((p) => hcloudRequest("GET", "/networks", { query: p }), "networks");
337
411
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
338
412
  }));
339
- server.tool("get_network", "Get a single network by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
340
- const response = await NetworksService.getNetworks1({ id });
413
+ server.registerTool("get_network", {
414
+ description: "Get a single network by ID",
415
+ inputSchema: { id: z.number() },
416
+ annotations: READ_ONLY,
417
+ }, async ({ id }, _extra) => withToolError(async () => {
418
+ const response = await hcloudRequest("GET", `/networks/${id}`);
341
419
  return { content: [{ type: "text", text: JSON.stringify(response.network, null, 2) }] };
342
420
  }));
343
- server.tool("create_network", "Create a new network", {
344
- name: z.string(),
345
- ip_range: z.string(),
346
- expose_routes_to_vswitch: z.boolean().optional(),
347
- routes: z
348
- .array(z.object({ destination: z.string(), gateway: z.string() }))
349
- .optional()
350
- .describe("Routes: destination (CIDR), gateway (IP)"),
351
- labels: z.record(z.string()).optional(),
421
+ server.registerTool("create_network", {
422
+ description: "Create a new network",
423
+ inputSchema: {
424
+ name: z.string(),
425
+ ip_range: z.string(),
426
+ expose_routes_to_vswitch: z.boolean().optional(),
427
+ routes: z
428
+ .array(z.object({ destination: z.string(), gateway: z.string() }))
429
+ .optional()
430
+ .describe("Routes: destination (CIDR), gateway (IP)"),
431
+ labels: z.record(z.string()).optional(),
432
+ },
433
+ annotations: ADDITIVE,
352
434
  }, async (args, _extra) => withToolError(async () => {
353
435
  const requestBody = {
354
436
  name: args.name,
@@ -357,122 +439,173 @@ export function registerTools(server) {
357
439
  routes: args.routes,
358
440
  labels: args.labels,
359
441
  };
360
- const response = await NetworksService.postNetworks({ requestBody });
442
+ const response = await hcloudRequest("POST", "/networks", { body: requestBody });
361
443
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
362
444
  }));
363
- server.tool("delete_network", "Delete a network", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
364
- await NetworksService.deleteNetworks({ id });
445
+ server.registerTool("delete_network", {
446
+ description: "Delete a network",
447
+ inputSchema: { id: z.number() },
448
+ annotations: DESTRUCTIVE_IDEMPOTENT,
449
+ }, async ({ id }, _extra) => withToolError(async () => {
450
+ await hcloudRequest("DELETE", `/networks/${id}`);
365
451
  return { content: [{ type: "text", text: "Network deleted successfully" }] };
366
452
  }));
367
- server.tool("update_network", "Update a network (name, labels)", {
368
- id: z.number(),
369
- name: z.string().optional(),
370
- labels: z.record(z.string()).optional(),
453
+ server.registerTool("update_network", {
454
+ description: "Update a network (name, labels)",
455
+ inputSchema: {
456
+ id: z.number(),
457
+ name: z.string().optional(),
458
+ labels: z.record(z.string()).optional(),
459
+ },
460
+ annotations: ADDITIVE_IDEMPOTENT,
371
461
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
372
- const response = await NetworksService.putNetworks({
373
- id,
374
- requestBody: { name, labels }
375
- });
376
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
377
- }));
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)", {
379
- id: z.number().describe("Network ID"),
380
- // "server" type is deprecated (removal 2027-04-15) and equivalent to "cloud".
381
- type: z.enum(["cloud", "vswitch"]),
382
- network_zone: z.string().describe("Network zone, e.g. eu-central"),
383
- ip_range: z.string().optional().describe("CIDR, e.g. 10.0.0.0/24; omit for auto /24"),
384
- vswitch_id: z.number().optional().describe("Required if type is vswitch"),
462
+ const response = await hcloudRequest("PUT", `/networks/${id}`, { body: { name, labels } });
463
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
464
+ }));
465
+ server.registerTool("add_network_subnet", {
466
+ description: "Add a subnet to a network (e.g. for private networking 10.0.0.0/16 in a zone)",
467
+ inputSchema: {
468
+ id: z.number().describe("Network ID"),
469
+ // "server" type is deprecated (removal 2027-04-15) and equivalent to "cloud".
470
+ type: z.enum(["cloud", "vswitch"]),
471
+ network_zone: z.string().describe("Network zone, e.g. eu-central"),
472
+ ip_range: z.string().optional().describe("CIDR, e.g. 10.0.0.0/24; omit for auto /24"),
473
+ vswitch_id: z.number().optional().describe("Required if type is vswitch"),
474
+ },
475
+ annotations: ADDITIVE,
385
476
  }, async ({ id, type, network_zone, ip_range, vswitch_id }, _extra) => withToolError(async () => {
386
- const response = await NetworkActionsService.postNetworksActionsAddSubnet({
387
- id,
388
- requestBody: { type, network_zone, ip_range, vswitch_id }
389
- });
477
+ const response = await hcloudRequest("POST", `/networks/${id}/actions/add_subnet`, { body: { type, network_zone, ip_range, vswitch_id } });
390
478
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
391
479
  }));
392
- server.tool("delete_network_subnet", "Delete a subnet from a network (detach servers from it first)", {
393
- id: z.number().describe("Network ID"),
394
- ip_range: z.string().describe("IP range of subnet to delete, e.g. 10.0.1.0/24"),
480
+ server.registerTool("delete_network_subnet", {
481
+ description: "Delete a subnet from a network (detach servers from it first)",
482
+ inputSchema: {
483
+ id: z.number().describe("Network ID"),
484
+ ip_range: z.string().describe("IP range of subnet to delete, e.g. 10.0.1.0/24"),
485
+ },
486
+ annotations: DESTRUCTIVE_IDEMPOTENT,
395
487
  }, async ({ id, ip_range }, _extra) => withToolError(async () => {
396
- const response = await NetworkActionsService.postNetworksActionsDeleteSubnet({
397
- id,
398
- requestBody: { ip_range }
399
- });
488
+ const response = await hcloudRequest("POST", `/networks/${id}/actions/delete_subnet`, { body: { ip_range } });
400
489
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
401
490
  }));
402
491
  // --- Volumes ---
403
- server.tool("list_volumes", "List all volumes", {}, async (_args, _extra) => withToolError(async () => {
404
- const items = await listAll((p) => VolumesService.getVolumes(p), "volumes");
492
+ server.registerTool("list_volumes", {
493
+ description: "List all volumes",
494
+ inputSchema: {},
495
+ annotations: READ_ONLY,
496
+ }, async (_args, _extra) => withToolError(async () => {
497
+ const items = await listAll((p) => hcloudRequest("GET", "/volumes", { query: p }), "volumes");
405
498
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
406
499
  }));
407
- server.tool("get_volume", "Get a single volume by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
408
- const response = await VolumesService.getVolumes1({ id });
500
+ server.registerTool("get_volume", {
501
+ description: "Get a single volume by ID",
502
+ inputSchema: { id: z.number() },
503
+ annotations: READ_ONLY,
504
+ }, async ({ id }, _extra) => withToolError(async () => {
505
+ const response = await hcloudRequest("GET", `/volumes/${id}`);
409
506
  return { content: [{ type: "text", text: JSON.stringify(response.volume, null, 2) }] };
410
507
  }));
411
- server.tool("create_volume", "Create a new volume", {
412
- name: z.string(),
413
- size: z.number(),
414
- automount: z.boolean().optional(),
415
- format: z.string().optional(),
416
- location: z.string().optional(),
417
- server: z.number().optional(),
418
- labels: z.record(z.string()).optional(),
508
+ server.registerTool("create_volume", {
509
+ description: "Create a new volume (size in GB, min 10). Give location, or server to create it in the server's location and attach it right away. In responses, read assignee ({type, id}); the old server field goes away on 2027-10-27",
510
+ inputSchema: {
511
+ name: z.string(),
512
+ size: z.number().describe("Size in GB (min 10)"),
513
+ automount: z.boolean().optional().describe("Only with server: mount automatically"),
514
+ format: z.enum(["xfs", "ext4"]).optional(),
515
+ location: z.string().optional().describe("Location name, e.g. fsn1 (omit if server set)"),
516
+ server: z.number().optional().describe("Server ID to attach to on creation (omit if location set)"),
517
+ labels: z.record(z.string()).optional(),
518
+ },
519
+ annotations: ADDITIVE,
419
520
  }, async (args, _extra) => withToolError(async () => {
521
+ const hasLocation = args.location != null && args.location !== "";
522
+ if (hasLocation === (args.server != null)) {
523
+ throw new Error("Provide exactly one of location or server (mutually exclusive)");
524
+ }
525
+ if (args.automount && args.server == null)
526
+ throw new Error("automount requires server");
527
+ // Volume attachment is generalised to `assignee` (2026-10-27); the old
528
+ // `server` request field is removed on 2027-10-27. Tool input stays a server ID.
420
529
  const requestBody = {
421
530
  name: args.name,
422
531
  size: args.size,
423
532
  automount: args.automount,
424
533
  format: args.format,
425
534
  location: args.location,
426
- server: args.server,
535
+ ...(args.server != null ? { assignee: { type: "server", id: args.server } } : {}),
427
536
  labels: args.labels,
428
537
  };
429
- const response = await VolumesService.postVolumes({ requestBody });
538
+ const response = await hcloudRequest("POST", "/volumes", { body: requestBody });
430
539
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
431
540
  }));
432
- server.tool("update_volume", "Update a volume (name, labels)", {
433
- id: z.number(),
434
- name: z.string().optional(),
435
- labels: z.record(z.string()).optional(),
541
+ server.registerTool("update_volume", {
542
+ description: "Update a volume (name, labels)",
543
+ inputSchema: {
544
+ id: z.number(),
545
+ name: z.string().optional(),
546
+ labels: z.record(z.string()).optional(),
547
+ },
548
+ annotations: ADDITIVE_IDEMPOTENT,
436
549
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
437
- const response = await VolumesService.putVolumes({
438
- id,
439
- requestBody: { name, labels }
440
- });
550
+ const response = await hcloudRequest("PUT", `/volumes/${id}`, { body: { name, labels } });
441
551
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
442
552
  }));
443
- server.tool("attach_volume", "Attach a volume to a server", {
444
- id: z.number(),
445
- server: z.number(),
446
- automount: z.boolean().optional(),
553
+ server.registerTool("attach_volume", {
554
+ description: "Attach a volume to a server (must be in the same location). Returns an Action",
555
+ inputSchema: {
556
+ id: z.number(),
557
+ server: z.number(),
558
+ automount: z.boolean().optional(),
559
+ },
560
+ annotations: ADDITIVE_IDEMPOTENT,
447
561
  }, async ({ id, server, automount }, _extra) => withToolError(async () => {
448
- const response = await VolumeActionsService.postVolumesActionsAttach({
449
- id,
450
- requestBody: { server, automount }
562
+ const response = await hcloudRequest("POST", `/volumes/${id}/actions/attach`, {
563
+ body: { assignee: { type: "server", id: server }, automount },
451
564
  });
452
565
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
453
566
  }));
454
- server.tool("detach_volume", "Detach a volume", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
455
- const response = await VolumeActionsService.postVolumesActionsDetach({ id });
567
+ server.registerTool("detach_volume", {
568
+ description: "Detach a volume",
569
+ inputSchema: { id: z.number() },
570
+ annotations: DESTRUCTIVE_IDEMPOTENT,
571
+ }, async ({ id }, _extra) => withToolError(async () => {
572
+ const response = await hcloudRequest("POST", `/volumes/${id}/actions/detach`);
456
573
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
457
574
  }));
458
- server.tool("delete_volume", "Delete a volume (must be detached; all data destroyed)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
459
- await VolumesService.deleteVolumes({ id });
575
+ server.registerTool("delete_volume", {
576
+ description: "Delete a volume (must be detached; all data destroyed)",
577
+ inputSchema: { id: z.number() },
578
+ annotations: DESTRUCTIVE_IDEMPOTENT,
579
+ }, async ({ id }, _extra) => withToolError(async () => {
580
+ await hcloudRequest("DELETE", `/volumes/${id}`);
460
581
  return { content: [{ type: "text", text: "Volume deleted successfully" }] };
461
582
  }));
462
583
  // --- Firewalls ---
463
- server.tool("list_firewalls", "List all firewalls", {}, async (_args, _extra) => withToolError(async () => {
464
- const items = await listAll((p) => FirewallsService.getFirewalls(p), "firewalls");
584
+ server.registerTool("list_firewalls", {
585
+ description: "List all firewalls",
586
+ inputSchema: {},
587
+ annotations: READ_ONLY,
588
+ }, async (_args, _extra) => withToolError(async () => {
589
+ const items = await listAll((p) => hcloudRequest("GET", "/firewalls", { query: p }), "firewalls");
465
590
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
466
591
  }));
467
- server.tool("get_firewall", "Get a single firewall by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
468
- const response = await FirewallsService.getFirewalls1({ id });
592
+ server.registerTool("get_firewall", {
593
+ description: "Get a single firewall by ID",
594
+ inputSchema: { id: z.number() },
595
+ annotations: READ_ONLY,
596
+ }, async ({ id }, _extra) => withToolError(async () => {
597
+ const response = await hcloudRequest("GET", `/firewalls/${id}`);
469
598
  return { content: [{ type: "text", text: JSON.stringify(response.firewall, null, 2) }] };
470
599
  }));
471
- server.tool("create_firewall", "Create a new firewall. Rules: direction 'in'|'out', protocol 'tcp'|'udp'|'icmp'|'esp'|'gre'; use source_ips for in, destination_ips for out (CIDRs, e.g. 0.0.0.0/0); port optional for tcp/udp. Optionally apply_to servers or label_selector at creation.", {
472
- name: z.string(),
473
- rules: z.array(firewallRuleSchema).optional(),
474
- apply_to: z.array(firewallApplyToSchema).optional().describe("Apply firewall to these servers or label_selector after creation"),
475
- labels: z.record(z.string()).optional(),
600
+ server.registerTool("create_firewall", {
601
+ description: "Create a new firewall. Rules: direction 'in'|'out', protocol 'tcp'|'udp'|'icmp'|'esp'|'gre'; use source_ips for in, destination_ips for out (CIDRs, e.g. 0.0.0.0/0); port optional for tcp/udp. Optionally apply_to servers or label_selector at creation.",
602
+ inputSchema: {
603
+ name: z.string(),
604
+ rules: z.array(firewallRuleSchema).optional(),
605
+ apply_to: z.array(firewallApplyToSchema).optional().describe("Apply firewall to these servers or label_selector after creation"),
606
+ labels: z.record(z.string()).optional(),
607
+ },
608
+ annotations: ADDITIVE,
476
609
  }, async (args, _extra) => withToolError(async () => {
477
610
  const body = {
478
611
  name: args.name,
@@ -480,59 +613,84 @@ export function registerTools(server) {
480
613
  labels: args.labels,
481
614
  apply_to: args.apply_to,
482
615
  };
483
- const response = await FirewallsService.postFirewalls({ requestBody: body });
616
+ const response = await hcloudRequest("POST", "/firewalls", { body });
484
617
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
485
618
  }));
486
- server.tool("update_firewall", "Update a firewall (name, labels)", {
487
- id: z.number(),
488
- name: z.string().optional(),
489
- labels: z.record(z.string()).optional(),
619
+ server.registerTool("update_firewall", {
620
+ description: "Update a firewall (name, labels)",
621
+ inputSchema: {
622
+ id: z.number(),
623
+ name: z.string().optional(),
624
+ labels: z.record(z.string()).optional(),
625
+ },
626
+ annotations: ADDITIVE_IDEMPOTENT,
490
627
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
491
- const response = await FirewallsService.putFirewalls({
492
- id,
493
- requestBody: { name, labels }
494
- });
628
+ const response = await hcloudRequest("PUT", `/firewalls/${id}`, { body: { name, labels } });
495
629
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
496
630
  }));
497
- server.tool("delete_firewall", "Delete a firewall (must not be in use)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
498
- await FirewallsService.deleteFirewalls({ id });
631
+ server.registerTool("delete_firewall", {
632
+ description: "Delete a firewall (must not be in use)",
633
+ inputSchema: { id: z.number() },
634
+ annotations: DESTRUCTIVE_IDEMPOTENT,
635
+ }, async ({ id }, _extra) => withToolError(async () => {
636
+ await hcloudRequest("DELETE", `/firewalls/${id}`);
499
637
  return { content: [{ type: "text", text: "Firewall deleted successfully" }] };
500
638
  }));
501
- server.tool("apply_firewall_to_resources", "Apply a firewall to servers or a label selector. Pass apply_to: [{ type: 'server', server: { id: 123 } }] or [{ type: 'label_selector', label_selector: { selector: 'env=web' } }].", {
502
- id: z.number().describe("Firewall ID"),
503
- apply_to: z.array(firewallApplyToSchema),
639
+ server.registerTool("apply_firewall_to_resources", {
640
+ description: "Apply a firewall to servers or a label selector. Pass apply_to: [{ type: 'server', server: { id: 123 } }] or [{ type: 'label_selector', label_selector: { selector: 'env=web' } }].",
641
+ inputSchema: {
642
+ id: z.number().describe("Firewall ID"),
643
+ apply_to: z.array(firewallApplyToSchema),
644
+ },
645
+ annotations: DESTRUCTIVE_IDEMPOTENT,
504
646
  }, async ({ id, apply_to }, _extra) => withToolError(async () => {
505
- const response = await FirewallActionsService.postFirewallsActionsApplyToResources({ id, requestBody: { apply_to } });
506
- return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
507
- }));
508
- server.tool("remove_firewall_from_resources", "Remove a firewall from servers. Pass remove_from: [{ type: 'server', server: { id: 123 } }].", {
509
- id: z.number().describe("Firewall ID"),
510
- remove_from: z.array(z.object({
511
- type: z.literal("server"),
512
- server: z.object({ id: z.number() }),
513
- })),
647
+ const response = await hcloudRequest("POST", `/firewalls/${id}/actions/apply_to_resources`, { body: { apply_to } });
648
+ return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
649
+ }));
650
+ server.registerTool("remove_firewall_from_resources", {
651
+ description: "Remove a firewall from servers. Pass remove_from: [{ type: 'server', server: { id: 123 } }].",
652
+ inputSchema: {
653
+ id: z.number().describe("Firewall ID"),
654
+ remove_from: z.array(z.object({
655
+ type: z.literal("server"),
656
+ server: z.object({ id: z.number() }),
657
+ })),
658
+ },
659
+ annotations: DESTRUCTIVE_IDEMPOTENT,
514
660
  }, async ({ id, remove_from }, _extra) => withToolError(async () => {
515
- const response = await FirewallActionsService.postFirewallsActionsRemoveFromResources({ id, requestBody: { remove_from } });
661
+ const response = await hcloudRequest("POST", `/firewalls/${id}/actions/remove_from_resources`, { body: { remove_from } });
516
662
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
517
663
  }));
518
- server.tool("set_firewall_rules", "Set rules on an existing firewall (overwrites all rules). Same rule format as create_firewall.", {
519
- id: z.number().describe("Firewall ID"),
520
- rules: z.array(firewallRuleSchema),
664
+ server.registerTool("set_firewall_rules", {
665
+ description: "Set rules on an existing firewall (overwrites all rules). Same rule format as create_firewall.",
666
+ inputSchema: {
667
+ id: z.number().describe("Firewall ID"),
668
+ rules: z.array(firewallRuleSchema),
669
+ },
670
+ annotations: DESTRUCTIVE_IDEMPOTENT,
521
671
  }, async ({ id, rules }, _extra) => withToolError(async () => {
522
- const response = await FirewallActionsService.postFirewallsActionsSetRules({ id, requestBody: { rules } });
672
+ const response = await hcloudRequest("POST", `/firewalls/${id}/actions/set_rules`, { body: { rules } });
523
673
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
524
674
  }));
525
675
  // --- Floating IPs ---
526
- server.tool("list_floating_ips", "List all floating IPs", {}, async (_args, _extra) => withToolError(async () => {
527
- const items = await listAll((p) => FloatingIPsService.getFloatingIps(p), "floating_ips");
676
+ server.registerTool("list_floating_ips", {
677
+ description: "List all floating IPs",
678
+ inputSchema: {},
679
+ annotations: READ_ONLY,
680
+ }, async (_args, _extra) => withToolError(async () => {
681
+ const items = await listAll((p) => hcloudRequest("GET", "/floating_ips", { query: p }), "floating_ips");
528
682
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
529
683
  }));
530
- server.tool("create_floating_ip", "Create a floating IP", {
531
- type: z.enum(["ipv4", "ipv6"]),
532
- home_location: z.string().optional(),
533
- server: z.number().optional(),
534
- description: z.string().optional(),
535
- labels: z.record(z.string()).optional(),
684
+ server.registerTool("create_floating_ip", {
685
+ description: "Create a floating IP",
686
+ inputSchema: {
687
+ type: z.enum(["ipv4", "ipv6"]),
688
+ home_location: z.string().optional(),
689
+ server: z.number().optional(),
690
+ description: z.string().optional(),
691
+ labels: z.record(z.string()).optional(),
692
+ },
693
+ annotations: ADDITIVE,
536
694
  }, async (args, _extra) => withToolError(async () => {
537
695
  const requestBody = {
538
696
  type: args.type,
@@ -541,58 +699,75 @@ export function registerTools(server) {
541
699
  description: args.description,
542
700
  labels: args.labels,
543
701
  };
544
- const response = await FloatingIPsService.postFloatingIps({ requestBody });
702
+ const response = await hcloudRequest("POST", "/floating_ips", { body: requestBody });
545
703
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
546
704
  }));
547
- server.tool("update_floating_ip", "Update a floating IP (description, labels)", {
548
- id: z.number(),
549
- description: z.string().optional(),
550
- labels: z.record(z.string()).optional(),
705
+ server.registerTool("update_floating_ip", {
706
+ description: "Update a floating IP (description, labels)",
707
+ inputSchema: {
708
+ id: z.number(),
709
+ description: z.string().optional(),
710
+ labels: z.record(z.string()).optional(),
711
+ },
712
+ annotations: ADDITIVE_IDEMPOTENT,
551
713
  }, async ({ id, description, labels }, _extra) => withToolError(async () => {
552
- const response = await FloatingIPsService.putFloatingIps({
553
- id,
554
- requestBody: { description, labels }
555
- });
714
+ const response = await hcloudRequest("PUT", `/floating_ips/${id}`, { body: { description, labels } });
556
715
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
557
716
  }));
558
- server.tool("assign_floating_ip", "Assign a floating IP to a server", {
559
- id: z.number(),
560
- server: z.number(),
717
+ server.registerTool("assign_floating_ip", {
718
+ description: "Assign a floating IP to a server",
719
+ inputSchema: {
720
+ id: z.number(),
721
+ server: z.number(),
722
+ },
723
+ annotations: DESTRUCTIVE_IDEMPOTENT,
561
724
  }, async ({ id, server }, _extra) => withToolError(async () => {
562
- const response = await FloatingIpActionsService.postFloatingIpsActionsAssign({
563
- id,
564
- requestBody: { server }
565
- });
725
+ const response = await hcloudRequest("POST", `/floating_ips/${id}/actions/assign`, { body: { server } });
566
726
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
567
727
  }));
568
- server.tool("unassign_floating_ip", "Unassign a floating IP", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
569
- const response = await FloatingIpActionsService.postFloatingIpsActionsUnassign({ id });
728
+ server.registerTool("unassign_floating_ip", {
729
+ description: "Unassign a floating IP",
730
+ inputSchema: { id: z.number() },
731
+ annotations: DESTRUCTIVE_IDEMPOTENT,
732
+ }, async ({ id }, _extra) => withToolError(async () => {
733
+ const response = await hcloudRequest("POST", `/floating_ips/${id}/actions/unassign`);
570
734
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
571
735
  }));
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 () => {
573
- await FloatingIPsService.deleteFloatingIps({ id });
736
+ server.registerTool("delete_floating_ip", {
737
+ description: "Delete a floating IP. Must be unassigned first (unassign_floating_ip), else fails with must_be_unassigned",
738
+ inputSchema: { id: z.number() },
739
+ annotations: DESTRUCTIVE_IDEMPOTENT,
740
+ }, async ({ id }, _extra) => withToolError(async () => {
741
+ await hcloudRequest("DELETE", `/floating_ips/${id}`);
574
742
  return { content: [{ type: "text", text: "Floating IP deleted successfully" }] };
575
743
  }));
576
744
  // --- Primary IPs ---
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");
745
+ server.registerTool("list_primary_ips", {
746
+ description: "List all Primary IPs (static IPs bound to a location, assignable to one server)",
747
+ inputSchema: {},
748
+ annotations: READ_ONLY,
749
+ }, async (_args, _extra) => withToolError(async () => {
750
+ const items = await listAll((p) => hcloudRequest("GET", "/primary_ips", { query: p }), "primary_ips");
579
751
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
580
752
  }));
581
- server.tool("create_primary_ip", "Create a Primary IP (location-scoped; server must be off to assign). Provide location OR assignee_id (server).", {
582
- name: z.string(),
583
- type: z.enum(["ipv4", "ipv6"]),
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)"),
586
- auto_delete: z.boolean().optional(),
587
- labels: z.record(z.string()).optional(),
753
+ server.registerTool("create_primary_ip", {
754
+ description: "Create a Primary IP (location-scoped; server must be off to assign). Provide location OR assignee_id (server).",
755
+ inputSchema: {
756
+ name: z.string(),
757
+ type: z.enum(["ipv4", "ipv6"]),
758
+ location: z.string().optional().describe("Location name or ID, e.g. fsn1 (omit if assignee_id set)"),
759
+ assignee_id: z.number().optional().describe("Server ID to assign to immediately (omit if location set)"),
760
+ auto_delete: z.boolean().optional(),
761
+ labels: z.record(z.string()).optional(),
762
+ },
763
+ annotations: ADDITIVE,
588
764
  }, async (args, _extra) => withToolError(async () => {
589
765
  const hasLocation = args.location != null && args.location !== "";
590
766
  const hasAssignee = args.assignee_id != null;
591
767
  if (hasLocation === hasAssignee) {
592
768
  throw new Error("Provide exactly one of location or assignee_id (mutually exclusive)");
593
769
  }
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.
770
+ // The API takes `location` (the `datacenter` field was removed 2026-07-01).
596
771
  const requestBody = {
597
772
  name: args.name,
598
773
  type: args.type,
@@ -602,51 +777,73 @@ export function registerTools(server) {
602
777
  auto_delete: args.auto_delete,
603
778
  labels: args.labels,
604
779
  };
605
- const response = await PrimaryIPsService.postPrimaryIps({ requestBody });
780
+ const response = await hcloudRequest("POST", "/primary_ips", { body: requestBody });
606
781
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
607
782
  }));
608
- server.tool("get_primary_ip", "Get a single Primary IP by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
609
- const response = await PrimaryIPsService.getPrimaryIps1({ id });
783
+ server.registerTool("get_primary_ip", {
784
+ description: "Get a single Primary IP by ID",
785
+ inputSchema: { id: z.number() },
786
+ annotations: READ_ONLY,
787
+ }, async ({ id }, _extra) => withToolError(async () => {
788
+ const response = await hcloudRequest("GET", `/primary_ips/${id}`);
610
789
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
611
790
  }));
612
- server.tool("update_primary_ip", "Update a Primary IP (name, labels)", {
613
- id: z.number(),
614
- name: z.string().optional(),
615
- labels: z.record(z.string()).optional(),
791
+ server.registerTool("update_primary_ip", {
792
+ description: "Update a Primary IP (name, labels)",
793
+ inputSchema: {
794
+ id: z.number(),
795
+ name: z.string().optional(),
796
+ labels: z.record(z.string()).optional(),
797
+ },
798
+ annotations: ADDITIVE_IDEMPOTENT,
616
799
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
617
- const response = await PrimaryIPsService.putPrimaryIps({
618
- id,
619
- requestBody: { name, labels }
620
- });
800
+ const response = await hcloudRequest("PUT", `/primary_ips/${id}`, { body: { name, labels } });
621
801
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
622
802
  }));
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 () => {
624
- await PrimaryIPsService.deletePrimaryIps({ id });
803
+ server.registerTool("delete_primary_ip", {
804
+ description: "Delete a Primary IP. Must be unassigned first (unassign_primary_ip, server powered off), else fails with must_be_unassigned",
805
+ inputSchema: { id: z.number() },
806
+ annotations: DESTRUCTIVE_IDEMPOTENT,
807
+ }, async ({ id }, _extra) => withToolError(async () => {
808
+ await hcloudRequest("DELETE", `/primary_ips/${id}`);
625
809
  return { content: [{ type: "text", text: "Primary IP deleted successfully" }] };
626
810
  }));
627
- server.tool("assign_primary_ip", "Assign a Primary IP to a server (server must be powered off)", {
628
- id: z.number().describe("Primary IP ID"),
629
- server: z.number().describe("Server ID"),
811
+ server.registerTool("assign_primary_ip", {
812
+ description: "Assign a Primary IP to a server (server must be powered off)",
813
+ inputSchema: {
814
+ id: z.number().describe("Primary IP ID"),
815
+ server: z.number().describe("Server ID"),
816
+ },
817
+ annotations: ADDITIVE_IDEMPOTENT,
630
818
  }, async ({ id, server }, _extra) => withToolError(async () => {
631
- const response = await PrimaryIpActionsService.postPrimaryIpsActionsAssign({
632
- id,
633
- requestBody: { assignee_id: server, assignee_type: "server" }
634
- });
819
+ const response = await hcloudRequest("POST", `/primary_ips/${id}/actions/assign`, { body: { assignee_id: server, assignee_type: "server" } });
635
820
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
636
821
  }));
637
- server.tool("unassign_primary_ip", "Unassign a Primary IP from its server (server must be powered off)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
638
- const response = await PrimaryIpActionsService.postPrimaryIpsActionsUnassign({ id });
822
+ server.registerTool("unassign_primary_ip", {
823
+ description: "Unassign a Primary IP from its server (server must be powered off)",
824
+ inputSchema: { id: z.number() },
825
+ annotations: DESTRUCTIVE_IDEMPOTENT,
826
+ }, async ({ id }, _extra) => withToolError(async () => {
827
+ const response = await hcloudRequest("POST", `/primary_ips/${id}/actions/unassign`);
639
828
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
640
829
  }));
641
830
  // --- SSH Keys ---
642
- server.tool("list_ssh_keys", "List all SSH keys", {}, async (_args, _extra) => withToolError(async () => {
643
- const items = await listAll((p) => SshKeysService.getSshKeys(p), "ssh_keys");
831
+ server.registerTool("list_ssh_keys", {
832
+ description: "List all SSH keys",
833
+ inputSchema: {},
834
+ annotations: READ_ONLY,
835
+ }, async (_args, _extra) => withToolError(async () => {
836
+ const items = await listAll((p) => hcloudRequest("GET", "/ssh_keys", { query: p }), "ssh_keys");
644
837
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
645
838
  }));
646
- server.tool("create_ssh_key", "Create a new SSH key (public_key is trimmed; the API rejects leading whitespace)", {
647
- name: z.string(),
648
- public_key: z.string(),
649
- labels: z.record(z.string()).optional(),
839
+ server.registerTool("create_ssh_key", {
840
+ description: "Create a new SSH key (public_key is trimmed; the API rejects leading whitespace)",
841
+ inputSchema: {
842
+ name: z.string(),
843
+ public_key: z.string(),
844
+ labels: z.record(z.string()).optional(),
845
+ },
846
+ annotations: ADDITIVE,
650
847
  }, async (args, _extra) => withToolError(async () => {
651
848
  const requestBody = {
652
849
  name: args.name,
@@ -654,102 +851,142 @@ export function registerTools(server) {
654
851
  public_key: args.public_key.trim(),
655
852
  labels: args.labels,
656
853
  };
657
- const response = await SshKeysService.postSshKeys({ requestBody });
854
+ const response = await hcloudRequest("POST", "/ssh_keys", { body: requestBody });
658
855
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
659
856
  }));
660
- server.tool("update_ssh_key", "Update an SSH key (name, labels)", {
661
- id: z.number(),
662
- name: z.string().optional(),
663
- labels: z.record(z.string()).optional(),
857
+ server.registerTool("update_ssh_key", {
858
+ description: "Update an SSH key (name, labels)",
859
+ inputSchema: {
860
+ id: z.number(),
861
+ name: z.string().optional(),
862
+ labels: z.record(z.string()).optional(),
863
+ },
864
+ annotations: ADDITIVE_IDEMPOTENT,
664
865
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
665
- const response = await SshKeysService.putSshKeys({
666
- id,
667
- requestBody: { name, labels }
668
- });
866
+ const response = await hcloudRequest("PUT", `/ssh_keys/${id}`, { body: { name, labels } });
669
867
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
670
868
  }));
671
- server.tool("delete_ssh_key", "Delete an SSH key", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
672
- await SshKeysService.deleteSshKeys({ id });
869
+ server.registerTool("delete_ssh_key", {
870
+ description: "Delete an SSH key",
871
+ inputSchema: { id: z.number() },
872
+ annotations: DESTRUCTIVE_IDEMPOTENT,
873
+ }, async ({ id }, _extra) => withToolError(async () => {
874
+ await hcloudRequest("DELETE", `/ssh_keys/${id}`);
673
875
  return { content: [{ type: "text", text: "SSH key deleted successfully" }] };
674
876
  }));
675
877
  // --- General Info ---
676
- server.tool("list_locations", "List all locations", {}, async (_args, _extra) => withToolError(async () => {
677
- const items = await listAll((p) => LocationsService.getLocations(p), "locations");
878
+ server.registerTool("list_locations", {
879
+ description: "List all locations",
880
+ inputSchema: {},
881
+ annotations: READ_ONLY,
882
+ }, async (_args, _extra) => withToolError(async () => {
883
+ const items = await listAll((p) => hcloudRequest("GET", "/locations", { query: p }), "locations");
678
884
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
679
885
  }));
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");
886
+ server.registerTool("list_images", {
887
+ description: "List all images (check each image's `deprecation` field; deprecated images can stop being usable for new servers)",
888
+ inputSchema: {},
889
+ annotations: READ_ONLY,
890
+ }, async (_args, _extra) => withToolError(async () => {
891
+ const items = await listAll((p) => hcloudRequest("GET", "/images", { query: p }), "images");
682
892
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
683
893
  }));
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");
894
+ server.registerTool("list_server_types", {
895
+ description: "List all server types. Per-location availability is in locations[]: available, recommended, deprecation (top-level `deprecated` was removed)",
896
+ inputSchema: {},
897
+ annotations: READ_ONLY,
898
+ }, async (_args, _extra) => withToolError(async () => {
899
+ const items = await listAll((p) => hcloudRequest("GET", "/server_types", { query: p }), "server_types");
686
900
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
687
901
  }));
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");
902
+ server.registerTool("list_load_balancer_types", {
903
+ description: "List all load balancer types (for create_load_balancer load_balancer_type; check `deprecation`)",
904
+ inputSchema: {},
905
+ annotations: READ_ONLY,
906
+ }, async (_args, _extra) => withToolError(async () => {
907
+ const items = await listAll((p) => hcloudRequest("GET", "/load_balancer_types", { query: p }), "load_balancer_types");
690
908
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
691
909
  }));
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)"),
694
- status: z.enum(["running", "success", "error"]).optional(),
695
- sort: z
696
- .enum([
697
- "id", "id:asc", "id:desc", "command", "command:asc", "command:desc",
698
- "status", "status:asc", "status:desc", "started", "started:asc", "started:desc",
699
- "finished", "finished:asc", "finished:desc",
700
- ])
701
- .optional(),
702
- page: z.number().optional(),
703
- per_page: z.number().optional(),
910
+ server.registerTool("list_actions", {
911
+ description: "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",
912
+ inputSchema: {
913
+ id: z.number().describe("Action ID (required by the API since 2025-01-30)"),
914
+ status: z.enum(["running", "success", "error"]).optional(),
915
+ sort: z
916
+ .enum([
917
+ "id", "id:asc", "id:desc", "command", "command:asc", "command:desc",
918
+ "status", "status:asc", "status:desc", "started", "started:asc", "started:desc",
919
+ "finished", "finished:asc", "finished:desc",
920
+ ])
921
+ .optional(),
922
+ page: z.number().optional(),
923
+ per_page: z.number().optional(),
924
+ },
925
+ annotations: READ_ONLY,
704
926
  }, async (args, _extra) => withToolError(async () => {
705
- const response = await ActionsService.getActions({
706
- id: args.id,
707
- status: args.status,
708
- sort: args.sort,
709
- page: args.page,
710
- perPage: args.per_page,
711
- });
927
+ const response = await hcloudRequest("GET", "/actions", { query: { id: args.id, status: args.status, sort: args.sort, page: args.page, per_page: args.per_page } });
712
928
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
713
929
  }));
714
- server.tool("get_action", "Get a single action by ID (e.g. to check progress or status after create/delete)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
715
- const response = await ActionsService.getActions1({ id });
930
+ server.registerTool("get_action", {
931
+ description: "Get a single action by ID (e.g. to check progress or status after create/delete)",
932
+ inputSchema: { id: z.number() },
933
+ annotations: READ_ONLY,
934
+ }, async ({ id }, _extra) => withToolError(async () => {
935
+ const response = await hcloudRequest("GET", `/actions/${id}`);
716
936
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
717
937
  }));
718
- server.tool("get_pricing", "Get all prices", {}, async (_args, _extra) => withToolError(async () => {
719
- const response = await PricingService.getPricing();
938
+ server.registerTool("get_pricing", {
939
+ description: "Get all prices",
940
+ inputSchema: {},
941
+ annotations: READ_ONLY,
942
+ }, async (_args, _extra) => withToolError(async () => {
943
+ const response = await hcloudRequest("GET", "/pricing");
720
944
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
721
945
  }));
722
946
  // --- Placement Groups ---
723
- server.tool("list_placement_groups", "List all placement groups", {}, async (_args, _extra) => withToolError(async () => {
724
- const items = await listAll((p) => PlacementGroupsService.getPlacementGroups(p), "placement_groups");
947
+ server.registerTool("list_placement_groups", {
948
+ description: "List all placement groups",
949
+ inputSchema: {},
950
+ annotations: READ_ONLY,
951
+ }, async (_args, _extra) => withToolError(async () => {
952
+ const items = await listAll((p) => hcloudRequest("GET", "/placement_groups", { query: p }), "placement_groups");
725
953
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
726
954
  }));
727
- server.tool("create_placement_group", "Create a new placement group", {
728
- name: z.string(),
729
- type: z.enum(["spread"]),
730
- labels: z.record(z.string()).optional(),
955
+ server.registerTool("create_placement_group", {
956
+ description: "Create a new placement group",
957
+ inputSchema: {
958
+ name: z.string(),
959
+ type: z.enum(["spread"]),
960
+ labels: z.record(z.string()).optional(),
961
+ },
962
+ annotations: ADDITIVE,
731
963
  }, async (args, _extra) => withToolError(async () => {
732
964
  const requestBody = {
733
965
  name: args.name,
734
966
  type: args.type,
735
967
  labels: args.labels,
736
968
  };
737
- const response = await PlacementGroupsService.postPlacementGroups({ requestBody });
969
+ const response = await hcloudRequest("POST", "/placement_groups", { body: requestBody });
738
970
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
739
971
  }));
740
- server.tool("delete_placement_group", "Delete a placement group", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
741
- await PlacementGroupsService.deletePlacementGroups({ id });
972
+ server.registerTool("delete_placement_group", {
973
+ description: "Delete a placement group",
974
+ inputSchema: { id: z.number() },
975
+ annotations: DESTRUCTIVE_IDEMPOTENT,
976
+ }, async ({ id }, _extra) => withToolError(async () => {
977
+ await hcloudRequest("DELETE", `/placement_groups/${id}`);
742
978
  return { content: [{ type: "text", text: "Placement Group deleted successfully" }] };
743
979
  }));
744
- server.tool("update_placement_group", "Update a placement group (name, labels)", {
745
- id: z.number(),
746
- name: z.string().optional(),
747
- labels: z.record(z.string()).optional(),
980
+ server.registerTool("update_placement_group", {
981
+ description: "Update a placement group (name, labels)",
982
+ inputSchema: {
983
+ id: z.number(),
984
+ name: z.string().optional(),
985
+ labels: z.record(z.string()).optional(),
986
+ },
987
+ annotations: ADDITIVE_IDEMPOTENT,
748
988
  }, async ({ id, name, labels }, _extra) => withToolError(async () => {
749
- const response = await PlacementGroupsService.putPlacementGroups({
750
- id,
751
- requestBody: { name, labels }
752
- });
989
+ const response = await hcloudRequest("PUT", `/placement_groups/${id}`, { body: { name, labels } });
753
990
  return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
754
991
  }));
755
992
  }