@fload-ai/mcp 0.12.0 → 0.12.3

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
@@ -447,6 +447,37 @@ async function translateReview(input, client) {
447
447
 
448
448
  // src/tools/analytics.ts
449
449
  import { z as z4 } from "zod";
450
+ function unavailableReasonValue(reason) {
451
+ if (reason.cause === "not_reported") return "not_reported";
452
+ if (reason.reason === "source_filter" || reason.cause === "filtered_out") {
453
+ return "source_filter";
454
+ }
455
+ return "no_data";
456
+ }
457
+ function unavailableReason(name, meta) {
458
+ if (!(meta.unavailableMetrics ?? []).includes(name)) return void 0;
459
+ const reason = meta.unavailableMetricReasons?.[name];
460
+ return {
461
+ reason: reason ? unavailableReasonValue(reason) : "no_data",
462
+ message: reason?.message ?? "Unavailable for this query."
463
+ };
464
+ }
465
+ function unavailableEntries(requested, data, meta) {
466
+ return requested.flatMap((name) => {
467
+ const unavailable = unavailableReason(name, meta);
468
+ if (!unavailable || name in data) return [];
469
+ return [
470
+ {
471
+ name,
472
+ displayName: METRIC_INFO[name]?.displayName || name,
473
+ type: METRIC_INFO[name]?.type || "count",
474
+ summary: null,
475
+ change: null,
476
+ unavailable
477
+ }
478
+ ];
479
+ });
480
+ }
450
481
  function summarize(points, change) {
451
482
  const values = (Array.isArray(points) ? points : []).map((point) => point.value ?? point.total).filter((value) => typeof value === "number");
452
483
  return {
@@ -679,16 +710,25 @@ async function getMetrics(input, client) {
679
710
  dateRange: { start: startDate, end: endDate },
680
711
  granularity,
681
712
  dimension: input.dimension || null,
682
- metrics: Object.keys(data).map((name) => ({
683
- name,
684
- displayName: info[name]?.displayName || name,
685
- type: info[name]?.type || "count",
686
- summary: summaries[name],
687
- change: changes[name] || null,
688
- ...input.dimension && {
689
- breakdown: summaryResponse.breakdownTotals?.[name] ?? null
690
- }
691
- })),
713
+ metrics: [
714
+ ...Object.keys(data).map((name) => ({
715
+ name,
716
+ displayName: info[name]?.displayName || name,
717
+ type: info[name]?.type || "count",
718
+ summary: summaries[name],
719
+ change: changes[name] || null,
720
+ ...input.dimension && {
721
+ breakdown: summaryResponse.breakdownTotals?.[name] ?? null
722
+ },
723
+ // A computed metric the API marks unavailable comes back as an
724
+ // empty series: it carries its reason too.
725
+ ...unavailableReason(name, meta) && {
726
+ unavailable: unavailableReason(name, meta)
727
+ }
728
+ })),
729
+ // FLO-2840: listed with the reason, never dropped or 0.
730
+ ...unavailableEntries(input.metrics, data, meta)
731
+ ],
692
732
  timeseries: data,
693
733
  meta
694
734
  })
@@ -1253,6 +1293,21 @@ function publicMcpErrorMessage(message, fallbackMessage = "Fload could not compl
1253
1293
  }
1254
1294
  return normalized;
1255
1295
  }
1296
+ var SCOPE_PATTERN = /^(read|write):[a-z]{2,20}$/;
1297
+ function insufficientScopeOf(status, wwwAuthenticate, body) {
1298
+ if (status !== 403) return null;
1299
+ const fromHeader = wwwAuthenticate?.includes("insufficient_scope") ? /scope="([^"]*)"/.exec(wwwAuthenticate)?.[1] : void 0;
1300
+ const record = body && typeof body === "object" ? body : {};
1301
+ if (fromHeader === void 0 && record.error !== "insufficient_scope") {
1302
+ return null;
1303
+ }
1304
+ const scope = fromHeader ?? (typeof record.scope === "string" ? record.scope : "");
1305
+ return SCOPE_PATTERN.test(scope) ? scope : "";
1306
+ }
1307
+ function insufficientScopeMessage(scope) {
1308
+ const permission = scope ? `the ${scope} permission` : "the permission this needs";
1309
+ return `This API key does not have ${permission}. Create a key that includes it in Fload: Settings \u2192 API keys.`;
1310
+ }
1256
1311
 
1257
1312
  // src/tools/actions.ts
1258
1313
  var listPendingActionsSchema = z9.object({
@@ -2089,7 +2144,7 @@ function registerTools(server, client, options = {}) {
2089
2144
  tool(
2090
2145
  "send_review_reply",
2091
2146
  "Send review reply",
2092
- "Send a reply to an app review on the App Store or Google Play. The response text will be submitted as the developer response. This is a write operation that publishes the reply publicly \u2014 treat as destructive (cannot be silently undone).",
2147
+ "Send a reply to an app review on the App Store or Google Play. The response text will be submitted as the developer response. This is a write operation that publishes the reply publicly \u2014 treat as destructive (cannot be silently undone). Needs the write:reviews and write:agents (Approve and run) permissions, as approving a reply in the inbox does.",
2093
2148
  sendReviewReplySchema,
2094
2149
  sendReviewReply,
2095
2150
  { readOnlyHint: false, destructiveHint: true, openWorldHint: true }
@@ -2113,7 +2168,7 @@ function registerTools(server, client, options = {}) {
2113
2168
  tool(
2114
2169
  "get_metrics",
2115
2170
  "Get metrics",
2116
- "Query metric timeseries data for an app. Supports 30+ metrics (proceeds, totalDownloads, activeSubs, sessions, crashes, adSpend, adAvgCPA, etc.). Can query multiple metrics at once. Supports dimensional breakdowns (by country, platform, campaign). Each metric's summary.value is its value over the period, aggregated the right way for that metric: summed for flows like downloads, the latest value for levels like active subscriptions, and total over total for ratios like CPA. It covers summary.effectiveFromDate to summary.effectiveToDate: the requested days, less recent days whose data is not complete yet. Quote summary.value with that range rather than adding up the points. Use discover_metrics first to see available metrics.",
2171
+ "Query metric timeseries data for an app. Supports 30+ metrics (proceeds, totalDownloads, activeSubs, sessions, crashes, adSpend, adAvgCPA, etc.). Can query multiple metrics at once. Supports dimensional breakdowns (by country, platform, campaign). Each metric's summary.value is its value over the period, aggregated the right way for that metric: summed for flows like downloads, the latest value for levels like active subscriptions, and total over total for ratios like CPA. It covers summary.effectiveFromDate to summary.effectiveToDate: the requested days, less recent days whose data is not complete yet. Quote summary.value with that range rather than adding up the points. On total reads (no dimension), a requested metric the API could not report is listed with summary null and unavailable {reason, message}: reason not_reported means none of the app's connected sources has ever sent it (say it is not reported); no_data means nothing in this window; source_filter means a source or dimension filter hides it. Never quote it as 0. Use discover_metrics first to see available metrics.",
2117
2172
  getMetricsSchema,
2118
2173
  getMetrics,
2119
2174
  { readOnlyHint: true, openWorldHint: false }
@@ -2338,12 +2393,15 @@ function registerTools(server, client, options = {}) {
2338
2393
  );
2339
2394
  }
2340
2395
 
2396
+ // src/version.ts
2397
+ var FLOAD_MCP_VERSION = "0.12.3";
2398
+
2341
2399
  // src/server.ts
2342
2400
  async function createMcpServer(_config, client) {
2343
2401
  console.error("[Fload MCP] Server initializing...");
2344
2402
  const server = new McpServer({
2345
2403
  name: "fload",
2346
- version: "0.1.0"
2404
+ version: FLOAD_MCP_VERSION
2347
2405
  });
2348
2406
  registerTools(server, client);
2349
2407
  console.error("[Fload MCP] Registered tools");
@@ -2351,6 +2409,20 @@ async function createMcpServer(_config, client) {
2351
2409
  }
2352
2410
 
2353
2411
  // src/api-client.ts
2412
+ function refusalError(response, error) {
2413
+ const scope = insufficientScopeOf(
2414
+ response.status,
2415
+ response.headers.get("www-authenticate"),
2416
+ error
2417
+ );
2418
+ if (scope !== null) return new Error(insufficientScopeMessage(scope));
2419
+ return new Error(
2420
+ publicMcpErrorMessage(
2421
+ error.publicMessage || error.message || response.statusText,
2422
+ response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
2423
+ )
2424
+ );
2425
+ }
2354
2426
  var FloadApiClient = class {
2355
2427
  constructor(baseUrl, apiKey) {
2356
2428
  this.baseUrl = baseUrl;
@@ -2371,11 +2443,7 @@ var FloadApiClient = class {
2371
2443
  });
2372
2444
  if (!response.ok) {
2373
2445
  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);
2446
+ throw refusalError(response, error);
2379
2447
  }
2380
2448
  return response.json();
2381
2449
  }
@@ -2411,6 +2479,12 @@ var FloadApiClient = class {
2411
2479
  body: body ? JSON.stringify(body) : void 0
2412
2480
  });
2413
2481
  const parsed = await response.json().catch(() => null);
2482
+ const scope = insufficientScopeOf(
2483
+ response.status,
2484
+ response.headers.get("www-authenticate"),
2485
+ parsed
2486
+ );
2487
+ if (scope !== null) throw new Error(insufficientScopeMessage(scope));
2414
2488
  return { ok: response.ok, status: response.status, body: parsed };
2415
2489
  }
2416
2490
  async patch(path, body) {
@@ -2439,11 +2513,7 @@ var FloadApiClient = class {
2439
2513
  });
2440
2514
  if (!response.ok) {
2441
2515
  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);
2516
+ throw refusalError(response, error);
2447
2517
  }
2448
2518
  return response.text();
2449
2519
  }