@jwjp/ftp-mcp 0.7.0 → 0.7.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/workspace.js +17 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jwjp/ftp-mcp",
3
- "version": "0.7.0",
3
+ "version": "0.7.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/workspace.js CHANGED
@@ -30,6 +30,10 @@ export class FtpWorkspace {
30
30
  #clientQueue = Promise.resolve();
31
31
  #idle = null;
32
32
  #closed = false;
33
+ // Parent directories already checked during the current operation, per
34
+ // connection. Checking each once saves a LIST per level on every lookup;
35
+ // a server-side change between checks was never excluded anyway.
36
+ #verified = new WeakMap();
33
37
 
34
38
  constructor(config, clientFactory = () => createTransport(config)) {
35
39
  this.config = config;
@@ -56,15 +60,18 @@ export class FtpWorkspace {
56
60
 
57
61
  async #useClient(action) {
58
62
  const client = await this.#acquire();
63
+ this.#verified.set(client, new Set());
59
64
  let result;
60
65
  try {
61
66
  result = await action(client);
62
67
  } catch (error) {
68
+ this.#verified.delete(client);
63
69
  // A failed operation can leave a transfer half done or the connection
64
70
  // in an unknown state. Never hand that connection to the next caller.
65
71
  await closeQuietly(client);
66
72
  throw error;
67
73
  }
74
+ this.#verified.delete(client);
68
75
  await this.#release(client);
69
76
  return result;
70
77
  }
@@ -121,7 +128,10 @@ export class FtpWorkspace {
121
128
 
122
129
  async entry(client, relative) {
123
130
  const parts = relative.split('/');
131
+ const verified = this.#verified.get(client);
124
132
  for (let i = 0; i < parts.length; i++) {
133
+ const directory = parts.slice(0, i + 1).join('/');
134
+ if (i < parts.length - 1 && verified?.has(directory)) continue;
125
135
  const parent = parts.slice(0, i).join('/') || '.';
126
136
  const entries = await client.list(parent);
127
137
  const found = entries.find(item => item.name === parts[i]);
@@ -132,6 +142,7 @@ export class FtpWorkspace {
132
142
  if (found.type === FileType.SymbolicLink) throw new UserError('Remote symlink paths are not allowed.');
133
143
  if (i < parts.length - 1 && found.type !== FileType.Directory) throw new UserError('Remote parent is not a directory.');
134
144
  if (i === parts.length - 1) return found;
145
+ verified?.add(directory);
135
146
  }
136
147
  }
137
148
 
@@ -139,12 +150,16 @@ export class FtpWorkspace {
139
150
  // An existing parent must be a real directory.
140
151
  async #missingDirectories(client, relative) {
141
152
  const parts = relative.split('/').slice(0, -1);
153
+ const verified = this.#verified.get(client);
142
154
  for (let i = 0; i < parts.length; i++) {
155
+ const directory = parts.slice(0, i + 1).join('/');
156
+ if (verified?.has(directory)) continue;
143
157
  const parent = parts.slice(0, i).join('/') || '.';
144
158
  const found = (await client.list(parent)).find(item => item.name === parts[i]);
145
159
  if (!found) return parts.slice(i).map((_, j) => parts.slice(0, i + j + 1).join('/'));
146
160
  if (found.type === FileType.SymbolicLink) throw new UserError('Remote symlink paths are not allowed.');
147
161
  if (found.type !== FileType.Directory) throw new UserError('Remote parent is not a directory.');
162
+ verified?.add(directory);
148
163
  }
149
164
  return [];
150
165
  }
@@ -374,6 +389,7 @@ export class FtpWorkspace {
374
389
  for (const directory of missing) {
375
390
  await client.mkdir(directory);
376
391
  created.push(directory);
392
+ this.#verified.get(client)?.add(directory);
377
393
  }
378
394
  } catch (error) {
379
395
  throw await this.#removeCreated(client, created, error);
@@ -416,6 +432,7 @@ export class FtpWorkspace {
416
432
  // rmdir remove only an empty directory, so another writer's files are kept.
417
433
  async #removeCreated(client, created, error) {
418
434
  for (const directory of created.toReversed()) {
435
+ this.#verified.get(client)?.delete(directory);
419
436
  try { await client.rmdir(directory); }
420
437
  catch {
421
438
  const reason = error instanceof UserError ? error.message : 'Upload failed.';