@fluxfiles/mcp 1.0.0 → 1.1.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.
@@ -82,6 +82,26 @@ function parentOf(p) {
82
82
  const s = p.replace(/^\/+|\/+$/g, "");
83
83
  return s.includes("/") ? s.slice(0, s.lastIndexOf("/")) : "";
84
84
  }
85
+ async function statPath(client, disk2, p) {
86
+ let info;
87
+ try {
88
+ info = await client.request("GET", "/meta", { query: { disk: disk2, path: p } });
89
+ } catch (e) {
90
+ if (e instanceof FluxFilesError && e.status === 404) return { exists: false };
91
+ throw e;
92
+ }
93
+ if (info?.type === "file" || info?.type === "dir") return { exists: true, type: info.type, info };
94
+ if (info && info.size != null) return { exists: true, type: "file", info };
95
+ if (info && info.modified != null) return { exists: true, type: "dir", info };
96
+ const clean = p.replace(/^\/+|\/+$/g, "");
97
+ if (clean === "") return { exists: true, type: "dir", info: info ?? {} };
98
+ const data = await client.request("GET", "/list", { query: { disk: disk2, path: parentOf(clean), limit: 500 } });
99
+ const items = Array.isArray(data) ? data : data?.items ?? [];
100
+ const name = clean.slice(clean.lastIndexOf("/") + 1);
101
+ const hit = items.find((i) => i.name === name || i.key === clean || i.key?.endsWith("/" + clean));
102
+ if (hit && hit.type === "dir") return { exists: true, type: "dir", info: info ?? {} };
103
+ return hit ? { exists: true, type: "file", info: info ?? {} } : { exists: false };
104
+ }
85
105
  function buildTools(client, opts) {
86
106
  const d = (v) => typeof v === "string" && v !== "" ? v : opts.disk;
87
107
  const tools = [
@@ -129,7 +149,9 @@ function buildTools(client, opts) {
129
149
  shape: { path, disk },
130
150
  run: async (a) => {
131
151
  const p = String(a.path);
132
- const info = await client.request("GET", "/meta", { query: { disk: d(a.disk), path: p } });
152
+ const st = await statPath(client, d(a.disk), p);
153
+ if (!st.exists) throw new FluxFilesError("File or directory not found", 404, "not_found");
154
+ const info = { ...st.info, type: st.type };
133
155
  let meta = null;
134
156
  try {
135
157
  meta = await client.request("GET", "/metadata", { query: { disk: d(a.disk), key: p } });
@@ -177,13 +199,11 @@ function buildTools(client, opts) {
177
199
  shape: { path, content: z.string().max(2e6), disk },
178
200
  run: async (a) => {
179
201
  const p = String(a.path).replace(/^\/+/, "");
180
- let exists = true;
181
- try {
182
- await client.request("GET", "/meta", { query: { disk: d(a.disk), path: p } });
183
- } catch (e) {
184
- if (!(e instanceof FluxFilesError) || e.status !== 404) throw e;
185
- exists = false;
202
+ const st = await statPath(client, d(a.disk), p);
203
+ if (st.exists && st.type === "dir") {
204
+ throw new FluxFilesError(`"${p}" is a folder, not a file`, 400, "is_directory");
186
205
  }
206
+ const exists = st.exists;
187
207
  if (exists) {
188
208
  return client.request("PUT", "/content", { json: { disk: d(a.disk), path: p, content: String(a.content) } });
189
209
  }
@@ -219,7 +239,7 @@ function buildTools(client, opts) {
219
239
 
220
240
  // src/server.ts
221
241
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
222
- var VERSION = "1.0.0";
242
+ var VERSION = "1.1.0";
223
243
  function createServer(cfg) {
224
244
  const client = new FluxFilesClient({ baseUrl: cfg.baseUrl, token: cfg.token, fetch: cfg.fetch, allowInsecureHttp: cfg.allowInsecureHttp });
225
245
  const server = new McpServer({ name: "fluxfiles", version: VERSION });
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createServer
4
- } from "./chunk-5R2GHIE2.js";
4
+ } from "./chunk-JRBJQITS.js";
5
5
 
6
6
  // src/cli.ts
7
7
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -12,12 +12,18 @@ if (!url || !token) {
12
12
  process.exit(1);
13
13
  }
14
14
  var on = (v) => v === "1" || v === "true";
15
- var server = createServer({
16
- baseUrl: url,
17
- token,
18
- disk: process.env.FLUXFILES_DISK || "local",
19
- allowWrite: on(process.env.FLUXFILES_MCP_WRITE),
20
- allowDelete: on(process.env.FLUXFILES_MCP_DELETE),
21
- allowInsecureHttp: on(process.env.FLUXFILES_MCP_ALLOW_HTTP)
22
- });
23
- await server.connect(new StdioServerTransport());
15
+ try {
16
+ const server = createServer({
17
+ baseUrl: url,
18
+ token,
19
+ disk: process.env.FLUXFILES_DISK || "local",
20
+ allowWrite: on(process.env.FLUXFILES_MCP_WRITE),
21
+ allowDelete: on(process.env.FLUXFILES_MCP_DELETE),
22
+ allowInsecureHttp: on(process.env.FLUXFILES_MCP_ALLOW_HTTP)
23
+ });
24
+ await server.connect(new StdioServerTransport());
25
+ } catch (e) {
26
+ process.stderr.write(`fluxfiles-mcp: ${e instanceof Error ? e.message : String(e)}
27
+ `);
28
+ process.exit(1);
29
+ }
package/dist/index.d.ts CHANGED
@@ -61,7 +61,7 @@ interface ServerConfig extends Partial<ToolOptions> {
61
61
  fetch?: typeof fetch;
62
62
  allowInsecureHttp?: boolean;
63
63
  }
64
- declare const VERSION = "1.0.0";
64
+ declare const VERSION = "1.1.0";
65
65
  declare function createServer(cfg: ServerConfig): McpServer;
66
66
 
67
67
  export { type ClientConfig, FluxFilesClient, FluxFilesError, type ServerConfig, type ToolDef, type ToolOptions, VERSION, assertSafeBaseUrl, buildTools, createServer };
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  assertSafeBaseUrl,
6
6
  buildTools,
7
7
  createServer
8
- } from "./chunk-5R2GHIE2.js";
8
+ } from "./chunk-JRBJQITS.js";
9
9
  export {
10
10
  FluxFilesClient,
11
11
  FluxFilesError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/mcp",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "Model Context Protocol server for FluxFiles — let AI agents browse, search and read (and optionally write) files through a scoped FluxFiles JWT",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -32,13 +32,13 @@
32
32
  },
33
33
  "dependencies": {
34
34
  "@modelcontextprotocol/sdk": "^1.32.1",
35
- "zod": "^3.25.0"
35
+ "zod": "^4.6.7"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^20.0.0",
39
39
  "tsup": "^8.0.0",
40
40
  "typescript": "^5.0.0",
41
- "vitest": "^2.1.8"
41
+ "vitest": "^4.1.12"
42
42
  },
43
43
  "author": "thai-pc",
44
44
  "homepage": "https://github.com/thai-pc/fluxfiles/tree/master/packages/mcp#readme",
package/src/cli.ts CHANGED
@@ -20,12 +20,17 @@ if (!url || !token) {
20
20
  }
21
21
  const on = (v?: string) => v === '1' || v === 'true';
22
22
 
23
- const server = createServer({
24
- baseUrl: url,
25
- token,
26
- disk: process.env.FLUXFILES_DISK || 'local',
27
- allowWrite: on(process.env.FLUXFILES_MCP_WRITE),
28
- allowDelete: on(process.env.FLUXFILES_MCP_DELETE),
29
- allowInsecureHttp: on(process.env.FLUXFILES_MCP_ALLOW_HTTP),
30
- });
31
- await server.connect(new StdioServerTransport());
23
+ try {
24
+ const server = createServer({
25
+ baseUrl: url,
26
+ token,
27
+ disk: process.env.FLUXFILES_DISK || 'local',
28
+ allowWrite: on(process.env.FLUXFILES_MCP_WRITE),
29
+ allowDelete: on(process.env.FLUXFILES_MCP_DELETE),
30
+ allowInsecureHttp: on(process.env.FLUXFILES_MCP_ALLOW_HTTP),
31
+ });
32
+ await server.connect(new StdioServerTransport());
33
+ } catch (e) {
34
+ process.stderr.write(`fluxfiles-mcp: ${e instanceof Error ? e.message : String(e)}\n`);
35
+ process.exit(1);
36
+ }
package/src/server.ts CHANGED
@@ -9,7 +9,7 @@ export interface ServerConfig extends Partial<ToolOptions> {
9
9
  allowInsecureHttp?: boolean;
10
10
  }
11
11
 
12
- export const VERSION = '1.0.0';
12
+ export const VERSION = '1.1.0';
13
13
 
14
14
  export function createServer(cfg: ServerConfig): McpServer {
15
15
  const client = new FluxFilesClient({ baseUrl: cfg.baseUrl, token: cfg.token, fetch: cfg.fetch, allowInsecureHttp: cfg.allowInsecureHttp });
package/src/tools.ts CHANGED
@@ -48,6 +48,35 @@ function parentOf(p: string): string {
48
48
  return s.includes('/') ? s.slice(0, s.lastIndexOf('/')) : '';
49
49
  }
50
50
 
51
+ type Stat = { exists: false } | { exists: true; type: 'file' | 'dir'; info: Record<string, unknown> };
52
+
53
+ /**
54
+ * Does `p` exist, and is it a file or a folder? Current cores answer /meta with 404 for
55
+ * a missing path and 200 with `type: 'file'|'dir'` otherwise, so the 200 is trusted.
56
+ * Older cores answered 200 {size:null, modified:null} for BOTH a missing path and a
57
+ * folder on S3/SFTP; those are told apart by the parent folder's listing.
58
+ */
59
+ async function statPath(client: FluxFilesClient, disk: string, p: string): Promise<Stat> {
60
+ let info: Record<string, unknown>;
61
+ try {
62
+ info = await client.request<Record<string, unknown>>('GET', '/meta', { query: { disk, path: p } });
63
+ } catch (e) {
64
+ if (e instanceof FluxFilesError && e.status === 404) return { exists: false };
65
+ throw e;
66
+ }
67
+ if (info?.type === 'file' || info?.type === 'dir') return { exists: true, type: info.type, info };
68
+ if (info && info.size != null) return { exists: true, type: 'file', info };
69
+ if (info && info.modified != null) return { exists: true, type: 'dir', info };
70
+ const clean = p.replace(/^\/+|\/+$/g, '');
71
+ if (clean === '') return { exists: true, type: 'dir', info: info ?? {} };
72
+ const data = await client.request<{ items?: Item[] } | Item[]>('GET', '/list', { query: { disk, path: parentOf(clean), limit: 500 } });
73
+ const items = Array.isArray(data) ? data : (data?.items ?? []);
74
+ const name = clean.slice(clean.lastIndexOf('/') + 1);
75
+ const hit = items.find((i) => i.name === name || i.key === clean || i.key?.endsWith('/' + clean));
76
+ if (hit && hit.type === 'dir') return { exists: true, type: 'dir', info: info ?? {} };
77
+ return hit ? { exists: true, type: 'file', info: info ?? {} } : { exists: false };
78
+ }
79
+
51
80
  export function buildTools(client: FluxFilesClient, opts: ToolOptions): ToolDef[] {
52
81
  const d = (v: unknown) => (typeof v === 'string' && v !== '' ? v : opts.disk);
53
82
 
@@ -88,7 +117,9 @@ export function buildTools(client: FluxFilesClient, opts: ToolOptions): ToolDef[
88
117
  shape: { path, disk },
89
118
  run: async (a) => {
90
119
  const p = String(a.path);
91
- const info = await client.request<Record<string, unknown>>('GET', '/meta', { query: { disk: d(a.disk), path: p } });
120
+ const st = await statPath(client, d(a.disk), p);
121
+ if (!st.exists) throw new FluxFilesError('File or directory not found', 404, 'not_found');
122
+ const info = { ...st.info, type: st.type };
92
123
  let meta: Record<string, unknown> | null = null;
93
124
  try {
94
125
  meta = await client.request<Record<string, unknown> | null>('GET', '/metadata', { query: { disk: d(a.disk), key: p } });
@@ -132,13 +163,11 @@ export function buildTools(client: FluxFilesClient, opts: ToolOptions): ToolDef[
132
163
  shape: { path, content: z.string().max(2_000_000), disk },
133
164
  run: async (a) => {
134
165
  const p = String(a.path).replace(/^\/+/, '');
135
- let exists = true;
136
- try {
137
- await client.request('GET', '/meta', { query: { disk: d(a.disk), path: p } });
138
- } catch (e) {
139
- if (!(e instanceof FluxFilesError) || e.status !== 404) throw e;
140
- exists = false;
166
+ const st = await statPath(client, d(a.disk), p);
167
+ if (st.exists && st.type === 'dir') {
168
+ throw new FluxFilesError(`"${p}" is a folder, not a file`, 400, 'is_directory');
141
169
  }
170
+ const exists = st.exists;
142
171
  if (exists) {
143
172
  return client.request('PUT', '/content', { json: { disk: d(a.disk), path: p, content: String(a.content) } });
144
173
  }