@carrierllc/mcp 0.2.5 → 0.2.7

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.
File without changes
package/dist/index.js CHANGED
@@ -3128,14 +3128,27 @@ function registerIntelligenceTools(server2, ctx) {
3128
3128
  annotations: { readOnlyHint: true }
3129
3129
  }, async ({ accountId }) => {
3130
3130
  const token2 = await ctx.getUserToken(ctx.props.sub);
3131
+ const resellerId = await getDefaultResellerId(ctx.env, token2).catch(() => void 0);
3131
3132
  const [statusResult, accountsResult] = await Promise.all([
3132
- safeCall(ctx.env, token2, "esimStatusPerAccount", accountId !== void 0 ? { accountId } : {}),
3133
- safeCall(ctx.env, token2, "listResellerAccount", {})
3133
+ safeCall(
3134
+ ctx.env,
3135
+ token2,
3136
+ "esimStatusPerAccount",
3137
+ accountId !== void 0 ? { accountId } : resellerId !== void 0 ? { resellerId } : {}
3138
+ ),
3139
+ safeCall(
3140
+ ctx.env,
3141
+ token2,
3142
+ "listResellerAccount",
3143
+ resellerId !== void 0 ? { resellerId } : {}
3144
+ )
3134
3145
  ]);
3135
3146
  const sections = ["# Fleet Health Dashboard\n"];
3136
- if (statusResult.data && Array.isArray(statusResult.data)) {
3137
- let totalActive = 0, totalSuspended = 0, totalInventory = 0, totalOther = 0;
3138
- for (const account of statusResult.data) {
3147
+ let totalActive = 0, totalSuspended = 0, totalInventory = 0, totalOther = 0;
3148
+ const statusOk = statusResult.data && Array.isArray(statusResult.data);
3149
+ const statusAccounts = statusOk ? statusResult.data : [];
3150
+ if (statusOk) {
3151
+ for (const account of statusAccounts) {
3139
3152
  totalActive += Number(account.active ?? 0);
3140
3153
  totalSuspended += Number(account.suspended ?? 0);
3141
3154
  totalInventory += Number(account.inventory ?? account.notActivated ?? 0);
@@ -3144,37 +3157,79 @@ function registerIntelligenceTools(server2, ctx) {
3144
3157
  const total = totalActive + totalSuspended + totalInventory + totalOther;
3145
3158
  const utilization = total > 0 ? (totalActive / total * 100).toFixed(1) : "0";
3146
3159
  sections.push(`## eSIM Fleet Status`);
3147
- sections.push(`| Metric | Count | % |`);
3148
- sections.push(`|--------|-------|---|`);
3149
- sections.push(`| Active | ${totalActive} | ${total > 0 ? (totalActive / total * 100).toFixed(1) : 0}% |`);
3150
- sections.push(`| Suspended | ${totalSuspended} | ${total > 0 ? (totalSuspended / total * 100).toFixed(1) : 0}% |`);
3151
- sections.push(`| Inventory | ${totalInventory} | ${total > 0 ? (totalInventory / total * 100).toFixed(1) : 0}% |`);
3152
- sections.push(`| Other | ${totalOther} | ${total > 0 ? (totalOther / total * 100).toFixed(1) : 0}% |`);
3153
- sections.push(`| **Total** | **${total}** | |`);
3154
- sections.push(`
3155
- **Fleet Utilization: ${utilization}%**`);
3156
- if (totalSuspended > totalActive * 0.1) {
3160
+ if (total === 0) {
3161
+ sections.push(`No eSIMs provisioned across ${statusAccounts.length} account(s).`);
3162
+ } else {
3163
+ sections.push(`| Metric | Count | % |`);
3164
+ sections.push(`|--------|-------|---|`);
3165
+ sections.push(`| Active | ${totalActive} | ${(totalActive / total * 100).toFixed(1)}% |`);
3166
+ sections.push(`| Suspended | ${totalSuspended} | ${(totalSuspended / total * 100).toFixed(1)}% |`);
3167
+ sections.push(`| Inventory | ${totalInventory} | ${(totalInventory / total * 100).toFixed(1)}% |`);
3168
+ sections.push(`| Other | ${totalOther} | ${(totalOther / total * 100).toFixed(1)}% |`);
3169
+ sections.push(`| **Total** | **${total}** | |`);
3157
3170
  sections.push(`
3158
- \u26A0 High suspension rate (${totalSuspended} suspended vs ${totalActive} active)`);
3171
+ **Fleet Utilization: ${utilization}%**`);
3172
+ if (totalSuspended > totalActive * 0.1) {
3173
+ sections.push(`
3174
+ High suspension rate (${totalSuspended} suspended vs ${totalActive} active)`);
3175
+ }
3159
3176
  }
3177
+ } else {
3178
+ sections.push(`## eSIM Fleet Status`);
3179
+ sections.push(`Unavailable: ${statusResult.error ?? "esimStatusPerAccount returned no data"}`);
3160
3180
  }
3161
- if (accountsResult.data && Array.isArray(accountsResult.data)) {
3162
- const lowBalance = accountsResult.data.filter(
3181
+ const accountsOk = accountsResult.data && Array.isArray(accountsResult.data);
3182
+ const accounts = accountsOk ? accountsResult.data : [];
3183
+ if (accountsOk) {
3184
+ const lowBalance = accounts.filter(
3163
3185
  (a) => Number(a.balance ?? 0) < 10
3164
3186
  );
3187
+ const packageOnlyZero = accounts.filter(
3188
+ (a) => Boolean(a.packageOnly) && Number(a.balance ?? 0) <= 0
3189
+ );
3190
+ sections.push(`
3191
+ ## Account Summary`);
3192
+ sections.push(`- Total accounts: ${accounts.length}`);
3193
+ sections.push(`- Low balance (< 10): ${lowBalance.length}`);
3194
+ sections.push(`- Package-only with 0 balance: ${packageOnlyZero.length}`);
3165
3195
  if (lowBalance.length > 0) {
3166
3196
  sections.push(`
3167
- ## Low Balance Accounts (< 10)`);
3168
- sections.push(`| Account | Balance |`);
3169
- sections.push(`|---------|---------|`);
3197
+ ### Low Balance Accounts (< 10)`);
3198
+ sections.push(`| Account | Balance | packageOnly |`);
3199
+ sections.push(`|---------|---------|-------------|`);
3170
3200
  for (const a of lowBalance) {
3171
- sections.push(`| ${a.name ?? a.accountId ?? "?"} | ${Number(a.balance ?? 0).toFixed(2)} |`);
3201
+ sections.push(`| ${a.name ?? a.accountId ?? "?"} | ${Number(a.balance ?? 0).toFixed(2)} | ${a.packageOnly ? "yes" : "no"} |`);
3172
3202
  }
3173
3203
  }
3204
+ const critical = packageOnlyZero.length;
3205
+ const warning = lowBalance.length - critical;
3206
+ const healthy = accounts.length - lowBalance.length;
3207
+ sections.push(`
3208
+ ## Fleet Health Verdict`);
3209
+ sections.push(`- Healthy: ${healthy}`);
3210
+ sections.push(`- Warning (low balance, not package-only-zero): ${Math.max(warning, 0)}`);
3211
+ sections.push(`- Critical (package-only and 0 balance): ${critical}`);
3212
+ if (accounts.length === 0) {
3213
+ sections.push(`
3214
+ No accounts found under this reseller.`);
3215
+ } else if (critical > 0) {
3216
+ sections.push(`
3217
+ Action: top up package-only accounts at 0 balance to keep packages assignable.`);
3218
+ } else if (lowBalance.length === 0) {
3219
+ sections.push(`
3220
+ All accounts healthy.`);
3221
+ }
3222
+ } else {
3174
3223
  sections.push(`
3175
3224
  ## Account Summary`);
3176
- sections.push(`- Total accounts: ${accountsResult.data.length}`);
3177
- sections.push(`- Low balance (< 10): ${lowBalance.length}`);
3225
+ sections.push(`Unavailable: ${accountsResult.error ?? "listResellerAccount returned no data"}`);
3226
+ }
3227
+ if (!statusOk && !accountsOk) {
3228
+ sections.push(`
3229
+ ## Errors`);
3230
+ if (statusResult.error) sections.push(`- esimStatusPerAccount: ${statusResult.error}`);
3231
+ if (accountsResult.error) sections.push(`- listResellerAccount: ${accountsResult.error}`);
3232
+ return result(sections.join("\n"), true);
3178
3233
  }
3179
3234
  return result(sections.join("\n"));
3180
3235
  });