@jwjp/ftp-mcp 0.8.0 → 0.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jwjp/ftp-mcp",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "A guarded FTP/SFTP MCP server for local AI coding workflows",
5
5
  "mcpName": "io.github.jwjp/ftp-mcp",
6
6
  "repository": {
package/src/transports.js CHANGED
@@ -117,7 +117,12 @@ export class FtpTransport {
117
117
  async mode(relative) {
118
118
  const parent = path.posix.dirname(relative);
119
119
  const name = path.posix.basename(relative);
120
- const permissions = (await this.client.list(parent)).find(entry => entry.name === name)?.permissions;
120
+ return this.modeFromListing((await this.client.list(parent)).find(entry => entry.name === name));
121
+ }
122
+ // The listing is the only source of FTP permissions, so an entry without
123
+ // them means there are none to keep.
124
+ modeFromListing(entry) {
125
+ const permissions = entry?.permissions;
121
126
  if (!permissions) return null;
122
127
  return (permissions.user << 6) | (permissions.group << 3) | permissions.world;
123
128
  }
package/src/workspace.js CHANGED
@@ -528,10 +528,15 @@ export class FtpWorkspace {
528
528
  // A replacement is a new file, so it would get the server's default
529
529
  // permissions. Give the staged file the target's permission bits before the
530
530
  // rename, so a private file such as a 0600 configuration stays private.
531
- async #copyMode(client, relative, staged) {
532
- const mode = await client.mode(relative);
533
- if (mode === null || mode === await client.mode(staged)) return null;
534
- try { await client.chmod(staged, mode); }
531
+ // An FTP listing already carries the permission bits, so the entries read
532
+ // during this upload answer without another LIST. Other transports, and
533
+ // listings without bits, ask the server.
534
+ async #copyMode(client, target, staged) {
535
+ const modeOf = async ({ relative, entry }) => client.modeFromListing?.(entry) ?? client.mode(relative);
536
+ const mode = await modeOf(target);
537
+ const relative = target.relative;
538
+ if (mode === null || mode === await modeOf(staged)) return null;
539
+ try { await client.chmod(staged.relative, mode); }
535
540
  catch { return `Upload succeeded, but the server refused to keep the previous permissions (${mode.toString(8).padStart(3, '0')}); check ${relative}.`; }
536
541
  return null;
537
542
  }
@@ -555,13 +560,15 @@ export class FtpWorkspace {
555
560
  source.destroy();
556
561
  await handle.close();
557
562
  }
558
- const stagedFile = await this.readRemote(client, staged);
563
+ const stagedEntry = await this.#remoteEntry(client, staged);
564
+ const stagedFile = stagedEntry ? await this.#readRemote(client, staged, stagedEntry) : null;
559
565
  if (stagedFile?.sha256 !== preview.localSha256) throw new UserError('Staged upload verification failed.');
560
566
  const latestLocal = await this.localFile(relative);
561
567
  if (latestLocal.sha256 !== preview.localSha256) throw new UserError('Local file changed during upload.');
562
- const latestRemote = await this.readRemote(client, relative);
568
+ const targetEntry = await this.#remoteEntry(client, relative);
569
+ const latestRemote = targetEntry ? await this.#readRemote(client, relative, targetEntry) : null;
563
570
  if ((latestRemote?.sha256 ?? null) !== preview.remoteSha256) throw new UserError('Remote file changed during upload.');
564
- const permissionWarning = latestRemote ? await this.#copyMode(client, relative, staged) : null;
571
+ const permissionWarning = latestRemote ? await this.#copyMode(client, { relative, entry: targetEntry }, { relative: staged, entry: stagedEntry }) : null;
565
572
  const backup = await client.rename(staged, relative, latestRemote !== null);
566
573
  return { backup, stagedFile, permissionWarning };
567
574
  } catch (error) {