@jwjp/ftp-mcp 0.5.0 → 0.6.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 -0
- package/package.json +1 -1
- package/src/server.js +48 -2
- package/src/workspace.js +2 -1
package/README.md
CHANGED
|
@@ -119,6 +119,8 @@ Replace the script path and set the required variables locally before starting C
|
|
|
119
119
|
4. `remote_preview_upload({"path":"src/example.php"})`. Review the path and both hashes. It returns an `uploadToken` when content differs. `createDirectories` lists remote parent directories that do not exist yet; the upload creates them.
|
|
120
120
|
5. `remote_upload({"path":"src/example.php","uploadToken":"..."})` within ten minutes. A changed local or remote file invalidates the preview, and so does a listed directory that someone else created in the meantime. The result lists any `createdDirectories`.
|
|
121
121
|
|
|
122
|
+
Each tool declares an output schema and returns its result as `structuredContent`, with the same JSON in a text block for clients that read only text. A listed `size` is `null` when the server's listing gives none.
|
|
123
|
+
|
|
122
124
|
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
125
|
|
|
124
126
|
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.
|
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -10,7 +10,49 @@ import { FtpWorkspace, LIST_LIMIT } from './workspace.js';
|
|
|
10
10
|
const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
11
11
|
const relativeInput = z.string().max(4096);
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// structuredContent lets clients read fields without parsing text; the JSON
|
|
14
|
+
// text stays for clients that read only content.
|
|
15
|
+
function result(value) { return { content: [{ type: 'text', text: JSON.stringify(value) }], structuredContent: value }; }
|
|
16
|
+
|
|
17
|
+
// Output schemas describe every field a tool returns. Optional fields stay
|
|
18
|
+
// optional: the SDK turns a result that fails its schema into an error, and a
|
|
19
|
+
// completed upload must not be reported as failed.
|
|
20
|
+
const sha256 = z.string().regex(/^[a-f0-9]{64}$/);
|
|
21
|
+
const listOutput = z.object({
|
|
22
|
+
entries: z.array(z.object({
|
|
23
|
+
name: z.string(),
|
|
24
|
+
type: z.enum(['directory', 'file']),
|
|
25
|
+
size: z.number().nullable(),
|
|
26
|
+
modifiedAt: z.string().nullable()
|
|
27
|
+
})),
|
|
28
|
+
truncated: z.boolean(),
|
|
29
|
+
nextCursor: z.string().nullable()
|
|
30
|
+
});
|
|
31
|
+
const downloadOutput = z.object({
|
|
32
|
+
path: z.string(),
|
|
33
|
+
status: z.enum(['downloaded', 'unchanged']),
|
|
34
|
+
sha256,
|
|
35
|
+
bytes: z.number(),
|
|
36
|
+
warning: z.string().optional()
|
|
37
|
+
});
|
|
38
|
+
const previewOutput = z.object({
|
|
39
|
+
path: z.string(),
|
|
40
|
+
changed: z.boolean(),
|
|
41
|
+
localSha256: sha256,
|
|
42
|
+
remoteSha256: sha256.nullable(),
|
|
43
|
+
localBytes: z.number(),
|
|
44
|
+
remoteBytes: z.number().nullable(),
|
|
45
|
+
createDirectories: z.array(z.string()),
|
|
46
|
+
uploadToken: z.string().nullable()
|
|
47
|
+
});
|
|
48
|
+
const uploadOutput = z.object({
|
|
49
|
+
path: z.string(),
|
|
50
|
+
status: z.literal('uploaded'),
|
|
51
|
+
sha256,
|
|
52
|
+
bytes: z.number(),
|
|
53
|
+
createdDirectories: z.array(z.string()).optional(),
|
|
54
|
+
warning: z.string().optional()
|
|
55
|
+
});
|
|
14
56
|
|
|
15
57
|
// Error codes such as 550 or ECONNREFUSED help the caller without exposing
|
|
16
58
|
// server text, which may echo paths or account details.
|
|
@@ -43,21 +85,25 @@ export function createServer(workspace) {
|
|
|
43
85
|
server.registerTool('remote_list', {
|
|
44
86
|
description: `List up to ${LIST_LIMIT} allowed entries in one remote directory, sorted by name. Use an empty path for the configured root. If truncated is true, pass nextCursor as cursor with the same path.`,
|
|
45
87
|
inputSchema: z.object({ path: relativeInput.default(''), cursor: relativeInput.optional() }),
|
|
88
|
+
outputSchema: listOutput,
|
|
46
89
|
annotations: { readOnlyHint: true }
|
|
47
90
|
}, tool('remote_list', workspace, ({ path, cursor }) => workspace.list(path, cursor)));
|
|
48
91
|
server.registerTool('remote_download', {
|
|
49
92
|
description: 'Download one remote file into the configured local root. Existing differing files require their current SHA-256 as expectedLocalSha256.',
|
|
50
|
-
inputSchema: z.object({ path: relativeInput, expectedLocalSha256:
|
|
93
|
+
inputSchema: z.object({ path: relativeInput, expectedLocalSha256: sha256.optional() }),
|
|
94
|
+
outputSchema: downloadOutput,
|
|
51
95
|
annotations: { readOnlyHint: false }
|
|
52
96
|
}, tool('remote_download', workspace, ({ path, expectedLocalSha256 }) => workspace.download(path, expectedLocalSha256)));
|
|
53
97
|
server.registerTool('remote_preview_upload', {
|
|
54
98
|
description: 'Compare one local file with its remote counterpart and issue a short-lived token if upload is needed. createDirectories lists the missing remote parent directories the upload would create.',
|
|
55
99
|
inputSchema: z.object({ path: relativeInput }),
|
|
100
|
+
outputSchema: previewOutput,
|
|
56
101
|
annotations: { readOnlyHint: true }
|
|
57
102
|
}, tool('remote_preview_upload', workspace, ({ path }) => workspace.previewUpload(path)));
|
|
58
103
|
server.registerTool('remote_upload', {
|
|
59
104
|
description: 'Upload exactly one file after preview, first creating the remote directories the preview listed. Reject changed local or remote content and verify uploaded bytes. Replacement may not be atomic.',
|
|
60
105
|
inputSchema: z.object({ path: relativeInput, uploadToken: z.string().uuid() }),
|
|
106
|
+
outputSchema: uploadOutput,
|
|
61
107
|
annotations: { readOnlyHint: false, destructiveHint: true }
|
|
62
108
|
}, tool('remote_upload', workspace, ({ path, uploadToken }) => workspace.upload(path, uploadToken)));
|
|
63
109
|
return server;
|
package/src/workspace.js
CHANGED
|
@@ -161,7 +161,8 @@ export class FtpWorkspace {
|
|
|
161
161
|
const page = allowed.slice(0, LIST_LIMIT);
|
|
162
162
|
const truncated = allowed.length > LIST_LIMIT;
|
|
163
163
|
return {
|
|
164
|
-
|
|
164
|
+
// A listing a server could not parse yields NaN, which JSON writes as null.
|
|
165
|
+
entries: page.map(item => ({ name: item.name, type: item.type === FileType.Directory ? 'directory' : 'file', size: Number.isFinite(item.size) ? item.size : null, modifiedAt: item.modifiedAt?.toISOString() ?? null })),
|
|
165
166
|
truncated,
|
|
166
167
|
nextCursor: truncated ? page.at(-1).name : null
|
|
167
168
|
};
|