@jwjp/ftp-mcp 0.3.1 → 0.3.2

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 CHANGED
@@ -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 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 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 remote replacement can change permissions, and an interruption can leave a temporary or backup file. Use a separate deployment or backup process when interruption cannot be tolerated.
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 remote replacement can change permissions, and 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
 
@@ -148,6 +148,8 @@ python -m pip install -r integration/requirements.txt
148
148
  python integration/run.py
149
149
  ```
150
150
 
151
- To release, bump the version in `package.json` and `package-lock.json` through a pull request, then publish a GitHub release tagged `v<version>` on the merge commit. The `Publish` workflow checks that the tag matches `package.json`, runs the tests, and publishes to npm through trusted publishing, so no npm token is stored in the repository.
151
+ To test an npm tarball locally, run `npm pack` and pass the printed filename to `python integration/run.py --package <filename>`. The integration suite installs the tarball in a temporary directory and starts the installed `ftp-workspace-mcp` command.
152
+
153
+ To release, bump the version in `package.json` and `package-lock.json` through a pull request, then publish a GitHub release tagged `v<version>` on the merge commit. The `Publish` workflow checks the tag, runs the tests, and verifies transfers through the installed CLI. It publishes the verified tarball through npm trusted publishing.
152
154
 
153
155
  Test against your own server before relying on a production upload. Contributions are welcome under the MIT license.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jwjp/ftp-mcp",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "A guarded FTP/SFTP MCP server for local AI coding workflows",
5
5
  "repository": {
6
6
  "type": "git",
package/src/transports.js CHANGED
@@ -9,6 +9,10 @@ import SftpClient from 'ssh2-sftp-client';
9
9
  import { DEFAULT_SFTP_TIMEOUT_MS } from './config.js';
10
10
  import { UserError } from './paths.js';
11
11
 
12
+ // How long a reused idle connection may take to answer a keepalive check
13
+ // before it is closed and replaced.
14
+ export const PING_TIMEOUT_MS = 5_000;
15
+
12
16
  export class FtpTransport {
13
17
  constructor(config, client = new FtpClient(30_000)) {
14
18
  this.config = config;
@@ -24,7 +28,17 @@ export class FtpTransport {
24
28
  async cd(root) { await this.client.cd(root); }
25
29
  async ping() {
26
30
  if (this.client.closed) throw new Error('FTP connection is closed.');
27
- await this.client.send('NOOP');
31
+ // A connection dropped silently by a firewall or NAT would otherwise wait
32
+ // for basic-ftp's 30 s timeout before the caller gets a new connection.
33
+ let timer;
34
+ const expired = new Promise((_, reject) => {
35
+ timer = setTimeout(() => {
36
+ this.client.close();
37
+ reject(new Error('FTP keepalive check timed out.'));
38
+ }, PING_TIMEOUT_MS);
39
+ });
40
+ try { await Promise.race([this.client.send('NOOP'), expired]); }
41
+ finally { clearTimeout(timer); }
28
42
  }
29
43
  async list(relative) { return this.client.list(relative); }
30
44
  async downloadTo(local, relative) { await this.client.downloadTo(local, relative); }
@@ -80,9 +94,9 @@ export class SftpTransport {
80
94
  // The timeout measures inactivity. A transfer passes `progress` a callback
81
95
  // to call for each chunk, so a large file that keeps moving is not cut off
82
96
  // while a stalled request still is.
83
- async #run(operation, action) {
97
+ async #run(operation, action, limitMs = Infinity) {
84
98
  if (this.#timeoutError) throw this.#timeoutError;
85
- const timeoutMs = this.config.sftpTimeoutMs ?? DEFAULT_SFTP_TIMEOUT_MS;
99
+ const timeoutMs = Math.min(this.config.sftpTimeoutMs ?? DEFAULT_SFTP_TIMEOUT_MS, limitMs);
86
100
  let timer;
87
101
  let settled = false;
88
102
  let expire;
@@ -123,7 +137,8 @@ export class SftpTransport {
123
137
  if (await this.#run('root check', () => this.client.exists(root)) !== 'd') throw new UserError('Remote root is not a directory.');
124
138
  this.root = root;
125
139
  }
126
- async ping() { await this.#run('keepalive check', () => this.client.cwd()); }
140
+ // A short limit lets a silently dropped connection be replaced quickly.
141
+ async ping() { await this.#run('keepalive check', () => this.client.cwd(), PING_TIMEOUT_MS); }
127
142
  remote(relative) {
128
143
  if (!this.root) throw new Error('SFTP root is not set.');
129
144
  return path.posix.join(this.root, relative);