hcloud-mcp 0.1.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 +129 -0
- package/dist/index.js +29 -0
- package/dist/mcp-server.js +45 -0
- package/dist/register-tools.js +742 -0
- package/package.json +41 -0
- package/run.js +13 -0
- package/scripts/audit-api-shapes.mjs +160 -0
- package/scripts/test-list-api.mjs +47 -0
- package/scripts/test-mcp-list.mjs +62 -0
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# HCloud MCP
|
|
2
|
+
|
|
3
|
+
Standalone **MCP (Model Context Protocol) server** for the [Hetzner Cloud API](https://docs.hetzner.cloud/). Use it with any MCP client: Cursor, Claude Desktop, CLI tools, [smithery.ai](https://smithery.ai), or custom agents.
|
|
4
|
+
|
|
5
|
+
- **Repository:** [github.com/Xodus-CO/hcloud-mcp](https://github.com/Xodus-CO/hcloud-mcp)
|
|
6
|
+
- **Cursor Plugin:** [github.com/Xodus-CO/hetzner-mcp](https://github.com/Xodus-CO/hetzner-mcp) — install from the Cursor Plugin marketplace.
|
|
7
|
+
- **Hetzner Cloud:** [Get started](https://hetzner.cloud/?ref=IAYKetqPnlq9) — new signups get €20 credit.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Requirements
|
|
12
|
+
|
|
13
|
+
- Node.js 18+
|
|
14
|
+
- A Hetzner Cloud API token. [Generate one](https://docs.hetzner.com/cloud/api/getting-started/generating-api-token) in the console (project → Security → API Tokens). Set it as `HCLOUD_TOKEN` in the environment or in your MCP client config.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### From npm (recommended)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g hcloud-mcp
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Or use `npx` to run without a global install.
|
|
25
|
+
|
|
26
|
+
### From source
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
git clone https://github.com/Xodus-CO/hcloud-mcp
|
|
30
|
+
cd hcloud-mcp
|
|
31
|
+
npm install
|
|
32
|
+
npm run build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
Add the server to your MCP client config. It uses MCP over **stdio** and requires `HCLOUD_TOKEN` in the environment.
|
|
38
|
+
|
|
39
|
+
**Example** — `mcp.json` (or your client’s equivalent) using the npm binary:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"hetzner-cloud": {
|
|
45
|
+
"command": "npx",
|
|
46
|
+
"args": ["hcloud-mcp"],
|
|
47
|
+
"env": {
|
|
48
|
+
"HCLOUD_TOKEN": "your_hetzner_cloud_api_token"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
If you installed from source, use an **absolute path** to `run.js` in `args` so the server runs from the project directory (e.g. when the MCP client’s CWD is different, as in dev containers):
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
"command": "node",
|
|
59
|
+
"args": ["/path/to/hcloud-mcp/run.js"]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Replace `/path/to/hcloud-mcp` with your actual project path (e.g. `/home/<username>/hcloud-mcp`).
|
|
63
|
+
|
|
64
|
+
## Tools
|
|
65
|
+
|
|
66
|
+
The server exposes Hetzner Cloud API operations as MCP tools:
|
|
67
|
+
|
|
68
|
+
| Area | Tools |
|
|
69
|
+
| ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
70
|
+
| **Servers** | `list_servers`, `get_server`, `create_server`, `delete_server`, `update_server`, `change_server_type`; power: `power_on_server`, `power_off_server`, `reboot_server`, `shutdown_server`, `reset_server`; `attach_iso`, `detach_iso`; `attach_server_to_network`, `detach_server_from_network` |
|
|
71
|
+
| **Load Balancers** | `list_load_balancers`, `get_load_balancer`, `create_load_balancer`, `update_load_balancer`, `delete_load_balancer`; `add_load_balancer_target`, `remove_load_balancer_target`; `add_load_balancer_service`, `update_load_balancer_service`, `delete_load_balancer_service`; `list_load_balancer_types` |
|
|
72
|
+
| **Networks** | `list_networks`, `get_network`, `create_network`, `update_network`, `delete_network`; `add_network_subnet`, `delete_network_subnet` |
|
|
73
|
+
| **Volumes** | `list_volumes`, `get_volume`, `create_volume`, `update_volume`, `delete_volume`; `attach_volume`, `detach_volume` |
|
|
74
|
+
| **Firewalls** | `list_firewalls`, `get_firewall`, `create_firewall`, `update_firewall`, `delete_firewall`; `apply_firewall_to_resources`, `remove_firewall_from_resources`, `set_firewall_rules` |
|
|
75
|
+
| **Floating IPs** | `list_floating_ips`, `create_floating_ip`, `update_floating_ip`, `delete_floating_ip`; `assign_floating_ip`, `unassign_floating_ip` |
|
|
76
|
+
| **Primary IPs** | `list_primary_ips`, `create_primary_ip`, `get_primary_ip`, `update_primary_ip`, `delete_primary_ip`; `assign_primary_ip`, `unassign_primary_ip` (server must be off) |
|
|
77
|
+
| **SSH Keys** | `list_ssh_keys`, `create_ssh_key`, `update_ssh_key`, `delete_ssh_key` |
|
|
78
|
+
| **Placement Groups** | `list_placement_groups`, `create_placement_group`, `update_placement_group`, `delete_placement_group` |
|
|
79
|
+
| **Metadata & actions** | `list_locations`, `list_images`, `list_server_types`, `list_load_balancer_types`, `list_datacenters`, `get_pricing`; `list_actions`, `get_action` (poll async operations) |
|
|
80
|
+
|
|
81
|
+
> **Note:** Subnets (not networks) are scoped to a `network_zone` (e.g., `eu-central`). Each Subnet has a `network_zone`; all Subnets within a Network share the same `network_zone`. Servers must be created in locations that match the Subnet's `network_zone`, so resources in the Network are constrained by the shared subnet `network_zone`.
|
|
82
|
+
|
|
83
|
+
## Usage examples
|
|
84
|
+
|
|
85
|
+
With the MCP client connected, you can ask the agent to run tools using natural language.
|
|
86
|
+
|
|
87
|
+
### Simple
|
|
88
|
+
|
|
89
|
+
- _List my servers in Nuremberg_
|
|
90
|
+
- _Create a cx22 server with Ubuntu 24.04_
|
|
91
|
+
- _Create a cx22 server with Ubuntu 24.04 using my SSH key 'macbook'_
|
|
92
|
+
- _Attach a 10GB volume to web-01_
|
|
93
|
+
- _Set up a load balancer for my web servers_
|
|
94
|
+
- _List load balancer types_
|
|
95
|
+
- _Show current pricing for cpx31 servers_
|
|
96
|
+
- _Get status of action 12345_
|
|
97
|
+
|
|
98
|
+
### Complex
|
|
99
|
+
|
|
100
|
+
- _Create a private network 10.0.0.0/16 in eu-central, add a subnet, then create two servers in that zone (e.g. fsn1 and nbg1) and attach them_
|
|
101
|
+
- _Create a firewall for SSH and HTTP, attach to my web servers, then create a load balancer and add those servers as targets_
|
|
102
|
+
- _List running actions and get status of action 12345_
|
|
103
|
+
- _Create a Primary IP in ash-dc1, power off web-01, assign the IP, power back on_
|
|
104
|
+
- _Create a 20GB volume and a cx22 server in nbg1, attach the volume to the server, and show me the device path_
|
|
105
|
+
- _Power off server 12345, change its type to cpx31, then power it back on_
|
|
106
|
+
- _Add server web-02 as a target to my load balancer prod-lb_
|
|
107
|
+
- _Tear down: detach/delete volumes, delete LB and firewall, unassign/delete floating IPs, delete servers web-01 and web-02_
|
|
108
|
+
|
|
109
|
+
## Development
|
|
110
|
+
|
|
111
|
+
| File | Purpose |
|
|
112
|
+
| ----------------------- | ----------------------------------------------------------- |
|
|
113
|
+
| `src/index.ts` | Entry point, stdio transport, `HCLOUD_TOKEN` check |
|
|
114
|
+
| `src/register-tools.ts` | Tool definitions and Hetzner API calls (uses SDK McpServer) |
|
|
115
|
+
|
|
116
|
+
**Scripts:**
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npm run build # compile
|
|
120
|
+
npm run start # run (requires HCLOUD_TOKEN)
|
|
121
|
+
npm run dev # watch and recompile
|
|
122
|
+
npm run test:api # test list_* Hetzner API calls (requires HCLOUD_TOKEN)
|
|
123
|
+
npm run test:mcp # integration test: MCP client calls list_locations (requires HCLOUD_TOKEN)
|
|
124
|
+
npm run audit:api # verify create_* request body shapes (DRY_RUN=1, no resources created)
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { dirname, join } from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { config as loadEnv } from "dotenv";
|
|
4
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
import { OpenAPI } from "hetzner-sdk-ts";
|
|
7
|
+
import { registerTools } from "./register-tools.js";
|
|
8
|
+
// Load .env from project root (parent of dist) so IDE-spawned server finds token when env isn't set
|
|
9
|
+
if (!process.env.HCLOUD_TOKEN) {
|
|
10
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
loadEnv({ path: join(__dirname, "..", ".env") });
|
|
12
|
+
}
|
|
13
|
+
const token = process.env.HCLOUD_TOKEN;
|
|
14
|
+
if (!token) {
|
|
15
|
+
console.error("Error: HCLOUD_TOKEN environment variable is required");
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
OpenAPI.TOKEN = token;
|
|
19
|
+
const server = new McpServer({ name: "hetzner-cloud", version: "0.1.0" }, { capabilities: { tools: {} } });
|
|
20
|
+
registerTools(server);
|
|
21
|
+
async function main() {
|
|
22
|
+
const transport = new StdioServerTransport();
|
|
23
|
+
await server.connect(transport);
|
|
24
|
+
console.error("Hetzner MCP Server running on stdio");
|
|
25
|
+
}
|
|
26
|
+
main().catch((error) => {
|
|
27
|
+
console.error("Fatal error in main():", error);
|
|
28
|
+
process.exit(1);
|
|
29
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
|
+
import { ListToolsRequestSchema, CallToolRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
5
|
+
export class McpServer {
|
|
6
|
+
server;
|
|
7
|
+
tools = new Map();
|
|
8
|
+
constructor(info) {
|
|
9
|
+
this.server = new Server(info, {
|
|
10
|
+
capabilities: {
|
|
11
|
+
tools: {},
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
15
|
+
return {
|
|
16
|
+
tools: Array.from(this.tools.entries()).map(([name, tool]) => ({
|
|
17
|
+
name,
|
|
18
|
+
description: tool.description,
|
|
19
|
+
inputSchema: zodToJsonSchema(tool.parameters),
|
|
20
|
+
})),
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
24
|
+
const tool = this.tools.get(request.params.name);
|
|
25
|
+
if (!tool) {
|
|
26
|
+
throw new McpError(ErrorCode.MethodNotFound, `Tool not found: ${request.params.name}`);
|
|
27
|
+
}
|
|
28
|
+
const args = tool.parameters.safeParse(request.params.arguments);
|
|
29
|
+
if (!args.success) {
|
|
30
|
+
throw new McpError(ErrorCode.InvalidParams, `Invalid arguments: ${args.error.message}`);
|
|
31
|
+
}
|
|
32
|
+
return await tool.handler(args.data);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
tool(name, description, parameters, handler) {
|
|
36
|
+
this.tools.set(name, {
|
|
37
|
+
description,
|
|
38
|
+
parameters: z.object(parameters),
|
|
39
|
+
handler,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async connect(transport) {
|
|
43
|
+
return this.server.connect(transport);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,742 @@
|
|
|
1
|
+
import { ServersService, LoadBalancersService, NetworksService, VolumesService, FirewallsService, FirewallActionsService, FloatingIPsService, SshKeysService, ImagesService, LocationsService, ServerTypesService, PlacementGroupsService, PrimaryIPsService, ServerActionsService, VolumeActionsService, FloatingIpActionsService, LoadBalancerActionsService, NetworkActionsService, PricingService, ActionsService, LoadBalancerTypesService, DatacentersService, PrimaryIpActionsService, } from "hetzner-sdk-ts";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
// Firewall rule: direction, protocol required; source_ips for 'in', destination_ips for 'out'; port for tcp/udp
|
|
4
|
+
const firewallRuleSchema = z.object({
|
|
5
|
+
direction: z.enum(["in", "out"]),
|
|
6
|
+
protocol: z.enum(["tcp", "udp", "icmp", "esp", "gre"]),
|
|
7
|
+
source_ips: z.array(z.string()).optional(),
|
|
8
|
+
destination_ips: z.array(z.string()).optional(),
|
|
9
|
+
port: z.string().optional(),
|
|
10
|
+
description: z.string().nullable().optional(),
|
|
11
|
+
});
|
|
12
|
+
const firewallApplyToSchema = z.object({
|
|
13
|
+
type: z.enum(["server", "label_selector"]),
|
|
14
|
+
server: z.object({ id: z.number() }).optional(),
|
|
15
|
+
label_selector: z.object({ selector: z.string() }).optional(),
|
|
16
|
+
});
|
|
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
|
+
export function registerTools(server) {
|
|
32
|
+
// --- Servers ---
|
|
33
|
+
server.tool("list_servers", "List all servers", {}, async (_args, _extra) => withToolError(async () => {
|
|
34
|
+
const response = await ServersService.getServers({});
|
|
35
|
+
return { content: [{ type: "text", text: JSON.stringify(response.servers, null, 2) }] };
|
|
36
|
+
}));
|
|
37
|
+
server.tool("get_server", "Get a single server by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
38
|
+
const response = await ServersService.getServers1({ id });
|
|
39
|
+
return { content: [{ type: "text", text: JSON.stringify(response.server, null, 2) }] };
|
|
40
|
+
}));
|
|
41
|
+
server.tool("create_server", "Create a new server", {
|
|
42
|
+
name: z.string(),
|
|
43
|
+
server_type: z.string(),
|
|
44
|
+
image: z.string(),
|
|
45
|
+
location: z.string().optional().describe("ID or name (omit if datacenter set)"),
|
|
46
|
+
datacenter: z.string().optional().describe("ID or name (omit if location set)"),
|
|
47
|
+
start_after_create: z.boolean().optional(),
|
|
48
|
+
ssh_keys: z.array(z.union([z.string(), z.number()])).optional().describe("List of SSH key names or IDs"),
|
|
49
|
+
firewalls: z.array(z.object({ firewall: z.number() })).optional(),
|
|
50
|
+
networks: z.array(z.number()).optional(),
|
|
51
|
+
placement_group: z.number().optional().describe("ID of placement group"),
|
|
52
|
+
public_net: z
|
|
53
|
+
.object({
|
|
54
|
+
enable_ipv4: z.boolean().optional(),
|
|
55
|
+
enable_ipv6: z.boolean().optional(),
|
|
56
|
+
ipv4: z.number().nullable().optional(),
|
|
57
|
+
ipv6: z.number().nullable().optional(),
|
|
58
|
+
})
|
|
59
|
+
.optional(),
|
|
60
|
+
user_data: z.string().optional().describe("Cloud-Init user data (max 32KiB)"),
|
|
61
|
+
volumes: z.array(z.number()).optional().describe("Volume IDs to attach at creation"),
|
|
62
|
+
labels: z.record(z.string()).optional(),
|
|
63
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
64
|
+
const requestBody = {
|
|
65
|
+
name: args.name,
|
|
66
|
+
server_type: args.server_type,
|
|
67
|
+
image: args.image,
|
|
68
|
+
location: args.location,
|
|
69
|
+
datacenter: args.datacenter,
|
|
70
|
+
start_after_create: args.start_after_create,
|
|
71
|
+
ssh_keys: args.ssh_keys?.map((k) => (typeof k === "number" ? String(k) : k)),
|
|
72
|
+
firewalls: args.firewalls,
|
|
73
|
+
networks: args.networks,
|
|
74
|
+
placement_group: args.placement_group,
|
|
75
|
+
public_net: args.public_net,
|
|
76
|
+
user_data: args.user_data,
|
|
77
|
+
volumes: args.volumes,
|
|
78
|
+
labels: args.labels,
|
|
79
|
+
};
|
|
80
|
+
const response = await ServersService.postServers({ requestBody });
|
|
81
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
82
|
+
}));
|
|
83
|
+
server.tool("delete_server", "Delete a server", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
84
|
+
const response = await ServersService.deleteServers({ id });
|
|
85
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
86
|
+
}));
|
|
87
|
+
server.tool("change_server_type", "Change the type of a server (scales resources). Server must be powered off.", {
|
|
88
|
+
id: z.number(),
|
|
89
|
+
server_type: z.string().describe("New server type (e.g. cx22)"),
|
|
90
|
+
upgrade_disk: z.boolean().default(true).describe("Whether to upgrade disk size. If true, cannot downgrade later."),
|
|
91
|
+
}, async ({ id, server_type, upgrade_disk }, _extra) => withToolError(async () => {
|
|
92
|
+
const response = await ServerActionsService.postServersActionsChangeType({
|
|
93
|
+
id,
|
|
94
|
+
requestBody: { server_type, upgrade_disk }
|
|
95
|
+
});
|
|
96
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
97
|
+
}));
|
|
98
|
+
server.tool("power_on_server", "Power on a server", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
99
|
+
const response = await ServerActionsService.postServersActionsPoweron({ id });
|
|
100
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
101
|
+
}));
|
|
102
|
+
server.tool("power_off_server", "Power off a server (hard)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
103
|
+
const response = await ServerActionsService.postServersActionsPoweroff({ id });
|
|
104
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
105
|
+
}));
|
|
106
|
+
server.tool("reboot_server", "Reboot a server (soft)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
107
|
+
const response = await ServerActionsService.postServersActionsReboot({ id });
|
|
108
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
109
|
+
}));
|
|
110
|
+
server.tool("shutdown_server", "Shutdown a server (soft)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
111
|
+
const response = await ServerActionsService.postServersActionsShutdown({ id });
|
|
112
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
113
|
+
}));
|
|
114
|
+
server.tool("reset_server", "Reset a server (hard)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
115
|
+
const response = await ServerActionsService.postServersActionsReset({ id });
|
|
116
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
117
|
+
}));
|
|
118
|
+
server.tool("update_server", "Update a server (name, labels)", {
|
|
119
|
+
id: z.number(),
|
|
120
|
+
name: z.string().optional(),
|
|
121
|
+
labels: z.record(z.string()).optional(),
|
|
122
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
123
|
+
const response = await ServersService.putServers({
|
|
124
|
+
id,
|
|
125
|
+
requestBody: { name, labels }
|
|
126
|
+
});
|
|
127
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
128
|
+
}));
|
|
129
|
+
server.tool("attach_iso", "Attach an ISO to a server", {
|
|
130
|
+
id: z.number(),
|
|
131
|
+
iso: z.string().describe("ID or name of the ISO"),
|
|
132
|
+
}, async ({ id, iso }, _extra) => withToolError(async () => {
|
|
133
|
+
const response = await ServerActionsService.postServersActionsAttachIso({
|
|
134
|
+
id,
|
|
135
|
+
requestBody: { iso }
|
|
136
|
+
});
|
|
137
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
138
|
+
}));
|
|
139
|
+
server.tool("detach_iso", "Detach an ISO from a server", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
140
|
+
const response = await ServerActionsService.postServersActionsDetachIso({ id });
|
|
141
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
142
|
+
}));
|
|
143
|
+
server.tool("attach_server_to_network", "Attach a server to a network", {
|
|
144
|
+
id: z.number(),
|
|
145
|
+
network: z.number().describe("ID of the network"),
|
|
146
|
+
ip: z.string().optional().describe("IP to request, otherwise auto-assigned"),
|
|
147
|
+
alias_ips: z.array(z.string()).optional(),
|
|
148
|
+
}, async ({ id, network, ip, alias_ips }, _extra) => withToolError(async () => {
|
|
149
|
+
const response = await ServerActionsService.postServersActionsAttachToNetwork({
|
|
150
|
+
id,
|
|
151
|
+
requestBody: { network, ip, alias_ips }
|
|
152
|
+
});
|
|
153
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
154
|
+
}));
|
|
155
|
+
server.tool("detach_server_from_network", "Detach a server from a network", {
|
|
156
|
+
id: z.number(),
|
|
157
|
+
network: z.number().describe("ID of the network"),
|
|
158
|
+
}, async ({ id, network }, _extra) => withToolError(async () => {
|
|
159
|
+
const response = await ServerActionsService.postServersActionsDetachFromNetwork({
|
|
160
|
+
id,
|
|
161
|
+
requestBody: { network }
|
|
162
|
+
});
|
|
163
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
164
|
+
}));
|
|
165
|
+
// --- Load Balancers ---
|
|
166
|
+
server.tool("list_load_balancers", "List all load balancers", {}, async (_args, _extra) => withToolError(async () => {
|
|
167
|
+
const response = await LoadBalancersService.getLoadBalancers({});
|
|
168
|
+
return { content: [{ type: "text", text: JSON.stringify(response.load_balancers, null, 2) }] };
|
|
169
|
+
}));
|
|
170
|
+
server.tool("get_load_balancer", "Get a single load balancer by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
171
|
+
const response = await LoadBalancersService.getLoadBalancers1({ id });
|
|
172
|
+
return { content: [{ type: "text", text: JSON.stringify(response.load_balancer, null, 2) }] };
|
|
173
|
+
}));
|
|
174
|
+
server.tool("create_load_balancer", "Create a new load balancer", {
|
|
175
|
+
name: z.string(),
|
|
176
|
+
algorithm: z.object({ type: z.enum(["round_robin", "least_connections"]) }).optional(),
|
|
177
|
+
location: z.string(),
|
|
178
|
+
load_balancer_type: z.string(),
|
|
179
|
+
network_zone: z.string().optional(),
|
|
180
|
+
labels: z.record(z.string()).optional(),
|
|
181
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
182
|
+
const requestBody = {
|
|
183
|
+
name: args.name,
|
|
184
|
+
load_balancer_type: args.load_balancer_type,
|
|
185
|
+
location: args.location,
|
|
186
|
+
algorithm: args.algorithm,
|
|
187
|
+
network_zone: args.network_zone,
|
|
188
|
+
labels: args.labels,
|
|
189
|
+
};
|
|
190
|
+
const response = await LoadBalancersService.postLoadBalancers({ requestBody });
|
|
191
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
192
|
+
}));
|
|
193
|
+
server.tool("delete_load_balancer", "Delete a load balancer", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
194
|
+
await LoadBalancersService.deleteLoadBalancers({ id });
|
|
195
|
+
return { content: [{ type: "text", text: "Load Balancer deleted successfully" }] };
|
|
196
|
+
}));
|
|
197
|
+
server.tool("update_load_balancer", "Update a load balancer (name, labels)", {
|
|
198
|
+
id: z.number(),
|
|
199
|
+
name: z.string().optional(),
|
|
200
|
+
labels: z.record(z.string()).optional(),
|
|
201
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
202
|
+
const response = await LoadBalancersService.putLoadBalancers({
|
|
203
|
+
id,
|
|
204
|
+
requestBody: { name, labels }
|
|
205
|
+
});
|
|
206
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
207
|
+
}));
|
|
208
|
+
server.tool("add_load_balancer_target", "Add a target to a load balancer", {
|
|
209
|
+
id: z.number(),
|
|
210
|
+
type: z.enum(["server", "label_selector", "ip"]),
|
|
211
|
+
server: z.object({ id: z.number() }).optional(),
|
|
212
|
+
label_selector: z.object({ selector: z.string() }).optional(),
|
|
213
|
+
ip: z.object({ ip: z.string() }).optional(),
|
|
214
|
+
use_private_ip: z.boolean().optional(),
|
|
215
|
+
}, async ({ id, type, server, label_selector, ip, use_private_ip }, _extra) => withToolError(async () => {
|
|
216
|
+
const response = await LoadBalancerActionsService.postLoadBalancersActionsAddTarget({
|
|
217
|
+
id,
|
|
218
|
+
requestBody: { type, server, label_selector, ip, use_private_ip }
|
|
219
|
+
});
|
|
220
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
221
|
+
}));
|
|
222
|
+
server.tool("remove_load_balancer_target", "Remove a target from a load balancer", {
|
|
223
|
+
id: z.number(),
|
|
224
|
+
type: z.enum(["server", "label_selector", "ip"]),
|
|
225
|
+
server: z.object({ id: z.number() }).optional(),
|
|
226
|
+
label_selector: z.object({ selector: z.string() }).optional(),
|
|
227
|
+
ip: z.object({ ip: z.string() }).optional(),
|
|
228
|
+
}, async ({ id, type, server, label_selector, ip }, _extra) => withToolError(async () => {
|
|
229
|
+
const response = await LoadBalancerActionsService.postLoadBalancersActionsRemoveTarget({
|
|
230
|
+
id,
|
|
231
|
+
requestBody: { type, server, label_selector, ip }
|
|
232
|
+
});
|
|
233
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
234
|
+
}));
|
|
235
|
+
server.tool("add_load_balancer_service", "Add a service to a load balancer", {
|
|
236
|
+
id: z.number(),
|
|
237
|
+
protocol: z.enum(["tcp", "http", "https"]),
|
|
238
|
+
listen_port: z.number(),
|
|
239
|
+
destination_port: z.number(),
|
|
240
|
+
proxyprotocol: z.boolean(),
|
|
241
|
+
health_check: z.object({
|
|
242
|
+
protocol: z.enum(["tcp", "http"]),
|
|
243
|
+
port: z.number(),
|
|
244
|
+
interval: z.number(),
|
|
245
|
+
timeout: z.number(),
|
|
246
|
+
retries: z.number(),
|
|
247
|
+
http: z.object({
|
|
248
|
+
domain: z.string().nullable().optional(),
|
|
249
|
+
path: z.string().optional(),
|
|
250
|
+
response: z.string().optional(),
|
|
251
|
+
status_codes: z.array(z.string()).optional(),
|
|
252
|
+
tls: z.boolean().optional(),
|
|
253
|
+
}).optional(),
|
|
254
|
+
}).optional(),
|
|
255
|
+
http: z.object({
|
|
256
|
+
cookie_name: z.string().optional(),
|
|
257
|
+
cookie_lifetime: z.number().optional(),
|
|
258
|
+
certificates: z.array(z.number()).optional(),
|
|
259
|
+
redirect_http: z.boolean().optional(),
|
|
260
|
+
sticky_sessions: z.boolean().optional(),
|
|
261
|
+
}).optional(),
|
|
262
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
263
|
+
const { id, ...body } = args;
|
|
264
|
+
const response = await LoadBalancerActionsService.postLoadBalancersActionsAddService({
|
|
265
|
+
id,
|
|
266
|
+
requestBody: body
|
|
267
|
+
});
|
|
268
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
269
|
+
}));
|
|
270
|
+
server.tool("delete_load_balancer_service", "Delete a service from a load balancer", {
|
|
271
|
+
id: z.number(),
|
|
272
|
+
listen_port: z.number(),
|
|
273
|
+
}, async ({ id, listen_port }, _extra) => withToolError(async () => {
|
|
274
|
+
const response = await LoadBalancerActionsService.postLoadBalancersActionsDeleteService({
|
|
275
|
+
id,
|
|
276
|
+
requestBody: { listen_port }
|
|
277
|
+
});
|
|
278
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
279
|
+
}));
|
|
280
|
+
server.tool("update_load_balancer_service", "Update a load balancer service (listen_port identifies the service)", {
|
|
281
|
+
id: z.number().describe("Load balancer ID"),
|
|
282
|
+
listen_port: z.number().describe("Listen port of the service to update"),
|
|
283
|
+
destination_port: z.number().optional(),
|
|
284
|
+
protocol: z.enum(["tcp", "http", "https"]).optional(),
|
|
285
|
+
proxyprotocol: z.boolean().optional(),
|
|
286
|
+
health_check: z
|
|
287
|
+
.object({
|
|
288
|
+
protocol: z.enum(["tcp", "http"]),
|
|
289
|
+
port: z.number(),
|
|
290
|
+
interval: z.number(),
|
|
291
|
+
timeout: z.number(),
|
|
292
|
+
retries: z.number(),
|
|
293
|
+
http: z
|
|
294
|
+
.object({
|
|
295
|
+
domain: z.string().nullable().optional(),
|
|
296
|
+
path: z.string().optional(),
|
|
297
|
+
response: z.string().optional(),
|
|
298
|
+
status_codes: z.array(z.string()).optional(),
|
|
299
|
+
tls: z.boolean().optional(),
|
|
300
|
+
})
|
|
301
|
+
.optional(),
|
|
302
|
+
})
|
|
303
|
+
.optional(),
|
|
304
|
+
http: z
|
|
305
|
+
.object({
|
|
306
|
+
cookie_name: z.string().optional(),
|
|
307
|
+
cookie_lifetime: z.number().optional(),
|
|
308
|
+
certificates: z.array(z.number()).optional(),
|
|
309
|
+
redirect_http: z.boolean().optional(),
|
|
310
|
+
sticky_sessions: z.boolean().optional(),
|
|
311
|
+
})
|
|
312
|
+
.optional(),
|
|
313
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
314
|
+
const { id, listen_port, ...body } = args;
|
|
315
|
+
const response = await LoadBalancerActionsService.postLoadBalancersActionsUpdateService({
|
|
316
|
+
id,
|
|
317
|
+
requestBody: { listen_port, ...body }
|
|
318
|
+
});
|
|
319
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
320
|
+
}));
|
|
321
|
+
// --- Networks ---
|
|
322
|
+
server.tool("list_networks", "List all networks", {}, async (_args, _extra) => withToolError(async () => {
|
|
323
|
+
const response = await NetworksService.getNetworks({});
|
|
324
|
+
return { content: [{ type: "text", text: JSON.stringify(response.networks, null, 2) }] };
|
|
325
|
+
}));
|
|
326
|
+
server.tool("get_network", "Get a single network by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
327
|
+
const response = await NetworksService.getNetworks1({ id });
|
|
328
|
+
return { content: [{ type: "text", text: JSON.stringify(response.network, null, 2) }] };
|
|
329
|
+
}));
|
|
330
|
+
server.tool("create_network", "Create a new network", {
|
|
331
|
+
name: z.string(),
|
|
332
|
+
ip_range: z.string(),
|
|
333
|
+
expose_routes_to_vswitch: z.boolean().optional(),
|
|
334
|
+
routes: z
|
|
335
|
+
.array(z.object({ destination: z.string(), gateway: z.string() }))
|
|
336
|
+
.optional()
|
|
337
|
+
.describe("Routes: destination (CIDR), gateway (IP)"),
|
|
338
|
+
labels: z.record(z.string()).optional(),
|
|
339
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
340
|
+
const requestBody = {
|
|
341
|
+
name: args.name,
|
|
342
|
+
ip_range: args.ip_range,
|
|
343
|
+
expose_routes_to_vswitch: args.expose_routes_to_vswitch,
|
|
344
|
+
routes: args.routes,
|
|
345
|
+
labels: args.labels,
|
|
346
|
+
};
|
|
347
|
+
const response = await NetworksService.postNetworks({ requestBody });
|
|
348
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
349
|
+
}));
|
|
350
|
+
server.tool("delete_network", "Delete a network", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
351
|
+
await NetworksService.deleteNetworks({ id });
|
|
352
|
+
return { content: [{ type: "text", text: "Network deleted successfully" }] };
|
|
353
|
+
}));
|
|
354
|
+
server.tool("update_network", "Update a network (name, labels)", {
|
|
355
|
+
id: z.number(),
|
|
356
|
+
name: z.string().optional(),
|
|
357
|
+
labels: z.record(z.string()).optional(),
|
|
358
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
359
|
+
const response = await NetworksService.putNetworks({
|
|
360
|
+
id,
|
|
361
|
+
requestBody: { name, labels }
|
|
362
|
+
});
|
|
363
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
364
|
+
}));
|
|
365
|
+
server.tool("add_network_subnet", "Add a subnet to a network (e.g. for private networking 10.0.0.0/16 in a zone)", {
|
|
366
|
+
id: z.number().describe("Network ID"),
|
|
367
|
+
type: z.enum(["cloud", "server", "vswitch"]),
|
|
368
|
+
network_zone: z.string().describe("Network zone, e.g. eu-central"),
|
|
369
|
+
ip_range: z.string().optional().describe("CIDR, e.g. 10.0.0.0/24; omit for auto /24"),
|
|
370
|
+
vswitch_id: z.number().optional().describe("Required if type is vswitch"),
|
|
371
|
+
}, async ({ id, type, network_zone, ip_range, vswitch_id }, _extra) => withToolError(async () => {
|
|
372
|
+
const response = await NetworkActionsService.postNetworksActionsAddSubnet({
|
|
373
|
+
id,
|
|
374
|
+
requestBody: { type, network_zone, ip_range, vswitch_id }
|
|
375
|
+
});
|
|
376
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
377
|
+
}));
|
|
378
|
+
server.tool("delete_network_subnet", "Delete a subnet from a network (detach servers from it first)", {
|
|
379
|
+
id: z.number().describe("Network ID"),
|
|
380
|
+
ip_range: z.string().describe("IP range of subnet to delete, e.g. 10.0.1.0/24"),
|
|
381
|
+
}, async ({ id, ip_range }, _extra) => withToolError(async () => {
|
|
382
|
+
const response = await NetworkActionsService.postNetworksActionsDeleteSubnet({
|
|
383
|
+
id,
|
|
384
|
+
requestBody: { ip_range }
|
|
385
|
+
});
|
|
386
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
387
|
+
}));
|
|
388
|
+
// --- Volumes ---
|
|
389
|
+
server.tool("list_volumes", "List all volumes", {}, async (_args, _extra) => withToolError(async () => {
|
|
390
|
+
const response = await VolumesService.getVolumes({});
|
|
391
|
+
return { content: [{ type: "text", text: JSON.stringify(response.volumes, null, 2) }] };
|
|
392
|
+
}));
|
|
393
|
+
server.tool("get_volume", "Get a single volume by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
394
|
+
const response = await VolumesService.getVolumes1({ id });
|
|
395
|
+
return { content: [{ type: "text", text: JSON.stringify(response.volume, null, 2) }] };
|
|
396
|
+
}));
|
|
397
|
+
server.tool("create_volume", "Create a new volume", {
|
|
398
|
+
name: z.string(),
|
|
399
|
+
size: z.number(),
|
|
400
|
+
automount: z.boolean().optional(),
|
|
401
|
+
format: z.string().optional(),
|
|
402
|
+
location: z.string().optional(),
|
|
403
|
+
server: z.number().optional(),
|
|
404
|
+
labels: z.record(z.string()).optional(),
|
|
405
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
406
|
+
const requestBody = {
|
|
407
|
+
name: args.name,
|
|
408
|
+
size: args.size,
|
|
409
|
+
automount: args.automount,
|
|
410
|
+
format: args.format,
|
|
411
|
+
location: args.location,
|
|
412
|
+
server: args.server,
|
|
413
|
+
labels: args.labels,
|
|
414
|
+
};
|
|
415
|
+
const response = await VolumesService.postVolumes({ requestBody });
|
|
416
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
417
|
+
}));
|
|
418
|
+
server.tool("update_volume", "Update a volume (name, labels)", {
|
|
419
|
+
id: z.number(),
|
|
420
|
+
name: z.string().optional(),
|
|
421
|
+
labels: z.record(z.string()).optional(),
|
|
422
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
423
|
+
const response = await VolumesService.putVolumes({
|
|
424
|
+
id,
|
|
425
|
+
requestBody: { name, labels }
|
|
426
|
+
});
|
|
427
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
428
|
+
}));
|
|
429
|
+
server.tool("attach_volume", "Attach a volume to a server", {
|
|
430
|
+
id: z.number(),
|
|
431
|
+
server: z.number(),
|
|
432
|
+
automount: z.boolean().optional(),
|
|
433
|
+
}, async ({ id, server, automount }, _extra) => withToolError(async () => {
|
|
434
|
+
const response = await VolumeActionsService.postVolumesActionsAttach({
|
|
435
|
+
id,
|
|
436
|
+
requestBody: { server, automount }
|
|
437
|
+
});
|
|
438
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
439
|
+
}));
|
|
440
|
+
server.tool("detach_volume", "Detach a volume", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
441
|
+
const response = await VolumeActionsService.postVolumesActionsDetach({ id });
|
|
442
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
443
|
+
}));
|
|
444
|
+
server.tool("delete_volume", "Delete a volume (must be detached; all data destroyed)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
445
|
+
await VolumesService.deleteVolumes({ id });
|
|
446
|
+
return { content: [{ type: "text", text: "Volume deleted successfully" }] };
|
|
447
|
+
}));
|
|
448
|
+
// --- Firewalls ---
|
|
449
|
+
server.tool("list_firewalls", "List all firewalls", {}, async (_args, _extra) => withToolError(async () => {
|
|
450
|
+
const response = await FirewallsService.getFirewalls({});
|
|
451
|
+
return { content: [{ type: "text", text: JSON.stringify(response.firewalls, null, 2) }] };
|
|
452
|
+
}));
|
|
453
|
+
server.tool("get_firewall", "Get a single firewall by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
454
|
+
const response = await FirewallsService.getFirewalls1({ id });
|
|
455
|
+
return { content: [{ type: "text", text: JSON.stringify(response.firewall, null, 2) }] };
|
|
456
|
+
}));
|
|
457
|
+
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.", {
|
|
458
|
+
name: z.string(),
|
|
459
|
+
rules: z.array(firewallRuleSchema).optional(),
|
|
460
|
+
apply_to: z.array(firewallApplyToSchema).optional().describe("Apply firewall to these servers or label_selector after creation"),
|
|
461
|
+
labels: z.record(z.string()).optional(),
|
|
462
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
463
|
+
const body = {
|
|
464
|
+
name: args.name,
|
|
465
|
+
rules: args.rules,
|
|
466
|
+
labels: args.labels,
|
|
467
|
+
apply_to: args.apply_to,
|
|
468
|
+
};
|
|
469
|
+
const response = await FirewallsService.postFirewalls({ requestBody: body });
|
|
470
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
471
|
+
}));
|
|
472
|
+
server.tool("update_firewall", "Update a firewall (name, labels)", {
|
|
473
|
+
id: z.number(),
|
|
474
|
+
name: z.string().optional(),
|
|
475
|
+
labels: z.record(z.string()).optional(),
|
|
476
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
477
|
+
const response = await FirewallsService.putFirewalls({
|
|
478
|
+
id,
|
|
479
|
+
requestBody: { name, labels }
|
|
480
|
+
});
|
|
481
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
482
|
+
}));
|
|
483
|
+
server.tool("delete_firewall", "Delete a firewall (must not be in use)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
484
|
+
await FirewallsService.deleteFirewalls({ id });
|
|
485
|
+
return { content: [{ type: "text", text: "Firewall deleted successfully" }] };
|
|
486
|
+
}));
|
|
487
|
+
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' } }].", {
|
|
488
|
+
id: z.number().describe("Firewall ID"),
|
|
489
|
+
apply_to: z.array(firewallApplyToSchema),
|
|
490
|
+
}, async ({ id, apply_to }, _extra) => withToolError(async () => {
|
|
491
|
+
const response = await FirewallActionsService.postFirewallsActionsApplyToResources({ id, requestBody: { apply_to } });
|
|
492
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
493
|
+
}));
|
|
494
|
+
server.tool("remove_firewall_from_resources", "Remove a firewall from servers. Pass remove_from: [{ type: 'server', server: { id: 123 } }].", {
|
|
495
|
+
id: z.number().describe("Firewall ID"),
|
|
496
|
+
remove_from: z.array(z.object({
|
|
497
|
+
type: z.literal("server"),
|
|
498
|
+
server: z.object({ id: z.number() }),
|
|
499
|
+
})),
|
|
500
|
+
}, async ({ id, remove_from }, _extra) => withToolError(async () => {
|
|
501
|
+
const response = await FirewallActionsService.postFirewallsActionsRemoveFromResources({ id, requestBody: { remove_from } });
|
|
502
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
503
|
+
}));
|
|
504
|
+
server.tool("set_firewall_rules", "Set rules on an existing firewall (overwrites all rules). Same rule format as create_firewall.", {
|
|
505
|
+
id: z.number().describe("Firewall ID"),
|
|
506
|
+
rules: z.array(firewallRuleSchema),
|
|
507
|
+
}, async ({ id, rules }, _extra) => withToolError(async () => {
|
|
508
|
+
const response = await FirewallActionsService.postFirewallsActionsSetRules({ id, requestBody: { rules } });
|
|
509
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
510
|
+
}));
|
|
511
|
+
// --- Floating IPs ---
|
|
512
|
+
server.tool("list_floating_ips", "List all floating IPs", {}, async (_args, _extra) => withToolError(async () => {
|
|
513
|
+
const response = await FloatingIPsService.getFloatingIps({});
|
|
514
|
+
return { content: [{ type: "text", text: JSON.stringify(response.floating_ips, null, 2) }] };
|
|
515
|
+
}));
|
|
516
|
+
server.tool("create_floating_ip", "Create a floating IP", {
|
|
517
|
+
type: z.enum(["ipv4", "ipv6"]),
|
|
518
|
+
home_location: z.string().optional(),
|
|
519
|
+
server: z.number().optional(),
|
|
520
|
+
description: z.string().optional(),
|
|
521
|
+
labels: z.record(z.string()).optional(),
|
|
522
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
523
|
+
const requestBody = {
|
|
524
|
+
type: args.type,
|
|
525
|
+
home_location: args.home_location,
|
|
526
|
+
server: args.server,
|
|
527
|
+
description: args.description,
|
|
528
|
+
labels: args.labels,
|
|
529
|
+
};
|
|
530
|
+
const response = await FloatingIPsService.postFloatingIps({ requestBody });
|
|
531
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
532
|
+
}));
|
|
533
|
+
server.tool("update_floating_ip", "Update a floating IP (description, labels)", {
|
|
534
|
+
id: z.number(),
|
|
535
|
+
description: z.string().optional(),
|
|
536
|
+
labels: z.record(z.string()).optional(),
|
|
537
|
+
}, async ({ id, description, labels }, _extra) => withToolError(async () => {
|
|
538
|
+
const response = await FloatingIPsService.putFloatingIps({
|
|
539
|
+
id,
|
|
540
|
+
requestBody: { description, labels }
|
|
541
|
+
});
|
|
542
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
543
|
+
}));
|
|
544
|
+
server.tool("assign_floating_ip", "Assign a floating IP to a server", {
|
|
545
|
+
id: z.number(),
|
|
546
|
+
server: z.number(),
|
|
547
|
+
}, async ({ id, server }, _extra) => withToolError(async () => {
|
|
548
|
+
const response = await FloatingIpActionsService.postFloatingIpsActionsAssign({
|
|
549
|
+
id,
|
|
550
|
+
requestBody: { server }
|
|
551
|
+
});
|
|
552
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
553
|
+
}));
|
|
554
|
+
server.tool("unassign_floating_ip", "Unassign a floating IP", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
555
|
+
const response = await FloatingIpActionsService.postFloatingIpsActionsUnassign({ id });
|
|
556
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
557
|
+
}));
|
|
558
|
+
server.tool("delete_floating_ip", "Delete a floating IP (unassigns from server if attached)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
559
|
+
await FloatingIPsService.deleteFloatingIps({ id });
|
|
560
|
+
return { content: [{ type: "text", text: "Floating IP deleted successfully" }] };
|
|
561
|
+
}));
|
|
562
|
+
// --- Primary IPs ---
|
|
563
|
+
server.tool("list_primary_ips", "List all Primary IPs (static IPs bound to a datacenter, assignable to one server)", {}, async (_args, _extra) => withToolError(async () => {
|
|
564
|
+
const response = await PrimaryIPsService.getPrimaryIps({});
|
|
565
|
+
return { content: [{ type: "text", text: JSON.stringify(response.primary_ips, null, 2) }] };
|
|
566
|
+
}));
|
|
567
|
+
server.tool("create_primary_ip", "Create a Primary IP (datacenter-scoped; server must be off to assign). Provide datacenter OR assignee_id (server).", {
|
|
568
|
+
name: z.string(),
|
|
569
|
+
type: z.enum(["ipv4", "ipv6"]),
|
|
570
|
+
datacenter: z.string().optional().describe("ID or name of datacenter (omit if assignee_id set)"),
|
|
571
|
+
assignee_id: z.number().optional().describe("Server ID to assign to immediately (omit if datacenter set)"),
|
|
572
|
+
auto_delete: z.boolean().optional(),
|
|
573
|
+
labels: z.record(z.string()).optional(),
|
|
574
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
575
|
+
const hasDatacenter = args.datacenter != null && args.datacenter !== "";
|
|
576
|
+
const hasAssignee = args.assignee_id != null;
|
|
577
|
+
if (hasDatacenter === hasAssignee) {
|
|
578
|
+
throw new Error("Provide exactly one of datacenter or assignee_id (mutually exclusive)");
|
|
579
|
+
}
|
|
580
|
+
const requestBody = {
|
|
581
|
+
name: args.name,
|
|
582
|
+
type: args.type,
|
|
583
|
+
assignee_type: "server",
|
|
584
|
+
datacenter: args.datacenter,
|
|
585
|
+
assignee_id: args.assignee_id,
|
|
586
|
+
auto_delete: args.auto_delete,
|
|
587
|
+
labels: args.labels,
|
|
588
|
+
};
|
|
589
|
+
const response = await PrimaryIPsService.postPrimaryIps({ requestBody });
|
|
590
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
591
|
+
}));
|
|
592
|
+
server.tool("get_primary_ip", "Get a single Primary IP by ID", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
593
|
+
const response = await PrimaryIPsService.getPrimaryIps1({ id });
|
|
594
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
595
|
+
}));
|
|
596
|
+
server.tool("update_primary_ip", "Update a Primary IP (name, labels)", {
|
|
597
|
+
id: z.number(),
|
|
598
|
+
name: z.string().optional(),
|
|
599
|
+
labels: z.record(z.string()).optional(),
|
|
600
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
601
|
+
const response = await PrimaryIPsService.putPrimaryIps({
|
|
602
|
+
id,
|
|
603
|
+
requestBody: { name, labels }
|
|
604
|
+
});
|
|
605
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
606
|
+
}));
|
|
607
|
+
server.tool("delete_primary_ip", "Delete a Primary IP (unassigns from server if assigned; server must be off)", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
608
|
+
await PrimaryIPsService.deletePrimaryIps({ id });
|
|
609
|
+
return { content: [{ type: "text", text: "Primary IP deleted successfully" }] };
|
|
610
|
+
}));
|
|
611
|
+
server.tool("assign_primary_ip", "Assign a Primary IP to a server (server must be powered off)", {
|
|
612
|
+
id: z.number().describe("Primary IP ID"),
|
|
613
|
+
server: z.number().describe("Server ID"),
|
|
614
|
+
}, async ({ id, server }, _extra) => withToolError(async () => {
|
|
615
|
+
const response = await PrimaryIpActionsService.postPrimaryIpsActionsAssign({
|
|
616
|
+
id,
|
|
617
|
+
requestBody: { assignee_id: server, assignee_type: "server" }
|
|
618
|
+
});
|
|
619
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
620
|
+
}));
|
|
621
|
+
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 () => {
|
|
622
|
+
const response = await PrimaryIpActionsService.postPrimaryIpsActionsUnassign({ id });
|
|
623
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
624
|
+
}));
|
|
625
|
+
// --- SSH Keys ---
|
|
626
|
+
server.tool("list_ssh_keys", "List all SSH keys", {}, async (_args, _extra) => withToolError(async () => {
|
|
627
|
+
const response = await SshKeysService.getSshKeys({});
|
|
628
|
+
return { content: [{ type: "text", text: JSON.stringify(response.ssh_keys, null, 2) }] };
|
|
629
|
+
}));
|
|
630
|
+
server.tool("create_ssh_key", "Create a new SSH key", {
|
|
631
|
+
name: z.string(),
|
|
632
|
+
public_key: z.string(),
|
|
633
|
+
labels: z.record(z.string()).optional(),
|
|
634
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
635
|
+
const requestBody = {
|
|
636
|
+
name: args.name,
|
|
637
|
+
public_key: args.public_key,
|
|
638
|
+
labels: args.labels,
|
|
639
|
+
};
|
|
640
|
+
const response = await SshKeysService.postSshKeys({ requestBody });
|
|
641
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
642
|
+
}));
|
|
643
|
+
server.tool("update_ssh_key", "Update an SSH key (name, labels)", {
|
|
644
|
+
id: z.number(),
|
|
645
|
+
name: z.string().optional(),
|
|
646
|
+
labels: z.record(z.string()).optional(),
|
|
647
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
648
|
+
const response = await SshKeysService.putSshKeys({
|
|
649
|
+
id,
|
|
650
|
+
requestBody: { name, labels }
|
|
651
|
+
});
|
|
652
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
653
|
+
}));
|
|
654
|
+
server.tool("delete_ssh_key", "Delete an SSH key", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
655
|
+
await SshKeysService.deleteSshKeys({ id });
|
|
656
|
+
return { content: [{ type: "text", text: "SSH key deleted successfully" }] };
|
|
657
|
+
}));
|
|
658
|
+
// --- General Info ---
|
|
659
|
+
server.tool("list_locations", "List all locations", {}, async (_args, _extra) => withToolError(async () => {
|
|
660
|
+
const response = await LocationsService.getLocations({});
|
|
661
|
+
return { content: [{ type: "text", text: JSON.stringify(response.locations, null, 2) }] };
|
|
662
|
+
}));
|
|
663
|
+
server.tool("list_images", "List all images", {}, async (_args, _extra) => withToolError(async () => {
|
|
664
|
+
const response = await ImagesService.getImages({});
|
|
665
|
+
return { content: [{ type: "text", text: JSON.stringify(response.images, null, 2) }] };
|
|
666
|
+
}));
|
|
667
|
+
server.tool("list_server_types", "List all server types", {}, async (_args, _extra) => withToolError(async () => {
|
|
668
|
+
const response = await ServerTypesService.getServerTypes({});
|
|
669
|
+
return { content: [{ type: "text", text: JSON.stringify(response.server_types, null, 2) }] };
|
|
670
|
+
}));
|
|
671
|
+
server.tool("list_load_balancer_types", "List all load balancer types (for create_load_balancer load_balancer_type)", {}, async (_args, _extra) => withToolError(async () => {
|
|
672
|
+
const response = await LoadBalancerTypesService.getLoadBalancerTypes({});
|
|
673
|
+
return { content: [{ type: "text", text: JSON.stringify(response.load_balancer_types, null, 2) }] };
|
|
674
|
+
}));
|
|
675
|
+
server.tool("list_datacenters", "List all datacenters (e.g. ash-dc1; where servers can be created)", {}, async (_args, _extra) => withToolError(async () => {
|
|
676
|
+
const response = await DatacentersService.getDatacenters({});
|
|
677
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
678
|
+
}));
|
|
679
|
+
server.tool("list_actions", "List actions (optionally filter by id, status); use to poll/wait for create/delete results", {
|
|
680
|
+
id: z.number().optional(),
|
|
681
|
+
status: z.enum(["running", "success", "error"]).optional(),
|
|
682
|
+
sort: z
|
|
683
|
+
.enum([
|
|
684
|
+
"id", "id:asc", "id:desc", "command", "command:asc", "command:desc",
|
|
685
|
+
"status", "status:asc", "status:desc", "started", "started:asc", "started:desc",
|
|
686
|
+
"finished", "finished:asc", "finished:desc",
|
|
687
|
+
])
|
|
688
|
+
.optional(),
|
|
689
|
+
page: z.number().optional(),
|
|
690
|
+
per_page: z.number().optional(),
|
|
691
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
692
|
+
const response = await ActionsService.getActions({
|
|
693
|
+
id: args.id,
|
|
694
|
+
status: args.status,
|
|
695
|
+
sort: args.sort,
|
|
696
|
+
page: args.page,
|
|
697
|
+
perPage: args.per_page,
|
|
698
|
+
});
|
|
699
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
700
|
+
}));
|
|
701
|
+
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 () => {
|
|
702
|
+
const response = await ActionsService.getActions1({ id });
|
|
703
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
704
|
+
}));
|
|
705
|
+
server.tool("get_pricing", "Get all prices", {}, async (_args, _extra) => withToolError(async () => {
|
|
706
|
+
const response = await PricingService.getPricing();
|
|
707
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
708
|
+
}));
|
|
709
|
+
// --- Placement Groups ---
|
|
710
|
+
server.tool("list_placement_groups", "List all placement groups", {}, async (_args, _extra) => withToolError(async () => {
|
|
711
|
+
const response = await PlacementGroupsService.getPlacementGroups({});
|
|
712
|
+
return { content: [{ type: "text", text: JSON.stringify(response.placement_groups, null, 2) }] };
|
|
713
|
+
}));
|
|
714
|
+
server.tool("create_placement_group", "Create a new placement group", {
|
|
715
|
+
name: z.string(),
|
|
716
|
+
type: z.enum(["spread"]),
|
|
717
|
+
labels: z.record(z.string()).optional(),
|
|
718
|
+
}, async (args, _extra) => withToolError(async () => {
|
|
719
|
+
const requestBody = {
|
|
720
|
+
name: args.name,
|
|
721
|
+
type: args.type,
|
|
722
|
+
labels: args.labels,
|
|
723
|
+
};
|
|
724
|
+
const response = await PlacementGroupsService.postPlacementGroups({ requestBody });
|
|
725
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
726
|
+
}));
|
|
727
|
+
server.tool("delete_placement_group", "Delete a placement group", { id: z.number() }, async ({ id }, _extra) => withToolError(async () => {
|
|
728
|
+
await PlacementGroupsService.deletePlacementGroups({ id });
|
|
729
|
+
return { content: [{ type: "text", text: "Placement Group deleted successfully" }] };
|
|
730
|
+
}));
|
|
731
|
+
server.tool("update_placement_group", "Update a placement group (name, labels)", {
|
|
732
|
+
id: z.number(),
|
|
733
|
+
name: z.string().optional(),
|
|
734
|
+
labels: z.record(z.string()).optional(),
|
|
735
|
+
}, async ({ id, name, labels }, _extra) => withToolError(async () => {
|
|
736
|
+
const response = await PlacementGroupsService.putPlacementGroups({
|
|
737
|
+
id,
|
|
738
|
+
requestBody: { name, labels }
|
|
739
|
+
});
|
|
740
|
+
return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }] };
|
|
741
|
+
}));
|
|
742
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hcloud-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Standalone MCP server for Hetzner Cloud API — use with Cursor, Claude Desktop, CLI, or any MCP client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"hcloud-mcp": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepublishOnly": "npm run build",
|
|
13
|
+
"start": "node dist/index.js",
|
|
14
|
+
"dev": "tsc --watch",
|
|
15
|
+
"test:api": "node scripts/test-list-api.mjs",
|
|
16
|
+
"test:mcp": "node scripts/test-mcp-list.mjs",
|
|
17
|
+
"audit:api": "cross-env DRY_RUN=1 node scripts/audit-api-shapes.mjs"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"mcp",
|
|
21
|
+
"hetzner",
|
|
22
|
+
"hcloud",
|
|
23
|
+
"model-context-protocol"
|
|
24
|
+
],
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"repository": "github:Xodus-CO/hcloud-mcp",
|
|
27
|
+
"homepage": "https://github.com/Xodus-CO/hcloud-mcp#readme",
|
|
28
|
+
"bugs": "https://github.com/Xodus-CO/hcloud-mcp/issues",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
31
|
+
"dotenv": "^17.3.1",
|
|
32
|
+
"hetzner-sdk-ts": "^1.0.1",
|
|
33
|
+
"zod": "^3.23.8",
|
|
34
|
+
"zod-to-json-schema": "^3.25.1"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^20.12.7",
|
|
38
|
+
"cross-env": "^7.0.3",
|
|
39
|
+
"typescript": "^5.4.5"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/run.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Launcher that runs the MCP server from the project directory regardless of CWD.
|
|
4
|
+
* Use an absolute path in MCP config when Cursor runs from a different directory
|
|
5
|
+
* (e.g. dev containers where CWD may be /root):
|
|
6
|
+
* "args": ["/path/to/hcloud-mcp/run.js"]
|
|
7
|
+
*/
|
|
8
|
+
import { dirname } from "path";
|
|
9
|
+
import { fileURLToPath } from "url";
|
|
10
|
+
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
process.chdir(__dirname);
|
|
13
|
+
await import("./dist/index.js");
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Audit script: verify request body shapes for create_* tools match the Hetzner API.
|
|
3
|
+
* Builds minimal valid payloads and calls the SDK.
|
|
4
|
+
* With DRY_RUN=1: uses invalid token so requests fail with 401 (no resources created).
|
|
5
|
+
* With real token: makes real API calls and may create resources.
|
|
6
|
+
* Run from project root: node scripts/audit-api-shapes.mjs
|
|
7
|
+
*/
|
|
8
|
+
import "dotenv/config";
|
|
9
|
+
import {
|
|
10
|
+
ServersService,
|
|
11
|
+
LoadBalancersService,
|
|
12
|
+
NetworksService,
|
|
13
|
+
VolumesService,
|
|
14
|
+
FloatingIPsService,
|
|
15
|
+
SshKeysService,
|
|
16
|
+
PlacementGroupsService,
|
|
17
|
+
OpenAPI,
|
|
18
|
+
} from "hetzner-sdk-ts";
|
|
19
|
+
|
|
20
|
+
let token = process.env.HCLOUD_TOKEN;
|
|
21
|
+
if (!token) {
|
|
22
|
+
console.error("Error: HCLOUD_TOKEN environment variable is required");
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
if (process.env.DRY_RUN === "1") {
|
|
26
|
+
token = "invalid";
|
|
27
|
+
console.log(
|
|
28
|
+
"DRY_RUN=1: using invalid token (no resources will be created)\n",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
OpenAPI.TOKEN = token;
|
|
32
|
+
|
|
33
|
+
function ok(name, err) {
|
|
34
|
+
const msg = err?.message || String(err);
|
|
35
|
+
if (msg.includes("Unauthorized") || msg.includes("401")) {
|
|
36
|
+
console.log(
|
|
37
|
+
`${name}: OK (request shape accepted, auth failed as expected or token invalid)`,
|
|
38
|
+
);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (msg.includes("invalid") || msg.includes("400")) {
|
|
42
|
+
console.error(`${name}: FAIL - API rejected payload:`, msg);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
console.error(`${name}: FAIL -`, msg);
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function run() {
|
|
50
|
+
let failed = 0;
|
|
51
|
+
|
|
52
|
+
console.log("Auditing create_* request body shapes...\n");
|
|
53
|
+
|
|
54
|
+
// create_server
|
|
55
|
+
try {
|
|
56
|
+
await ServersService.postServers({
|
|
57
|
+
requestBody: {
|
|
58
|
+
name: "audit-test-server",
|
|
59
|
+
server_type: "cx11",
|
|
60
|
+
image: "ubuntu-24.04",
|
|
61
|
+
location: "fsn1",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
console.log("create_server: OK (request sent)");
|
|
65
|
+
} catch (e) {
|
|
66
|
+
if (!ok("create_server", e)) failed++;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// create_load_balancer
|
|
70
|
+
try {
|
|
71
|
+
await LoadBalancersService.postLoadBalancers({
|
|
72
|
+
requestBody: {
|
|
73
|
+
name: "audit-test-lb",
|
|
74
|
+
load_balancer_type: "lb11",
|
|
75
|
+
location: "fsn1",
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
console.log("create_load_balancer: OK (request sent)");
|
|
79
|
+
} catch (e) {
|
|
80
|
+
if (!ok("create_load_balancer", e)) failed++;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// create_network
|
|
84
|
+
try {
|
|
85
|
+
await NetworksService.postNetworks({
|
|
86
|
+
requestBody: {
|
|
87
|
+
name: "audit-test-network",
|
|
88
|
+
ip_range: "10.0.0.0/16",
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
console.log("create_network: OK (request sent)");
|
|
92
|
+
} catch (e) {
|
|
93
|
+
if (!ok("create_network", e)) failed++;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// create_volume
|
|
97
|
+
try {
|
|
98
|
+
await VolumesService.postVolumes({
|
|
99
|
+
requestBody: {
|
|
100
|
+
name: "audit-test-volume",
|
|
101
|
+
size: 10,
|
|
102
|
+
location: "fsn1",
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
console.log("create_volume: OK (request sent)");
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (!ok("create_volume", e)) failed++;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// create_floating_ip
|
|
111
|
+
try {
|
|
112
|
+
await FloatingIPsService.postFloatingIps({
|
|
113
|
+
requestBody: {
|
|
114
|
+
type: "ipv4",
|
|
115
|
+
home_location: "fsn1",
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
console.log("create_floating_ip: OK (request sent)");
|
|
119
|
+
} catch (e) {
|
|
120
|
+
if (!ok("create_floating_ip", e)) failed++;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// create_ssh_key
|
|
124
|
+
try {
|
|
125
|
+
await SshKeysService.postSshKeys({
|
|
126
|
+
requestBody: {
|
|
127
|
+
name: "audit-test-key",
|
|
128
|
+
public_key:
|
|
129
|
+
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAI audit-test-invalid-key",
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
console.log("create_ssh_key: OK (request sent)");
|
|
133
|
+
} catch (e) {
|
|
134
|
+
if (!ok("create_ssh_key", e)) failed++;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// create_placement_group
|
|
138
|
+
try {
|
|
139
|
+
await PlacementGroupsService.postPlacementGroups({
|
|
140
|
+
requestBody: {
|
|
141
|
+
name: "audit-test-pg",
|
|
142
|
+
type: "spread",
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
console.log("create_placement_group: OK (request sent)");
|
|
146
|
+
} catch (e) {
|
|
147
|
+
if (!ok("create_placement_group", e)) failed++;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
console.log("");
|
|
151
|
+
if (failed > 0) {
|
|
152
|
+
console.error(
|
|
153
|
+
`${failed} audit(s) failed. Check payload shapes against SDK/API.`,
|
|
154
|
+
);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
console.log("All create_* payload shapes accepted by API.");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
run();
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test list_* API calls using the same Hetzner SDK as the MCP server.
|
|
3
|
+
* Run from project root: node scripts/test-list-api.mjs
|
|
4
|
+
* Uses HCLOUD_TOKEN from environment or .env.
|
|
5
|
+
*/
|
|
6
|
+
import "dotenv/config";
|
|
7
|
+
import {
|
|
8
|
+
LocationsService,
|
|
9
|
+
ServerTypesService,
|
|
10
|
+
DatacentersService,
|
|
11
|
+
OpenAPI,
|
|
12
|
+
} from "hetzner-sdk-ts";
|
|
13
|
+
|
|
14
|
+
const token = process.env.HCLOUD_TOKEN;
|
|
15
|
+
if (!token) {
|
|
16
|
+
console.error("Error: HCLOUD_TOKEN environment variable is required");
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
OpenAPI.TOKEN = token;
|
|
20
|
+
|
|
21
|
+
async function run() {
|
|
22
|
+
console.log("Testing list_locations...");
|
|
23
|
+
try {
|
|
24
|
+
const r = await LocationsService.getLocations({});
|
|
25
|
+
console.log("list_locations OK, count:", r.locations?.length ?? 0);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.error("list_locations failed:", e.message || e);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log("Testing list_server_types...");
|
|
31
|
+
try {
|
|
32
|
+
const r = await ServerTypesService.getServerTypes({});
|
|
33
|
+
console.log("list_server_types OK, count:", r.server_types?.length ?? 0);
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error("list_server_types failed:", e.message || e);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
console.log("Testing list_datacenters...");
|
|
39
|
+
try {
|
|
40
|
+
const r = await DatacentersService.getDatacenters({});
|
|
41
|
+
console.log("list_datacenters OK, datacenters:", r.datacenters?.length ?? 0);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
console.error("list_datacenters failed:", e.message || e);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
run();
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test: spawn the MCP server and call list_locations via the MCP client.
|
|
3
|
+
* Run from project root: node scripts/test-mcp-list.mjs
|
|
4
|
+
* Uses HCLOUD_TOKEN from environment or .env.
|
|
5
|
+
*/
|
|
6
|
+
import "dotenv/config";
|
|
7
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
8
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
9
|
+
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import { dirname, join } from "path";
|
|
12
|
+
|
|
13
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const projectRoot = join(__dirname, "..");
|
|
15
|
+
|
|
16
|
+
const token = process.env.HCLOUD_TOKEN;
|
|
17
|
+
if (!token) {
|
|
18
|
+
console.error("Error: HCLOUD_TOKEN environment variable is required");
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const transport = new StdioClientTransport({
|
|
23
|
+
command: "node",
|
|
24
|
+
args: [join(projectRoot, "dist/index.js")],
|
|
25
|
+
env: { ...process.env, HCLOUD_TOKEN: token },
|
|
26
|
+
cwd: projectRoot,
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const client = new Client(
|
|
30
|
+
{ name: "test-client", version: "1.0.0" },
|
|
31
|
+
{ capabilities: {} }
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
async function main() {
|
|
35
|
+
console.log("Connecting to MCP server...");
|
|
36
|
+
await client.connect(transport);
|
|
37
|
+
|
|
38
|
+
console.log("Calling list_locations...");
|
|
39
|
+
const result = await client.callTool(
|
|
40
|
+
{ name: "list_locations", arguments: {} },
|
|
41
|
+
CallToolResultSchema
|
|
42
|
+
);
|
|
43
|
+
console.log("isError:", result.isError);
|
|
44
|
+
if (result.content?.length) {
|
|
45
|
+
for (const part of result.content) {
|
|
46
|
+
if (part.type === "text") {
|
|
47
|
+
const preview = part.text.slice(0, 500);
|
|
48
|
+
console.log("content (preview):", preview + (part.text.length > 500 ? "..." : ""));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
console.log("content:", result.content);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await client.close();
|
|
56
|
+
process.exit(result.isError ? 1 : 0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
main().catch((err) => {
|
|
60
|
+
console.error("Test failed:", err);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|