ecp-mcp-server 0.4.0 → 0.6.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/.env.sample CHANGED
@@ -14,6 +14,12 @@ ECP_REMEMBER=false
14
14
  # Defaults to ./audit.log next to this file if unset.
15
15
  ECP_MCP_AUDIT_LOG_PATH=
16
16
 
17
+ # Folders on this computer that ecp_files_upload (and sql_file_path on the
18
+ # import tools) may read from without asking, separated by ":" (";" on
19
+ # Windows). The MCP client's own working folders are always allowed. Any
20
+ # other file needs the user's yes in an approval prompt.
21
+ ECP_UPLOAD_DIRS=
22
+
17
23
  # Dev-only escape hatch: disables TLS certificate verification for this
18
24
  # process (e.g. a self-signed dev ECP instance). Leave unset/false for any
19
25
  # real account - this affects every outgoing HTTPS request the process
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.0 — 2026-11-30
4
+
5
+ Plugin 0.3.0 uses this release.
6
+
7
+ ### Added
8
+ - n8n tools for ECP's one-click n8n installer: `ecp_n8n_status`, `ecp_n8n_install`, `ecp_n8n_activate`, `ecp_n8n_create_owner`, `ecp_n8n_update`, `ecp_n8n_rollback`, `ecp_n8n_restart`, `ecp_n8n_uninstall`. Install and update run in the background; the domain is connected only after the owner account is created. There's no tool for the encryption key, which stays on ECP's n8n page. n8n's Code node runs JavaScript only. Needs the ECP and EHM releases with the n8n installer; on older ECP these tools answer with an error.
9
+ - Plugin: the launch-website skill walks through installing n8n.
10
+
11
+ ## 0.5.1 — 2026-11-26
12
+
13
+ ### Fixed
14
+ - `ecp_files_upload` / `sql_file_path` only open regular files. A named pipe or device path is refused before it's opened, so it can't hang the tool call or trigger a device's side effects, including for files outside the allowed folders that weren't approved.
15
+
16
+ ## 0.5.0 — 2026-11-26
17
+
18
+ Plugin 0.2.0 uses this release.
19
+
20
+ ### Added
21
+ - `ecp_files_upload`: upload a file from this computer to the account, text or binary, any size up to `ecp_files_upload_limit`. It's streamed from disk to ECP's own upload route, so it never passes through the chat and isn't held in memory. Files outside the client's working folders and the new `ECP_UPLOAD_DIRS` need the user's approval in a prompt.
22
+ - `ecp_mysql_import_database` / `ecp_postgres_import_database` take `sql_file_path`, a .sql file on this computer, as well as `sql_content`. Pass one of the two.
23
+
24
+ ### Fixed
25
+ - Uploading anything bigger than what fits in a chat message. The only way to put a file on the account was `ecp_files_write`, which sends the content through the chat as text (and ECP caps it at 32 MB), so big and binary files couldn't be uploaded at all.
26
+
3
27
  ## 0.4.0 — 2026-11-21
4
28
 
5
29
  Ships with the ECP plugin for Claude (`plugin/`), which bundles this server.
package/README.md CHANGED
@@ -17,12 +17,13 @@ It talks to ECP's own API (the same one ECP's web UI uses) as the hosting accoun
17
17
  - **asdf** — language runtime version management
18
18
  - **Git integrations** — connect GitHub/GitLab/Bitbucket, browse repos, manage per-app deploy webhooks
19
19
  - **Managed WordPress** — full install, status/event history, cache mode and purge, security status, XML-RPC toggle, admin password reset, one-time wp-admin login
20
+ - **n8n** — one-click install of n8n (workflow automation) on one of the account's domains, owner account setup, update with rollback, restart, uninstall
20
21
  - **Resource monitoring / notifications** — resource status, current-cycle bandwidth use
21
22
  - **storage.bd** — backup config and job status
22
23
  - **cPanel import** — discover and import sites from a cPanel server over SSH
23
24
  - **Shell** — run a command in the account's container and get its exit code and output, with your approval for every command (see Security notes)
24
25
 
25
- **What it deliberately does *not* do:** start a local file backup or restore. Those need a live browser connection for progress; use ECP's own web UI.
26
+ **What it deliberately does *not* do:** start a local file backup or restore. Those need a live browser connection for progress; use ECP's own web UI. It also doesn't hand out n8n's encryption key, which decrypts every credential saved in n8n and would end up in the chat transcript; download it from ECP's n8n page.
26
27
 
27
28
  ## Easiest: the ECP plugin for Claude
28
29
 
@@ -68,6 +69,7 @@ This server is configured entirely through environment variables — no config f
68
69
  | `ECP_ACCOUNT_USERNAME` | yes | The hosting account to log in as. One server instance manages one account. |
69
70
  | `ECP_ACCOUNT_PASSWORD` | yes | That account's password. |
70
71
  | `ECP_REMEMBER` | no | `true` for a 30-day session instead of 24h. |
72
+ | `ECP_UPLOAD_DIRS` | no | Folders on this computer that `ecp_files_upload` and the `sql_file_path` imports may read from without asking, separated by `:` (`;` on Windows). Your MCP client's own working folders (MCP roots, e.g. Claude Code's project folder) are always allowed. |
71
73
  | `ECP_TLS_INSECURE` | no | Dev-only escape hatch for a self-signed ECP instance. Never set this for a real account — see the comment in `.env.sample`. |
72
74
 
73
75
  ## Use it
@@ -116,6 +118,7 @@ Worth understanding before you point this at an account you care about:
116
118
  - **Scope**: one server instance = one hosting account, authenticated exactly as that account (same permissions, same rate limits as logging into ECP's web UI yourself). It cannot reach any other account.
117
119
  - **Destructive/security-sensitive actions require `confirm: true`** as an explicit tool argument (dropping a table, deleting a file, granting privileges, etc.) — this makes the intent unambiguous in both your MCP client's approval prompt and the audit log below. Don't run this with your client's "auto-approve all tools" setting on.
118
120
  - **Local audit log**: every tool call is appended to a local file (`ECP_MCP_AUDIT_LOG_PATH`, defaults to `audit.log` next to the installed package) with secrets redacted — since ECP itself doesn't currently keep a durable record of actions taken this way.
121
+ - **Uploads read files from your computer, so they're limited to folders you chose.** `ecp_files_upload` and the `sql_file_path` option of the import tools stream a local file straight to ECP (it never goes through the chat). They read without asking only inside your MCP client's working folders and `ECP_UPLOAD_DIRS`, checked after resolving symlinks. Any other file needs your yes in an elicitation prompt that names the file, and the upload is refused if your client can't show one. This keeps an AI that was steered by text it read from sending something like `~/.ssh` to your hosting account.
119
122
  - **Credentials** live only in the environment variables you provide and in-process memory — never written to disk beyond what you configure.
120
123
  - **Shell commands need your approval for each command.** `ecp_shell_exec` runs a command as the account user, with the same reach as ECP's browser terminal. Before anything runs, the server shows you the exact command through an MCP elicitation prompt. Declining runs nothing. The `confirm: true` pattern above isn't enough here, because the AI fills in that argument itself and could be steered by text it reads. If your client can't show elicitation prompts, the tool refuses to run. Commands are non-interactive and are killed after their timeout (max 300s). Every command is recorded in the audit log.
121
124
 
@@ -1,8 +1,8 @@
1
- // Client for ECP's own API (ecp-go), never EHM-API directly - see the plan
2
- // doc for why. Mirrors ecp-ui's own auth.js: log in once, hold the
3
- // refresh_token httpOnly cookie ourselves (there's no browser to do it for
4
- // us), refresh proactively before the access token expires or reactively on
5
- // a 401.
1
+ import { randomUUID } from "node:crypto";
2
+ import { request as httpRequest } from "node:http";
3
+ import { request as httpsRequest } from "node:https";
4
+ import { Readable } from "node:stream";
5
+ import { pipeline } from "node:stream/promises";
6
6
  function decodeJwtExpMs(token) {
7
7
  const parts = token.split(".");
8
8
  if (parts.length !== 3)
@@ -23,6 +23,11 @@ function extractRefreshCookie(setCookieHeaders) {
23
23
  }
24
24
  return null;
25
25
  }
26
+ // Per the HTML form-data encoding: '"' and line breaks in a name or filename
27
+ // are percent-encoded, which is what Go's multipart reader expects.
28
+ function escapeFormName(value) {
29
+ return value.replace(/"/g, "%22").replace(/\r/g, "%0D").replace(/\n/g, "%0A");
30
+ }
26
31
  function safeJsonParse(text) {
27
32
  try {
28
33
  return JSON.parse(text);
@@ -149,26 +154,92 @@ export class EcpClient {
149
154
  }
150
155
  return data;
151
156
  }
152
- /** multipart/form-data POST, e.g. for importDatabase's file upload. */
153
- async requestMultipart(path, fields, file) {
157
+ /**
158
+ * multipart/form-data POST, e.g. for importDatabase's file upload. content
159
+ * is either the file's text, or a file on this computer, which is streamed
160
+ * from disk. The body is built by hand and sent with node:http because
161
+ * Node's fetch holds a FormData or streamed body in memory (measured:
162
+ * ~700 MB peak RSS for a 600 MB file, ~90 MB this way).
163
+ */
164
+ async requestMultipart(path, fields, file, query) {
165
+ try {
166
+ return await this.sendMultipart(path, fields, file, query);
167
+ }
168
+ finally {
169
+ // The handle is ours once passed in, whether or not the upload worked.
170
+ if (typeof file.content !== "string")
171
+ await file.content.handle.close();
172
+ }
173
+ }
174
+ async sendMultipart(path, fields, file, query) {
154
175
  const token = await this.ensureAccessToken();
155
176
  const url = new URL(`${this.baseUrl}/${path.replace(/^\/+/, "")}`);
156
- const buildForm = () => {
157
- const form = new FormData();
158
- for (const [key, value] of Object.entries(fields)) {
177
+ if (query) {
178
+ for (const [key, value] of Object.entries(query)) {
159
179
  if (value !== undefined && value !== null)
160
- form.set(key, String(value));
180
+ url.searchParams.set(key, String(value));
161
181
  }
162
- form.set(file.fieldName, new Blob([file.content], { type: file.contentType ?? "application/octet-stream" }), file.fileName);
163
- return form;
182
+ }
183
+ const boundary = `----ecp-mcp-${randomUUID()}`;
184
+ let head = "";
185
+ for (const [key, value] of Object.entries(fields)) {
186
+ if (value === undefined || value === null)
187
+ continue;
188
+ head += `--${boundary}\r\ncontent-disposition: form-data; name="${escapeFormName(key)}"\r\n\r\n${String(value)}\r\n`;
189
+ }
190
+ head +=
191
+ `--${boundary}\r\ncontent-disposition: form-data; name="${escapeFormName(file.fieldName)}"; filename="${escapeFormName(file.fileName)}"\r\n` +
192
+ `content-type: ${file.contentType ?? "application/octet-stream"}\r\n\r\n`;
193
+ const headBytes = Buffer.from(head, "utf8");
194
+ const tailBytes = Buffer.from(`\r\n--${boundary}--\r\n`, "utf8");
195
+ const content = file.content;
196
+ const textBytes = typeof content === "string" ? Buffer.from(content, "utf8") : null;
197
+ const length = headBytes.length + tailBytes.length + (textBytes ? textBytes.length : content.size);
198
+ const body = () => {
199
+ if (textBytes)
200
+ return Readable.from([Buffer.concat([headBytes, textBytes, tailBytes])]);
201
+ const local = content;
202
+ return Readable.from((async function* () {
203
+ yield headBytes;
204
+ // A file that changed size since it was checked would make the
205
+ // body disagree with content-length - fail rather than send it.
206
+ let sent = 0;
207
+ for await (const chunk of local.handle.createReadStream({ start: 0, autoClose: false })) {
208
+ sent += chunk.length;
209
+ yield chunk;
210
+ }
211
+ if (sent !== local.size)
212
+ throw new Error(`${local.path} changed while it was being uploaded.`);
213
+ yield tailBytes;
214
+ })());
164
215
  };
165
- const doFetch = (bearer) => fetch(url, { method: "POST", headers: { authorization: `Bearer ${bearer}` }, body: buildForm() });
166
- let res = await doFetch(token);
216
+ const send = (bearer) => new Promise((resolve, reject) => {
217
+ const request = url.protocol === "https:" ? httpsRequest : httpRequest;
218
+ const req = request(url, {
219
+ method: "POST",
220
+ headers: {
221
+ authorization: `Bearer ${bearer}`,
222
+ "content-type": `multipart/form-data; boundary=${boundary}`,
223
+ "content-length": String(length),
224
+ },
225
+ }, (res) => {
226
+ const chunks = [];
227
+ res.on("data", (chunk) => chunks.push(chunk));
228
+ res.on("end", () => {
229
+ const status = res.statusCode ?? 0;
230
+ resolve({ status, ok: status >= 200 && status < 300, text: Buffer.concat(chunks).toString("utf8") });
231
+ });
232
+ res.on("error", reject);
233
+ });
234
+ req.on("error", reject);
235
+ pipeline(body(), req).catch(reject);
236
+ });
237
+ let res = await send(token);
167
238
  if (res.status === 401) {
168
239
  await this.refresh();
169
- res = await doFetch(this.accessToken);
240
+ res = await send(this.accessToken);
170
241
  }
171
- const text = await res.text();
242
+ const text = res.text;
172
243
  const data = text ? safeJsonParse(text) : undefined;
173
244
  if (!res.ok) {
174
245
  throw new Error(`ECP API POST ${path} failed (${res.status}): ${text}`);
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ import { mssqlTools, postgresTools } from "./tools/relational-engines.js";
15
15
  import { systemTools } from "./tools/system.js";
16
16
  import { asdfTools } from "./tools/asdf.js";
17
17
  import { wordpressHostingTools } from "./tools/wordpress-hosting.js";
18
+ import { n8nTools } from "./tools/n8n.js";
18
19
  import { gitIntegrationTools } from "./tools/git-integrations.js";
19
20
  import { resourceMonitorTools } from "./tools/resource-monitor.js";
20
21
  import { storageBdTools } from "./tools/storage-bd.js";
@@ -22,6 +23,7 @@ import { backupTools } from "./tools/backup.js";
22
23
  import { cpanelImportTools } from "./tools/cpanel-import.js";
23
24
  import { shellTools } from "./tools/shell.js";
24
25
  import { createRequire } from "node:module";
26
+ import { fileURLToPath } from "node:url";
25
27
  // Dev-only escape hatch for a self-signed target (see .env.sample). Process-
26
28
  // wide and opt-in only - never the default, since it weakens every HTTPS
27
29
  // request this process makes, not just ones to the configured ECP host.
@@ -77,6 +79,7 @@ const allTools = [
77
79
  ...systemTools,
78
80
  ...asdfTools,
79
81
  ...wordpressHostingTools,
82
+ ...n8nTools,
80
83
  ...gitIntegrationTools,
81
84
  ...resourceMonitorTools,
82
85
  ...storageBdTools,
@@ -96,6 +99,19 @@ const toolContext = {
96
99
  });
97
100
  return result.action === "accept";
98
101
  },
102
+ listRoots: async () => {
103
+ if (!server.server.getClientCapabilities()?.roots)
104
+ return [];
105
+ try {
106
+ const { roots } = await server.server.listRoots();
107
+ return roots
108
+ .filter((root) => root.uri.startsWith("file://"))
109
+ .map((root) => fileURLToPath(root.uri));
110
+ }
111
+ catch {
112
+ return [];
113
+ }
114
+ },
99
115
  };
100
116
  for (const tool of allTools) {
101
117
  server.registerTool(tool.name, { description: tool.description, inputSchema: tool.inputSchema }, async (args) => {
@@ -0,0 +1,154 @@
1
+ import { constants } from "node:fs";
2
+ import { open, realpath, stat } from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ // Uploads read a file from the machine this server runs on and send it to
7
+ // ECP, so the bytes never pass through the model (which is what capped
8
+ // ecp_files_write / sql_content at whatever fits in a chat message, and made
9
+ // binary files impossible).
10
+ //
11
+ // Reading a local file is also the risky part: a model steered by text it
12
+ // read somewhere could try to send ~/.ssh/id_rsa to the hosting account,
13
+ // where a public folder would serve it. So a file is sent without asking
14
+ // only if it's inside a folder the user already gave the client (MCP roots,
15
+ // e.g. Claude Code's working folders) or listed in ECP_UPLOAD_DIRS.
16
+ // Anything else needs the user's yes in an approval prompt, and fails closed
17
+ // when the client can't show one.
18
+ function configuredDirs() {
19
+ const raw = process.env.ECP_UPLOAD_DIRS?.trim() ?? "";
20
+ // An unfilled plugin option arrives as the literal "${...}" placeholder.
21
+ if (!raw || /^\$\{[^}]*\}$/.test(raw))
22
+ return [];
23
+ return raw
24
+ .split(path.delimiter)
25
+ .map((d) => d.trim())
26
+ .filter(Boolean)
27
+ .map((d) => (d.startsWith("~") ? path.join(os.homedir(), d.slice(1)) : d));
28
+ }
29
+ async function allowedDirs(ctx) {
30
+ const dirs = [...configuredDirs(), ...(await ctx.listRoots())];
31
+ const resolved = [];
32
+ for (const dir of dirs) {
33
+ try {
34
+ resolved.push(await realpath(path.resolve(dir)));
35
+ }
36
+ catch {
37
+ // A configured folder that doesn't exist just allows nothing.
38
+ }
39
+ }
40
+ return resolved;
41
+ }
42
+ function isInside(file, dir) {
43
+ const rel = path.relative(dir, file);
44
+ return rel !== "" && !rel.startsWith("..") && !path.isAbsolute(rel);
45
+ }
46
+ function formatSize(bytes) {
47
+ if (bytes >= 1 << 30)
48
+ return `${(bytes / (1 << 30)).toFixed(1)} GB`;
49
+ if (bytes >= 1 << 20)
50
+ return `${(bytes / (1 << 20)).toFixed(1)} MB`;
51
+ if (bytes >= 1 << 10)
52
+ return `${(bytes / (1 << 10)).toFixed(1)} KB`;
53
+ return `${bytes} bytes`;
54
+ }
55
+ /** ECP's per-upload limit in bytes, or null on an ECP too old to say (pre-2.0.5). */
56
+ async function uploadLimitBytes(client) {
57
+ try {
58
+ const res = await client.request("GET", "file-system/upload-limit");
59
+ return typeof res?.upload_max_size_mb === "number" ? res.upload_max_size_mb * (1 << 20) : null;
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ /**
66
+ * Resolve, check and open a local file for upload. `purpose` describes where
67
+ * it's going, for the approval prompt (e.g. "to ~/public_html on ECP").
68
+ */
69
+ export async function openLocalUpload(localPath, purpose, client, ctx) {
70
+ const given = localPath.startsWith("file://")
71
+ ? fileURLToPath(localPath)
72
+ : localPath.startsWith("~")
73
+ ? path.join(os.homedir(), localPath.slice(1))
74
+ : localPath;
75
+ if (!path.isAbsolute(given)) {
76
+ throw new Error(`local_path must be an absolute path on this computer, got "${localPath}".`);
77
+ }
78
+ // Nothing about a file outside the allowed folders (whether it exists, its
79
+ // size or type) reaches the model before the user approves it: they all
80
+ // get the same error. A path that doesn't resolve is judged by its text.
81
+ const real = await realpath(given).catch(() => null);
82
+ const dirs = await allowedDirs(ctx);
83
+ const inside = dirs.some((dir) => isInside(real ?? path.resolve(given), dir));
84
+ const outsideError = () => new Error(`${given} is outside the folders this server may upload from (the chat app's working folders and ECP_UPLOAD_DIRS), and it wasn't approved. Move the file into one of those folders, or add its folder to ECP_UPLOAD_DIRS (the plugin's "Upload folder" option).`);
85
+ if (!real)
86
+ throw inside ? new Error(`No file at ${given} on this computer.`) : outsideError();
87
+ // Open once and send from this handle, so the file that was checked is the
88
+ // file that's sent: swapping in a symlink after the check can't redirect
89
+ // it. O_NOFOLLOW refuses a final-component symlink at open; the second
90
+ // realpath + inode comparison catches a swapped parent folder.
91
+ // Only regular files are opened at all: opening a FIFO blocks and opening a
92
+ // device can have side effects. O_NONBLOCK covers a FIFO swapped in
93
+ // between this stat and the open (the inode check below then rejects it).
94
+ const pre = await stat(real).catch(() => null);
95
+ if (!pre?.isFile()) {
96
+ throw inside
97
+ ? new Error(pre
98
+ ? `${given} isn't a file. To send a folder, compress it into a .zip first, upload that, then ecp_files_extract it.`
99
+ : `No file at ${given} on this computer.`)
100
+ : outsideError();
101
+ }
102
+ const handle = await open(real, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0)).catch(() => null);
103
+ if (!handle)
104
+ throw inside ? new Error(`Can't open ${given} on this computer.`) : outsideError();
105
+ try {
106
+ const info = await handle.stat();
107
+ const again = await realpath(given).catch(() => null);
108
+ const againInfo = again ? await stat(again).catch(() => null) : null;
109
+ if (!againInfo ||
110
+ again !== real ||
111
+ againInfo.ino !== info.ino ||
112
+ againInfo.dev !== info.dev ||
113
+ pre.ino !== info.ino ||
114
+ pre.dev !== info.dev) {
115
+ throw inside ? new Error(`${given} changed while it was being checked. Try again.`) : outsideError();
116
+ }
117
+ if (!info.isFile()) {
118
+ throw inside
119
+ ? new Error(`${given} isn't a file. To send a folder, compress it into a .zip first, upload that, then ecp_files_extract it.`)
120
+ : outsideError();
121
+ }
122
+ if (!inside) {
123
+ const shown = real === given ? real : `${given} (which points to ${real})`;
124
+ const ok = await ctx
125
+ .askUser(`Send ${shown} (${formatSize(info.size)}) from this computer ${purpose}? It's outside the folders this server may upload from without asking.`)
126
+ .catch(() => false);
127
+ if (!ok)
128
+ throw outsideError();
129
+ }
130
+ const limit = await uploadLimitBytes(client);
131
+ if (limit !== null && info.size > limit) {
132
+ throw new Error(`${given} is ${formatSize(info.size)}, over this ECP's ${formatSize(limit)} upload limit. The hosting admin can raise the account's upload limit in EHM.`);
133
+ }
134
+ return { path: real, size: info.size, handle };
135
+ }
136
+ catch (err) {
137
+ await handle.close();
138
+ throw err;
139
+ }
140
+ }
141
+ /**
142
+ * The SQL for an *_import_database tool: either pasted text (sql_content, for
143
+ * a small dump) or a .sql file on this computer (sql_file_path, any size up
144
+ * to the upload limit). Exactly one must be given.
145
+ */
146
+ export async function importSqlSource(args, client, ctx) {
147
+ const hasText = typeof args.sql_content === "string" && args.sql_content !== "";
148
+ const hasFile = typeof args.sql_file_path === "string" && args.sql_file_path !== "";
149
+ if (hasText === hasFile)
150
+ throw new Error("Pass exactly one of sql_content (the SQL as text) or sql_file_path (a .sql file on this computer).");
151
+ if (hasText)
152
+ return args.sql_content;
153
+ return openLocalUpload(args.sql_file_path, `to ECP, to import into database ${args.db_name} (overwriting it)`, client, ctx);
154
+ }
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { importSqlSource } from "../local-files.js";
2
3
  // Maps to router/database.go (MySQL + engine-agnostic status/connection-info)
3
4
  // and the MySQL-user/privilege portion of router/database.go that proxies to
4
5
  // ehm-api's mysql.controller.ts. db_name you pass is NOT pre-prefixed -
@@ -129,12 +130,17 @@ export const databaseTools = [
129
130
  },
130
131
  {
131
132
  name: "ecp_mysql_import_database",
132
- description: "Import a .sql dump into an existing MySQL database, overwriting its content. Irreversible - pass the full SQL as text.",
133
- inputSchema: { db_name: z.string(), sql_content: z.string(), confirm: z.literal(true) },
134
- handler: async (args, client) => client.requestMultipart("database/importDatabase", { db_name: args.db_name }, {
133
+ description: "Import a .sql dump into an existing MySQL database, overwriting its content. Irreversible. Give the dump as a .sql file on this computer (sql_file_path - any size up to ecp_files_upload_limit, streamed from disk) or, for a small one, as text (sql_content).",
134
+ inputSchema: {
135
+ db_name: z.string(),
136
+ sql_file_path: z.string().optional().describe("Absolute path of a .sql file on this computer"),
137
+ sql_content: z.string().optional().describe("The SQL as text, for a small dump"),
138
+ confirm: z.literal(true),
139
+ },
140
+ handler: async (args, client, ctx) => client.requestMultipart("database/importDatabase", { db_name: args.db_name }, {
135
141
  fieldName: "file",
136
142
  fileName: `${args.db_name}.sql`,
137
- content: String(args.sql_content),
143
+ content: await importSqlSource(args, client, ctx),
138
144
  contentType: "application/sql",
139
145
  }),
140
146
  },
@@ -1,14 +1,16 @@
1
1
  import { z } from "zod";
2
+ import path from "node:path";
3
+ import { openLocalUpload } from "../local-files.js";
2
4
  // Maps to router/file-system.go + router/code-editory.go - real local
3
5
  // filesystem access on the account's own container, with no EHM-API
4
6
  // equivalent at all. Genuinely useful ("show me this app's .env", "fix this
5
7
  // config") and genuinely capable of damaging a live site, so every
6
8
  // destructive op (delete, overwrite, move) requires confirm: true.
7
9
  //
8
- // direct-download and upload-recursive are intentionally NOT exposed here:
9
- // both move raw binary bytes, which doesn't fit an MCP tool response well
10
- // (same reasoning as the DB import/export punt in the plan) - revisit later
11
- // if there's a concrete need.
10
+ // direct-download is intentionally NOT exposed: it returns raw binary bytes,
11
+ // which don't fit an MCP tool response. upload-recursive IS exposed, as
12
+ // ecp_files_upload, by reading the file from this computer's disk - the
13
+ // bytes go straight to ECP and never through the model (see local-files.ts).
12
14
  export const filesTools = [
13
15
  {
14
16
  name: "ecp_files_upload_limit",
@@ -16,6 +18,37 @@ export const filesTools = [
16
18
  inputSchema: {},
17
19
  handler: async (_args, client) => client.request("GET", "file-system/upload-limit"),
18
20
  },
21
+ {
22
+ name: "ecp_files_upload",
23
+ description: "Upload a file from this computer (where this MCP server runs) to the ECP account - any size up to ecp_files_upload_limit, text or binary (images, zips, videos). The file is read from disk and streamed to ECP, so use this instead of ecp_files_write for anything that isn't a small text edit. To upload a folder, zip it first, upload the zip, then ecp_files_extract it. Files outside the chat app's working folders and ECP_UPLOAD_DIRS need the user's approval in a prompt.",
24
+ inputSchema: {
25
+ local_path: z.string().describe("Absolute path of the file on this computer, e.g. /home/me/site/hero.jpg or ~/Downloads/site.zip"),
26
+ destination: z.string().describe("Folder on the ECP account to put it in, e.g. 'public_html' or 'apps/my-app'. Created if missing."),
27
+ file_name: z.string().optional().describe("Name to save it as; defaults to the local file's name"),
28
+ overwrite: z
29
+ .boolean()
30
+ .optional()
31
+ .describe("Replace a file that already exists there. Default false: the upload fails instead."),
32
+ },
33
+ handler: async (rawArgs, client, ctx) => {
34
+ const args = rawArgs;
35
+ const name = args.file_name ?? path.basename(args.local_path);
36
+ if (!name || name === "." || name === ".." || /[\\/]/.test(name)) {
37
+ throw new Error(`file_name must be a plain file name (no folders), got "${name}".`);
38
+ }
39
+ const destination = args.destination.replace(/\/+$/, "") || "/";
40
+ const target = `${destination}/${name}`;
41
+ if (!args.overwrite) {
42
+ const exists = await client.request("GET", "file-system/is-directory-exists", { query: { directory: target } });
43
+ if (exists === true || exists === "true") {
44
+ throw new Error(`${target} already exists on ECP. Pass overwrite: true to replace it.`);
45
+ }
46
+ }
47
+ const upload = await openLocalUpload(args.local_path, `to ${target} on the ECP account`, client, ctx);
48
+ await client.requestMultipart("file-system/upload-recursive", { destination }, { fieldName: "file", fileName: name, content: upload }, { relative_path: name });
49
+ return { uploaded: upload.path, to: target, bytes: upload.size };
50
+ },
51
+ },
19
52
  {
20
53
  name: "ecp_files_list",
21
54
  description: "List files/folders in a directory.",
@@ -46,7 +79,7 @@ export const filesTools = [
46
79
  },
47
80
  {
48
81
  name: "ecp_files_write",
49
- description: "Overwrite a text file's content (creates it if it doesn't exist). Can break a running app if it's a config/env/source file - review the current content first. ECP 2.0.5+ rejects requests over 32 MB.",
82
+ description: "Overwrite a text file's content (creates it if it doesn't exist). Can break a running app if it's a config/env/source file - review the current content first. For files that already exist on this computer, or anything large or binary, use ecp_files_upload instead - this one sends the content through the chat, and ECP 2.0.5+ rejects requests over 32 MB.",
50
83
  inputSchema: { file_path: z.string(), file_content: z.string(), confirm: z.literal(true) },
51
84
  handler: async (args, client) => client.request("POST", "code-editor/file", {
52
85
  body: { "file-path": args.file_path, "file-content": args.file_content },
@@ -0,0 +1,79 @@
1
+ import { z } from "zod";
2
+ // Maps to router.N8n's routes (ecp-go) - ECP's one-click n8n installer, see
3
+ // ecp-go/docs/N8N_ONE_CLICK.md. Install and update only *prepare* a version in
4
+ // the background (Node + npm install, several minutes); activate is a separate
5
+ // short call that switches to it. The public domain is only pointed at n8n
6
+ // once its owner account exists (ecp_n8n_create_owner), so nobody else can
7
+ // claim a fresh instance.
8
+ //
9
+ // GET /n8n/encryption-key is deliberately not exposed: the key decrypts every
10
+ // credential saved in n8n, and a tool would put it in the chat transcript.
11
+ // The ECP n8n page has a download button for it.
12
+ export const n8nTools = [
13
+ {
14
+ name: "ecp_n8n_status",
15
+ description: "Get the account's n8n install state: installed version, latest on npm and whether an update is available, running, URL, the background job (install/update: state running|prepared|failed, step, error), " +
16
+ "needs_owner (domain not connected yet - call ecp_n8n_create_owner), existing_data (kept ~/.n8n from an earlier install), and while not installed EHM's preflight (whether the account has enough memory and the installer is on). " +
17
+ "Call it first, and poll it while a job is running.",
18
+ inputSchema: {},
19
+ handler: async (_args, client) => client.request("GET", "n8n/status"),
20
+ },
21
+ {
22
+ name: "ecp_n8n_install",
23
+ description: "Start installing n8n (workflow automation) on one of the account's domains. Use a domain or subdomain that isn't used by another site - its traffic will go to n8n. " +
24
+ "Runs in the background for about 5-10 minutes (Node.js + npm install). Poll ecp_n8n_status until job.state is 'prepared', then call ecp_n8n_activate, wait for running, then ecp_n8n_create_owner. " +
25
+ "Omit version for the latest release. After a failed install, call it again to retry (the domain is reused). Needs ECP with the n8n installer.",
26
+ inputSchema: { domain: z.string(), version: z.string().optional() },
27
+ handler: async (args, client) => client.request("POST", "n8n/install", { body: { domain: args.domain, version: args.version } }),
28
+ },
29
+ {
30
+ name: "ecp_n8n_update",
31
+ description: "Start preparing a newer n8n version next to the running one (n8n keeps running meanwhile). Omit version for the latest. Poll ecp_n8n_status until job.state is 'prepared', then call ecp_n8n_activate to switch - " +
32
+ "that stops n8n briefly and backs up its database first, so ecp_n8n_rollback can undo it.",
33
+ inputSchema: { version: z.string().optional() },
34
+ handler: async (args, client) => client.request("POST", "n8n/update", { body: { version: args.version } }),
35
+ },
36
+ {
37
+ name: "ecp_n8n_activate",
38
+ description: "Switch to the version prepared by ecp_n8n_install or ecp_n8n_update (only once ecp_n8n_status shows job.state 'prepared'). " +
39
+ "After an install it starts n8n but doesn't connect the domain yet: wait until ecp_n8n_status shows running, then call ecp_n8n_create_owner. " +
40
+ "After an update it restarts n8n on the new version, and puts the old one back if that fails.",
41
+ inputSchema: {},
42
+ handler: async (_args, client) => client.request("POST", "n8n/activate"),
43
+ },
44
+ {
45
+ name: "ecp_n8n_create_owner",
46
+ description: "Create n8n's owner (admin) account, then connect the domain to n8n. Call it once ecp_n8n_status shows running and needs_owner. Until then the domain doesn't reach n8n, so nobody else can claim the instance. " +
47
+ "Ask the user for the email, name and password they want for n8n's login - don't make up a password unless they ask you to, and then tell them what it is. n8n requires 8-64 characters with at least one number and one capital letter. " +
48
+ "The password goes straight to n8n and isn't stored by ECP. email, first_name and password are required for a new owner. Over kept data that already has an owner (existing_data), call it without fields: it only connects the domain. " +
49
+ "A 409 saying n8n already has an owner ECP didn't create means someone may have reached n8n first - the domain stays unconnected; tell the user (the fix is to uninstall with delete_data and install again) rather than retrying.",
50
+ inputSchema: {
51
+ email: z.string().optional(),
52
+ first_name: z.string().optional(),
53
+ last_name: z.string().optional(),
54
+ password: z.string().optional(),
55
+ },
56
+ handler: async (args, client) => client.request("POST", "n8n/owner", {
57
+ body: { email: args.email, first_name: args.first_name, last_name: args.last_name, password: args.password },
58
+ }),
59
+ },
60
+ {
61
+ name: "ecp_n8n_rollback",
62
+ description: "Go back to the n8n version that ran before the last update, together with the copy of n8n's database taken just before it. Anything changed in n8n since that update (workflows, executions, credentials) is lost.",
63
+ inputSchema: { confirm: z.literal(true) },
64
+ handler: async (_args, client) => client.request("POST", "n8n/rollback"),
65
+ },
66
+ {
67
+ name: "ecp_n8n_restart",
68
+ description: "Restart n8n. It also picks up the domain's current SSL state, so call it after adding a certificate to switch n8n to https.",
69
+ inputSchema: {},
70
+ handler: async (_args, client) => client.request("POST", "n8n/restart"),
71
+ },
72
+ {
73
+ name: "ecp_n8n_uninstall",
74
+ description: "Uninstall n8n: removes the app and its process, and the domain goes back to the account's default site. n8n's data in ~/.n8n (workflows, credentials, encryption key) is kept, so a later install picks it up again, " +
75
+ "unless delete_data is true - that deletes it for good, so only do it when the user has explicitly asked to delete their n8n data, and make sure they have downloaded the encryption key from the ECP n8n page if they might need it.",
76
+ inputSchema: { delete_data: z.boolean().optional(), confirm: z.literal(true) },
77
+ handler: async (args, client) => client.request("POST", "n8n/uninstall", { body: { delete_data: args.delete_data ?? false } }),
78
+ },
79
+ ];
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { importSqlSource } from "../local-files.js";
2
3
  const rowCredsShape = { db_name: z.string(), table_name: z.string(), db_username: z.string(), password: z.string() };
3
4
  export function makeSqlEngineTools(cfg) {
4
5
  const p = (path) => `${cfg.routePrefix}/${path}`;
@@ -163,12 +164,17 @@ export function makeSqlEngineTools(cfg) {
163
164
  handler: async (args, client) => client.request("GET", p("exportDatabase"), { query: { db_name: args.db_name } }),
164
165
  }, {
165
166
  name: name("import_database"),
166
- description: `Import a .sql dump into an existing ${cfg.label} database, overwriting its content. Irreversible - pass the full SQL as text.`,
167
- inputSchema: { db_name: z.string(), sql_content: z.string(), confirm: z.literal(true) },
168
- handler: async (args, client) => client.requestMultipart(p("importDatabase"), { db_name: args.db_name }, {
167
+ description: `Import a .sql dump into an existing ${cfg.label} database, overwriting its content. Irreversible. Give the dump as a .sql file on this computer (sql_file_path - any size up to ecp_files_upload_limit, streamed from disk) or, for a small one, as text (sql_content).`,
168
+ inputSchema: {
169
+ db_name: z.string(),
170
+ sql_file_path: z.string().optional().describe("Absolute path of a .sql file on this computer"),
171
+ sql_content: z.string().optional().describe("The SQL as text, for a small dump"),
172
+ confirm: z.literal(true),
173
+ },
174
+ handler: async (args, client, ctx) => client.requestMultipart(p("importDatabase"), { db_name: args.db_name }, {
169
175
  fieldName: "file",
170
176
  fileName: `${args.db_name}.sql`,
171
- content: String(args.sql_content),
177
+ content: await importSqlSource(args, client, ctx),
172
178
  contentType: "application/sql",
173
179
  }),
174
180
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecp-mcp-server",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "MCP server for ECP (Epic Control Panel) - manage a hosting account's apps, domains, databases, files, PHP, SSL and more conversationally through an MCP client like Claude Code or Claude Desktop.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {