ecp-mcp-server 0.3.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 +10 -3
- package/CHANGELOG.md +31 -0
- package/README.md +20 -3
- package/dist/config.js +73 -0
- package/dist/ecp-client.js +110 -26
- package/dist/index.js +36 -15
- package/dist/local-files.js +154 -0
- package/dist/tools/apps.js +1 -1
- package/dist/tools/asdf.js +10 -0
- package/dist/tools/database.js +10 -4
- package/dist/tools/files.js +52 -9
- package/dist/tools/sql-engine-factory.js +10 -4
- package/dist/tools/system.js +2 -2
- package/package.json +1 -1
package/.env.sample
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
#
|
|
2
|
-
#
|
|
3
|
-
ECP_API_BASE_URL
|
|
1
|
+
# Your ECP address. Any of these work: example.com, the panel address
|
|
2
|
+
# https://example.com:2323, or the API URL https://example.com:2324/api.
|
|
3
|
+
# (ECP_API_BASE_URL is the older name and still works.)
|
|
4
|
+
ECP_URL=
|
|
4
5
|
|
|
5
6
|
# The hosting account this MCP server logs in as. One server = one account.
|
|
6
7
|
ECP_ACCOUNT_USERNAME=
|
|
@@ -13,6 +14,12 @@ ECP_REMEMBER=false
|
|
|
13
14
|
# Defaults to ./audit.log next to this file if unset.
|
|
14
15
|
ECP_MCP_AUDIT_LOG_PATH=
|
|
15
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
|
+
|
|
16
23
|
# Dev-only escape hatch: disables TLS certificate verification for this
|
|
17
24
|
# process (e.g. a self-signed dev ECP instance). Leave unset/false for any
|
|
18
25
|
# real account - this affects every outgoing HTTPS request the process
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,36 @@
|
|
|
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
|
+
|
|
19
|
+
## 0.4.0 — 2026-11-21
|
|
20
|
+
|
|
21
|
+
Ships with the ECP plugin for Claude (`plugin/`), which bundles this server.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- `ECP_URL`: your ECP address in any form people actually have it - `example.com`, the panel address `https://example.com:2323`, or the API URL. `ECP_API_BASE_URL` still works.
|
|
25
|
+
- `ecp_asdf_recommend`: picks a runtime version for an app that doesn't pin one exactly (newest LTS within its declared constraints).
|
|
26
|
+
- `ecp_files_compress` takes an optional `format` (zip, tar, tar.gz, tar.bz2, tar.xz). Older ECP ignores it and makes a zip.
|
|
27
|
+
- `ecp_files_change_permission` takes `recursive`. `false` changes only the folder itself, not its contents. Omitting it keeps the old behaviour (the folder and everything inside). Needs the ECP release after 2.0.6; older ECP ignores `false`.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
- Missing or invalid settings no longer stop the server at launch. It starts, and every tool replies with what's missing and where to set it, so the chat app shows a useful message instead of a failed server.
|
|
31
|
+
- Login errors say what went wrong in plain words: wrong username/password, or the ECP address can't be reached (with the cause).
|
|
32
|
+
- `ecp_system_update` is described as what it actually does: apply an ECP update by rebuilding the account's container (sites restart; files and databases kept). It never changed a password. `ecp_password` is now optional, as ECP doesn't use it.
|
|
33
|
+
|
|
3
34
|
## 0.3.0 — 2026-10-26
|
|
4
35
|
|
|
5
36
|
Matches ECP 2.0.5 / EHM 2.0.8.
|
package/README.md
CHANGED
|
@@ -24,6 +24,19 @@ It talks to ECP's own API (the same one ECP's web UI uses) as the hosting accoun
|
|
|
24
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
26
|
|
|
27
|
+
## Easiest: the ECP plugin for Claude
|
|
28
|
+
|
|
29
|
+
For people who just want to run their hosting from chat, without editing config files: install the **ECP plugin**, which bundles this server with step-by-step guides for websites, domains, HTTPS, databases, files and troubleshooting. In Claude Code:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
/plugin marketplace add EpicLabs23/ecp-mcp-server
|
|
33
|
+
/plugin install ecp@epiclabs23
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
It asks for your ECP panel address, username and password (the password goes to your system's secure storage). See [`plugin/README.md`](./plugin/README.md).
|
|
37
|
+
|
|
38
|
+
The rest of this page is for using the server directly with any MCP client.
|
|
39
|
+
|
|
27
40
|
## Requirements
|
|
28
41
|
|
|
29
42
|
- Node.js 18+
|
|
@@ -51,10 +64,11 @@ This server is configured entirely through environment variables — no config f
|
|
|
51
64
|
|
|
52
65
|
| Variable | Required | Description |
|
|
53
66
|
|---|---|---|
|
|
54
|
-
| `
|
|
67
|
+
| `ECP_URL` | yes | Your ECP address: `yourdomain.com`, the panel address `https://yourdomain.com:2323`, or the API URL `https://yourdomain.com:2324/api` all work. (`ECP_API_BASE_URL` is the older name and still works.) |
|
|
55
68
|
| `ECP_ACCOUNT_USERNAME` | yes | The hosting account to log in as. One server instance manages one account. |
|
|
56
69
|
| `ECP_ACCOUNT_PASSWORD` | yes | That account's password. |
|
|
57
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. |
|
|
58
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`. |
|
|
59
73
|
|
|
60
74
|
## Use it
|
|
@@ -64,7 +78,7 @@ This server is configured entirely through environment variables — no config f
|
|
|
64
78
|
```bash
|
|
65
79
|
claude mcp add ecp-mcp-server \
|
|
66
80
|
--scope user \
|
|
67
|
-
-e
|
|
81
|
+
-e ECP_URL=https://yourdomain.com:2323 \
|
|
68
82
|
-e ECP_ACCOUNT_USERNAME=youraccount \
|
|
69
83
|
-e ECP_ACCOUNT_PASSWORD=yourpassword \
|
|
70
84
|
-- npx ecp-mcp-server
|
|
@@ -83,7 +97,7 @@ Add to your `claude_desktop_config.json`:
|
|
|
83
97
|
"command": "npx",
|
|
84
98
|
"args": ["ecp-mcp-server"],
|
|
85
99
|
"env": {
|
|
86
|
-
"
|
|
100
|
+
"ECP_URL": "https://yourdomain.com:2323",
|
|
87
101
|
"ECP_ACCOUNT_USERNAME": "youraccount",
|
|
88
102
|
"ECP_ACCOUNT_PASSWORD": "yourpassword"
|
|
89
103
|
}
|
|
@@ -103,6 +117,7 @@ Worth understanding before you point this at an account you care about:
|
|
|
103
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.
|
|
104
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.
|
|
105
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.
|
|
106
121
|
- **Credentials** live only in the environment variables you provide and in-process memory — never written to disk beyond what you configure.
|
|
107
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.
|
|
108
123
|
|
|
@@ -117,6 +132,8 @@ npm run build
|
|
|
117
132
|
npm run inspect # opens the MCP Inspector to test tools manually
|
|
118
133
|
```
|
|
119
134
|
|
|
135
|
+
Releasing the server and the plugin: see [`docs/RELEASE.md`](./docs/RELEASE.md).
|
|
136
|
+
|
|
120
137
|
## License
|
|
121
138
|
|
|
122
139
|
MIT
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Turns whatever the user typed as their ECP address into ecp-go's API base
|
|
2
|
+
// URL. People know the panel they log into (https://example.com:2323), not
|
|
3
|
+
// the API behind it, so all of these work:
|
|
4
|
+
// example.com
|
|
5
|
+
// https://example.com:2323 (the panel itself)
|
|
6
|
+
// https://example.com:2323/dashboard (a copied panel link)
|
|
7
|
+
// https://example.com:2324/api (the API, as older configs had it)
|
|
8
|
+
// ecp-go always serves the panel on 2323 and the API on 2324 of the same host.
|
|
9
|
+
export function normalizeApiBaseUrl(input) {
|
|
10
|
+
let raw = input.trim();
|
|
11
|
+
if (!/^[a-z][a-z0-9+.-]*:\/\//i.test(raw))
|
|
12
|
+
raw = `https://${raw}`;
|
|
13
|
+
let url;
|
|
14
|
+
try {
|
|
15
|
+
url = new URL(raw);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new Error(`"${input}" isn't a web address. Use your ECP panel address, e.g. https://example.com:2323`);
|
|
19
|
+
}
|
|
20
|
+
if (url.protocol !== "https:" && url.protocol !== "http:") {
|
|
21
|
+
throw new Error(`"${input}" isn't a web address. Use your ECP panel address, e.g. https://example.com:2323`);
|
|
22
|
+
}
|
|
23
|
+
// An explicit API URL on a non-standard port is kept as given (a proxied
|
|
24
|
+
// or dev setup); everything else is mapped to <host>:2324/api.
|
|
25
|
+
const path = url.pathname.replace(/\/+$/, "");
|
|
26
|
+
if (/\/api$/.test(path) && url.port !== "2323") {
|
|
27
|
+
return `${url.origin}${path}`;
|
|
28
|
+
}
|
|
29
|
+
return `${url.protocol}//${url.hostname}:2324/api`;
|
|
30
|
+
}
|
|
31
|
+
/** The panel URL to send users to for anything this server can't do. */
|
|
32
|
+
export function panelUrlFromApiBase(apiBaseUrl) {
|
|
33
|
+
return apiBaseUrl.replace(/:2324\/api\/?$/, ":2323");
|
|
34
|
+
}
|
|
35
|
+
const read = (name) => process.env[name]?.trim() ?? "";
|
|
36
|
+
// ECP_URL is the friendly name; ECP_API_BASE_URL is kept for existing setups.
|
|
37
|
+
// Unexpanded "${...}" placeholders (a plugin option that was never filled in)
|
|
38
|
+
// count as empty.
|
|
39
|
+
const value = (name) => {
|
|
40
|
+
const v = read(name);
|
|
41
|
+
return /^\$\{[^}]*\}$/.test(v) ? "" : v;
|
|
42
|
+
};
|
|
43
|
+
export function loadConfig() {
|
|
44
|
+
const address = value("ECP_URL") || value("ECP_API_BASE_URL");
|
|
45
|
+
const username = value("ECP_ACCOUNT_USERNAME");
|
|
46
|
+
const password = value("ECP_ACCOUNT_PASSWORD");
|
|
47
|
+
let apiBaseUrl;
|
|
48
|
+
if (address) {
|
|
49
|
+
try {
|
|
50
|
+
apiBaseUrl = normalizeApiBaseUrl(address);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
return { ok: false, problem: err.message };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const missing = [
|
|
57
|
+
!address && "your ECP panel address",
|
|
58
|
+
!username && "your ECP username",
|
|
59
|
+
!password && "your ECP password",
|
|
60
|
+
].filter(Boolean);
|
|
61
|
+
if (missing.length > 0 || !apiBaseUrl) {
|
|
62
|
+
return { ok: false, problem: `ECP isn't set up yet: missing ${missing.join(", ")}.`, apiBaseUrl };
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
ok: true,
|
|
66
|
+
config: {
|
|
67
|
+
apiBaseUrl,
|
|
68
|
+
username,
|
|
69
|
+
password,
|
|
70
|
+
remember: value("ECP_REMEMBER").toLowerCase() === "true",
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
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);
|
|
@@ -61,17 +66,30 @@ export class EcpClient {
|
|
|
61
66
|
this.accessTokenExpiresAt = exp ? exp - 60_000 : Date.now() + 10 * 60_000;
|
|
62
67
|
}
|
|
63
68
|
async login() {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
let res;
|
|
70
|
+
try {
|
|
71
|
+
res = await fetch(`${this.baseUrl}/auth/login`, {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { "content-type": "application/json" },
|
|
74
|
+
body: JSON.stringify({
|
|
75
|
+
username: this.username,
|
|
76
|
+
password: this.password,
|
|
77
|
+
remember: this.remember,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
catch (err) {
|
|
82
|
+
// fetch only throws for transport problems (DNS, refused, TLS), and its
|
|
83
|
+
// own message is just "fetch failed" - name the address and the cause.
|
|
84
|
+
const cause = err.cause;
|
|
85
|
+
const detail = cause?.code ?? cause?.message ?? err.message;
|
|
86
|
+
throw new Error(`Couldn't reach ECP at ${this.baseUrl} (${detail}). Check the panel address in the settings and that the server is online.`);
|
|
87
|
+
}
|
|
73
88
|
if (!res.ok) {
|
|
74
89
|
const text = await res.text().catch(() => "");
|
|
90
|
+
if (res.status === 400 || res.status === 401 || res.status === 403) {
|
|
91
|
+
throw new Error(`ECP didn't accept the username or password (${res.status}). Check them in the settings - they're the same ones you use to log into the ECP panel. ${text}`.trim());
|
|
92
|
+
}
|
|
75
93
|
throw new Error(`ECP login failed (${res.status}): ${text}`);
|
|
76
94
|
}
|
|
77
95
|
this.captureRefreshCookie(res);
|
|
@@ -136,26 +154,92 @@ export class EcpClient {
|
|
|
136
154
|
}
|
|
137
155
|
return data;
|
|
138
156
|
}
|
|
139
|
-
/**
|
|
140
|
-
|
|
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) {
|
|
141
175
|
const token = await this.ensureAccessToken();
|
|
142
176
|
const url = new URL(`${this.baseUrl}/${path.replace(/^\/+/, "")}`);
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
for (const [key, value] of Object.entries(fields)) {
|
|
177
|
+
if (query) {
|
|
178
|
+
for (const [key, value] of Object.entries(query)) {
|
|
146
179
|
if (value !== undefined && value !== null)
|
|
147
|
-
|
|
180
|
+
url.searchParams.set(key, String(value));
|
|
148
181
|
}
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
})());
|
|
151
215
|
};
|
|
152
|
-
const
|
|
153
|
-
|
|
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);
|
|
154
238
|
if (res.status === 401) {
|
|
155
239
|
await this.refresh();
|
|
156
|
-
res = await
|
|
240
|
+
res = await send(this.accessToken);
|
|
157
241
|
}
|
|
158
|
-
const text =
|
|
242
|
+
const text = res.text;
|
|
159
243
|
const data = text ? safeJsonParse(text) : undefined;
|
|
160
244
|
if (!res.ok) {
|
|
161
245
|
throw new Error(`ECP API POST ${path} failed (${res.status}): ${text}`);
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import "dotenv/config";
|
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
5
|
import { EcpClient } from "./ecp-client.js";
|
|
6
|
+
import { loadConfig, panelUrlFromApiBase } from "./config.js";
|
|
6
7
|
import { auditLog } from "./audit-log.js";
|
|
7
8
|
import { accountTools } from "./tools/account.js";
|
|
8
9
|
import { appsTools } from "./tools/apps.js";
|
|
@@ -21,6 +22,7 @@ import { backupTools } from "./tools/backup.js";
|
|
|
21
22
|
import { cpanelImportTools } from "./tools/cpanel-import.js";
|
|
22
23
|
import { shellTools } from "./tools/shell.js";
|
|
23
24
|
import { createRequire } from "node:module";
|
|
25
|
+
import { fileURLToPath } from "node:url";
|
|
24
26
|
// Dev-only escape hatch for a self-signed target (see .env.sample). Process-
|
|
25
27
|
// wide and opt-in only - never the default, since it weakens every HTTPS
|
|
26
28
|
// request this process makes, not just ones to the configured ECP host.
|
|
@@ -28,29 +30,33 @@ if ((process.env.ECP_TLS_INSECURE ?? "false").toLowerCase() === "true") {
|
|
|
28
30
|
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
|
29
31
|
console.error("[ecp-mcp-server] WARNING: ECP_TLS_INSECURE=true - TLS certificate verification is disabled for this process.");
|
|
30
32
|
}
|
|
31
|
-
function requireEnv(name) {
|
|
32
|
-
const value = process.env[name]?.trim();
|
|
33
|
-
if (!value) {
|
|
34
|
-
throw new Error(`Missing required env var ${name} (see .env.sample)`);
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
}
|
|
38
33
|
// Same relative path from src/ (tsx) and dist/ (built), and package.json
|
|
39
34
|
// always ships in the npm tarball - keeps the handshake version in step with
|
|
40
35
|
// the published one.
|
|
41
36
|
const { version } = createRequire(import.meta.url)("../package.json");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
37
|
+
// A missing or bad setting doesn't stop the server: it still starts, and every
|
|
38
|
+
// tool answers with what's wrong. In a chat client a server that exits at
|
|
39
|
+
// launch just shows up as "failed", which tells a non-technical user nothing.
|
|
40
|
+
const configResult = loadConfig();
|
|
41
|
+
const client = configResult.ok
|
|
42
|
+
? new EcpClient({
|
|
43
|
+
baseUrl: configResult.config.apiBaseUrl,
|
|
44
|
+
username: configResult.config.username,
|
|
45
|
+
password: configResult.config.password,
|
|
46
|
+
remember: configResult.config.remember,
|
|
47
|
+
})
|
|
48
|
+
: null;
|
|
49
|
+
const setupProblem = configResult.ok
|
|
50
|
+
? null
|
|
51
|
+
: `${configResult.problem} Add the missing details in this MCP server's settings (in the ECP plugin: its options; otherwise the ECP_URL, ECP_ACCOUNT_USERNAME and ECP_ACCOUNT_PASSWORD environment variables), then restart the chat app.`;
|
|
52
|
+
if (setupProblem)
|
|
53
|
+
console.error(`[ecp-mcp-server] ${setupProblem}`);
|
|
49
54
|
// ecp-go serves its browser UI on port 2323 and its API (what this server
|
|
50
55
|
// talks to) on 2324, same host - derived here so the "go do this in ecp-ui"
|
|
51
56
|
// guidance below points at a real, clickable URL instead of a vague
|
|
52
57
|
// pointer.
|
|
53
|
-
const
|
|
58
|
+
const apiBaseUrl = configResult.ok ? configResult.config.apiBaseUrl : configResult.apiBaseUrl;
|
|
59
|
+
const ecpUiUrl = apiBaseUrl ? panelUrlFromApiBase(apiBaseUrl) : "your ECP panel (port 2323 of your domain)";
|
|
54
60
|
const server = new McpServer({ name: "ecp-mcp-server", version }, {
|
|
55
61
|
instructions: `This server manages one ECP hosting account's apps, domains, databases, files, PHP, SSL, and related settings.
|
|
56
62
|
|
|
@@ -91,10 +97,25 @@ const toolContext = {
|
|
|
91
97
|
});
|
|
92
98
|
return result.action === "accept";
|
|
93
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
|
+
},
|
|
94
113
|
};
|
|
95
114
|
for (const tool of allTools) {
|
|
96
115
|
server.registerTool(tool.name, { description: tool.description, inputSchema: tool.inputSchema }, async (args) => {
|
|
97
116
|
try {
|
|
117
|
+
if (!client)
|
|
118
|
+
throw new Error(setupProblem ?? "ECP isn't set up yet.");
|
|
98
119
|
const result = await tool.handler(args, client, toolContext);
|
|
99
120
|
await auditLog({ tool: tool.name, args, result: "success" });
|
|
100
121
|
return {
|
|
@@ -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/apps.js
CHANGED
|
@@ -40,7 +40,7 @@ export const appsTools = [
|
|
|
40
40
|
},
|
|
41
41
|
{
|
|
42
42
|
name: "ecp_apps_detect",
|
|
43
|
-
description: "Inspect an app directory and detect its app root, tech stack (deploy_type + framework_hint), web root, whether it needs a database, its runtime (asdf_key + version), and suggested install/build/start commands. " +
|
|
43
|
+
description: "Inspect an app directory and detect its app root, tech stack (deploy_type + framework_hint), web root, whether it needs a database, its runtime (asdf_key + version, or runtime_constraints when there's no exact pin - feed those to ecp_asdf_recommend), and suggested install/build/start commands. " +
|
|
44
44
|
"Read-only: it runs no commands and changes nothing, so it's safe to call before creating or deploying an app. app_dir is a folder name under ~/apps or an absolute path inside it. " +
|
|
45
45
|
"If root_ambiguous is true, pick one of root_candidates and call this again with it.",
|
|
46
46
|
inputSchema: { app_dir: z.string() },
|
package/dist/tools/asdf.js
CHANGED
|
@@ -30,6 +30,16 @@ export const asdfTools = [
|
|
|
30
30
|
inputSchema: { name: z.string() },
|
|
31
31
|
handler: async (args, client) => client.request("GET", `asdf/list-installed/${args.name}`),
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
name: "ecp_asdf_recommend",
|
|
35
|
+
description: "Pick a runtime version for an app that doesn't pin one exactly (ecp_apps_detect returned no runtime_version). " +
|
|
36
|
+
"Pass runtime_constraints from ecp_apps_detect as constraints (or [] if there were none). Returns the newest LTS release " +
|
|
37
|
+
"(newest stable for tools with no LTS, like python) that satisfies all of them - e.g. engines.node \">=22\" gets the latest Node LTS, not 22. " +
|
|
38
|
+
"installed_match is an installed version on that line to use as-is; otherwise install `version`. relaxed=true means no release met every upper bound, so only minimums were applied. " +
|
|
39
|
+
"Prefer this over choosing a version yourself.",
|
|
40
|
+
inputSchema: { name: z.string(), constraints: z.array(z.string()).default([]) },
|
|
41
|
+
handler: async (args, client) => client.request("POST", "asdf/recommend", { body: { name: args.name, constraints: args.constraints } }),
|
|
42
|
+
},
|
|
33
43
|
{
|
|
34
44
|
name: "ecp_asdf_install",
|
|
35
45
|
description: "Start installing a plugin version. Returns once the install STARTS - building can take minutes (python compiles from source). " +
|
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 },
|
|
@@ -96,29 +129,39 @@ export const filesTools = [
|
|
|
96
129
|
},
|
|
97
130
|
{
|
|
98
131
|
name: "ecp_files_change_permission",
|
|
99
|
-
description: "chmod a file (e.g. new_permission: '644').",
|
|
100
|
-
inputSchema: {
|
|
132
|
+
description: "chmod a file or folder (e.g. new_permission: '644'). For a folder, ECP applies the mode to the folder and everything inside it unless recursive is false.",
|
|
133
|
+
inputSchema: {
|
|
134
|
+
current_directory: z.string(),
|
|
135
|
+
file_name: z.string(),
|
|
136
|
+
new_permission: z.string(),
|
|
137
|
+
recursive: z
|
|
138
|
+
.boolean()
|
|
139
|
+
.optional()
|
|
140
|
+
.describe("Folders only. false changes just the folder itself; omitted or true also changes every file and subfolder to the same mode (files usually want 644, folders 755). Needs the ECP release after 2.0.6; older ECP ignores false and changes everything."),
|
|
141
|
+
},
|
|
101
142
|
handler: async (args, client) => client.request("POST", "file-system/change-permission", { body: args }),
|
|
102
143
|
},
|
|
103
144
|
{
|
|
104
145
|
name: "ecp_files_compress",
|
|
105
|
-
description: "Compress one or more files/folders into an archive.",
|
|
146
|
+
description: "Compress one or more files/folders (paths relative to current_directory) into an archive in current_directory. Fails if the archive already exists.",
|
|
106
147
|
inputSchema: {
|
|
107
148
|
file_paths: z.array(z.string()),
|
|
108
149
|
output_filename: z.string(),
|
|
109
150
|
current_directory: z.string(),
|
|
151
|
+
format: z.enum(["zip", "tar", "tar.gz", "tar.bz2", "tar.xz"]).optional().describe("Archive format; default zip"),
|
|
110
152
|
},
|
|
111
153
|
handler: async (args, client) => client.request("POST", "file-system/compress", {
|
|
112
154
|
body: {
|
|
113
155
|
filePaths: args.file_paths,
|
|
114
156
|
outputFilename: args.output_filename,
|
|
115
157
|
currentDirectory: args.current_directory,
|
|
158
|
+
...(args.format ? { format: args.format } : {}),
|
|
116
159
|
},
|
|
117
160
|
}),
|
|
118
161
|
},
|
|
119
162
|
{
|
|
120
163
|
name: "ecp_files_extract",
|
|
121
|
-
description: "Extract an archive into a destination directory.",
|
|
164
|
+
description: "Extract an archive (.zip, .tar, .tar.gz/.tgz, .tar.bz2, .tar.xz) into a destination directory.",
|
|
122
165
|
inputSchema: { file_path: z.string(), destination: z.string() },
|
|
123
166
|
handler: async (args, client) => client.request("POST", "file-system/extract", { body: args }),
|
|
124
167
|
},
|
|
@@ -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/dist/tools/system.js
CHANGED
|
@@ -84,9 +84,9 @@ export const systemTools = [
|
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
86
|
name: "ecp_system_update",
|
|
87
|
-
description: "
|
|
87
|
+
description: "Apply an ECP/hosting update (what ECP's own Update button does): EHM rebuilds this account's container on the current or given hosting environment/version, then restores logins, settings and site configs. Files and databases are kept, but every site restarts and is briefly offline. Check ecp_system_check_for_update first. It does not change any password.",
|
|
88
88
|
inputSchema: {
|
|
89
|
-
ecp_password: z.string(),
|
|
89
|
+
ecp_password: z.string().optional().describe("Not used by ECP; accepted for compatibility with older clients."),
|
|
90
90
|
hosting_environment: z.string().optional(),
|
|
91
91
|
hosting_version: z.string().optional(),
|
|
92
92
|
confirm: z.literal(true),
|
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": {
|