panelica-mcp 0.2.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/dist/index.js ADDED
@@ -0,0 +1,148 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Panelica MCP Server
4
+ *
5
+ * Exposes the Panelica External API (404 endpoints, HMAC-authenticated) as MCP
6
+ * tools so AI assistants like Claude Desktop, Cursor, and ChatGPT can manage
7
+ * hosting accounts, domains, databases, email, DNS, SSL, FTP, security, and
8
+ * server resources through natural language.
9
+ *
10
+ * Environment variables:
11
+ * PANELICA_BASE_URL Base URL of the External API (e.g. https://panel.example.com:3002)
12
+ * PANELICA_API_KEY External API key (from panel: Settings -> API Keys)
13
+ * PANELICA_API_SECRET External API secret (paired with the key above)
14
+ * PANELICA_TIMEOUT_MS Optional request timeout (default 30000)
15
+ *
16
+ * Run:
17
+ * panelica-mcp # stdio transport (default for Claude Desktop)
18
+ */
19
+ import { readFileSync } from "node:fs";
20
+ import { dirname, resolve } from "node:path";
21
+ import { fileURLToPath } from "node:url";
22
+ import { createHmac } from "node:crypto";
23
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
24
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
25
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
26
+ const __dirname = dirname(fileURLToPath(import.meta.url));
27
+ const toolsPath = resolve(__dirname, "../tools/tools.json");
28
+ const tools = JSON.parse(readFileSync(toolsPath, "utf8"));
29
+ const toolMap = new Map(tools.map(t => [t.name, t]));
30
+ function requireEnv(name) {
31
+ const v = process.env[name];
32
+ if (!v) {
33
+ throw new Error(`Missing required environment variable: ${name}.\n` +
34
+ `Generate an API key/secret pair in your Panelica panel (Settings -> API Keys) and set:\n` +
35
+ ` PANELICA_BASE_URL e.g. https://panel.example.com:3002\n` +
36
+ ` PANELICA_API_KEY X-API-Key value\n` +
37
+ ` PANELICA_API_SECRET paired secret`);
38
+ }
39
+ return v;
40
+ }
41
+ function sign(method, fullPath, timestamp, body, secret) {
42
+ // Backend formula: HMAC-SHA256(METHOD + PATH + TIMESTAMP + BODY, SECRET)
43
+ // DELETE requests exclude body from the signature.
44
+ const bodyForSign = method === "DELETE" ? "" : body;
45
+ const stringToSign = method + fullPath + timestamp + bodyForSign;
46
+ return createHmac("sha256", secret).update(stringToSign).digest("hex");
47
+ }
48
+ function buildPathAndQuery(template, args) {
49
+ // Substitute :param style placeholders from args.
50
+ let path = template;
51
+ const used = new Set();
52
+ for (const m of template.matchAll(/:([a-zA-Z_][a-zA-Z0-9_]*)/g)) {
53
+ const key = m[1];
54
+ const value = args[key];
55
+ if (value === undefined || value === null) {
56
+ throw new Error(`Missing required path parameter: ${key}`);
57
+ }
58
+ path = path.replace(`:${key}`, encodeURIComponent(String(value)));
59
+ used.add(key);
60
+ }
61
+ return { path, queryUsed: used };
62
+ }
63
+ async function callPanelica(tool, args) {
64
+ const baseUrl = requireEnv("PANELICA_BASE_URL").replace(/\/+$/, "");
65
+ const apiKey = requireEnv("PANELICA_API_KEY");
66
+ const apiSecret = requireEnv("PANELICA_API_SECRET");
67
+ const timeoutMs = Number(process.env.PANELICA_TIMEOUT_MS ?? 30_000);
68
+ const { method, path: pathTemplate } = tool.metadata;
69
+ const { path: resolvedPath, queryUsed } = buildPathAndQuery(pathTemplate, args);
70
+ // Remaining args that are not path params and not body -> query string.
71
+ const queryParams = new URLSearchParams();
72
+ for (const [k, v] of Object.entries(args)) {
73
+ if (k === "body" || queryUsed.has(k) || v === undefined || v === null)
74
+ continue;
75
+ queryParams.append(k, String(v));
76
+ }
77
+ const queryString = queryParams.toString();
78
+ const fullPath = queryString ? `${resolvedPath}?${queryString}` : resolvedPath;
79
+ const bodyString = args.body !== undefined ? JSON.stringify(args.body) : "";
80
+ const timestamp = Math.floor(Date.now() / 1000).toString();
81
+ const signature = sign(method, fullPath, timestamp, bodyString, apiSecret);
82
+ const headers = {
83
+ "X-API-Key": apiKey,
84
+ "X-Timestamp": timestamp,
85
+ "X-Signature": signature,
86
+ "Accept": "application/json",
87
+ "User-Agent": "panelica-mcp/0.2.0",
88
+ };
89
+ if (bodyString)
90
+ headers["Content-Type"] = "application/json";
91
+ const ctrl = new AbortController();
92
+ const timer = setTimeout(() => ctrl.abort(), timeoutMs);
93
+ let response;
94
+ try {
95
+ response = await fetch(`${baseUrl}${fullPath}`, {
96
+ method,
97
+ headers,
98
+ body: bodyString || undefined,
99
+ signal: ctrl.signal,
100
+ });
101
+ }
102
+ catch (err) {
103
+ const msg = err instanceof Error ? err.message : String(err);
104
+ throw new Error(`Request to ${method} ${fullPath} failed: ${msg}`);
105
+ }
106
+ finally {
107
+ clearTimeout(timer);
108
+ }
109
+ const text = await response.text();
110
+ if (!response.ok) {
111
+ throw new Error(`Panelica API ${response.status} ${response.statusText} on ${method} ${fullPath}:\n${text.slice(0, 4000)}`);
112
+ }
113
+ return text;
114
+ }
115
+ const server = new Server({ name: "panelica-mcp", version: "0.2.0" }, { capabilities: { tools: {} } });
116
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
117
+ tools: tools.map(t => ({
118
+ name: t.name,
119
+ description: t.description,
120
+ inputSchema: t.inputSchema,
121
+ // Safety hints let MCP clients auto-approve read-only calls and warn before
122
+ // destructive ones (DELETE). Generated per HTTP method by build-tools.mjs.
123
+ ...(t.annotations ? { annotations: t.annotations } : {}),
124
+ })),
125
+ }));
126
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
127
+ const { name, arguments: args } = request.params;
128
+ const tool = toolMap.get(name);
129
+ if (!tool) {
130
+ return {
131
+ isError: true,
132
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
133
+ };
134
+ }
135
+ try {
136
+ const body = await callPanelica(tool, (args ?? {}));
137
+ return { content: [{ type: "text", text: body }] };
138
+ }
139
+ catch (err) {
140
+ const msg = err instanceof Error ? err.message : String(err);
141
+ return {
142
+ isError: true,
143
+ content: [{ type: "text", text: msg }],
144
+ };
145
+ }
146
+ });
147
+ const transport = new StdioServerTransport();
148
+ await server.connect(transport);
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "panelica-mcp",
3
+ "version": "0.2.0",
4
+ "description": "MCP server exposing the Panelica hosting panel External API to AI assistants. Manage accounts, domains, databases, email, DNS, SSL, FTP, security, and server resources through natural language.",
5
+ "type": "module",
6
+ "bin": {
7
+ "panelica-mcp": "dist/index.js"
8
+ },
9
+ "main": "dist/index.js",
10
+ "files": [
11
+ "dist",
12
+ "tools/tools.json",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc -p tsconfig.json",
18
+ "rebuild-tools": "node tools/build-tools.mjs",
19
+ "prepare": "npm run build",
20
+ "start": "node dist/index.js",
21
+ "refresh": "node tools/build-tools.mjs # set PANELICA_SPEC_URL to pull the live spec"
22
+ },
23
+ "keywords": [
24
+ "mcp",
25
+ "model-context-protocol",
26
+ "panelica",
27
+ "hosting",
28
+ "control-panel",
29
+ "sysadmin",
30
+ "devops",
31
+ "automation",
32
+ "ai"
33
+ ],
34
+ "author": "Panelica <info@panelica.com> (https://panelica.com)",
35
+ "license": "MIT",
36
+ "homepage": "https://github.com/Panelica/panelica-mcp",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/Panelica/panelica-mcp.git"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/Panelica/panelica-mcp/issues"
43
+ },
44
+ "engines": {
45
+ "node": ">=20"
46
+ },
47
+ "dependencies": {
48
+ "@modelcontextprotocol/sdk": "^1.0.4"
49
+ },
50
+ "devDependencies": {
51
+ "@types/node": "^22.10.0",
52
+ "typescript": "^5.6.3"
53
+ }
54
+ }