hcloud-mcp 0.4.1 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -3
- package/dist/index.js +14 -3
- package/dist/instructions.js +8 -0
- package/dist/robot-api.js +141 -0
- package/dist/robot-tools.js +131 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://mcprush.com/to/hcloud-mcp?ref=badge)
|
|
4
4
|
|
|
5
|
-
Standalone **MCP (Model Context Protocol) server** for the [Hetzner Cloud API](https://docs.hetzner.cloud/): servers, networking, load balancers, volumes, DNS, certificates, snapshots and
|
|
5
|
+
Standalone **MCP (Model Context Protocol) server** for the [Hetzner Cloud API](https://docs.hetzner.cloud/): servers, networking, load balancers, volumes, DNS, certificates, snapshots, Storage Boxes and (opt-in) Robot dedicated servers. It has 162 Cloud tools plus 17 opt-in Robot tools, and every tool tells the client whether it is read-only or destructive. Use it with any MCP client: Cursor, Claude Desktop, Claude Code, CLI tools, [smithery.ai](https://smithery.ai), or custom agents.
|
|
6
6
|
|
|
7
7
|
- **Repository:** [github.com/Xodus-CO/hcloud-mcp](https://github.com/Xodus-CO/hcloud-mcp)
|
|
8
8
|
- **Hetzner Cloud:** [Get started](https://hetzner.cloud/?ref=IAYKetqPnlq9) — new signups get €20 credit.
|
|
@@ -93,7 +93,7 @@ The server exposes Hetzner Cloud API operations as MCP tools:
|
|
|
93
93
|
|
|
94
94
|
### Limiting tools (`HCLOUD_TOOLSETS`)
|
|
95
95
|
|
|
96
|
-
The server exposes 162 tools. Some MCP clients cap the total number of tools, or slow down with very many. Set `HCLOUD_TOOLSETS` to load only the groups you need. The `core` group is always loaded.
|
|
96
|
+
The server exposes 162 Cloud tools, plus 17 Robot tools when Robot credentials are set. Some MCP clients cap the total number of tools, or slow down with very many. Set `HCLOUD_TOOLSETS` to load only the groups you need. The `core` group is always loaded.
|
|
97
97
|
|
|
98
98
|
| Toolset | Contents |
|
|
99
99
|
|---|---|
|
|
@@ -103,9 +103,40 @@ The server exposes 162 tools. Some MCP clients cap the total number of tools, or
|
|
|
103
103
|
| `ops` | Rescue, console, root password, metrics |
|
|
104
104
|
| `certificates` | TLS certificates |
|
|
105
105
|
| `storage_boxes` | Storage Boxes, subaccounts, snapshots |
|
|
106
|
+
| `robot` | Hetzner Robot dedicated-server tools; also needs `HROBOT_USER` and `HROBOT_PASSWORD` (see below) |
|
|
106
107
|
|
|
107
108
|
Example: `"env": { "HCLOUD_TOKEN": "...", "HCLOUD_TOOLSETS": "dns,images" }`. If you leave it unset, or set it to `all`, everything loads. `core` alone is 91 tools; `core` plus `dns` is 112.
|
|
108
109
|
|
|
110
|
+
### Hetzner Robot (dedicated servers, opt-in)
|
|
111
|
+
|
|
112
|
+
The 17 `robot_*` tools manage **dedicated servers** through the [Robot webservice](https://robot.hetzner.com/doc/webservice/en.html). They are off by default. They load only when **both** `HROBOT_USER` and `HROBOT_PASSWORD` are set. Without them, the server has exactly the Cloud tools and never contacts Robot.
|
|
113
|
+
|
|
114
|
+
Create a webservice user in Robot under *Settings > Web service and app settings*. It is separate from your Robot login. Set the credentials in the environment or in your MCP client config:
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
"env": {
|
|
118
|
+
"HCLOUD_TOKEN": "...",
|
|
119
|
+
"HROBOT_USER": "#ws+12345678",
|
|
120
|
+
"HROBOT_PASSWORD": "..."
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Quote the values in a shell or `.env` file: webservice usernames start with `#` and passwords may contain `$`. Write `HROBOT_USER='#ws+12345678'` and `HROBOT_PASSWORD='...'` with single quotes. Unquoted, a shell expands `$...` in the password and dotenv treats `#...` as a comment. In an MCP client's JSON config the values work as they are.
|
|
125
|
+
|
|
126
|
+
Credentials are read only from the environment, sent only as HTTP Basic auth to `https://robot-ws.your-server.de` (the host in Hetzner's docs), and are never logged or included in errors or tool output. Robot blocks an IP for 10 minutes after 3 failed logins, so fix a rejected credential instead of retrying. `HCLOUD_TOKEN` is still required.
|
|
127
|
+
|
|
128
|
+
| Kind | Tools |
|
|
129
|
+
|---|---|
|
|
130
|
+
| **Read** | `robot_list_servers`, `robot_get_server`, `robot_list_ips`, `robot_get_ip`, `robot_list_subnets`, `robot_get_subnet`, `robot_list_rdns`, `robot_get_rdns`, `robot_get_traffic`, `robot_get_boot_config` (rescue state), `robot_get_reset_options` |
|
|
131
|
+
| **Rescue** | `robot_enable_rescue` (optional SSH key fingerprints; arms the next boot, no reboot), `robot_disable_rescue` |
|
|
132
|
+
| **Reset** | `robot_reset_server` (`sw`, `hw`, `power`, `power_long`, `man`; use a type listed by `robot_get_reset_options`) |
|
|
133
|
+
| **Reverse DNS** | `robot_set_rdns`, `robot_delete_rdns` |
|
|
134
|
+
| **Power** | `robot_wake_on_lan` |
|
|
135
|
+
|
|
136
|
+
Reads are `readOnlyHint`. `robot_reset_server`, `robot_enable_rescue`, `robot_disable_rescue` and `robot_delete_rdns` are `destructiveHint`. Cancellation, orders and billing are not covered; use the Robot web interface. Typical wipe flow: `robot_enable_rescue`, then `robot_reset_server` with `hw`, then log in to the rescue system (the root password is returned once by `robot_enable_rescue`; treat it as a secret).
|
|
137
|
+
|
|
138
|
+
With `HCLOUD_TOOLSETS` set, list `robot` to keep the Robot tools (for example `core,robot`). Robot has low rate limits (50 resets and 10 wake-on-LAN packets per hour).
|
|
139
|
+
|
|
109
140
|
### Tool annotations
|
|
110
141
|
|
|
111
142
|
Every tool declares MCP [tool annotations](https://modelcontextprotocol.io/specification/2025-06-18/server/tools#tool-annotations), which clients can use to decide when to ask for confirmation:
|
|
@@ -144,12 +175,12 @@ The tools follow the Hetzner API as of November 2026 ([Hetzner changelog](https:
|
|
|
144
175
|
- **Unassign before deleting.** Floating IPs and Primary IPs must be unassigned before you delete them.
|
|
145
176
|
- **Errors** come back as `code (status): message`, for example `not_found (404): server not found`.
|
|
146
177
|
|
|
147
|
-
Hetzner Robot (dedicated servers) is not covered yet; see [#21](https://github.com/Xodus-CO/hcloud-mcp/issues/21).
|
|
148
178
|
|
|
149
179
|
## Changelog
|
|
150
180
|
|
|
151
181
|
See [GitHub Releases](https://github.com/Xodus-CO/hcloud-mcp/releases) for full notes.
|
|
152
182
|
|
|
183
|
+
- **0.5.0:** Opt-in Hetzner Robot tool group (`robot_*`) for dedicated servers, enabled by `HROBOT_USER` and `HROBOT_PASSWORD` (#21).
|
|
153
184
|
- **0.4.1:** README update only (no code changes).
|
|
154
185
|
- **0.4.0:** Removed the Hetzner SDK dependency; every tool now calls the API through one small fetch client. Every tool declares MCP annotations. `create_load_balancer` accepts an existing Primary IP, a network, services and targets.
|
|
155
186
|
- **0.3.1:** Volumes use `assignee`. CI added. (Not published to npm separately; included in 0.4.0.)
|
|
@@ -201,6 +232,8 @@ With the MCP client connected, you can ask the agent to run tools using natural
|
|
|
201
232
|
| `src/server-ops-tools.ts` | Rescue, console, root password, server/LB metrics |
|
|
202
233
|
| `src/certificate-tools.ts` | TLS certificates |
|
|
203
234
|
| `src/storage-box-tools.ts` | Storage Boxes (api.hetzner.com, same token) |
|
|
235
|
+
| `src/robot-api.ts` | Robot webservice client (HTTP Basic auth, form bodies, error mapping) |
|
|
236
|
+
| `src/robot-tools.ts` | Opt-in `robot_*` tools (dedicated servers) |
|
|
204
237
|
| `src/instructions.ts` | Server instructions sent to MCP clients at initialize |
|
|
205
238
|
| `skills/hetzner-cloud/` | Agent skill (SKILL.md) for driving this server safely |
|
|
206
239
|
|
|
@@ -211,6 +244,7 @@ npm run build # compile
|
|
|
211
244
|
npm run start # run (requires HCLOUD_TOKEN)
|
|
212
245
|
npm run dev # watch and recompile
|
|
213
246
|
npm run test:smoke # offline: server starts, 162 tools register with annotations, toolsets work (runs in CI)
|
|
247
|
+
npm run test:robot # offline: Robot tools against a mocked fetch (runs in CI)
|
|
214
248
|
npm run test:api # read-only checks of the API client: pagination, error format (requires HCLOUD_TOKEN, run build first)
|
|
215
249
|
npm run test:mcp # integration test: MCP client calls list_locations (requires HCLOUD_TOKEN)
|
|
216
250
|
npm run test:live:dns # DNS create→teardown on a throwaway zone (free)
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,9 @@ import { registerCertificateTools } from "./certificate-tools.js";
|
|
|
12
12
|
import { registerImageTools } from "./image-tools.js";
|
|
13
13
|
import { registerServerOpsTools } from "./server-ops-tools.js";
|
|
14
14
|
import { registerActionGapTools } from "./action-gap-tools.js";
|
|
15
|
-
import {
|
|
15
|
+
import { registerRobotTools } from "./robot-tools.js";
|
|
16
|
+
import { robotConfigured } from "./robot-api.js";
|
|
17
|
+
import { SERVER_INSTRUCTIONS, ROBOT_INSTRUCTIONS } from "./instructions.js";
|
|
16
18
|
// Load .env from project root (parent of dist) so IDE-spawned server finds token when env isn't set
|
|
17
19
|
if (!process.env.HCLOUD_TOKEN) {
|
|
18
20
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
@@ -22,7 +24,8 @@ if (!process.env.HCLOUD_TOKEN) {
|
|
|
22
24
|
console.error("Error: HCLOUD_TOKEN environment variable is required");
|
|
23
25
|
process.exit(1);
|
|
24
26
|
}
|
|
25
|
-
const
|
|
27
|
+
const robotEnabled = robotConfigured();
|
|
28
|
+
const server = new McpServer({ name: "hetzner-cloud", version: "0.5.0" }, { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS + (robotEnabled ? ROBOT_INSTRUCTIONS : "") });
|
|
26
29
|
// Tool groups. HCLOUD_TOOLSETS (comma-separated) limits which load, for clients with
|
|
27
30
|
// tool-count limits; default is all. "core" is always loaded.
|
|
28
31
|
const TOOLSETS = {
|
|
@@ -32,6 +35,8 @@ const TOOLSETS = {
|
|
|
32
35
|
ops: [registerServerOpsTools],
|
|
33
36
|
certificates: [registerCertificateTools],
|
|
34
37
|
storage_boxes: [registerStorageBoxTools],
|
|
38
|
+
// Opt-in Hetzner Robot (dedicated servers): also needs HROBOT_USER and HROBOT_PASSWORD.
|
|
39
|
+
robot: [registerRobotTools],
|
|
35
40
|
};
|
|
36
41
|
const requested = (process.env.HCLOUD_TOOLSETS ?? "")
|
|
37
42
|
.split(",").map((t) => t.trim().toLowerCase()).filter(Boolean);
|
|
@@ -43,9 +48,15 @@ if (unknown.length) {
|
|
|
43
48
|
const enabled = requested.length === 0 || requested.includes("all")
|
|
44
49
|
? Object.keys(TOOLSETS)
|
|
45
50
|
: ["core", ...requested.filter((t) => t !== "core")];
|
|
46
|
-
for (const name of enabled)
|
|
51
|
+
for (const name of enabled) {
|
|
52
|
+
if (name === "robot" && !robotEnabled) {
|
|
53
|
+
if (requested.includes("robot"))
|
|
54
|
+
console.error("Warning: HCLOUD_TOOLSETS includes robot but HROBOT_USER / HROBOT_PASSWORD are not both set; Robot tools not loaded");
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
47
57
|
for (const register of TOOLSETS[name])
|
|
48
58
|
register(server);
|
|
59
|
+
}
|
|
49
60
|
async function main() {
|
|
50
61
|
const transport = new StdioServerTransport();
|
|
51
62
|
await server.connect(transport);
|
package/dist/instructions.js
CHANGED
|
@@ -20,3 +20,11 @@ export const SERVER_INSTRUCTIONS = `Hetzner Cloud API tools. Notes:
|
|
|
20
20
|
- Managed certificates only work for domains in a primary Hetzner DNS zone that is delegated to Hetzner. Certificates are attached to load balancers through http.certificates on update_load_balancer_service.
|
|
21
21
|
- Storage Boxes live on api.hetzner.com and use the same token. Poll their actions with get_storage_box_action. rollback_storage_box_snapshot discards everything newer than the snapshot.
|
|
22
22
|
- Pricing: get_pricing returns prices per location and server type, in EUR, with and without VAT.`;
|
|
23
|
+
// Appended only when the Robot tools are enabled (HROBOT_USER and HROBOT_PASSWORD set).
|
|
24
|
+
export const ROBOT_INSTRUCTIONS = `
|
|
25
|
+
|
|
26
|
+
Hetzner Robot tools (robot_*) manage dedicated servers, which are separate from Cloud servers. Use the Robot server_number, not a Cloud server ID.
|
|
27
|
+
- Rescue: robot_enable_rescue only arms the NEXT boot and does not reboot. After it, call robot_get_reset_options and use a reset type it lists with robot_reset_server to boot into rescue (hw is the usual choice; sw only where offered). Confirm with the user before any reset. Rescue disarms after one boot; robot_disable_rescue cancels it.
|
|
28
|
+
- The rescue root_password is a secret: show it to the user only, never store it or pass it to other tools.
|
|
29
|
+
- Robot rate limits are low (50 resets/hour, 10 wake-on-LAN/hour) and it blocks the caller's IP for 10 minutes after 3 failed logins, so do not retry authentication errors.
|
|
30
|
+
- Cancellation, orders and billing are not available; use the Robot web interface.`;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Minimal fetch client for the Hetzner Robot webservice (dedicated servers).
|
|
2
|
+
// Opt-in: only used when HROBOT_USER and HROBOT_PASSWORD are both set. Credentials are
|
|
3
|
+
// read from the environment at call time and only ever go into the Authorization header:
|
|
4
|
+
// they are never logged, put into URLs, errors or tool output.
|
|
5
|
+
// Host as documented at https://robot.hetzner.com/doc/webservice/en.html. Deliberately a
|
|
6
|
+
// constant (no env override) so the credentials can only be sent to Hetzner.
|
|
7
|
+
export const ROBOT_API = "https://robot-ws.your-server.de";
|
|
8
|
+
export class RobotApiError extends Error {
|
|
9
|
+
status;
|
|
10
|
+
code;
|
|
11
|
+
constructor(status, code, message) {
|
|
12
|
+
super(`${code} (${status}): ${message}`);
|
|
13
|
+
this.status = status;
|
|
14
|
+
this.code = code;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** True when both Robot credentials are set and non-empty. */
|
|
18
|
+
export function robotConfigured(env = process.env) {
|
|
19
|
+
return Boolean(env.HROBOT_USER) && Boolean(env.HROBOT_PASSWORD);
|
|
20
|
+
}
|
|
21
|
+
/** HTTP Basic header value ("Basic base64(user:password)", UTF-8). */
|
|
22
|
+
export function buildAuthHeader(user, password) {
|
|
23
|
+
return `Basic ${Buffer.from(`${user}:${password}`, "utf8").toString("base64")}`;
|
|
24
|
+
}
|
|
25
|
+
function authHeader() {
|
|
26
|
+
const { HROBOT_USER: user, HROBOT_PASSWORD: password } = process.env;
|
|
27
|
+
if (!user || !password)
|
|
28
|
+
throw new Error("HROBOT_USER and HROBOT_PASSWORD must both be set");
|
|
29
|
+
return buildAuthHeader(user, password);
|
|
30
|
+
}
|
|
31
|
+
/** Remove the credentials (and their base64 form) from any text before it leaves this module. */
|
|
32
|
+
function scrub(text) {
|
|
33
|
+
let out = text;
|
|
34
|
+
const { HROBOT_USER: user, HROBOT_PASSWORD: password } = process.env;
|
|
35
|
+
const secrets = [password, user, user && password ? Buffer.from(`${user}:${password}`).toString("base64") : undefined];
|
|
36
|
+
for (const s of secrets)
|
|
37
|
+
if (s && s.length >= 3)
|
|
38
|
+
out = out.split(s).join("[redacted]");
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
// Friendly hints for the errors an agent is most likely to hit; the Robot code and
|
|
42
|
+
// message are always kept. Codes from https://robot.hetzner.com/doc/webservice/en.html.
|
|
43
|
+
const HINTS = {
|
|
44
|
+
UNAUTHORIZED: "Robot rejected the credentials. Check HROBOT_USER / HROBOT_PASSWORD (a webservice user from Robot > Settings > Web service and app settings, not your account login). Do not retry in a loop: Hetzner blocks the calling IP for 10 minutes after 3 failed logins",
|
|
45
|
+
RATE_LIMIT_EXCEEDED: "Robot request limit reached (it answers 403, not 429); wait before retrying",
|
|
46
|
+
SERVER_NOT_FOUND: "No dedicated server with this number (or IP) in this Robot account. Use robot_list_servers",
|
|
47
|
+
IP_NOT_FOUND: "This IP is not in this Robot account. Use robot_list_ips",
|
|
48
|
+
RDNS_NOT_FOUND: "This IP has no reverse DNS entry yet",
|
|
49
|
+
BOOT_NOT_AVAILABLE: "This server has no boot configuration (rescue is not available for it)",
|
|
50
|
+
RESET_NOT_AVAILABLE: "This server has no reset option",
|
|
51
|
+
RESET_MANUAL_ACTIVE: "A manual reset is already running for this server",
|
|
52
|
+
WOL_NOT_AVAILABLE: "Wake-on-LAN is not available on this server",
|
|
53
|
+
MAINTENANCE: "The Robot webservice is down for maintenance; try again later",
|
|
54
|
+
};
|
|
55
|
+
function robotError(status, data, statusText) {
|
|
56
|
+
const err = data?.error ?? {};
|
|
57
|
+
const code = err.code ?? (status === 401 ? "UNAUTHORIZED" : "http_error");
|
|
58
|
+
let message = HINTS[code] ?? err.message ?? statusText ?? "request failed";
|
|
59
|
+
if (code === "INVALID_INPUT") {
|
|
60
|
+
const parts = [];
|
|
61
|
+
if (Array.isArray(err.missing) && err.missing.length)
|
|
62
|
+
parts.push(`missing: ${err.missing.join(", ")}`);
|
|
63
|
+
if (Array.isArray(err.invalid) && err.invalid.length)
|
|
64
|
+
parts.push(`invalid: ${err.invalid.join(", ")}`);
|
|
65
|
+
message = `Robot rejected the input${parts.length ? ` (${parts.join("; ")})` : ""}`;
|
|
66
|
+
}
|
|
67
|
+
if (code === "RATE_LIMIT_EXCEEDED" && err.max_request && err.interval) {
|
|
68
|
+
message += ` (max ${err.max_request} requests per ${err.interval}s)`;
|
|
69
|
+
}
|
|
70
|
+
if (status === 503 && !HINTS[code])
|
|
71
|
+
message = HINTS.MAINTENANCE;
|
|
72
|
+
return new RobotApiError(status, code, scrub(message));
|
|
73
|
+
}
|
|
74
|
+
function formBody(form) {
|
|
75
|
+
const params = new URLSearchParams();
|
|
76
|
+
for (const [k, raw] of Object.entries(form)) {
|
|
77
|
+
// Robot takes arrays as repeated `name[]=` fields (ip[]=..., authorized_key[]=...).
|
|
78
|
+
if (Array.isArray(raw)) {
|
|
79
|
+
for (const v of raw)
|
|
80
|
+
if (v !== undefined && v !== null && v !== "")
|
|
81
|
+
params.append(`${k}[]`, String(v));
|
|
82
|
+
}
|
|
83
|
+
else if (raw !== undefined && raw !== null && raw !== "") {
|
|
84
|
+
params.append(k, String(raw));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return params.toString();
|
|
88
|
+
}
|
|
89
|
+
export async function robotRequest(method, path, options = {}) {
|
|
90
|
+
const url = new URL(ROBOT_API + path);
|
|
91
|
+
for (const [k, v] of Object.entries(options.query ?? {})) {
|
|
92
|
+
if (v !== undefined && v !== null && v !== "")
|
|
93
|
+
url.searchParams.append(k, String(v));
|
|
94
|
+
}
|
|
95
|
+
let res;
|
|
96
|
+
try {
|
|
97
|
+
res = await fetch(url, {
|
|
98
|
+
method,
|
|
99
|
+
headers: {
|
|
100
|
+
Authorization: authHeader(),
|
|
101
|
+
...(options.form ? { "Content-Type": "application/x-www-form-urlencoded" } : {}),
|
|
102
|
+
},
|
|
103
|
+
body: options.form ? formBody(options.form) : undefined,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
// Keep only a scrubbed message; never attach the original error object.
|
|
108
|
+
throw new Error(scrub(`Robot request failed: ${e instanceof Error ? e.message : String(e)}`));
|
|
109
|
+
}
|
|
110
|
+
const text = await res.text();
|
|
111
|
+
let data = {};
|
|
112
|
+
try {
|
|
113
|
+
data = text ? JSON.parse(text) : {};
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
if (!res.ok)
|
|
117
|
+
throw robotError(res.status, undefined, res.statusText);
|
|
118
|
+
throw new Error("Robot returned a non-JSON response");
|
|
119
|
+
}
|
|
120
|
+
if (!res.ok)
|
|
121
|
+
throw robotError(res.status, data, res.statusText);
|
|
122
|
+
return data;
|
|
123
|
+
}
|
|
124
|
+
/** Robot wraps every list item ([{server: {...}}, ...]); unwrap by key. */
|
|
125
|
+
export function unwrap(list, key) {
|
|
126
|
+
return (Array.isArray(list) ? list : []).map((item) => item?.[key] ?? item);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* List endpoints answer 404 (NOT_FOUND) when there is nothing to list; return [] for that.
|
|
130
|
+
* Other 404s (e.g. SERVER_NOT_FOUND) still surface as errors.
|
|
131
|
+
*/
|
|
132
|
+
export async function robotList(path, key, query) {
|
|
133
|
+
try {
|
|
134
|
+
return unwrap(await robotRequest("GET", path, { query }), key);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
if (e instanceof RobotApiError && e.status === 404 && e.code === "NOT_FOUND")
|
|
138
|
+
return [];
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Hetzner Robot (dedicated servers) tools, issue #21. Opt-in: registered only when
|
|
2
|
+
// HROBOT_USER and HROBOT_PASSWORD are set (see index.ts). Cancellation, orders and
|
|
3
|
+
// billing are deliberately out of scope.
|
|
4
|
+
import { isIP } from "node:net";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { robotList, robotRequest } from "./robot-api.js";
|
|
7
|
+
import { ADDITIVE, ADDITIVE_IDEMPOTENT, DESTRUCTIVE, DESTRUCTIVE_IDEMPOTENT, READ_ONLY, json, withToolError } from "./tool-helpers.js";
|
|
8
|
+
const serverNumber = z.number().int().positive().describe("Robot server number (server_number from robot_list_servers)");
|
|
9
|
+
const ipArg = z.string().refine((v) => isIP(v) !== 0, "Must be an IPv4 or IPv6 address").describe("IP address");
|
|
10
|
+
const serverIpFilter = z.string().refine((v) => isIP(v) !== 0, "Must be an IP address").optional()
|
|
11
|
+
.describe("Only entries assigned to the server with this main IP");
|
|
12
|
+
export function registerRobotTools(server) {
|
|
13
|
+
// --- Reads ---
|
|
14
|
+
server.registerTool("robot_list_servers", {
|
|
15
|
+
description: "List Hetzner Robot dedicated servers (not Cloud servers): number, name, main IP, product, datacenter, status, paid_until",
|
|
16
|
+
inputSchema: {},
|
|
17
|
+
annotations: READ_ONLY,
|
|
18
|
+
}, async () => withToolError(async () => json(await robotList("/server", "server"))));
|
|
19
|
+
server.registerTool("robot_get_server", {
|
|
20
|
+
description: "Get one Robot dedicated server by server number, including its IPs and subnets",
|
|
21
|
+
inputSchema: { server_number: serverNumber },
|
|
22
|
+
annotations: READ_ONLY,
|
|
23
|
+
}, async ({ server_number }) => withToolError(async () => json((await robotRequest("GET", `/server/${server_number}`)).server)));
|
|
24
|
+
server.registerTool("robot_list_ips", {
|
|
25
|
+
description: "List Robot IP addresses (single IPv4s) with their server, locked and traffic-warning settings",
|
|
26
|
+
inputSchema: { server_ip: serverIpFilter },
|
|
27
|
+
annotations: READ_ONLY,
|
|
28
|
+
}, async ({ server_ip }) => withToolError(async () => json(await robotList("/ip", "ip", { server_ip }))));
|
|
29
|
+
server.registerTool("robot_get_ip", {
|
|
30
|
+
description: "Get one Robot IP address",
|
|
31
|
+
inputSchema: { ip: ipArg },
|
|
32
|
+
annotations: READ_ONLY,
|
|
33
|
+
}, async ({ ip }) => withToolError(async () => json((await robotRequest("GET", `/ip/${encodeURIComponent(ip)}`)).ip)));
|
|
34
|
+
server.registerTool("robot_list_subnets", {
|
|
35
|
+
description: "List Robot subnets (IPv6 /64s and additional IPv4 subnets)",
|
|
36
|
+
inputSchema: { server_ip: serverIpFilter },
|
|
37
|
+
annotations: READ_ONLY,
|
|
38
|
+
}, async ({ server_ip }) => withToolError(async () => json(await robotList("/subnet", "subnet", { server_ip }))));
|
|
39
|
+
server.registerTool("robot_get_subnet", {
|
|
40
|
+
description: "Get one Robot subnet by its network address (e.g. 2a01:4f8:111:4221::)",
|
|
41
|
+
inputSchema: { net_ip: ipArg.describe("Subnet network address, without the mask") },
|
|
42
|
+
annotations: READ_ONLY,
|
|
43
|
+
}, async ({ net_ip }) => withToolError(async () => json((await robotRequest("GET", `/subnet/${encodeURIComponent(net_ip)}`)).subnet)));
|
|
44
|
+
server.registerTool("robot_list_rdns", {
|
|
45
|
+
description: "List Robot reverse DNS (PTR) entries, optionally only those of one server",
|
|
46
|
+
inputSchema: { server_ip: serverIpFilter },
|
|
47
|
+
annotations: READ_ONLY,
|
|
48
|
+
}, async ({ server_ip }) => withToolError(async () => json(await robotList("/rdns", "rdns", { server_ip }))));
|
|
49
|
+
server.registerTool("robot_get_rdns", {
|
|
50
|
+
description: "Get the reverse DNS (PTR) entry of one Robot IP. Errors with RDNS_NOT_FOUND if none is set",
|
|
51
|
+
inputSchema: { ip: ipArg },
|
|
52
|
+
annotations: READ_ONLY,
|
|
53
|
+
}, async ({ ip }) => withToolError(async () => json((await robotRequest("GET", `/rdns/${encodeURIComponent(ip)}`)).rdns)));
|
|
54
|
+
server.registerTool("robot_get_traffic", {
|
|
55
|
+
description: "Traffic (GB in/out/sum) for Robot IPs or subnets. type=day: hourly data within a day (from/to like 2026-11-01T00); month: daily data (2026-11-01); year: monthly data (2026-11). Data only exists once the period has passed. Give at least one ip or subnet",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: z.enum(["day", "month", "year"]),
|
|
58
|
+
from: z.string().describe("Start: YYYY-MM-DDTHH for day, YYYY-MM-DD for month, YYYY-MM for year"),
|
|
59
|
+
to: z.string().describe("End, same format as from"),
|
|
60
|
+
ips: z.array(ipArg).optional().describe("IP addresses to query"),
|
|
61
|
+
subnets: z.array(ipArg).optional().describe("Subnet network addresses to query"),
|
|
62
|
+
single_values: z.boolean().optional().describe("Return one value per hour/day/month instead of a sum over the interval"),
|
|
63
|
+
},
|
|
64
|
+
annotations: READ_ONLY,
|
|
65
|
+
}, async ({ type, from, to, ips, subnets, single_values }) => withToolError(async () => {
|
|
66
|
+
if (!ips?.length && !subnets?.length)
|
|
67
|
+
throw new Error("Pass at least one of ips or subnets");
|
|
68
|
+
const res = await robotRequest("POST", "/traffic", {
|
|
69
|
+
form: { type, from, to, "ip": ips, "subnet": subnets, single_values: single_values ? "true" : undefined },
|
|
70
|
+
});
|
|
71
|
+
return json(res.traffic);
|
|
72
|
+
}));
|
|
73
|
+
server.registerTool("robot_get_boot_config", {
|
|
74
|
+
description: "Boot configuration of a Robot server: shows whether the Rescue System is active (rescue.active), its available OS and authorized keys, plus other boot options (linux install, vnc, windows). The rescue password is only returned right after robot_enable_rescue",
|
|
75
|
+
inputSchema: { server_number: serverNumber },
|
|
76
|
+
annotations: READ_ONLY,
|
|
77
|
+
}, async ({ server_number }) => withToolError(async () => json((await robotRequest("GET", `/boot/${server_number}`)).boot)));
|
|
78
|
+
server.registerTool("robot_get_reset_options", {
|
|
79
|
+
description: "Reset options of a Robot server: available types (sw = software/ACPI, hw = hardware reset, power = power button, power_long = long press of the power button, i.e. forced power-off, man = manual technician). Many servers offer only power, power_long, hw and man and operating_status where supported. Omit server_number to list every server that has a reset option",
|
|
80
|
+
inputSchema: { server_number: serverNumber.optional() },
|
|
81
|
+
annotations: READ_ONLY,
|
|
82
|
+
}, async ({ server_number }) => withToolError(async () => server_number === undefined
|
|
83
|
+
? json(await robotList("/reset", "reset"))
|
|
84
|
+
: json((await robotRequest("GET", `/reset/${server_number}`)).reset)));
|
|
85
|
+
// --- Actions ---
|
|
86
|
+
server.registerTool("robot_enable_rescue", {
|
|
87
|
+
description: "Activate the Robot Rescue System for the NEXT boot of a dedicated server. Does not reboot: once the user agrees, call robot_get_reset_options and follow with robot_reset_server using a listed type (hw is the usual choice). Returns a root password (treat as a secret; show only to the user). Pass authorized_keys (fingerprints of keys stored in Robot) to log in by key. Rescue deactivates itself after the first boot into it",
|
|
88
|
+
inputSchema: {
|
|
89
|
+
server_number: serverNumber,
|
|
90
|
+
os: z.string().regex(/^[a-z0-9_]+$/).optional().describe("Rescue OS, one of rescue.os from robot_get_boot_config (e.g. linux, vkvm). Default linux"),
|
|
91
|
+
authorized_keys: z.array(z.string().min(1)).optional().describe("SSH key fingerprints (as listed in Robot, e.g. 56:29:99:...) to authorize"),
|
|
92
|
+
keyboard: z.string().optional().describe("Keyboard layout (default us)"),
|
|
93
|
+
},
|
|
94
|
+
annotations: DESTRUCTIVE,
|
|
95
|
+
}, async ({ server_number, os, authorized_keys, keyboard }) => withToolError(async () => json((await robotRequest("POST", `/boot/${server_number}/rescue`, {
|
|
96
|
+
form: { os: os ?? "linux", authorized_key: authorized_keys, keyboard },
|
|
97
|
+
})).rescue)));
|
|
98
|
+
server.registerTool("robot_disable_rescue", {
|
|
99
|
+
description: "Deactivate the Robot Rescue System so the server boots from its own disk. Does not reboot",
|
|
100
|
+
inputSchema: { server_number: serverNumber },
|
|
101
|
+
annotations: DESTRUCTIVE_IDEMPOTENT,
|
|
102
|
+
}, async ({ server_number }) => withToolError(async () => json((await robotRequest("DELETE", `/boot/${server_number}/rescue`)).rescue)));
|
|
103
|
+
server.registerTool("robot_reset_server", {
|
|
104
|
+
description: "Reset (reboot) a dedicated server NOW; running services are interrupted and there is no undo. sw = software/ACPI reset (only where offered), hw = hardware reset (usual choice to boot into rescue), power = press the power button, power_long = long press of the power button (forced power-off), man = manual reset by a data centre technician (can take a while; only one at a time). Call robot_get_reset_options first and use a type it lists. Robot allows only 50 resets per hour. Confirm with the user first",
|
|
105
|
+
inputSchema: {
|
|
106
|
+
server_number: serverNumber,
|
|
107
|
+
type: z.enum(["sw", "hw", "power", "power_long", "man"]),
|
|
108
|
+
},
|
|
109
|
+
annotations: DESTRUCTIVE,
|
|
110
|
+
}, async ({ server_number, type }) => withToolError(async () => json((await robotRequest("POST", `/reset/${server_number}`, { form: { type } })).reset)));
|
|
111
|
+
server.registerTool("robot_set_rdns", {
|
|
112
|
+
description: "Create or replace the reverse DNS (PTR) entry of a Robot IP",
|
|
113
|
+
inputSchema: { ip: ipArg, ptr: z.string().min(1).describe("Hostname, e.g. mail.example.com") },
|
|
114
|
+
annotations: ADDITIVE_IDEMPOTENT,
|
|
115
|
+
},
|
|
116
|
+
// POST creates or updates; PUT would fail with RDNS_ALREADY_EXISTS on an existing entry.
|
|
117
|
+
async ({ ip, ptr }) => withToolError(async () => json((await robotRequest("POST", `/rdns/${encodeURIComponent(ip)}`, { form: { ptr } })).rdns)));
|
|
118
|
+
server.registerTool("robot_delete_rdns", {
|
|
119
|
+
description: "Delete the reverse DNS (PTR) entry of a Robot IP",
|
|
120
|
+
inputSchema: { ip: ipArg },
|
|
121
|
+
annotations: DESTRUCTIVE_IDEMPOTENT,
|
|
122
|
+
}, async ({ ip }) => withToolError(async () => {
|
|
123
|
+
await robotRequest("DELETE", `/rdns/${encodeURIComponent(ip)}`);
|
|
124
|
+
return json({ deleted: true, ip });
|
|
125
|
+
}));
|
|
126
|
+
server.registerTool("robot_wake_on_lan", {
|
|
127
|
+
description: "Send a Wake-on-LAN packet to a dedicated server (powers on a server that is off). Robot allows 10 per hour",
|
|
128
|
+
inputSchema: { server_number: serverNumber },
|
|
129
|
+
annotations: ADDITIVE,
|
|
130
|
+
}, async ({ server_number }) => withToolError(async () => json((await robotRequest("POST", `/wol/${server_number}`, { form: {} })).wol)));
|
|
131
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hcloud-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
"start": "node dist/index.js",
|
|
19
19
|
"dev": "tsc --watch",
|
|
20
20
|
"test:smoke": "node scripts/smoke-mcp.mjs",
|
|
21
|
+
"test:robot": "node --test scripts/test-robot.mjs",
|
|
21
22
|
"test:api": "node scripts/test-list-api.mjs",
|
|
22
23
|
"test:mcp": "node scripts/test-mcp-list.mjs",
|
|
23
24
|
"test:live": "node scripts/test-live-lifecycle.mjs",
|