@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/index.js CHANGED
@@ -20,8 +20,37 @@ function publicMcpErrorMessage(message, fallbackMessage = "Fload could not compl
20
20
  }
21
21
  return normalized;
22
22
  }
23
+ var SCOPE_PATTERN = /^(read|write):[a-z]{2,20}$/;
24
+ function insufficientScopeOf(status, wwwAuthenticate, body) {
25
+ if (status !== 403) return null;
26
+ const fromHeader = wwwAuthenticate?.includes("insufficient_scope") ? /scope="([^"]*)"/.exec(wwwAuthenticate)?.[1] : void 0;
27
+ const record = body && typeof body === "object" ? body : {};
28
+ if (fromHeader === void 0 && record.error !== "insufficient_scope") {
29
+ return null;
30
+ }
31
+ const scope = fromHeader ?? (typeof record.scope === "string" ? record.scope : "");
32
+ return SCOPE_PATTERN.test(scope) ? scope : "";
33
+ }
34
+ function insufficientScopeMessage(scope) {
35
+ const permission = scope ? `the ${scope} permission` : "the permission this needs";
36
+ return `This API key does not have ${permission}. Create a key that includes it in Fload: Settings \u2192 API keys.`;
37
+ }
23
38
 
24
39
  // src/api-client.ts
40
+ function refusalError(response, error) {
41
+ const scope = insufficientScopeOf(
42
+ response.status,
43
+ response.headers.get("www-authenticate"),
44
+ error
45
+ );
46
+ if (scope !== null) return new Error(insufficientScopeMessage(scope));
47
+ return new Error(
48
+ publicMcpErrorMessage(
49
+ error.publicMessage || error.message || response.statusText,
50
+ response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
51
+ )
52
+ );
53
+ }
25
54
  var FloadApiClient = class {
26
55
  constructor(baseUrl, apiKey) {
27
56
  this.baseUrl = baseUrl;
@@ -42,11 +71,7 @@ var FloadApiClient = class {
42
71
  });
43
72
  if (!response.ok) {
44
73
  const error = await response.json().catch(() => ({ message: response.statusText }));
45
- const safeError = publicMcpErrorMessage(
46
- error.publicMessage || error.message || response.statusText,
47
- response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
48
- );
49
- throw new Error(safeError);
74
+ throw refusalError(response, error);
50
75
  }
51
76
  return response.json();
52
77
  }
@@ -82,6 +107,12 @@ var FloadApiClient = class {
82
107
  body: body ? JSON.stringify(body) : void 0
83
108
  });
84
109
  const parsed = await response.json().catch(() => null);
110
+ const scope = insufficientScopeOf(
111
+ response.status,
112
+ response.headers.get("www-authenticate"),
113
+ parsed
114
+ );
115
+ if (scope !== null) throw new Error(insufficientScopeMessage(scope));
85
116
  return { ok: response.ok, status: response.status, body: parsed };
86
117
  }
87
118
  async patch(path, body) {
@@ -110,11 +141,7 @@ var FloadApiClient = class {
110
141
  });
111
142
  if (!response.ok) {
112
143
  const error = await response.json().catch(() => ({ message: response.statusText }));
113
- const safeError = publicMcpErrorMessage(
114
- error.publicMessage || error.message || response.statusText,
115
- response.status >= 500 ? "Fload could not complete the request. Please try again." : "Fload rejected the request. Please check access and try again."
116
- );
117
- throw new Error(safeError);
144
+ throw refusalError(response, error);
118
145
  }
119
146
  return response.text();
120
147
  }
@@ -527,6 +554,37 @@ async function translateReview(input, client) {
527
554
 
528
555
  // src/tools/analytics.ts
529
556
  import { z as z3 } from "zod";
557
+ function unavailableReasonValue(reason) {
558
+ if (reason.cause === "not_reported") return "not_reported";
559
+ if (reason.reason === "source_filter" || reason.cause === "filtered_out") {
560
+ return "source_filter";
561
+ }
562
+ return "no_data";
563
+ }
564
+ function unavailableReason(name, meta) {
565
+ if (!(meta.unavailableMetrics ?? []).includes(name)) return void 0;
566
+ const reason = meta.unavailableMetricReasons?.[name];
567
+ return {
568
+ reason: reason ? unavailableReasonValue(reason) : "no_data",
569
+ message: reason?.message ?? "Unavailable for this query."
570
+ };
571
+ }
572
+ function unavailableEntries(requested, data, meta) {
573
+ return requested.flatMap((name) => {
574
+ const unavailable = unavailableReason(name, meta);
575
+ if (!unavailable || name in data) return [];
576
+ return [
577
+ {
578
+ name,
579
+ displayName: METRIC_INFO[name]?.displayName || name,
580
+ type: METRIC_INFO[name]?.type || "count",
581
+ summary: null,
582
+ change: null,
583
+ unavailable
584
+ }
585
+ ];
586
+ });
587
+ }
530
588
  function summarize(points, change) {
531
589
  const values = (Array.isArray(points) ? points : []).map((point) => point.value ?? point.total).filter((value) => typeof value === "number");
532
590
  return {
@@ -759,16 +817,25 @@ async function getMetrics(input, client) {
759
817
  dateRange: { start: startDate, end: endDate },
760
818
  granularity,
761
819
  dimension: input.dimension || null,
762
- metrics: Object.keys(data).map((name) => ({
763
- name,
764
- displayName: info[name]?.displayName || name,
765
- type: info[name]?.type || "count",
766
- summary: summaries[name],
767
- change: changes[name] || null,
768
- ...input.dimension && {
769
- breakdown: summaryResponse.breakdownTotals?.[name] ?? null
770
- }
771
- })),
820
+ metrics: [
821
+ ...Object.keys(data).map((name) => ({
822
+ name,
823
+ displayName: info[name]?.displayName || name,
824
+ type: info[name]?.type || "count",
825
+ summary: summaries[name],
826
+ change: changes[name] || null,
827
+ ...input.dimension && {
828
+ breakdown: summaryResponse.breakdownTotals?.[name] ?? null
829
+ },
830
+ // A computed metric the API marks unavailable comes back as an
831
+ // empty series: it carries its reason too.
832
+ ...unavailableReason(name, meta) && {
833
+ unavailable: unavailableReason(name, meta)
834
+ }
835
+ })),
836
+ // FLO-2840: listed with the reason, never dropped or 0.
837
+ ...unavailableEntries(input.metrics, data, meta)
838
+ ],
772
839
  timeseries: data,
773
840
  meta
774
841
  })
@@ -2144,7 +2211,7 @@ function registerTools(server, client, options = {}) {
2144
2211
  tool(
2145
2212
  "send_review_reply",
2146
2213
  "Send review reply",
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).",
2214
+ "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.",
2148
2215
  sendReviewReplySchema,
2149
2216
  sendReviewReply,
2150
2217
  { readOnlyHint: false, destructiveHint: true, openWorldHint: true }
@@ -2168,7 +2235,7 @@ function registerTools(server, client, options = {}) {
2168
2235
  tool(
2169
2236
  "get_metrics",
2170
2237
  "Get 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. Use discover_metrics first to see available metrics.",
2238
+ "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.",
2172
2239
  getMetricsSchema,
2173
2240
  getMetrics,
2174
2241
  { readOnlyHint: true, openWorldHint: false }
@@ -2393,12 +2460,15 @@ function registerTools(server, client, options = {}) {
2393
2460
  );
2394
2461
  }
2395
2462
 
2463
+ // src/version.ts
2464
+ var FLOAD_MCP_VERSION = "0.12.3";
2465
+
2396
2466
  // src/server.ts
2397
2467
  async function createMcpServer(_config, client) {
2398
2468
  console.error("[Fload MCP] Server initializing...");
2399
2469
  const server = new McpServer({
2400
2470
  name: "fload",
2401
- version: "0.1.0"
2471
+ version: FLOAD_MCP_VERSION
2402
2472
  });
2403
2473
  registerTools(server, client);
2404
2474
  console.error("[Fload MCP] Registered tools");