@jwjp/ftp-mcp 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/package.json +1 -1
- package/src/paths.js +6 -5
- package/src/transports.js +16 -0
- package/src/workspace.js +18 -4
package/README.md
CHANGED
|
@@ -53,7 +53,7 @@ SFTP is SSH File Transfer Protocol, not FTP over TLS. For SFTP, get the SSH host
|
|
|
53
53
|
|
|
54
54
|
The former `FTP_*` variables still work for existing FTP/FTPS configurations. A missing `REMOTE_PROTOCOL` follows the old `FTP_SECURE` setting (`true` → `ftps`, `false` → `ftp`, `implicit` → `ftps-implicit`). If neither is set, the server uses `ftps` and prints a warning to stderr at startup. New configurations should use the `REMOTE_*` names and explicitly set the protocol.
|
|
55
55
|
|
|
56
|
-
The built-in exclusion list blocks these names anywhere in the path: `.git`, `.env` and `.env.*`, `vendor`, `node_modules`, credential files (`.ssh`, `.netrc`, `.git-credentials`, `.htpasswd`), and agent or MCP configuration (`.mcp.json`, `.claude`, `.codex`).
|
|
56
|
+
The built-in exclusion list blocks these names anywhere in the path: version control (`.git`, `.hg`), `.env` and `.env.*`, `vendor`, `node_modules`, credential files (`.ssh`, `.netrc`, `.git-credentials`, `.htpasswd`, `.npmrc`, `.pypirc`, `.pgpass`), and agent, editor, or MCP configuration (`.mcp.json`, `.claude`, `.codex`, `.cursor`, `.gemini`, `.vscode`). Configuration is excluded because a downloaded file could make a local agent or editor run commands, for example through an MCP server definition, a task that runs when the folder opens, or a Mercurial hook. Credential files are excluded so an upload cannot publish a token. There is no setting to allow a built-in exclusion. Extra entries match a name segment or an exact relative path and its descendants, case-insensitively. Review exclusions for each project. Install dependencies or build generated files locally when appropriate.
|
|
57
57
|
|
|
58
58
|
### VS Code with GitHub Copilot
|
|
59
59
|
|
|
@@ -121,7 +121,7 @@ Replace the script path and set the required variables locally before starting C
|
|
|
121
121
|
|
|
122
122
|
Upload tokens are single-use and held only in the MCP process. Restarting it requires a fresh preview. Uploads first create the directories the preview listed, one at a time, outermost first. If the upload then fails before the file is renamed into place, the server removes those directories again, innermost first. It removes only empty directories, so files another writer added are kept, and it reports any directory it could not remove. Uploads then check the remote listing against the preview, so a file that appeared, disappeared, or changed size stops the upload before any bytes are sent. They then write a temporary remote file, verify it by SHA-256, compare the remote target with the preview by SHA-256 again, and rename the temporary file into place. After the rename, the listing must show a file of the uploaded size. For FTP replacement, the old file is moved to a backup name because some servers refuse to rename over an existing file. If the final rename fails, the server checks whether the target is absent before attempting to restore the backup. If it cannot confirm the result, it reports the target and backup paths for inspection. The server also keeps the FTP backup until it verifies the final file and reports the backup location if verification or cleanup fails. For SFTP replacement, the server must support the `posix-rename@openssh.com` extension.
|
|
123
123
|
|
|
124
|
-
Each MCP process keeps one remote connection and runs one tool call on it at a time. A connection unused for `REMOTE_IDLE_TIMEOUT_MS` is closed, and an idle connection is checked (FTP `NOOP`, or an SFTP directory query) before reuse, so one the server has dropped is replaced. A check that gets no answer within 5 seconds, as happens when a firewall drops an idle connection silently, also leads to a new connection. A failed tool call closes its connection, and the next call reconnects. Each MCP process runs one upload or download at a time. Other MCP processes, editors, and remote writers can still change files between verification and rename. FTP replacement has a brief interval when the target name is absent. A
|
|
124
|
+
Each MCP process keeps one remote connection and runs one tool call on it at a time. A connection unused for `REMOTE_IDLE_TIMEOUT_MS` is closed, and an idle connection is checked (FTP `NOOP`, or an SFTP directory query) before reuse, so one the server has dropped is replaced. A check that gets no answer within 5 seconds, as happens when a firewall drops an idle connection silently, also leads to a new connection. A failed tool call closes its connection, and the next call reconnects. Each MCP process runs one upload or download at a time. Other MCP processes, editors, and remote writers can still change files between verification and rename. FTP replacement has a brief interval when the target name is absent. A replacement keeps the permission bits of the file it replaces: the server copies them to the temporary file before the rename. SFTP reads and sets them directly. FTP reads them from a Unix-style listing and sets them with `SITE CHMOD`; a server that lists no permissions, such as most Windows servers, is left alone. If the server refuses the change, the upload still completes and its result carries a warning with the previous mode. Ownership is not preserved. An interruption can leave a temporary or backup file. Use a separate deployment or backup process when interruption cannot be tolerated.
|
|
125
125
|
|
|
126
126
|
## Boundaries
|
|
127
127
|
|
package/package.json
CHANGED
package/src/paths.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
// Version control, secrets, dependency trees, and agent or MCP
|
|
5
|
-
// that a downloaded file could use to run commands on this
|
|
4
|
+
// Version control, secrets, dependency trees, and agent, editor, or MCP
|
|
5
|
+
// configuration that a downloaded file could use to run commands on this
|
|
6
|
+
// machine. Mercurial's .hg/hgrc can define hooks that run commands.
|
|
6
7
|
const DEFAULT_EXCLUDES = [
|
|
7
|
-
'.git', '.env', 'node_modules', 'vendor',
|
|
8
|
-
'.ssh', '.netrc', '.git-credentials', '.htpasswd',
|
|
9
|
-
'.mcp.json', '.claude', '.codex'
|
|
8
|
+
'.git', '.hg', '.env', 'node_modules', 'vendor',
|
|
9
|
+
'.ssh', '.netrc', '.git-credentials', '.htpasswd', '.npmrc', '.pypirc', '.pgpass',
|
|
10
|
+
'.mcp.json', '.claude', '.codex', '.cursor', '.gemini', '.vscode'
|
|
10
11
|
];
|
|
11
12
|
const TRANSFER_TEMP = /^\.mcp-(?:upload|backup|download)-[0-9a-f-]{36}\.tmp$/iu;
|
|
12
13
|
|
package/src/transports.js
CHANGED
|
@@ -83,6 +83,17 @@ export class FtpTransport {
|
|
|
83
83
|
// empty directory is removed.
|
|
84
84
|
async mkdir(relative) { await this.client.send(`MKD ${relative}`); }
|
|
85
85
|
async rmdir(relative) { await this.client.removeEmptyDir(relative); }
|
|
86
|
+
// Permission bits from a Unix-style listing, or null when the server does
|
|
87
|
+
// not report them (as Windows FTP servers do not).
|
|
88
|
+
async mode(relative) {
|
|
89
|
+
const parent = path.posix.dirname(relative);
|
|
90
|
+
const name = path.posix.basename(relative);
|
|
91
|
+
const permissions = (await this.client.list(parent)).find(entry => entry.name === name)?.permissions;
|
|
92
|
+
if (!permissions) return null;
|
|
93
|
+
return (permissions.user << 6) | (permissions.group << 3) | permissions.world;
|
|
94
|
+
}
|
|
95
|
+
// SITE CHMOD is a common extension, not part of the FTP standard.
|
|
96
|
+
async chmod(relative, mode) { await this.client.send(`SITE CHMOD ${mode.toString(8).padStart(3, '0')} ${relative}`); }
|
|
86
97
|
async close() { this.client.close(); }
|
|
87
98
|
}
|
|
88
99
|
|
|
@@ -217,6 +228,11 @@ export class SftpTransport {
|
|
|
217
228
|
}));
|
|
218
229
|
}
|
|
219
230
|
async rmdir(relative) { await this.#run('directory cleanup', () => this.client.rmdir(this.remote(relative), false)); }
|
|
231
|
+
async mode(relative) {
|
|
232
|
+
const { mode } = await this.#run('permission check', () => this.client.stat(this.remote(relative)));
|
|
233
|
+
return Number.isInteger(mode) ? mode & 0o777 : null;
|
|
234
|
+
}
|
|
235
|
+
async chmod(relative, mode) { await this.#run('permission change', () => this.client.chmod(this.remote(relative), mode)); }
|
|
220
236
|
async close() {
|
|
221
237
|
if (!this.#timeoutError) await this.#run('disconnect', () => this.client.end());
|
|
222
238
|
}
|
package/src/workspace.js
CHANGED
|
@@ -341,8 +341,9 @@ export class FtpWorkspace {
|
|
|
341
341
|
}
|
|
342
342
|
let backup;
|
|
343
343
|
let stagedFile;
|
|
344
|
+
let permissionWarning;
|
|
344
345
|
try {
|
|
345
|
-
({ backup, stagedFile } = await this.#stageAndRename(client, relative, preview));
|
|
346
|
+
({ backup, stagedFile, permissionWarning } = await this.#stageAndRename(client, relative, preview));
|
|
346
347
|
} catch (error) {
|
|
347
348
|
// Nothing was renamed into place, so the new directories hold no file
|
|
348
349
|
// of this upload. Remove them so the remote tree is as it was.
|
|
@@ -358,11 +359,12 @@ export class FtpWorkspace {
|
|
|
358
359
|
if (uploaded?.type !== FileType.File || (Number.isSafeInteger(uploaded.size) && uploaded.size !== stagedFile.bytes)) {
|
|
359
360
|
throw new UserError(`Upload verification failed; inspect the remote file before retrying.${recovery}`);
|
|
360
361
|
}
|
|
361
|
-
|
|
362
|
+
const warnings = permissionWarning ? [permissionWarning] : [];
|
|
362
363
|
if (backup) {
|
|
363
364
|
try { await client.remove(backup); }
|
|
364
|
-
catch {
|
|
365
|
+
catch { warnings.push(`Upload succeeded, but the previous version remains at ${backup}; remove it manually.`); }
|
|
365
366
|
}
|
|
367
|
+
const warning = warnings.join(' ');
|
|
366
368
|
return {
|
|
367
369
|
path: relative, status: 'uploaded', ...stagedFile,
|
|
368
370
|
...(created.length ? { createdDirectories: created } : {}),
|
|
@@ -384,6 +386,17 @@ export class FtpWorkspace {
|
|
|
384
386
|
return error;
|
|
385
387
|
}
|
|
386
388
|
|
|
389
|
+
// A replacement is a new file, so it would get the server's default
|
|
390
|
+
// permissions. Give the staged file the target's permission bits before the
|
|
391
|
+
// rename, so a private file such as a 0600 configuration stays private.
|
|
392
|
+
async #copyMode(client, relative, staged) {
|
|
393
|
+
const mode = await client.mode(relative);
|
|
394
|
+
if (mode === null || mode === await client.mode(staged)) return null;
|
|
395
|
+
try { await client.chmod(staged, mode); }
|
|
396
|
+
catch { return `Upload succeeded, but the server refused to keep the previous permissions (${mode.toString(8).padStart(3, '0')}); check ${relative}.`; }
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
|
|
387
400
|
async #stageAndRename(client, relative, preview) {
|
|
388
401
|
// A listing catches a remote file that appeared, disappeared, or changed
|
|
389
402
|
// size before any bytes are sent. A same-size change is caught by the
|
|
@@ -409,8 +422,9 @@ export class FtpWorkspace {
|
|
|
409
422
|
if (latestLocal.sha256 !== preview.localSha256) throw new UserError('Local file changed during upload.');
|
|
410
423
|
const latestRemote = await this.readRemote(client, relative);
|
|
411
424
|
if ((latestRemote?.sha256 ?? null) !== preview.remoteSha256) throw new UserError('Remote file changed during upload.');
|
|
425
|
+
const permissionWarning = latestRemote ? await this.#copyMode(client, relative, staged) : null;
|
|
412
426
|
const backup = await client.rename(staged, relative, latestRemote !== null);
|
|
413
|
-
return { backup, stagedFile };
|
|
427
|
+
return { backup, stagedFile, permissionWarning };
|
|
414
428
|
} catch (error) {
|
|
415
429
|
try {
|
|
416
430
|
if (await this.entry(client, staged)) await client.remove(staged);
|