nodebench-mcp 2.31.2 → 2.33.0

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.
Files changed (97) hide show
  1. package/README.md +14 -6
  2. package/dist/engine/server.js +14 -4
  3. package/dist/engine/server.js.map +1 -1
  4. package/dist/index.js +1581 -670
  5. package/dist/index.js.map +1 -1
  6. package/dist/security/SecurityError.d.ts +18 -0
  7. package/dist/security/SecurityError.js +22 -0
  8. package/dist/security/SecurityError.js.map +1 -0
  9. package/dist/security/__tests__/security.test.d.ts +8 -0
  10. package/dist/security/__tests__/security.test.js +295 -0
  11. package/dist/security/__tests__/security.test.js.map +1 -0
  12. package/dist/security/auditLog.d.ts +36 -0
  13. package/dist/security/auditLog.js +178 -0
  14. package/dist/security/auditLog.js.map +1 -0
  15. package/dist/security/commandSandbox.d.ts +33 -0
  16. package/dist/security/commandSandbox.js +159 -0
  17. package/dist/security/commandSandbox.js.map +1 -0
  18. package/dist/security/config.d.ts +23 -0
  19. package/dist/security/config.js +43 -0
  20. package/dist/security/config.js.map +1 -0
  21. package/dist/security/credentialRedactor.d.ts +22 -0
  22. package/dist/security/credentialRedactor.js +118 -0
  23. package/dist/security/credentialRedactor.js.map +1 -0
  24. package/dist/security/index.d.ts +20 -0
  25. package/dist/security/index.js +21 -0
  26. package/dist/security/index.js.map +1 -0
  27. package/dist/security/pathSandbox.d.ts +23 -0
  28. package/dist/security/pathSandbox.js +160 -0
  29. package/dist/security/pathSandbox.js.map +1 -0
  30. package/dist/security/urlValidator.d.ts +23 -0
  31. package/dist/security/urlValidator.js +125 -0
  32. package/dist/security/urlValidator.js.map +1 -0
  33. package/dist/tools/agentBootstrapTools.js +22 -29
  34. package/dist/tools/agentBootstrapTools.js.map +1 -1
  35. package/dist/tools/contextSandboxTools.js +7 -9
  36. package/dist/tools/contextSandboxTools.js.map +1 -1
  37. package/dist/tools/deepSimTools.d.ts +2 -0
  38. package/dist/tools/deepSimTools.js +404 -0
  39. package/dist/tools/deepSimTools.js.map +1 -0
  40. package/dist/tools/dimensionTools.d.ts +2 -0
  41. package/dist/tools/dimensionTools.js +246 -0
  42. package/dist/tools/dimensionTools.js.map +1 -0
  43. package/dist/tools/executionTraceTools.d.ts +2 -0
  44. package/dist/tools/executionTraceTools.js +446 -0
  45. package/dist/tools/executionTraceTools.js.map +1 -0
  46. package/dist/tools/founderTools.d.ts +13 -0
  47. package/dist/tools/founderTools.js +595 -0
  48. package/dist/tools/founderTools.js.map +1 -0
  49. package/dist/tools/founderTrackingTools.d.ts +9 -0
  50. package/dist/tools/founderTrackingTools.js +644 -0
  51. package/dist/tools/founderTrackingTools.js.map +1 -0
  52. package/dist/tools/gitWorkflowTools.js +14 -10
  53. package/dist/tools/gitWorkflowTools.js.map +1 -1
  54. package/dist/tools/githubTools.js +19 -2
  55. package/dist/tools/githubTools.js.map +1 -1
  56. package/dist/tools/index.d.ts +87 -0
  57. package/dist/tools/index.js +102 -0
  58. package/dist/tools/index.js.map +1 -0
  59. package/dist/tools/localFileTools.js +24 -12
  60. package/dist/tools/localFileTools.js.map +1 -1
  61. package/dist/tools/memoryDecay.d.ts +70 -0
  62. package/dist/tools/memoryDecay.js +247 -0
  63. package/dist/tools/memoryDecay.js.map +1 -0
  64. package/dist/tools/missionHarnessTools.d.ts +32 -0
  65. package/dist/tools/missionHarnessTools.js +972 -0
  66. package/dist/tools/missionHarnessTools.js.map +1 -0
  67. package/dist/tools/observabilityTools.d.ts +15 -0
  68. package/dist/tools/observabilityTools.js +787 -0
  69. package/dist/tools/observabilityTools.js.map +1 -0
  70. package/dist/tools/openclawTools.js +151 -36
  71. package/dist/tools/openclawTools.js.map +1 -1
  72. package/dist/tools/progressiveDiscoveryTools.js +5 -4
  73. package/dist/tools/progressiveDiscoveryTools.js.map +1 -1
  74. package/dist/tools/qualityGateTools.js +118 -2
  75. package/dist/tools/qualityGateTools.js.map +1 -1
  76. package/dist/tools/rssTools.js +3 -0
  77. package/dist/tools/rssTools.js.map +1 -1
  78. package/dist/tools/scraplingTools.js +15 -0
  79. package/dist/tools/scraplingTools.js.map +1 -1
  80. package/dist/tools/seoTools.js +66 -1
  81. package/dist/tools/seoTools.js.map +1 -1
  82. package/dist/tools/sessionMemoryTools.js +50 -11
  83. package/dist/tools/sessionMemoryTools.js.map +1 -1
  84. package/dist/tools/temporalIntelligenceTools.d.ts +12 -0
  85. package/dist/tools/temporalIntelligenceTools.js +1068 -0
  86. package/dist/tools/temporalIntelligenceTools.js.map +1 -0
  87. package/dist/tools/toolRegistry.d.ts +19 -0
  88. package/dist/tools/toolRegistry.js +956 -31
  89. package/dist/tools/toolRegistry.js.map +1 -1
  90. package/dist/tools/webTools.js +14 -1
  91. package/dist/tools/webTools.js.map +1 -1
  92. package/dist/tools/webmcpTools.js +13 -2
  93. package/dist/tools/webmcpTools.js.map +1 -1
  94. package/dist/toolsetRegistry.js +14 -0
  95. package/dist/toolsetRegistry.js.map +1 -1
  96. package/dist/types.d.ts +10 -0
  97. package/package.json +124 -124
@@ -0,0 +1,404 @@
1
+ function normalizeGatewayBaseUrl(raw) {
2
+ if (!raw)
3
+ return null;
4
+ const trimmed = raw.replace(/\/$/, "");
5
+ if (trimmed.includes(".convex.cloud")) {
6
+ return trimmed.replace(".convex.cloud", ".convex.site");
7
+ }
8
+ return trimmed;
9
+ }
10
+ function getDeepSimConfig() {
11
+ const siteUrl = normalizeGatewayBaseUrl(process.env.CONVEX_SITE_URL || process.env.VITE_CONVEX_URL || process.env.CONVEX_URL);
12
+ const secret = process.env.MCP_SECRET;
13
+ if (!siteUrl || !secret)
14
+ return null;
15
+ return { siteUrl, secret };
16
+ }
17
+ /** TIMEOUT: Gateway call timeout in ms */
18
+ const GATEWAY_TIMEOUT_MS = 30_000;
19
+ /** BOUND_READ: Max response body size (2 MB) */
20
+ const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
21
+ async function callGateway(fn, args) {
22
+ const config = getDeepSimConfig();
23
+ if (!config) {
24
+ return {
25
+ success: false,
26
+ error: "Missing CONVEX_SITE_URL, VITE_CONVEX_URL, or CONVEX_URL, or MCP_SECRET. Cannot call Deep Sim backend.",
27
+ };
28
+ }
29
+ // ERROR_BOUNDARY: Wrap entire fetch+parse in try/catch
30
+ try {
31
+ // TIMEOUT: AbortController with budget gate
32
+ const controller = new AbortController();
33
+ const timeout = setTimeout(() => controller.abort(), GATEWAY_TIMEOUT_MS);
34
+ const res = await fetch(`${config.siteUrl}/api/mcpGateway`, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ "x-mcp-secret": config.secret,
39
+ },
40
+ body: JSON.stringify({ fn, args }),
41
+ signal: controller.signal,
42
+ });
43
+ clearTimeout(timeout);
44
+ // BOUND_READ: Cap response body size before parsing
45
+ const contentLength = res.headers.get("content-length");
46
+ if (contentLength && parseInt(contentLength, 10) > MAX_RESPONSE_BYTES) {
47
+ return {
48
+ success: false,
49
+ error: `Response too large (${contentLength} bytes, max ${MAX_RESPONSE_BYTES}). Reduce scope or use pagination.`,
50
+ };
51
+ }
52
+ const text = await res.text();
53
+ if (text.length > MAX_RESPONSE_BYTES) {
54
+ return {
55
+ success: false,
56
+ error: `Response body too large (${text.length} chars, max ${MAX_RESPONSE_BYTES}). Reduce scope or use pagination.`,
57
+ };
58
+ }
59
+ let payload;
60
+ try {
61
+ payload = JSON.parse(text);
62
+ }
63
+ catch {
64
+ return {
65
+ success: false,
66
+ error: `Deep Sim backend returned non-JSON response (HTTP ${res.status}): ${text.slice(0, 200)}`,
67
+ };
68
+ }
69
+ if (!res.ok) {
70
+ const errorMessage = ("error" in payload ? payload.error : undefined) ||
71
+ payload.message ||
72
+ `Deep Sim backend returned HTTP ${res.status}`;
73
+ return { success: false, error: errorMessage };
74
+ }
75
+ return payload;
76
+ }
77
+ catch (err) {
78
+ const message = err instanceof Error ? err.message : String(err);
79
+ if (message.includes("abort")) {
80
+ return { success: false, error: `Deep Sim gateway timed out after ${GATEWAY_TIMEOUT_MS}ms for ${fn}` };
81
+ }
82
+ return { success: false, error: `Deep Sim gateway call failed for ${fn}: ${message}` };
83
+ }
84
+ }
85
+ function successOrError(result, latencyMs) {
86
+ if (!result.success) {
87
+ return { error: true, message: result.error, latencyMs };
88
+ }
89
+ return { success: true, latencyMs, data: result.data };
90
+ }
91
+ // ---------------------------------------------------------------------------
92
+ // 7 Deep Sim MCP Tools
93
+ // ---------------------------------------------------------------------------
94
+ export const deepSimTools = [
95
+ // -----------------------------------------------------------------------
96
+ // 1. build_claim_graph
97
+ // -----------------------------------------------------------------------
98
+ {
99
+ name: "build_claim_graph",
100
+ description: "Extract claims from a source packet and link each claim to its evidence. Returns a directed graph of claims with supporting/contradicting evidence, confidence per claim, and whatWouldChangeMyMind for each.",
101
+ inputSchema: {
102
+ type: "object",
103
+ properties: {
104
+ entityKey: {
105
+ type: "string",
106
+ description: "Canonical entity key, e.g. company/acme-ai",
107
+ },
108
+ sources: {
109
+ type: "array",
110
+ items: { type: "string" },
111
+ maxItems: 50,
112
+ description: "Source texts, URLs, or document keys to extract claims from",
113
+ },
114
+ maxClaims: {
115
+ type: "number",
116
+ default: 20,
117
+ maximum: 50,
118
+ description: "Maximum number of claims to extract (default 20, max 50)",
119
+ },
120
+ },
121
+ required: ["entityKey", "sources"],
122
+ },
123
+ handler: async (args) => {
124
+ const started = Date.now();
125
+ const result = await callGateway("buildClaimGraph", {
126
+ entityKey: args.entityKey,
127
+ sources: args.sources,
128
+ maxClaims: Math.min(args.maxClaims ?? 20, 50),
129
+ });
130
+ return successOrError(result, Date.now() - started);
131
+ },
132
+ },
133
+ // -----------------------------------------------------------------------
134
+ // 2. extract_variables
135
+ // -----------------------------------------------------------------------
136
+ {
137
+ name: "extract_variables",
138
+ description: "Identify and weight the key variables driving an entity's trajectory across 6 categories (intrinsic, temporal, network, intervention, market, constraint). Returns ranked variables with sensitivity estimates, data completeness, and whatWouldChangeMyMind.",
139
+ inputSchema: {
140
+ type: "object",
141
+ properties: {
142
+ entityKey: {
143
+ type: "string",
144
+ description: "Canonical entity key",
145
+ },
146
+ claimGraphId: {
147
+ type: "string",
148
+ description: "ID from build_claim_graph output (optional, for context enrichment)",
149
+ },
150
+ variableCategories: {
151
+ type: "array",
152
+ items: {
153
+ type: "string",
154
+ enum: ["intrinsic", "temporal", "network", "intervention", "market", "constraint"],
155
+ },
156
+ default: ["intrinsic", "temporal", "network", "intervention", "market", "constraint"],
157
+ description: "Which variable categories to analyze",
158
+ },
159
+ maxVariables: {
160
+ type: "number",
161
+ default: 15,
162
+ maximum: 30,
163
+ description: "Maximum variables to return (default 15, max 30)",
164
+ },
165
+ },
166
+ required: ["entityKey"],
167
+ },
168
+ handler: async (args) => {
169
+ const started = Date.now();
170
+ const result = await callGateway("extractVariables", {
171
+ entityKey: args.entityKey,
172
+ claimGraphId: args.claimGraphId,
173
+ variableCategories: args.variableCategories ?? [
174
+ "intrinsic", "temporal", "network", "intervention", "market", "constraint",
175
+ ],
176
+ maxVariables: Math.min(args.maxVariables ?? 15, 30),
177
+ });
178
+ return successOrError(result, Date.now() - started);
179
+ },
180
+ },
181
+ // -----------------------------------------------------------------------
182
+ // 3. generate_countermodels
183
+ // -----------------------------------------------------------------------
184
+ {
185
+ name: "generate_countermodels",
186
+ description: "For every main thesis or scenario, generate serious alternative explanations with their own evidence and confidence. Forces intellectual honesty by surfacing counter-arguments and what would validate each.",
187
+ inputSchema: {
188
+ type: "object",
189
+ properties: {
190
+ entityKey: {
191
+ type: "string",
192
+ description: "Canonical entity key",
193
+ },
194
+ thesis: {
195
+ type: "string",
196
+ description: "The main claim or scenario to challenge",
197
+ },
198
+ claimGraphId: {
199
+ type: "string",
200
+ description: "Optional claim graph ID for context enrichment",
201
+ },
202
+ maxCounterModels: {
203
+ type: "number",
204
+ default: 3,
205
+ maximum: 5,
206
+ description: "Maximum counter-models to generate (default 3, max 5)",
207
+ },
208
+ },
209
+ required: ["entityKey", "thesis"],
210
+ },
211
+ handler: async (args) => {
212
+ const started = Date.now();
213
+ const result = await callGateway("generateCounterModels", {
214
+ entityKey: args.entityKey,
215
+ thesis: args.thesis,
216
+ claimGraphId: args.claimGraphId,
217
+ maxCounterModels: Math.min(args.maxCounterModels ?? 3, 5),
218
+ });
219
+ return successOrError(result, Date.now() - started);
220
+ },
221
+ },
222
+ // -----------------------------------------------------------------------
223
+ // 4. run_deep_sim
224
+ // -----------------------------------------------------------------------
225
+ {
226
+ name: "run_deep_sim",
227
+ description: "Run a multi-agent scenario simulation with bounded branching and budget controls. Instantiates agents with personas and incentives, varies conditions across branches, and generates an analytical report with convergence metrics.",
228
+ inputSchema: {
229
+ type: "object",
230
+ properties: {
231
+ entityKey: {
232
+ type: "string",
233
+ description: "Canonical entity key",
234
+ },
235
+ workflow: {
236
+ type: "string",
237
+ enum: [
238
+ "investor_diligence",
239
+ "founder_strategy",
240
+ "ceo_decision",
241
+ "gtm_analysis",
242
+ "creator_trajectory",
243
+ "trend_forecast",
244
+ ],
245
+ description: "Which analysis workflow to run",
246
+ },
247
+ variableOverrides: {
248
+ type: "object",
249
+ description: "Override specific variable values for what-if analysis",
250
+ },
251
+ maxBranches: {
252
+ type: "number",
253
+ default: 3,
254
+ maximum: 5,
255
+ description: "Maximum scenario branches (default 3, max 5)",
256
+ },
257
+ maxRounds: {
258
+ type: "number",
259
+ default: 4,
260
+ maximum: 6,
261
+ description: "Maximum deliberation rounds per branch (default 4, max 6)",
262
+ },
263
+ budgetSeconds: {
264
+ type: "number",
265
+ default: 90,
266
+ maximum: 180,
267
+ description: "Total wall-clock budget in seconds (default 90, max 180)",
268
+ },
269
+ },
270
+ required: ["entityKey", "workflow"],
271
+ },
272
+ handler: async (args) => {
273
+ const started = Date.now();
274
+ const result = await callGateway("runDeepSim", {
275
+ entityKey: args.entityKey,
276
+ workflow: args.workflow,
277
+ variableOverrides: args.variableOverrides ?? {},
278
+ maxBranches: Math.min(args.maxBranches ?? 3, 5),
279
+ maxRounds: Math.min(args.maxRounds ?? 4, 6),
280
+ budgetSeconds: Math.min(args.budgetSeconds ?? 90, 180),
281
+ });
282
+ return successOrError(result, Date.now() - started);
283
+ },
284
+ },
285
+ // -----------------------------------------------------------------------
286
+ // 5. rank_interventions
287
+ // -----------------------------------------------------------------------
288
+ {
289
+ name: "rank_interventions",
290
+ description: "Rank potential interventions by expected trajectory delta. Each intervention includes expected impact, confidence, cost, timeframe, and what evidence would confirm or deny its effect.",
291
+ inputSchema: {
292
+ type: "object",
293
+ properties: {
294
+ entityKey: {
295
+ type: "string",
296
+ description: "Canonical entity key",
297
+ },
298
+ scenarioId: {
299
+ type: "string",
300
+ description: "Scenario ID from run_deep_sim output to optimize for",
301
+ },
302
+ maxInterventions: {
303
+ type: "number",
304
+ default: 5,
305
+ maximum: 10,
306
+ description: "Maximum interventions to rank (default 5, max 10)",
307
+ },
308
+ },
309
+ required: ["entityKey", "scenarioId"],
310
+ },
311
+ handler: async (args) => {
312
+ const started = Date.now();
313
+ const result = await callGateway("rankInterventions", {
314
+ entityKey: args.entityKey,
315
+ scenarioId: args.scenarioId,
316
+ maxInterventions: Math.min(args.maxInterventions ?? 5, 10),
317
+ });
318
+ return successOrError(result, Date.now() - started);
319
+ },
320
+ },
321
+ // -----------------------------------------------------------------------
322
+ // 6. score_compounding
323
+ // -----------------------------------------------------------------------
324
+ {
325
+ name: "score_compounding",
326
+ description: "Compute the full 8-dimension trajectory score for an entity. Returns trust-adjusted compounding, drift, adaptation velocity, and all sub-scores with explanations. Output includes TrajectoryScoreBreakdown and TrajectorySummaryData.",
327
+ inputSchema: {
328
+ type: "object",
329
+ properties: {
330
+ entityKey: {
331
+ type: "string",
332
+ description: "Canonical entity key",
333
+ },
334
+ entityType: {
335
+ type: "string",
336
+ enum: ["product", "startup", "founder", "workflow", "agent", "mission", "team"],
337
+ description: "Entity type for scoring context",
338
+ },
339
+ windowDays: {
340
+ type: "number",
341
+ default: 90,
342
+ minimum: 7,
343
+ maximum: 365,
344
+ description: "Lookback window in days for trajectory computation (default 90)",
345
+ },
346
+ },
347
+ required: ["entityKey", "entityType"],
348
+ },
349
+ handler: async (args) => {
350
+ const started = Date.now();
351
+ const windowDays = Math.max(7, Math.min(args.windowDays ?? 90, 365));
352
+ const result = await callGateway("scoreCompounding", {
353
+ entityKey: args.entityKey,
354
+ entityType: args.entityType,
355
+ windowDays,
356
+ });
357
+ return successOrError(result, Date.now() - started);
358
+ },
359
+ },
360
+ // -----------------------------------------------------------------------
361
+ // 7. render_decision_memo
362
+ // -----------------------------------------------------------------------
363
+ {
364
+ name: "render_decision_memo",
365
+ description: "Render a 1-page executive decision memo from a completed Deep Sim analysis. Combines claim graph, variables, scenarios, interventions, and compounding score into a structured memo with counter-models, forecast check date, and whatWouldChangeMyMind.",
366
+ inputSchema: {
367
+ type: "object",
368
+ properties: {
369
+ entityKey: {
370
+ type: "string",
371
+ description: "Canonical entity key",
372
+ },
373
+ workflow: {
374
+ type: "string",
375
+ description: "Workflow name used in the Deep Sim run",
376
+ },
377
+ format: {
378
+ type: "string",
379
+ enum: ["markdown", "json", "html"],
380
+ default: "markdown",
381
+ description: "Output format for the rendered memo (default markdown)",
382
+ },
383
+ audienceRole: {
384
+ type: "string",
385
+ enum: ["ceo", "investor", "founder", "builder"],
386
+ default: "founder",
387
+ description: "Target audience role for tone and emphasis (default founder)",
388
+ },
389
+ },
390
+ required: ["entityKey", "workflow"],
391
+ },
392
+ handler: async (args) => {
393
+ const started = Date.now();
394
+ const result = await callGateway("renderDecisionMemo", {
395
+ entityKey: args.entityKey,
396
+ workflow: args.workflow,
397
+ format: args.format ?? "markdown",
398
+ audienceRole: args.audienceRole ?? "founder",
399
+ });
400
+ return successOrError(result, Date.now() - started);
401
+ },
402
+ },
403
+ ];
404
+ //# sourceMappingURL=deepSimTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepSimTools.js","sourceRoot":"","sources":["../../src/tools/deepSimTools.ts"],"names":[],"mappings":"AAWA,SAAS,uBAAuB,CAAC,GAAuB;IACtD,IAAI,CAAC,GAAG;QAAE,OAAO,IA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ACD,MAAM,EAAE;oBACN,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC;oBAClC,OAAO,EAAE,UAAU;oBACnB,WAAW,EAAE,wDAAwD;iBACtE;gBACD,YAAY,EAAE;oBACZ,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,CAAC;oBAC/C,OAAO,EAAE,SAAS;oBAClB,WAAW,EAAE,8DAA8D;iBAC5E;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,EAAE,UAAU,CAAC;SACpC;QACD,OAAO,EAAE,KAAK,EAAE,IAKf,EAAE,EAAE;YACH,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3B,MAAM,MAAM,GAAG,MAAM,WAAW,CAAM,oBAAoB,EAAE;gBAC1D,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,UAAU;gBACjC,YAAY,EAAE,IAAI,CAAC,YAAY,IAAI,SAAS;aAC7C,CAAC,CAAC;YACH,OAAO,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,CAAC;QACtD,CAAC;KACF;CACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { McpTool } from "../types.js";
2
+ export declare const dimensionTools: McpTool[];
@@ -0,0 +1,246 @@
1
+ function normalizeGatewayBaseUrl(raw) {
2
+ if (!raw)
3
+ return null;
4
+ const trimmed = raw.replace(/\/$/, "");
5
+ if (trimmed.includes(".convex.cloud")) {
6
+ return trimmed.replace(".convex.cloud", ".convex.site");
7
+ }
8
+ return trimmed;
9
+ }
10
+ function getDimensionConfig() {
11
+ const siteUrl = normalizeGatewayBaseUrl(process.env.CONVEX_SITE_URL || process.env.VITE_CONVEX_URL || process.env.CONVEX_URL);
12
+ const secret = process.env.MCP_SECRET;
13
+ if (!siteUrl || !secret)
14
+ return null;
15
+ return { siteUrl, secret };
16
+ }
17
+ /** TIMEOUT: Gateway call timeout in ms */
18
+ const GATEWAY_TIMEOUT_MS = 30_000;
19
+ /** BOUND_READ: Max response body size (2 MB) */
20
+ const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
21
+ async function callGateway(fn, args) {
22
+ const config = getDimensionConfig();
23
+ if (!config) {
24
+ return {
25
+ success: false,
26
+ error: "Missing CONVEX_SITE_URL, VITE_CONVEX_URL, or CONVEX_URL, or MCP_SECRET. Cannot call DeepTrace dimension backend.",
27
+ };
28
+ }
29
+ // ERROR_BOUNDARY: Wrap entire fetch+parse in try/catch
30
+ try {
31
+ // TIMEOUT: AbortController with budget gate
32
+ const controller = new AbortController();
33
+ const timeout = setTimeout(() => controller.abort(), GATEWAY_TIMEOUT_MS);
34
+ const res = await fetch(`${config.siteUrl}/api/mcpGateway`, {
35
+ method: "POST",
36
+ headers: {
37
+ "Content-Type": "application/json",
38
+ "x-mcp-secret": config.secret,
39
+ },
40
+ body: JSON.stringify({ fn, args }),
41
+ signal: controller.signal,
42
+ });
43
+ clearTimeout(timeout);
44
+ // BOUND_READ: Cap response body size before parsing
45
+ const contentLength = res.headers.get("content-length");
46
+ if (contentLength && parseInt(contentLength, 10) > MAX_RESPONSE_BYTES) {
47
+ return {
48
+ success: false,
49
+ error: `Response too large (${contentLength} bytes, max ${MAX_RESPONSE_BYTES}). Reduce scope or use pagination.`,
50
+ };
51
+ }
52
+ const text = await res.text();
53
+ if (text.length > MAX_RESPONSE_BYTES) {
54
+ return {
55
+ success: false,
56
+ error: `Response body too large (${text.length} chars, max ${MAX_RESPONSE_BYTES}). Reduce scope or use pagination.`,
57
+ };
58
+ }
59
+ let payload;
60
+ try {
61
+ payload = JSON.parse(text);
62
+ }
63
+ catch {
64
+ return {
65
+ success: false,
66
+ error: `DeepTrace backend returned non-JSON response (HTTP ${res.status}): ${text.slice(0, 200)}`,
67
+ };
68
+ }
69
+ if (!res.ok) {
70
+ const errorMessage = ("error" in payload ? payload.error : undefined)
71
+ || payload.message
72
+ || `DeepTrace dimension backend returned HTTP ${res.status}`;
73
+ return {
74
+ success: false,
75
+ error: errorMessage,
76
+ };
77
+ }
78
+ return payload;
79
+ }
80
+ catch (err) {
81
+ const message = err instanceof Error ? err.message : String(err);
82
+ if (message.includes("abort")) {
83
+ return { success: false, error: `DeepTrace gateway timed out after ${GATEWAY_TIMEOUT_MS}ms for ${fn}` };
84
+ }
85
+ return { success: false, error: `DeepTrace gateway call failed for ${fn}: ${message}` };
86
+ }
87
+ }
88
+ function successOrError(result, latencyMs) {
89
+ if (!result.success) {
90
+ return { error: true, message: result.error, latencyMs };
91
+ }
92
+ return { success: true, latencyMs, data: result.data };
93
+ }
94
+ export const dimensionTools = [
95
+ {
96
+ name: "compute_dimension_profile",
97
+ description: "Recompute and persist the DeepTrace dimension profile for an entity. Use after new company evidence, relationship updates, or temporal signals land.",
98
+ inputSchema: {
99
+ type: "object",
100
+ properties: {
101
+ entityKey: { type: "string", description: "Canonical entity key, e.g. company/acme-ai" },
102
+ entityName: { type: "string", description: "Optional display name when entity context is sparse" },
103
+ entityType: { type: "string", description: "Optional entity type such as company or person" },
104
+ triggerEventKey: { type: "string", description: "Optional event key or reason for recomputation" },
105
+ },
106
+ required: ["entityKey"],
107
+ },
108
+ handler: async (args) => {
109
+ const started = Date.now();
110
+ const result = await callGateway("refreshDimensionProfile", args);
111
+ return successOrError(result, Date.now() - started);
112
+ },
113
+ },
114
+ {
115
+ name: "get_dimension_profile",
116
+ description: "Fetch the latest persisted DeepTrace dimension profile, including regime label, policy context, confidence, and the normalized dimension state.",
117
+ inputSchema: {
118
+ type: "object",
119
+ properties: {
120
+ entityKey: { type: "string", description: "Canonical entity key" },
121
+ },
122
+ required: ["entityKey"],
123
+ },
124
+ handler: async (args) => {
125
+ const started = Date.now();
126
+ const result = await callGateway("getDimensionProfile", args);
127
+ return successOrError(result, Date.now() - started);
128
+ },
129
+ },
130
+ {
131
+ name: "list_dimension_snapshots",
132
+ description: "List historical DeepTrace dimension snapshots for an entity to inspect regime transitions over time.",
133
+ inputSchema: {
134
+ type: "object",
135
+ properties: {
136
+ entityKey: { type: "string", description: "Canonical entity key" },
137
+ limit: { type: "number", description: "Maximum number of snapshots to return (default 12)" },
138
+ },
139
+ required: ["entityKey"],
140
+ },
141
+ handler: async (args) => {
142
+ const started = Date.now();
143
+ const result = await callGateway("listDimensionSnapshots", args);
144
+ return successOrError(result, Date.now() - started);
145
+ },
146
+ },
147
+ {
148
+ name: "list_dimension_evidence",
149
+ description: "List the durable evidence rows behind a DeepTrace dimension profile. Useful for auditing why a score or availability status was assigned.",
150
+ inputSchema: {
151
+ type: "object",
152
+ properties: {
153
+ entityKey: { type: "string", description: "Canonical entity key" },
154
+ dimensionFamily: { type: "string", description: "Optional family such as capital, people, or narrative" },
155
+ dimensionName: { type: "string", description: "Optional metric name within the family" },
156
+ limit: { type: "number", description: "Maximum rows to return (default 40)" },
157
+ },
158
+ required: ["entityKey"],
159
+ },
160
+ handler: async (args) => {
161
+ const started = Date.now();
162
+ const result = await callGateway("listDimensionEvidence", args);
163
+ return successOrError(result, Date.now() - started);
164
+ },
165
+ },
166
+ {
167
+ name: "list_dimension_interactions",
168
+ description: "List stored interaction effects for an entity, such as capital plus investor quality reducing execution fragility or narrative outpacing evidence.",
169
+ inputSchema: {
170
+ type: "object",
171
+ properties: {
172
+ entityKey: { type: "string", description: "Canonical entity key" },
173
+ limit: { type: "number", description: "Maximum rows to return (default 16)" },
174
+ },
175
+ required: ["entityKey"],
176
+ },
177
+ handler: async (args) => {
178
+ const started = Date.now();
179
+ const result = await callGateway("listDimensionInteractions", args);
180
+ return successOrError(result, Date.now() - started);
181
+ },
182
+ },
183
+ {
184
+ name: "export_dimension_bundle",
185
+ description: "Export the full DeepTrace dimension bundle for an entity: latest profile, snapshots, evidence, and interaction effects in one response.",
186
+ inputSchema: {
187
+ type: "object",
188
+ properties: {
189
+ entityKey: { type: "string", description: "Canonical entity key" },
190
+ snapshotLimit: { type: "number", description: "Maximum snapshots to include" },
191
+ evidenceLimit: { type: "number", description: "Maximum evidence rows to include" },
192
+ interactionLimit: { type: "number", description: "Maximum interaction rows to include" },
193
+ },
194
+ required: ["entityKey"],
195
+ },
196
+ handler: async (args) => {
197
+ const started = Date.now();
198
+ const result = await callGateway("getDimensionBundle", args);
199
+ return successOrError(result, Date.now() - started);
200
+ },
201
+ },
202
+ {
203
+ name: "run_research_cell",
204
+ description: "Run a bounded re-analysis cell for a DeepTrace entity investigation. Queries existing DeepTrace state through parallel branches (evidence gap analysis, counter-hypothesis, dimension coverage, source diversification) to surface gaps and weaknesses. Does NOT acquire new external evidence — use due-diligence orchestrator for that. Triggers when confidence is low, coverage is sparse, or operator requests deeper analysis. Returns merged findings in standard DeepTrace format with receipts and dimension profile.",
205
+ inputSchema: {
206
+ type: "object",
207
+ properties: {
208
+ entityKey: { type: "string", description: "Canonical entity key, e.g. company/acme-ai" },
209
+ entityName: { type: "string", description: "Optional display name" },
210
+ confidence: { type: "number", description: "Current investigation confidence [0,1]. Cell auto-triggers below 0.65" },
211
+ dimensionCoverage: { type: "number", description: "Current dimension coverage ratio [0,1]. Cell auto-triggers below 0.70" },
212
+ durableSourceCount: { type: "number", description: "Number of durable evidence sources. Cell auto-triggers below 3" },
213
+ operatorRequested: { type: "boolean", description: "Force-trigger the research cell regardless of thresholds" },
214
+ existingFacts: { type: "array", items: { type: "string" }, description: "Known facts to avoid redundant research" },
215
+ maxBranches: { type: "number", description: "Max parallel research branches (default 3, max 3)" },
216
+ maxRefinementRounds: { type: "number", description: "Max refinement rounds (default 2, max 2)" },
217
+ },
218
+ required: ["entityKey", "confidence", "dimensionCoverage", "durableSourceCount"],
219
+ },
220
+ handler: async (args) => {
221
+ const started = Date.now();
222
+ const result = await callGateway("runResearchCell", args);
223
+ return successOrError(result, Date.now() - started);
224
+ },
225
+ },
226
+ {
227
+ name: "run_entity_intelligence_mission",
228
+ description: "Run a full DeepTrace entity intelligence mission with optional bounded research cell. Unifies relationship mapping, ownership, supply chain, signals, and causal analysis. Pass researchCell=true for threshold-driven re-analysis when the investigation has gaps, or forceResearchCell=true to explicitly force the bounded cell.",
229
+ inputSchema: {
230
+ type: "object",
231
+ properties: {
232
+ entityKey: { type: "string", description: "Canonical entity key" },
233
+ entityName: { type: "string", description: "Optional display name" },
234
+ researchCell: { type: "boolean", description: "Enable threshold-driven autoresearch cell for low-confidence investigations" },
235
+ forceResearchCell: { type: "boolean", description: "Force the bounded research cell even if thresholds are healthy" },
236
+ },
237
+ required: ["entityKey"],
238
+ },
239
+ handler: async (args) => {
240
+ const started = Date.now();
241
+ const result = await callGateway("runEntityIntelligenceMission", args);
242
+ return successOrError(result, Date.now() - started);
243
+ },
244
+ },
245
+ ];
246
+ //# sourceMappingURL=dimensionTools.js.map