ecp-mcp-server 0.4.0 → 0.5.1
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 +6 -0
- package/CHANGELOG.md +16 -0
- package/README.md +2 -0
- package/dist/ecp-client.js +88 -17
- package/dist/index.js +14 -0
- package/dist/local-files.js +154 -0
- package/dist/tools/database.js +10 -4
- package/dist/tools/files.js +38 -5
- package/dist/tools/sql-engine-factory.js +10 -4
- package/package.json +1 -1
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,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.1 — 2026-11-26
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- `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.
|
|
7
|
+
|
|
8
|
+
## 0.5.0 — 2026-11-26
|
|
9
|
+
|
|
10
|
+
Plugin 0.2.0 uses this release.
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `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.
|
|
14
|
+
- `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.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- 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.
|
|
18
|
+
|
|
3
19
|
## 0.4.0 — 2026-11-21
|
|
4
20
|
|
|
5
21
|
Ships with the ECP plugin for Claude (`plugin/`), which bundles this server.
|
package/README.md
CHANGED
|
@@ -68,6 +68,7 @@ This server is configured entirely through environment variables — no config f
|
|
|
68
68
|
| `ECP_ACCOUNT_USERNAME` | yes | The hosting account to log in as. One server instance manages one account. |
|
|
69
69
|
| `ECP_ACCOUNT_PASSWORD` | yes | That account's password. |
|
|
70
70
|
| `ECP_REMEMBER` | no | `true` for a 30-day session instead of 24h. |
|
|
71
|
+
| `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
72
|
| `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
73
|
|
|
73
74
|
## Use it
|
|
@@ -116,6 +117,7 @@ Worth understanding before you point this at an account you care about:
|
|
|
116
117
|
- **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
118
|
- **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
119
|
- **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.
|
|
120
|
+
- **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
121
|
- **Credentials** live only in the environment variables you provide and in-process memory — never written to disk beyond what you configure.
|
|
120
122
|
- **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
123
|
|
package/dist/ecp-client.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
/**
|
|
153
|
-
|
|
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
|
-
|
|
157
|
-
const
|
|
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
|
-
|
|
180
|
+
url.searchParams.set(key, String(value));
|
|
161
181
|
}
|
|
162
|
-
|
|
163
|
-
|
|
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
|
|
166
|
-
|
|
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
|
|
240
|
+
res = await send(this.accessToken);
|
|
170
241
|
}
|
|
171
|
-
const 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
|
@@ -22,6 +22,7 @@ import { backupTools } from "./tools/backup.js";
|
|
|
22
22
|
import { cpanelImportTools } from "./tools/cpanel-import.js";
|
|
23
23
|
import { shellTools } from "./tools/shell.js";
|
|
24
24
|
import { createRequire } from "node:module";
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
25
26
|
// Dev-only escape hatch for a self-signed target (see .env.sample). Process-
|
|
26
27
|
// wide and opt-in only - never the default, since it weakens every HTTPS
|
|
27
28
|
// request this process makes, not just ones to the configured ECP host.
|
|
@@ -96,6 +97,19 @@ const toolContext = {
|
|
|
96
97
|
});
|
|
97
98
|
return result.action === "accept";
|
|
98
99
|
},
|
|
100
|
+
listRoots: async () => {
|
|
101
|
+
if (!server.server.getClientCapabilities()?.roots)
|
|
102
|
+
return [];
|
|
103
|
+
try {
|
|
104
|
+
const { roots } = await server.server.listRoots();
|
|
105
|
+
return roots
|
|
106
|
+
.filter((root) => root.uri.startsWith("file://"))
|
|
107
|
+
.map((root) => fileURLToPath(root.uri));
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
},
|
|
99
113
|
};
|
|
100
114
|
for (const tool of allTools) {
|
|
101
115
|
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
|
+
}
|
package/dist/tools/database.js
CHANGED
|
@@ -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 -
|
|
133
|
-
inputSchema: {
|
|
134
|
-
|
|
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:
|
|
143
|
+
content: await importSqlSource(args, client, ctx),
|
|
138
144
|
contentType: "application/sql",
|
|
139
145
|
}),
|
|
140
146
|
},
|
package/dist/tools/files.js
CHANGED
|
@@ -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
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
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 },
|
|
@@ -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 -
|
|
167
|
-
inputSchema: {
|
|
168
|
-
|
|
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:
|
|
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.
|
|
3
|
+
"version": "0.5.1",
|
|
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": {
|