@fload-ai/mcp 0.12.0 → 0.12.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/dist/bin.js CHANGED
@@ -1253,6 +1253,21 @@ function publicMcpErrorMessage(message, fallbackMessage = "Fload could not compl
1253
1253
  }
1254
1254
  return normalized;
1255
1255
  }
1256
+ var SCOPE_PATTERN = /^(read|write):[a-z]{2,20}$/;
1257
+ function insufficientScopeOf(status, wwwAuthenticate, body) {
1258
+ if (status !== 403) return null;
1259
+ const fromHeader = wwwAuthenticate?.includes("insufficient_scope") ? /scope="([^"]*)"/.exec(wwwAuthenticate)?.[1] : void 0;
1260
+ const record = body && typeof body === "object" ? body : {};
1261
+ if (fromHeader === void 0 && record.error !== "insufficient_scope") {
1262
+ return null;
1263
+ }
1264
+ const scope = fromHeader ?? (typeof record.scope === "string" ? record.scope : "");
1265
+ return SCOPE_PATTERN.test(scope) ? scope : "";
1266
+ }
1267
+ function insufficientScopeMessage(scope) {
1268
+ const permission = scope ? `the ${scope} permission` : "the permission this needs";
1269
+ return `This API key does not have ${permission}. Create a key that includes it in Fload: Settings \u2192 API keys.`;
1270
+ }
1256
1271
 
1257
1272
  // src/tools/actions.ts
1258
1273
  var listPendingActionsSchema = z9.object({
@@ -2338,12 +2353,15 @@ function registerTools(server, client, options = {}) {
2338
2353
  );
2339
2354
  }
2340
2355
 
2356
+ // src/version.ts
2357
+ var FLOAD_MCP_VERSION = "0.12.2";
2358
+
2341
2359
  // src/server.ts
2342
2360
  async function createMcpServer(_config, client) {
2343
2361
  console.error("[Fload MCP] Server initializing...");
2344
2362
  const server = new McpServer({
2345
2363
  name: "fload",
2346
- version: "0.1.0"
2364
+ version: FLOAD_MCP_VERSION
2347
2365
  });
2348
2366
  registerTools(server, client);
2349
2367
  console.error("[Fload MCP] Registered tools");
@@ -2351,6 +2369,20 @@ async function createMcpServer(_config, client) {
2351
2369
  }
2352
2370
 
2353
2371
  // src/api-client.ts
2372
+ function refusalError(response, error) {
2373
+ const scope = insufficientScopeOf(
2374
+ response.status,
2375
+ response.headers.get("www-authenticate"),
2376
+ error
2377
+ );
2378
+ if (scope !== null) return new Error(insufficientScopeMessage(scope));
2379
+ return new Error(
2380
+ publicMcpErrorMessage(
2381
+ error.publicMessage || error.message || response.statusText,
2382
+ response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
2383
+ )
2384
+ );
2385
+ }
2354
2386
  var FloadApiClient = class {
2355
2387
  constructor(baseUrl, apiKey) {
2356
2388
  this.baseUrl = baseUrl;
@@ -2371,11 +2403,7 @@ var FloadApiClient = class {
2371
2403
  });
2372
2404
  if (!response.ok) {
2373
2405
  const error = await response.json().catch(() => ({ message: response.statusText }));
2374
- const safeError = publicMcpErrorMessage(
2375
- error.publicMessage || error.message || response.statusText,
2376
- response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
2377
- );
2378
- throw new Error(safeError);
2406
+ throw refusalError(response, error);
2379
2407
  }
2380
2408
  return response.json();
2381
2409
  }
@@ -2411,6 +2439,12 @@ var FloadApiClient = class {
2411
2439
  body: body ? JSON.stringify(body) : void 0
2412
2440
  });
2413
2441
  const parsed = await response.json().catch(() => null);
2442
+ const scope = insufficientScopeOf(
2443
+ response.status,
2444
+ response.headers.get("www-authenticate"),
2445
+ parsed
2446
+ );
2447
+ if (scope !== null) throw new Error(insufficientScopeMessage(scope));
2414
2448
  return { ok: response.ok, status: response.status, body: parsed };
2415
2449
  }
2416
2450
  async patch(path, body) {
@@ -2439,11 +2473,7 @@ var FloadApiClient = class {
2439
2473
  });
2440
2474
  if (!response.ok) {
2441
2475
  const error = await response.json().catch(() => ({ message: response.statusText }));
2442
- const safeError = publicMcpErrorMessage(
2443
- error.publicMessage || error.message || response.statusText,
2444
- response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
2445
- );
2446
- throw new Error(safeError);
2476
+ throw refusalError(response, error);
2447
2477
  }
2448
2478
  return response.text();
2449
2479
  }