@forcefield/mcp-server 0.1.13 → 0.1.15

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.
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  PRODUCTION_SUPABASE_PUBLISHABLE_KEY,
4
- PRODUCTION_SUPABASE_URL
5
- } from "./chunk-UOMOGP46.js";
4
+ PRODUCTION_SUPABASE_URL,
5
+ package_default
6
+ } from "./chunk-DS44IZQ7.js";
6
7
 
7
8
  // src/index.ts
8
9
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
@@ -536,12 +537,14 @@ var FfCompanySchema = z3.discriminatedUnion("action", [
536
537
  import { z as z4 } from "zod";
537
538
  var ScanFileSchema = z4.object({
538
539
  action: z4.literal("file"),
539
- companyId: CompanyIdSchema,
540
+ // Optional for pre-onboarding document preview flows.
541
+ companyId: CompanyIdSchema.optional(),
540
542
  filePath: z4.string().min(1).describe("Absolute path to local file")
541
543
  });
542
544
  var ScanFolderSchema = z4.object({
543
545
  action: z4.literal("folder"),
544
- companyId: CompanyIdSchema,
546
+ // Optional for pre-onboarding document preview flows.
547
+ companyId: CompanyIdSchema.optional(),
545
548
  folderPath: z4.string().min(1).describe("Absolute path to local folder"),
546
549
  recursive: z4.boolean().default(true)
547
550
  });
@@ -2223,6 +2226,24 @@ async function listFilingHistory(supabase, companyId, limit = 25, offset = 0) {
2223
2226
 
2224
2227
  // src/tools/ff-company.ts
2225
2228
  var TOOL_NAME = "ff_company";
2229
+ function getErrorCode(error) {
2230
+ if (!error || typeof error !== "object") return void 0;
2231
+ const candidate = error.code;
2232
+ return typeof candidate === "string" ? candidate : void 0;
2233
+ }
2234
+ function getErrorMessage(error) {
2235
+ if (error instanceof Error) return error.message;
2236
+ if (typeof error === "string") return error;
2237
+ return "";
2238
+ }
2239
+ function isBackendUnavailableError(error) {
2240
+ const code = getErrorCode(error);
2241
+ const message = getErrorMessage(error).toLowerCase();
2242
+ if (code && (code.startsWith("PGRST") || code === "08006" || code === "57P01")) {
2243
+ return true;
2244
+ }
2245
+ return message.includes("fetch failed") || message.includes("failed to fetch") || message.includes("network") || message.includes("connection") || message.includes("enotfound") || message.includes("econnrefused") || message.includes("service unavailable");
2246
+ }
2226
2247
  var TRIGGER_FIELDS = /* @__PURE__ */ new Set([
2227
2248
  "stateOfFormation",
2228
2249
  "entityType",
@@ -2518,6 +2539,13 @@ async function handleFfCompany(ctx, rawInput, _extra) {
2518
2539
  });
2519
2540
  return formatErrorResponse(ffErr);
2520
2541
  }
2542
+ if (getErrorCode(error) === "CONFLICT") {
2543
+ const msg = getErrorMessage(error) || "Company already exists.";
2544
+ return formatErrorResponse(ffError.conflict("company", msg));
2545
+ }
2546
+ if (isBackendUnavailableError(error)) {
2547
+ return formatErrorResponse(ffError.serviceUnavailable("Forcefield backend"));
2548
+ }
2521
2549
  writeAuditLog(ctx.supabase, ctx.userId, {
2522
2550
  tool: TOOL_NAME,
2523
2551
  action: rawInput.action ?? "unknown",
@@ -2736,6 +2764,16 @@ function countWords(text) {
2736
2764
 
2737
2765
  // src/tools/ff-scan.ts
2738
2766
  var TOOL_NAME2 = "ff_scan";
2767
+ function buildVaultNextAction(companyId) {
2768
+ if (!companyId) return void 0;
2769
+ return { tool: "ff_vault", action: "upload", params: { companyId } };
2770
+ }
2771
+ function buildVaultPrompt(companyId) {
2772
+ if (!companyId) {
2773
+ return "This is a preview scan. Create/select a company first if you want to save files to the vault.";
2774
+ }
2775
+ return "Would you like to save this document to your vault?";
2776
+ }
2739
2777
  async function handleFfScan(ctx, rawInput, extra) {
2740
2778
  const done = logger.toolInvocation(TOOL_NAME2, rawInput.action ?? "unknown");
2741
2779
  try {
@@ -2749,7 +2787,9 @@ async function handleFfScan(ctx, rawInput, extra) {
2749
2787
  }
2750
2788
  const input = parseResult.data;
2751
2789
  assertActionAllowed(ctx.gating, TOOL_NAME2, input.action, ctx.tier);
2752
- await validateCompanyOwnership(ctx.supabase, input.companyId, ctx.userId);
2790
+ if (input.companyId) {
2791
+ await validateCompanyOwnership(ctx.supabase, input.companyId, ctx.userId);
2792
+ }
2753
2793
  switch (input.action) {
2754
2794
  case "file": {
2755
2795
  const resolvedPath = await validateScanPath(input.filePath);
@@ -2764,7 +2804,7 @@ async function handleFfScan(ctx, rawInput, extra) {
2764
2804
  writeAuditLog(ctx.supabase, ctx.userId, {
2765
2805
  tool: TOOL_NAME2,
2766
2806
  action: "file",
2767
- companyId: input.companyId,
2807
+ ...input.companyId && { companyId: input.companyId },
2768
2808
  input: { filePath: basename(resolvedPath) },
2769
2809
  result: "success"
2770
2810
  });
@@ -2775,8 +2815,8 @@ async function handleFfScan(ctx, rawInput, extra) {
2775
2815
  ...result
2776
2816
  },
2777
2817
  message: buildFileMessage(basename(resolvedPath), result),
2778
- nextAction: { tool: "ff_vault", action: "upload", params: { companyId: input.companyId } },
2779
- prompt: "Would you like to save this document to your vault?"
2818
+ ...buildVaultNextAction(input.companyId) && { nextAction: buildVaultNextAction(input.companyId) },
2819
+ ...buildVaultPrompt(input.companyId) && { prompt: buildVaultPrompt(input.companyId) }
2780
2820
  });
2781
2821
  }
2782
2822
  case "folder": {
@@ -2844,7 +2884,7 @@ async function handleFfScan(ctx, rawInput, extra) {
2844
2884
  writeAuditLog(ctx.supabase, ctx.userId, {
2845
2885
  tool: TOOL_NAME2,
2846
2886
  action: "folder",
2847
- companyId: input.companyId,
2887
+ ...input.companyId && { companyId: input.companyId },
2848
2888
  input: { folderPath: basename(resolvedPath), fileCount: validFiles.length },
2849
2889
  result: "success"
2850
2890
  });
@@ -2858,8 +2898,8 @@ async function handleFfScan(ctx, rawInput, extra) {
2858
2898
  files: results
2859
2899
  },
2860
2900
  message: `Scanned ${basename(resolvedPath)}/ (${validFiles.length} files). Extracted ${totalWords.toLocaleString()} words, ${formatSize2(totalSize)} total.`,
2861
- nextAction: { tool: "ff_vault", action: "upload", params: { companyId: input.companyId } },
2862
- prompt: "Ready to analyze. Would you like to save these documents to your vault?"
2901
+ ...buildVaultNextAction(input.companyId) && { nextAction: buildVaultNextAction(input.companyId) },
2902
+ ...input.companyId ? { prompt: "Ready to analyze. Would you like to save these documents to your vault?" } : { prompt: buildVaultPrompt(input.companyId) }
2863
2903
  });
2864
2904
  }
2865
2905
  }
@@ -4201,7 +4241,7 @@ async function enrichDeadlines(items, tier) {
4201
4241
 
4202
4242
  // src/tools/ff-system.ts
4203
4243
  var TOOL_NAME4 = "ff_system";
4204
- var SERVER_VERSION = "0.1.0";
4244
+ var SERVER_VERSION = package_default.version;
4205
4245
  var MIN_SCHEMA_VERSION = 1;
4206
4246
  function isLocalDevMode() {
4207
4247
  const value = process.env.FORCEFIELD_LOCAL_DEV;
@@ -8978,7 +9018,7 @@ function mapToCalendarDeadline(d) {
8978
9018
  // src/server.ts
8979
9019
  var WORKFLOWS_DIR = join4(dirname2(fileURLToPath2(import.meta.url)), "..", "workflows");
8980
9020
  var SERVER_NAME = "forcefield";
8981
- var SERVER_VERSION2 = "0.0.0";
9021
+ var SERVER_VERSION2 = package_default.version;
8982
9022
  var WORKFLOW_NAMES = [
8983
9023
  "ff-start",
8984
9024
  "ff-onboard",
@@ -9149,4 +9189,4 @@ async function runMcpCli() {
9149
9189
  export {
9150
9190
  runMcpCli
9151
9191
  };
9152
- //# sourceMappingURL=chunk-N46MYH57.js.map
9192
+ //# sourceMappingURL=chunk-YBELASNC.js.map