@triedotdev/mcp 1.0.168 → 1.0.170

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 (149) hide show
  1. package/README.md +54 -500
  2. package/dist/chunk-2YXOBNKW.js +619 -0
  3. package/dist/chunk-2YXOBNKW.js.map +1 -0
  4. package/dist/chunk-QR64Y5TI.js +363 -0
  5. package/dist/chunk-QR64Y5TI.js.map +1 -0
  6. package/dist/cli/main.d.ts +0 -15
  7. package/dist/cli/main.js +356 -3100
  8. package/dist/cli/main.js.map +1 -1
  9. package/dist/index.js +2 -36
  10. package/dist/index.js.map +1 -1
  11. package/dist/server/mcp-server.js +2 -36
  12. package/package.json +8 -31
  13. package/dist/autonomy-config-FSERX3O3.js +0 -30
  14. package/dist/autonomy-config-FSERX3O3.js.map +0 -1
  15. package/dist/chat-store-JNGNTDSN.js +0 -15
  16. package/dist/chat-store-JNGNTDSN.js.map +0 -1
  17. package/dist/chunk-2HF65EHQ.js +0 -311
  18. package/dist/chunk-2HF65EHQ.js.map +0 -1
  19. package/dist/chunk-43X6JBEM.js +0 -36
  20. package/dist/chunk-43X6JBEM.js.map +0 -1
  21. package/dist/chunk-4MXH2ZPT.js +0 -1827
  22. package/dist/chunk-4MXH2ZPT.js.map +0 -1
  23. package/dist/chunk-575YT2SD.js +0 -737
  24. package/dist/chunk-575YT2SD.js.map +0 -1
  25. package/dist/chunk-5BRRRTN6.js +0 -354
  26. package/dist/chunk-5BRRRTN6.js.map +0 -1
  27. package/dist/chunk-6NLHFIYA.js +0 -344
  28. package/dist/chunk-6NLHFIYA.js.map +0 -1
  29. package/dist/chunk-7WITSO22.js +0 -824
  30. package/dist/chunk-7WITSO22.js.map +0 -1
  31. package/dist/chunk-DGUM43GV.js +0 -11
  32. package/dist/chunk-DGUM43GV.js.map +0 -1
  33. package/dist/chunk-EFWVF6TI.js +0 -267
  34. package/dist/chunk-EFWVF6TI.js.map +0 -1
  35. package/dist/chunk-F6WFNUAY.js +0 -216
  36. package/dist/chunk-F6WFNUAY.js.map +0 -1
  37. package/dist/chunk-FQ45QP5A.js +0 -361
  38. package/dist/chunk-FQ45QP5A.js.map +0 -1
  39. package/dist/chunk-G2TGF6TR.js +0 -573
  40. package/dist/chunk-G2TGF6TR.js.map +0 -1
  41. package/dist/chunk-GTKYBOXL.js +0 -700
  42. package/dist/chunk-GTKYBOXL.js.map +0 -1
  43. package/dist/chunk-HVCDY3AK.js +0 -850
  44. package/dist/chunk-HVCDY3AK.js.map +0 -1
  45. package/dist/chunk-JVMBCWKS.js +0 -348
  46. package/dist/chunk-JVMBCWKS.js.map +0 -1
  47. package/dist/chunk-KDHN2ZQE.js +0 -313
  48. package/dist/chunk-KDHN2ZQE.js.map +0 -1
  49. package/dist/chunk-LQIMKE3P.js +0 -12524
  50. package/dist/chunk-LQIMKE3P.js.map +0 -1
  51. package/dist/chunk-ME2OERF5.js +0 -345
  52. package/dist/chunk-ME2OERF5.js.map +0 -1
  53. package/dist/chunk-MRHKX5M5.js +0 -662
  54. package/dist/chunk-MRHKX5M5.js.map +0 -1
  55. package/dist/chunk-OBQ74FOU.js +0 -27
  56. package/dist/chunk-OBQ74FOU.js.map +0 -1
  57. package/dist/chunk-OMR4YCBS.js +0 -987
  58. package/dist/chunk-OMR4YCBS.js.map +0 -1
  59. package/dist/chunk-Q5EKA5YA.js +0 -254
  60. package/dist/chunk-Q5EKA5YA.js.map +0 -1
  61. package/dist/chunk-Q63FFI6D.js +0 -132
  62. package/dist/chunk-Q63FFI6D.js.map +0 -1
  63. package/dist/chunk-SY6KQG44.js +0 -983
  64. package/dist/chunk-SY6KQG44.js.map +0 -1
  65. package/dist/chunk-T63OHG4Q.js +0 -440
  66. package/dist/chunk-T63OHG4Q.js.map +0 -1
  67. package/dist/chunk-TN5WEKWI.js +0 -173
  68. package/dist/chunk-TN5WEKWI.js.map +0 -1
  69. package/dist/chunk-VUL52BQL.js +0 -402
  70. package/dist/chunk-VUL52BQL.js.map +0 -1
  71. package/dist/chunk-VVITXIHN.js +0 -189
  72. package/dist/chunk-VVITXIHN.js.map +0 -1
  73. package/dist/chunk-WCN7S3EI.js +0 -14
  74. package/dist/chunk-WCN7S3EI.js.map +0 -1
  75. package/dist/chunk-XE6KQRKZ.js +0 -816
  76. package/dist/chunk-XE6KQRKZ.js.map +0 -1
  77. package/dist/chunk-XPZZFPBZ.js +0 -491
  78. package/dist/chunk-XPZZFPBZ.js.map +0 -1
  79. package/dist/chunk-XTFWT2XM.js +0 -727
  80. package/dist/chunk-XTFWT2XM.js.map +0 -1
  81. package/dist/chunk-YDHUCDHM.js +0 -4011
  82. package/dist/chunk-YDHUCDHM.js.map +0 -1
  83. package/dist/chunk-YZ6Y2H3P.js +0 -1289
  84. package/dist/chunk-YZ6Y2H3P.js.map +0 -1
  85. package/dist/chunk-ZJF5FTBX.js +0 -1396
  86. package/dist/chunk-ZJF5FTBX.js.map +0 -1
  87. package/dist/chunk-ZV2K6M7T.js +0 -74
  88. package/dist/chunk-ZV2K6M7T.js.map +0 -1
  89. package/dist/cli/create-agent.d.ts +0 -1
  90. package/dist/cli/create-agent.js +0 -1050
  91. package/dist/cli/create-agent.js.map +0 -1
  92. package/dist/cli/yolo-daemon.d.ts +0 -1
  93. package/dist/cli/yolo-daemon.js +0 -423
  94. package/dist/cli/yolo-daemon.js.map +0 -1
  95. package/dist/client-NJPZE5JT.js +0 -28
  96. package/dist/client-NJPZE5JT.js.map +0 -1
  97. package/dist/codebase-index-VAPF32XX.js +0 -12
  98. package/dist/codebase-index-VAPF32XX.js.map +0 -1
  99. package/dist/fast-analyzer-XXYMOXRK.js +0 -216
  100. package/dist/fast-analyzer-XXYMOXRK.js.map +0 -1
  101. package/dist/git-EO5SRFMN.js +0 -28
  102. package/dist/git-EO5SRFMN.js.map +0 -1
  103. package/dist/github-ingester-ZOKK6GRS.js +0 -11
  104. package/dist/github-ingester-ZOKK6GRS.js.map +0 -1
  105. package/dist/goal-manager-YOB7VWK7.js +0 -25
  106. package/dist/goal-manager-YOB7VWK7.js.map +0 -1
  107. package/dist/goal-validator-ULKIBDPX.js +0 -24
  108. package/dist/goal-validator-ULKIBDPX.js.map +0 -1
  109. package/dist/graph-B3NA4S7I.js +0 -10
  110. package/dist/graph-B3NA4S7I.js.map +0 -1
  111. package/dist/hypothesis-7BFFT5JY.js +0 -23
  112. package/dist/hypothesis-7BFFT5JY.js.map +0 -1
  113. package/dist/incident-index-EFNUSGWL.js +0 -11
  114. package/dist/incident-index-EFNUSGWL.js.map +0 -1
  115. package/dist/insight-store-EC4PLSAW.js +0 -22
  116. package/dist/insight-store-EC4PLSAW.js.map +0 -1
  117. package/dist/issue-store-ZIRP23EP.js +0 -36
  118. package/dist/issue-store-ZIRP23EP.js.map +0 -1
  119. package/dist/ledger-TWZTGDFA.js +0 -58
  120. package/dist/ledger-TWZTGDFA.js.map +0 -1
  121. package/dist/linear-ingester-XXPAZZRW.js +0 -11
  122. package/dist/linear-ingester-XXPAZZRW.js.map +0 -1
  123. package/dist/output-manager-RVJ37XKA.js +0 -13
  124. package/dist/output-manager-RVJ37XKA.js.map +0 -1
  125. package/dist/parse-goal-violation-SACGFG3C.js +0 -8
  126. package/dist/parse-goal-violation-SACGFG3C.js.map +0 -1
  127. package/dist/pattern-discovery-F7LU5K6E.js +0 -8
  128. package/dist/pattern-discovery-F7LU5K6E.js.map +0 -1
  129. package/dist/progress-SRQ2V3BP.js +0 -18
  130. package/dist/progress-SRQ2V3BP.js.map +0 -1
  131. package/dist/project-state-AHPA77SM.js +0 -28
  132. package/dist/project-state-AHPA77SM.js.map +0 -1
  133. package/dist/sync-M2FSWPBC.js +0 -12
  134. package/dist/sync-M2FSWPBC.js.map +0 -1
  135. package/dist/terminal-spawn-5YXDMUCF.js +0 -157
  136. package/dist/terminal-spawn-5YXDMUCF.js.map +0 -1
  137. package/dist/tiered-storage-Z3YCR465.js +0 -12
  138. package/dist/tiered-storage-Z3YCR465.js.map +0 -1
  139. package/dist/trie-agent-3YDPEGHJ.js +0 -28
  140. package/dist/trie-agent-3YDPEGHJ.js.map +0 -1
  141. package/dist/ui/chat.html +0 -1014
  142. package/dist/ui/goals.html +0 -967
  143. package/dist/ui/hypotheses.html +0 -1011
  144. package/dist/ui/ledger.html +0 -954
  145. package/dist/ui/nudges.html +0 -995
  146. package/dist/vibe-code-signatures-F6URTBW3.js +0 -16
  147. package/dist/vibe-code-signatures-F6URTBW3.js.map +0 -1
  148. package/dist/vulnerability-signatures-T7SKHORW.js +0 -18
  149. package/dist/vulnerability-signatures-T7SKHORW.js.map +0 -1
@@ -0,0 +1,619 @@
1
+ import {
2
+ cloudClient,
3
+ fetchDocuments,
4
+ fetchGraph,
5
+ fetchLedger,
6
+ fetchSignals,
7
+ sessionCache
8
+ } from "./chunk-QR64Y5TI.js";
9
+
10
+ // src/server/mcp-server.ts
11
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
12
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
13
+ import {
14
+ CallToolRequestSchema,
15
+ ListToolsRequestSchema,
16
+ ListResourcesRequestSchema,
17
+ ReadResourceRequestSchema
18
+ } from "@modelcontextprotocol/sdk/types.js";
19
+
20
+ // src/utils/ai-tool-detector.ts
21
+ function detectAITool() {
22
+ if (process.env.CLAUDE_CODE_VERSION || process.env.CLAUDE_CODE) {
23
+ return {
24
+ name: "Claude Code",
25
+ preferredOutputFormat: "markdown",
26
+ supportsDiffs: true,
27
+ supportsInlineActions: true
28
+ };
29
+ }
30
+ if (process.env.CURSOR_IDE || process.env.CURSOR_TRACE_ID) {
31
+ return {
32
+ name: "Cursor",
33
+ preferredOutputFormat: "rich-text",
34
+ supportsDiffs: true,
35
+ supportsInlineActions: false
36
+ };
37
+ }
38
+ if (process.env.OPENCODE_INSTANCE) {
39
+ return {
40
+ name: "OpenCode",
41
+ preferredOutputFormat: "plain-text",
42
+ supportsDiffs: false,
43
+ supportsInlineActions: false
44
+ };
45
+ }
46
+ if (process.env.VSCODE_PID || process.env.VSCODE_IPC_HOOK) {
47
+ return {
48
+ name: "VS Code",
49
+ preferredOutputFormat: "markdown",
50
+ supportsDiffs: true,
51
+ supportsInlineActions: false
52
+ };
53
+ }
54
+ const parentProcess = process.env.PARENT_PROCESS_NAME || process.env._ || "";
55
+ if (parentProcess.toLowerCase().includes("claude")) {
56
+ return {
57
+ name: "Claude Code",
58
+ preferredOutputFormat: "markdown",
59
+ supportsDiffs: true,
60
+ supportsInlineActions: true
61
+ };
62
+ }
63
+ if (parentProcess.toLowerCase().includes("cursor")) {
64
+ return {
65
+ name: "Cursor",
66
+ preferredOutputFormat: "rich-text",
67
+ supportsDiffs: true,
68
+ supportsInlineActions: false
69
+ };
70
+ }
71
+ if (process.env.npm_execpath || process.argv[1]?.includes("npx")) {
72
+ return {
73
+ name: "MCP Client",
74
+ preferredOutputFormat: "markdown",
75
+ supportsDiffs: true,
76
+ supportsInlineActions: false
77
+ };
78
+ }
79
+ return {
80
+ name: "MCP Client",
81
+ preferredOutputFormat: "markdown",
82
+ supportsDiffs: true,
83
+ supportsInlineActions: false
84
+ };
85
+ }
86
+
87
+ // src/config/defaults.ts
88
+ var DEFAULT_API_BASE_URL = process.env.TRIE_API_BASE_URL || "https://trie-api.vercel.app";
89
+ var DEFAULT_CACHE_TTL_MS = {
90
+ context: 6e4,
91
+ graph: 5 * 6e4,
92
+ ledger: 5 * 6e4,
93
+ signals: 2 * 6e4,
94
+ documents: 5 * 6e4
95
+ };
96
+
97
+ // src/tools/common.ts
98
+ function asText(data) {
99
+ return {
100
+ content: [
101
+ {
102
+ type: "text",
103
+ text: typeof data === "string" ? data : JSON.stringify(data, null, 2)
104
+ }
105
+ ],
106
+ data
107
+ };
108
+ }
109
+
110
+ // src/tools/context.ts
111
+ var TrieContextTool = class {
112
+ async execute() {
113
+ const data = await sessionCache.get("context", DEFAULT_CACHE_TTL_MS.context, async () => {
114
+ const [graph, signals, documents] = await Promise.all([
115
+ fetchGraph({ view: "weekly", types: ["signal", "insight", "decision", "shipped"] }),
116
+ fetchSignals(20),
117
+ fetchDocuments()
118
+ ]);
119
+ const hotZones = graph.nodes.filter((n) => typeof n.path === "string").slice(0, 5).map((n) => ({
120
+ path: n.path || "",
121
+ risk: n.severity || "medium",
122
+ reason: "Related incidents and signals in cloud graph"
123
+ }));
124
+ return {
125
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
126
+ graphSummary: {
127
+ nodes: graph.nodes.length,
128
+ edges: graph.edges.length
129
+ },
130
+ hot_zones: hotZones,
131
+ recentSignals: signals.slice(0, 10),
132
+ recentDocuments: documents.slice(0, 10)
133
+ };
134
+ });
135
+ return asText(data);
136
+ }
137
+ };
138
+
139
+ // src/tools/check-file.ts
140
+ function severityScore(sev) {
141
+ if (sev === "high") return 3;
142
+ if (sev === "medium") return 2;
143
+ return 1;
144
+ }
145
+ function getRiskLevel(warnings) {
146
+ const max = Math.max(0, ...warnings.map((w) => severityScore(w.severity)));
147
+ if (max >= 3) return "high";
148
+ if (max >= 2) return "medium";
149
+ return "low";
150
+ }
151
+ var TrieCheckFileTool = class {
152
+ async execute(input = {}) {
153
+ const file = input.file?.trim();
154
+ if (!file) throw new Error("`file` is required.");
155
+ const [ledger, graph, signals] = await Promise.all([
156
+ fetchLedger(input.project),
157
+ fetchGraph({ types: ["insight", "decision", "signal", "shipped"] }),
158
+ fetchSignals(50)
159
+ ]);
160
+ const warnings = [];
161
+ const ledgerBlob = JSON.stringify(ledger).toLowerCase();
162
+ if (ledgerBlob.includes(file.toLowerCase())) {
163
+ warnings.push({
164
+ type: "incident_history",
165
+ severity: "high",
166
+ message: "This file appears in prior incidents/ledger events."
167
+ });
168
+ }
169
+ const relatedNodes = graph.nodes.filter((n) => (n.path || "").includes(file));
170
+ if (relatedNodes.length > 0) {
171
+ warnings.push({
172
+ type: "architectural_decision",
173
+ severity: "medium",
174
+ message: `${relatedNodes.length} graph node(s) relate to this file.`,
175
+ details: relatedNodes.slice(0, 3).map((n) => n.label || n.id)
176
+ });
177
+ }
178
+ const relatedSignals = signals.filter(
179
+ (s) => JSON.stringify(s).toLowerCase().includes(file.toLowerCase())
180
+ );
181
+ if (relatedSignals.length > 0) {
182
+ warnings.push({
183
+ type: "active_alerts",
184
+ severity: "high",
185
+ message: `${relatedSignals.length} signal(s) mention this file.`
186
+ });
187
+ }
188
+ if (warnings.length === 0) {
189
+ warnings.push({
190
+ type: "no_known_risks",
191
+ severity: "info",
192
+ message: "No known cloud risks found for this file."
193
+ });
194
+ }
195
+ const result = {
196
+ file,
197
+ risk_level: getRiskLevel(warnings),
198
+ warnings,
199
+ recommendation: warnings.some((w) => w.severity === "high") ? "High-risk area detected. Proceed carefully and verify with tests." : "No high-risk alerts; proceed with normal caution."
200
+ };
201
+ return asText(result);
202
+ }
203
+ };
204
+
205
+ // src/tools/graph.ts
206
+ var TrieGraphTool = class {
207
+ async execute(input = {}) {
208
+ const key = `graph:${JSON.stringify(input)}`;
209
+ const data = await sessionCache.get(key, DEFAULT_CACHE_TTL_MS.graph, () => fetchGraph(input));
210
+ return asText(data);
211
+ }
212
+ };
213
+
214
+ // src/tools/signals.ts
215
+ import { z } from "zod";
216
+ var SignalsInputSchema = z.object({
217
+ limit: z.number().int().min(1).max(100).optional()
218
+ }).strict();
219
+ var TrieSignalsTool = class {
220
+ async execute(input = {}) {
221
+ const parsedInput = SignalsInputSchema.parse(input);
222
+ const limit = parsedInput.limit || 20;
223
+ const key = `signals:${limit}`;
224
+ const data = await sessionCache.get(key, DEFAULT_CACHE_TTL_MS.signals, () => fetchSignals(limit));
225
+ return asText(data);
226
+ }
227
+ };
228
+
229
+ // src/tools/documents.ts
230
+ var TrieDocumentsTool = class {
231
+ async execute() {
232
+ const data = await sessionCache.get("documents", DEFAULT_CACHE_TTL_MS.documents, fetchDocuments);
233
+ return asText(data);
234
+ }
235
+ };
236
+
237
+ // src/tools/ledger.ts
238
+ var TrieLedgerTool = class {
239
+ async execute(input = {}) {
240
+ const key = `ledger:${input.project || "default"}`;
241
+ const data = await sessionCache.get(key, DEFAULT_CACHE_TTL_MS.ledger, () => fetchLedger(input.project));
242
+ return asText(data);
243
+ }
244
+ };
245
+
246
+ // src/cloud/chat.ts
247
+ async function searchContext(query) {
248
+ return cloudClient.request("/api/cloud/chat", {
249
+ method: "POST",
250
+ body: JSON.stringify({
251
+ messages: [{ role: "user", content: query }]
252
+ })
253
+ });
254
+ }
255
+
256
+ // src/tools/search.ts
257
+ import { z as z2 } from "zod";
258
+ var SearchInputSchema = z2.object({
259
+ query: z2.string().trim().min(1).max(2e3)
260
+ }).strict();
261
+ var TrieSearchTool = class {
262
+ async execute(input = {}) {
263
+ const parsedInput = SearchInputSchema.parse(input);
264
+ const data = await searchContext(parsedInput.query);
265
+ return asText(data);
266
+ }
267
+ };
268
+
269
+ // src/server/tool-registry.ts
270
+ var ToolRegistry = class {
271
+ tools = /* @__PURE__ */ new Map();
272
+ definitions = [];
273
+ constructor() {
274
+ this.initializeTools();
275
+ this.defineToolSchemas();
276
+ }
277
+ initializeTools() {
278
+ this.tools.set("context", new TrieContextTool());
279
+ this.tools.set("check_file", new TrieCheckFileTool());
280
+ this.tools.set("graph", new TrieGraphTool());
281
+ this.tools.set("signals", new TrieSignalsTool());
282
+ this.tools.set("documents", new TrieDocumentsTool());
283
+ this.tools.set("ledger", new TrieLedgerTool());
284
+ this.tools.set("search", new TrieSearchTool());
285
+ }
286
+ defineToolSchemas() {
287
+ this.definitions = [
288
+ {
289
+ name: "trie_context",
290
+ description: "Get consolidated Trie cloud context (hot zones, graph summary, recent signals/documents).",
291
+ inputSchema: {
292
+ type: "object",
293
+ properties: {}
294
+ }
295
+ },
296
+ {
297
+ name: "trie_check_file",
298
+ description: "Proactively assess risk for a file: incidents, alerts, brittleness, and decisions.",
299
+ inputSchema: {
300
+ type: "object",
301
+ properties: {
302
+ file: {
303
+ type: "string"
304
+ },
305
+ project: {
306
+ type: "string"
307
+ }
308
+ },
309
+ required: ["file"]
310
+ }
311
+ },
312
+ {
313
+ name: "trie_graph",
314
+ description: "Read ANT graph from Trie cloud.",
315
+ inputSchema: {
316
+ type: "object",
317
+ properties: {
318
+ view: { type: "string" },
319
+ types: { type: "array", items: { type: "string" } },
320
+ since: { type: "string" },
321
+ until: { type: "string" }
322
+ }
323
+ }
324
+ },
325
+ {
326
+ name: "trie_signals",
327
+ description: "Read cloud signals feed.",
328
+ inputSchema: {
329
+ type: "object",
330
+ properties: {
331
+ limit: { type: "number" }
332
+ }
333
+ }
334
+ },
335
+ {
336
+ name: "trie_documents",
337
+ description: "Read cloud documents.",
338
+ inputSchema: {
339
+ type: "object",
340
+ properties: {}
341
+ }
342
+ },
343
+ {
344
+ name: "trie_ledger",
345
+ description: "Read cloud ledger entries.",
346
+ inputSchema: {
347
+ type: "object",
348
+ properties: {
349
+ project: { type: "string" }
350
+ }
351
+ }
352
+ },
353
+ {
354
+ name: "trie_search",
355
+ description: "Search cloud context via natural language.",
356
+ inputSchema: {
357
+ type: "object",
358
+ properties: {
359
+ query: { type: "string" }
360
+ },
361
+ required: ["query"]
362
+ }
363
+ }
364
+ ];
365
+ }
366
+ getTool(name) {
367
+ return this.tools.get(name);
368
+ }
369
+ getAllTools() {
370
+ return this.definitions;
371
+ }
372
+ getToolNames() {
373
+ return Array.from(this.tools.keys());
374
+ }
375
+ hasTool(name) {
376
+ return this.tools.has(name);
377
+ }
378
+ };
379
+
380
+ // src/server/resource-manager.ts
381
+ var ResourceManager = class {
382
+ /**
383
+ * Get all available resources dynamically
384
+ */
385
+ async getAvailableResources() {
386
+ const resources = [];
387
+ resources.push(
388
+ {
389
+ uri: "trie://context",
390
+ name: "Trie Cloud Context",
391
+ description: "Consolidated cloud context with hot zones and active signals.",
392
+ mimeType: "application/json"
393
+ },
394
+ {
395
+ uri: "trie://graph",
396
+ name: "Trie ANT Graph",
397
+ description: "Raw ANT graph from cloud.",
398
+ mimeType: "application/json"
399
+ }
400
+ );
401
+ return resources;
402
+ }
403
+ /**
404
+ * Read content for a specific resource
405
+ */
406
+ async readResourceContent(uri) {
407
+ if (uri === "trie://context") {
408
+ return await this.getContextResource(uri);
409
+ }
410
+ if (uri === "trie://graph") {
411
+ return await this.getGraphResource(uri);
412
+ }
413
+ throw new Error(`Unknown resource: ${uri}`);
414
+ }
415
+ async getContextResource(uri) {
416
+ const data = await sessionCache.get("context-resource", DEFAULT_CACHE_TTL_MS.context, async () => {
417
+ const [graph, signals, documents] = await Promise.all([
418
+ fetchGraph({ view: "weekly", types: ["signal", "insight", "decision", "shipped"] }),
419
+ fetchSignals(20),
420
+ fetchDocuments()
421
+ ]);
422
+ const hotZones = graph.nodes.filter((n) => typeof n.path === "string").slice(0, 10).map((n) => ({
423
+ path: n.path,
424
+ risk: n.severity || "medium",
425
+ reason: "Graph-linked incidents/signals"
426
+ }));
427
+ return {
428
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
429
+ graph: { nodes: graph.nodes.length, edges: graph.edges.length },
430
+ hot_zones: hotZones,
431
+ signals: signals.slice(0, 10),
432
+ documents: documents.slice(0, 10)
433
+ };
434
+ });
435
+ return {
436
+ contents: [{
437
+ uri,
438
+ mimeType: "application/json",
439
+ text: JSON.stringify(data, null, 2)
440
+ }]
441
+ };
442
+ }
443
+ async getGraphResource(uri) {
444
+ const graph = await sessionCache.get(
445
+ "graph-resource",
446
+ DEFAULT_CACHE_TTL_MS.graph,
447
+ () => fetchGraph({ view: "weekly" })
448
+ );
449
+ return {
450
+ contents: [{
451
+ uri,
452
+ mimeType: "application/json",
453
+ text: JSON.stringify(graph, null, 2)
454
+ }]
455
+ };
456
+ }
457
+ };
458
+
459
+ // src/server/request-handlers.ts
460
+ var RequestHandlers = class {
461
+ constructor(toolRegistry, resourceManager) {
462
+ this.toolRegistry = toolRegistry;
463
+ this.resourceManager = resourceManager;
464
+ }
465
+ /**
466
+ * Handle tool execution requests
467
+ */
468
+ async handleToolCall(name, args) {
469
+ const normalizedName = this.normalizeName(name);
470
+ try {
471
+ const tool = this.toolRegistry.getTool(normalizedName);
472
+ if (!tool) {
473
+ throw new Error(`Unknown tool: ${name}`);
474
+ }
475
+ return await tool.execute(this.sanitizeArgs(args));
476
+ } catch (error) {
477
+ return {
478
+ content: [{
479
+ type: "text",
480
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`
481
+ }]
482
+ };
483
+ }
484
+ }
485
+ /**
486
+ * Handle resource listing requests
487
+ */
488
+ async handleListResources() {
489
+ const resources = await this.resourceManager.getAvailableResources();
490
+ return { resources };
491
+ }
492
+ /**
493
+ * Handle resource reading requests
494
+ */
495
+ async handleReadResource(uri) {
496
+ return await this.resourceManager.readResourceContent(uri);
497
+ }
498
+ normalizeName(name) {
499
+ const stripNamespace = (n) => {
500
+ const trimmed = n.trim().replace(/\s*\([^)]*\)\s*$/, "").trim();
501
+ const withoutSlash = trimmed.startsWith("/") ? trimmed.slice(1) : trimmed;
502
+ const parts = withoutSlash.split(":");
503
+ const base = (parts[0] || withoutSlash).trim();
504
+ const slashParts = base.split("/");
505
+ return (slashParts[slashParts.length - 1] || base).trim();
506
+ };
507
+ const rawName = stripNamespace(name);
508
+ return rawName.startsWith("trie_") ? rawName.slice("trie_".length) : rawName;
509
+ }
510
+ sanitizeArgs(args) {
511
+ if (args == null) return {};
512
+ if (typeof args !== "object" || Array.isArray(args)) {
513
+ throw new Error("Tool args must be a JSON object.");
514
+ }
515
+ const serialized = JSON.stringify(args);
516
+ if (serialized.length > 32 * 1024) {
517
+ throw new Error("Tool args exceed 32KB limit.");
518
+ }
519
+ return args;
520
+ }
521
+ };
522
+
523
+ // src/server/mcp-server.ts
524
+ var MCPServer = class {
525
+ server;
526
+ toolRegistry;
527
+ resourceManager;
528
+ requestHandlers;
529
+ constructor() {
530
+ this.server = new Server(
531
+ {
532
+ name: "trie",
533
+ version: "1.0.0",
534
+ description: "Trie Cloud context bridge for Cursor and Claude Code. Read trie://context first and call trie_check_file before editing high-risk files."
535
+ },
536
+ {
537
+ capabilities: {
538
+ tools: {},
539
+ resources: {}
540
+ }
541
+ }
542
+ );
543
+ this.toolRegistry = new ToolRegistry();
544
+ this.resourceManager = new ResourceManager();
545
+ this.requestHandlers = new RequestHandlers(this.toolRegistry, this.resourceManager);
546
+ this.setupRequestHandlers();
547
+ }
548
+ setupRequestHandlers() {
549
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => {
550
+ return {
551
+ tools: this.toolRegistry.getAllTools()
552
+ };
553
+ });
554
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
555
+ const { name, arguments: args } = request.params;
556
+ return await this.requestHandlers.handleToolCall(name, args);
557
+ });
558
+ this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
559
+ return await this.requestHandlers.handleListResources();
560
+ });
561
+ this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
562
+ const { uri } = request.params;
563
+ return await this.requestHandlers.handleReadResource(uri);
564
+ });
565
+ }
566
+ /**
567
+ * Show startup banner
568
+ */
569
+ showStartupBanner(toolCount, aiTool) {
570
+ console.error(`
571
+ \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
572
+ \u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D
573
+ \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2557
574
+ \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u255D
575
+ \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557
576
+ \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D
577
+ Your central registry for Trie tools
578
+
579
+ by Louis Kishfy
580
+
581
+ Download the Trie workspace: https://www.trie.dev
582
+ Follow me on X: https://x.com/louiskishfy
583
+
584
+ ${toolCount} tools ready | ${aiTool}
585
+
586
+ Quick Start:
587
+ \u2022 "Scan this code" - Run Trie analysis
588
+ \u2022 "Use trie" - Open the Trie menu
589
+ \u2022 "Use trie_fix" - Apply high-confidence fixes
590
+
591
+ Ready.
592
+ `);
593
+ }
594
+ /**
595
+ * Initialize and start the server
596
+ */
597
+ async start() {
598
+ try {
599
+ const aiTool = detectAITool();
600
+ const toolCount = this.toolRegistry.getAllTools().length;
601
+ this.showStartupBanner(toolCount, aiTool.name);
602
+ const transport = new StdioServerTransport();
603
+ await this.server.connect(transport);
604
+ } catch (error) {
605
+ console.error("Fatal error starting MCP server:", error);
606
+ process.exit(1);
607
+ }
608
+ }
609
+ };
610
+ async function startServer() {
611
+ const server = new MCPServer();
612
+ await server.start();
613
+ }
614
+
615
+ export {
616
+ MCPServer,
617
+ startServer
618
+ };
619
+ //# sourceMappingURL=chunk-2YXOBNKW.js.map