@miniaxolotl/grove 0.2.4 → 0.2.5

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 (40) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +8 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/index.js +253 -289
  7. package/dist/index.js.map +1 -1
  8. package/dist/repositories/entity.repository.d.ts.map +1 -1
  9. package/dist/repositories/entity.repository.js +24 -41
  10. package/dist/repositories/entity.repository.js.map +1 -1
  11. package/dist/repositories/memory.repository.d.ts +16 -21
  12. package/dist/repositories/memory.repository.d.ts.map +1 -1
  13. package/dist/repositories/memory.repository.js +71 -132
  14. package/dist/repositories/memory.repository.js.map +1 -1
  15. package/dist/repositories/relation.repository.d.ts.map +1 -1
  16. package/dist/repositories/relation.repository.js +25 -43
  17. package/dist/repositories/relation.repository.js.map +1 -1
  18. package/dist/services/embedding.d.ts +1 -0
  19. package/dist/services/embedding.d.ts.map +1 -1
  20. package/dist/services/embedding.js +8 -1
  21. package/dist/services/embedding.js.map +1 -1
  22. package/dist/services/qdrant.d.ts +5 -2
  23. package/dist/services/qdrant.d.ts.map +1 -1
  24. package/dist/services/qdrant.js +27 -10
  25. package/dist/services/qdrant.js.map +1 -1
  26. package/dist/utils/filter.d.ts +10 -0
  27. package/dist/utils/filter.d.ts.map +1 -0
  28. package/dist/utils/filter.js +15 -0
  29. package/dist/utils/filter.js.map +1 -0
  30. package/eslint.config.js +1 -1
  31. package/package.json +12 -12
  32. package/src/config.ts +5 -0
  33. package/src/index.ts +263 -336
  34. package/src/repositories/entity.repository.ts +30 -42
  35. package/src/repositories/memory.repository.ts +105 -166
  36. package/src/repositories/relation.repository.ts +33 -41
  37. package/src/services/embedding.ts +9 -1
  38. package/src/services/qdrant.ts +30 -13
  39. package/src/utils/filter.ts +20 -0
  40. package/tsconfig.json +1 -1
package/dist/index.js CHANGED
@@ -6,11 +6,19 @@ import { entityRepository } from "./repositories/entity.repository.js";
6
6
  import { relationRepository } from "./repositories/relation.repository.js";
7
7
  import { config, hasRemoteReranking } from "./config.js";
8
8
  import { rerankDocuments } from "./services/reranking.js";
9
+ import { warmup } from "./services/embedding.js";
9
10
  let collectionsReady = false;
10
11
  const server = new FastMCP({
11
12
  name: "grove",
12
13
  version: "0.1.0",
13
14
  });
15
+ function text(content) {
16
+ return { content: [{ type: "text", text: content }] };
17
+ }
18
+ function toolErr(err) {
19
+ const message = err instanceof Error ? err.message : String(err);
20
+ return text(`Error: ${message}`);
21
+ }
14
22
  // ── Memory Tools ──────────────────────────────────────────────────────────────
15
23
  server.addTool({
16
24
  name: "memory_save",
@@ -26,11 +34,16 @@ server.addTool({
26
34
  .optional(),
27
35
  }),
28
36
  execute: async (args) => {
29
- const result = await memoryRepository.save(args.information, {
30
- ...args.metadata,
31
- createdAt: new Date().toISOString(),
32
- });
33
- return `Saved memory: ${result.id}`;
37
+ try {
38
+ const result = await memoryRepository.save(args.information, {
39
+ ...args.metadata,
40
+ createdAt: new Date().toISOString(),
41
+ });
42
+ return text(`Saved memory: ${result.id}`);
43
+ }
44
+ catch (err) {
45
+ return toolErr(err);
46
+ }
34
47
  },
35
48
  });
36
49
  server.addTool({
@@ -41,37 +54,31 @@ server.addTool({
41
54
  project: z.string().optional(),
42
55
  tags: z.array(z.string()).optional(),
43
56
  limit: z.number().optional().default(5),
44
- rerank: z.boolean().optional().default(true),
57
+ rerank: z.boolean().optional().default(hasRemoteReranking),
45
58
  rerankTopK: z.number().optional().default(20),
46
59
  }),
47
60
  execute: async (args) => {
48
- const limit = args.limit ?? 5;
49
- const rerankTopK = args.rerankTopK ?? 20;
50
- const results = await memoryRepository.search(args.query, {
51
- project: args.project,
52
- tags: args.tags,
53
- limit: args.rerank && hasRemoteReranking ? rerankTopK : limit,
54
- });
55
- if (args.rerank && hasRemoteReranking && results.length > limit) {
56
- const docs = results.map((r) => r.text);
57
- const reranked = await rerankDocuments(args.query, docs, limit);
58
- const rerankedResults = reranked
59
- .map((r) => ({ ...results[r.index], score: r.relevanceScore }))
60
- .filter((r) => r.text !== undefined);
61
- return {
62
- content: [
63
- {
64
- type: "text",
65
- text: JSON.stringify(rerankedResults, null, 2),
66
- },
67
- ],
68
- };
69
- }
70
- return {
71
- content: [
72
- { type: "text", text: JSON.stringify(results, null, 2) },
73
- ],
74
- };
61
+ try {
62
+ const limit = args.limit ?? 5;
63
+ const rerankTopK = args.rerankTopK ?? 20;
64
+ const results = await memoryRepository.search(args.query, {
65
+ project: args.project,
66
+ tags: args.tags,
67
+ limit: args.rerank && hasRemoteReranking ? rerankTopK : limit,
68
+ });
69
+ if (args.rerank && hasRemoteReranking && results.length > limit) {
70
+ const docs = results.map((r) => r.text);
71
+ const reranked = await rerankDocuments(args.query, docs, limit);
72
+ const rerankedResults = reranked
73
+ .map((r) => ({ ...results[r.index], score: r.relevanceScore }))
74
+ .filter((r) => r.text !== undefined);
75
+ return text(JSON.stringify(rerankedResults, null, 2));
76
+ }
77
+ return text(JSON.stringify(results, null, 2));
78
+ }
79
+ catch (err) {
80
+ return toolErr(err);
81
+ }
75
82
  },
76
83
  });
77
84
  server.addTool({
@@ -83,18 +90,65 @@ server.addTool({
83
90
  tags: z.array(z.string()).optional(),
84
91
  }),
85
92
  execute: async (args) => {
86
- if (args.ids && args.ids.length > 0) {
87
- await memoryRepository.delete(args.ids);
88
- return `Deleted ${args.ids.length} memories`;
93
+ try {
94
+ if (args.ids && args.ids.length > 0) {
95
+ await memoryRepository.delete(args.ids);
96
+ return text(`Deleted ${args.ids.length} memories`);
97
+ }
98
+ if (args.project || args.tags) {
99
+ await memoryRepository.deleteByFilter({
100
+ project: args.project,
101
+ tags: args.tags,
102
+ });
103
+ return text("Deleted memories by filter");
104
+ }
105
+ return text("No IDs or filter provided");
106
+ }
107
+ catch (err) {
108
+ return toolErr(err);
89
109
  }
90
- if (args.project || args.tags) {
91
- await memoryRepository.deleteByFilter({
110
+ },
111
+ });
112
+ server.addTool({
113
+ name: "memory_compact",
114
+ description: "Compact memories by session or project, removing low-importance ones (importance < 0.6)",
115
+ parameters: z.object({
116
+ project: z.string().optional(),
117
+ sessionId: z.string().optional(),
118
+ importanceThreshold: z.number().optional().default(0.6),
119
+ }),
120
+ execute: async (args) => {
121
+ try {
122
+ const result = await memoryRepository.compact({
123
+ project: args.project,
124
+ sessionId: args.sessionId,
125
+ importanceThreshold: args.importanceThreshold,
126
+ });
127
+ return text(`Compacted ${result.compacted} memories`);
128
+ }
129
+ catch (err) {
130
+ return toolErr(err);
131
+ }
132
+ },
133
+ });
134
+ server.addTool({
135
+ name: "memory_prune",
136
+ description: "Delete memories below an importance threshold",
137
+ parameters: z.object({
138
+ threshold: z.number(),
139
+ project: z.string().optional(),
140
+ }),
141
+ execute: async (args) => {
142
+ try {
143
+ const result = await memoryRepository.prune({
144
+ threshold: args.threshold,
92
145
  project: args.project,
93
- tags: args.tags,
94
146
  });
95
- return "Deleted memories by filter";
147
+ return text(`Pruned ${result.pruned} memories`);
148
+ }
149
+ catch (err) {
150
+ return toolErr(err);
96
151
  }
97
- return "No IDs or filter provided";
98
152
  },
99
153
  });
100
154
  // ── Entity Tools ──────────────────────────────────────────────────────────────
@@ -108,8 +162,13 @@ server.addTool({
108
162
  metadata: z.record(z.unknown()).optional(),
109
163
  }),
110
164
  execute: async (args) => {
111
- const result = await entityRepository.create(args.name, args.entityType, args.observations ?? [], args.metadata);
112
- return `Created entity: ${result.name} (${result.id})`;
165
+ try {
166
+ const result = await entityRepository.create(args.name, args.entityType, args.observations ?? [], args.metadata);
167
+ return text(`Created entity: ${result.name} (${result.id})`);
168
+ }
169
+ catch (err) {
170
+ return toolErr(err);
171
+ }
113
172
  },
114
173
  });
115
174
  server.addTool({
@@ -121,12 +180,13 @@ server.addTool({
121
180
  limit: z.number().optional().default(10),
122
181
  }),
123
182
  execute: async (args) => {
124
- const results = await entityRepository.search(args.query, args.entityType, args.limit);
125
- return {
126
- content: [
127
- { type: "text", text: JSON.stringify(results, null, 2) },
128
- ],
129
- };
183
+ try {
184
+ const results = await entityRepository.search(args.query, args.entityType, args.limit);
185
+ return text(JSON.stringify(results, null, 2));
186
+ }
187
+ catch (err) {
188
+ return toolErr(err);
189
+ }
130
190
  },
131
191
  });
132
192
  server.addTool({
@@ -137,10 +197,15 @@ server.addTool({
137
197
  observations: z.array(z.string()),
138
198
  }),
139
199
  execute: async (args) => {
140
- const result = await entityRepository.addObservations(args.name, args.observations);
141
- if (!result)
142
- return `Entity not found: ${args.name}`;
143
- return `Added observations to: ${result.name}`;
200
+ try {
201
+ const result = await entityRepository.addObservations(args.name, args.observations);
202
+ if (!result)
203
+ return text(`Entity not found: ${args.name}`);
204
+ return text(`Added observations to: ${result.name}`);
205
+ }
206
+ catch (err) {
207
+ return toolErr(err);
208
+ }
144
209
  },
145
210
  });
146
211
  server.addTool({
@@ -150,14 +215,15 @@ server.addTool({
150
215
  name: z.string(),
151
216
  }),
152
217
  execute: async (args) => {
153
- const result = await entityRepository.get(args.name);
154
- if (!result)
155
- return `Entity not found: ${args.name}`;
156
- return {
157
- content: [
158
- { type: "text", text: JSON.stringify(result, null, 2) },
159
- ],
160
- };
218
+ try {
219
+ const result = await entityRepository.get(args.name);
220
+ if (!result)
221
+ return text(`Entity not found: ${args.name}`);
222
+ return text(JSON.stringify(result, null, 2));
223
+ }
224
+ catch (err) {
225
+ return toolErr(err);
226
+ }
161
227
  },
162
228
  });
163
229
  // ── Relation Tools ────────────────────────────────────────────────────────────
@@ -171,8 +237,13 @@ server.addTool({
171
237
  metadata: z.record(z.unknown()).optional(),
172
238
  }),
173
239
  execute: async (args) => {
174
- const result = await relationRepository.create(args.from, args.relationType, args.to, args.metadata);
175
- return `Created relation: ${args.from} --[${args.relationType}]--> ${args.to} (${result.id})`;
240
+ try {
241
+ const result = await relationRepository.create(args.from, args.relationType, args.to, args.metadata);
242
+ return text(`Created relation: ${args.from} --[${args.relationType}]--> ${args.to} (${result.id})`);
243
+ }
244
+ catch (err) {
245
+ return toolErr(err);
246
+ }
176
247
  },
177
248
  });
178
249
  server.addTool({
@@ -185,12 +256,13 @@ server.addTool({
185
256
  limit: z.number().optional().default(20),
186
257
  }),
187
258
  execute: async (args) => {
188
- const results = await relationRepository.search(args, args.limit);
189
- return {
190
- content: [
191
- { type: "text", text: JSON.stringify(results, null, 2) },
192
- ],
193
- };
259
+ try {
260
+ const results = await relationRepository.search(args, args.limit);
261
+ return text(JSON.stringify(results, null, 2));
262
+ }
263
+ catch (err) {
264
+ return toolErr(err);
265
+ }
194
266
  },
195
267
  });
196
268
  server.addTool({
@@ -202,63 +274,16 @@ server.addTool({
202
274
  relationType: z.string().optional(),
203
275
  }),
204
276
  execute: async (args) => {
205
- await relationRepository.delete(args);
206
- return "Relations deleted";
207
- },
208
- });
209
- // ── Batch Memory Tools ─────────────────────────────────────────────────────────
210
- server.addTool({
211
- name: "memory_save_batch",
212
- description: "Save multiple memories in a single call for efficiency",
213
- parameters: z.object({
214
- items: z.array(z.object({
215
- information: z.string(),
216
- metadata: z
217
- .object({
218
- source: z.string().optional(),
219
- project: z.string().optional(),
220
- tags: z.array(z.string()).optional(),
221
- })
222
- .optional(),
223
- })),
224
- }),
225
- execute: async (args) => {
226
- const items = args.items.map((item) => ({
227
- text: item.information,
228
- metadata: item.metadata,
229
- }));
230
- const results = await memoryRepository.saveBatch(items);
231
- return {
232
- content: [
233
- {
234
- type: "text",
235
- text: JSON.stringify({ saved: results.length, ids: results.map((r) => r.id) }, null, 2),
236
- },
237
- ],
238
- };
239
- },
240
- });
241
- server.addTool({
242
- name: "memory_search_batch",
243
- description: "Search multiple queries at once for efficiency",
244
- parameters: z.object({
245
- queries: z.array(z.object({
246
- query: z.string(),
247
- project: z.string().optional(),
248
- tags: z.array(z.string()).optional(),
249
- limit: z.number().optional().default(5),
250
- })),
251
- }),
252
- execute: async (args) => {
253
- const results = await memoryRepository.searchBatch(args.queries);
254
- return {
255
- content: [
256
- { type: "text", text: JSON.stringify(results, null, 2) },
257
- ],
258
- };
277
+ try {
278
+ await relationRepository.delete(args);
279
+ return text("Relations deleted");
280
+ }
281
+ catch (err) {
282
+ return toolErr(err);
283
+ }
259
284
  },
260
285
  });
261
- // ── Memory Update / Get ────────────────────────────────────────────────────────
286
+ // ── Memory Update ─────────────────────────────────────────────────────────────
262
287
  server.addTool({
263
288
  name: "memory_update",
264
289
  description: "Update text or metadata of an existing memory by ID",
@@ -274,34 +299,18 @@ server.addTool({
274
299
  .optional(),
275
300
  }),
276
301
  execute: async (args) => {
277
- const result = await memoryRepository.update(args.id, {
278
- text: args.text,
279
- metadata: args.metadata,
280
- });
281
- if (!result)
282
- return `Memory not found: ${args.id}`;
283
- return {
284
- content: [
285
- { type: "text", text: JSON.stringify(result, null, 2) },
286
- ],
287
- };
288
- },
289
- });
290
- server.addTool({
291
- name: "memory_get",
292
- description: "Get a single memory by its ID",
293
- parameters: z.object({
294
- id: z.string(),
295
- }),
296
- execute: async (args) => {
297
- const result = await memoryRepository.getById(args.id);
298
- if (!result)
299
- return `Memory not found: ${args.id}`;
300
- return {
301
- content: [
302
- { type: "text", text: JSON.stringify(result, null, 2) },
303
- ],
304
- };
302
+ try {
303
+ const result = await memoryRepository.update(args.id, {
304
+ text: args.text,
305
+ metadata: args.metadata,
306
+ });
307
+ if (!result)
308
+ return text(`Memory not found: ${args.id}`);
309
+ return text(JSON.stringify(result, null, 2));
310
+ }
311
+ catch (err) {
312
+ return toolErr(err);
313
+ }
305
314
  },
306
315
  });
307
316
  // ── Memory Scroll / Stats ─────────────────────────────────────────────────────
@@ -315,20 +324,18 @@ server.addTool({
315
324
  offset: z.string().optional(),
316
325
  }),
317
326
  execute: async (args) => {
318
- const { memories, offset } = await memoryRepository.scroll({
319
- project: args.project,
320
- tags: args.tags,
321
- limit: args.limit,
322
- offset: args.offset,
323
- });
324
- return {
325
- content: [
326
- {
327
- type: "text",
328
- text: JSON.stringify({ memories, nextOffset: offset }, null, 2),
329
- },
330
- ],
331
- };
327
+ try {
328
+ const { memories, offset } = await memoryRepository.scroll({
329
+ project: args.project,
330
+ tags: args.tags,
331
+ limit: args.limit,
332
+ offset: args.offset,
333
+ });
334
+ return text(JSON.stringify({ memories, nextOffset: offset }, null, 2));
335
+ }
336
+ catch (err) {
337
+ return toolErr(err);
338
+ }
332
339
  },
333
340
  });
334
341
  server.addTool({
@@ -336,50 +343,13 @@ server.addTool({
336
343
  description: "Get statistics about the memories collection",
337
344
  parameters: z.object({}),
338
345
  execute: async () => {
339
- const stats = await memoryRepository.stats();
340
- return {
341
- content: [
342
- { type: "text", text: JSON.stringify(stats, null, 2) },
343
- ],
344
- };
345
- },
346
- });
347
- // ── Memory Import / Export ────────────────────────────────────────────────────
348
- server.addTool({
349
- name: "memory_export",
350
- description: "Export all memories as JSON",
351
- parameters: z.object({}),
352
- execute: async () => {
353
- const memories = await memoryRepository.export();
354
- return {
355
- content: [
356
- { type: "text", text: JSON.stringify(memories, null, 2) },
357
- ],
358
- };
359
- },
360
- });
361
- server.addTool({
362
- name: "memory_import",
363
- description: "Import memories from JSON array",
364
- parameters: z.object({
365
- items: z.array(z.object({
366
- text: z.string(),
367
- metadata: z
368
- .object({
369
- source: z.string().optional(),
370
- project: z.string().optional(),
371
- tags: z.array(z.string()).optional(),
372
- })
373
- .optional(),
374
- })),
375
- }),
376
- execute: async (args) => {
377
- const result = await memoryRepository.import(args.items);
378
- return {
379
- content: [
380
- { type: "text", text: JSON.stringify(result, null, 2) },
381
- ],
382
- };
346
+ try {
347
+ const stats = await memoryRepository.stats();
348
+ return text(JSON.stringify(stats, null, 2));
349
+ }
350
+ catch (err) {
351
+ return toolErr(err);
352
+ }
383
353
  },
384
354
  });
385
355
  // ── Entity / Relation Stats ───────────────────────────────────────────────────
@@ -393,18 +363,19 @@ server.addTool({
393
363
  metadata: z.record(z.unknown()).optional(),
394
364
  }),
395
365
  execute: async (args) => {
396
- const result = await entityRepository.update(args.id, {
397
- name: args.name,
398
- entityType: args.entityType,
399
- metadata: args.metadata,
400
- });
401
- if (!result)
402
- return `Entity not found: ${args.id}`;
403
- return {
404
- content: [
405
- { type: "text", text: JSON.stringify(result, null, 2) },
406
- ],
407
- };
366
+ try {
367
+ const result = await entityRepository.update(args.id, {
368
+ name: args.name,
369
+ entityType: args.entityType,
370
+ metadata: args.metadata,
371
+ });
372
+ if (!result)
373
+ return text(`Entity not found: ${args.id}`);
374
+ return text(JSON.stringify(result, null, 2));
375
+ }
376
+ catch (err) {
377
+ return toolErr(err);
378
+ }
408
379
  },
409
380
  });
410
381
  server.addTool({
@@ -412,12 +383,13 @@ server.addTool({
412
383
  description: "Get statistics about the entities collection",
413
384
  parameters: z.object({}),
414
385
  execute: async () => {
415
- const stats = await entityRepository.stats();
416
- return {
417
- content: [
418
- { type: "text", text: JSON.stringify(stats, null, 2) },
419
- ],
420
- };
386
+ try {
387
+ const stats = await entityRepository.stats();
388
+ return text(JSON.stringify(stats, null, 2));
389
+ }
390
+ catch (err) {
391
+ return toolErr(err);
392
+ }
421
393
  },
422
394
  });
423
395
  server.addTool({
@@ -425,12 +397,13 @@ server.addTool({
425
397
  description: "Get statistics about the relations collection",
426
398
  parameters: z.object({}),
427
399
  execute: async () => {
428
- const stats = await relationRepository.stats();
429
- return {
430
- content: [
431
- { type: "text", text: JSON.stringify(stats, null, 2) },
432
- ],
433
- };
400
+ try {
401
+ const stats = await relationRepository.stats();
402
+ return text(JSON.stringify(stats, null, 2));
403
+ }
404
+ catch (err) {
405
+ return toolErr(err);
406
+ }
434
407
  },
435
408
  });
436
409
  // ── List Tools ────────────────────────────────────────────────────────────────
@@ -443,42 +416,18 @@ server.addTool({
443
416
  tags: z.array(z.string()).optional(),
444
417
  }),
445
418
  execute: async (args) => {
446
- const tags = [...(args.tags ?? []), "note"];
447
- const result = await memoryRepository.save(args.content, {
448
- project: args.project,
449
- tags,
450
- createdAt: new Date().toISOString(),
451
- });
452
- return `Saved note: ${result.id}`;
453
- },
454
- });
455
- server.addTool({
456
- name: "memory_notes",
457
- description: "Save multiple notes at once (batch lightweight memory saves)",
458
- parameters: z.object({
459
- notes: z.array(z.object({
460
- content: z.string(),
461
- project: z.string().optional(),
462
- tags: z.array(z.string()).optional(),
463
- })),
464
- }),
465
- execute: async (args) => {
466
- const items = args.notes.map((n) => ({
467
- text: n.content,
468
- metadata: {
469
- project: n.project,
470
- tags: [...(n.tags ?? []), "note"],
471
- },
472
- }));
473
- const results = await memoryRepository.saveBatch(items);
474
- return {
475
- content: [
476
- {
477
- type: "text",
478
- text: JSON.stringify({ saved: results.length, ids: results.map((r) => r.id) }, null, 2),
479
- },
480
- ],
481
- };
419
+ try {
420
+ const tags = [...(args.tags ?? []), "note"];
421
+ const result = await memoryRepository.save(args.content, {
422
+ project: args.project,
423
+ tags,
424
+ createdAt: new Date().toISOString(),
425
+ });
426
+ return text(`Saved note: ${result.id}`);
427
+ }
428
+ catch (err) {
429
+ return toolErr(err);
430
+ }
482
431
  },
483
432
  });
484
433
  server.addTool({
@@ -490,15 +439,13 @@ server.addTool({
490
439
  offset: z.string().optional(),
491
440
  }),
492
441
  execute: async (args) => {
493
- const { entities, offset } = await entityRepository.list(args.entityType, args.limit, args.offset);
494
- return {
495
- content: [
496
- {
497
- type: "text",
498
- text: JSON.stringify({ entities, nextOffset: offset }, null, 2),
499
- },
500
- ],
501
- };
442
+ try {
443
+ const { entities, offset } = await entityRepository.list(args.entityType, args.limit, args.offset);
444
+ return text(JSON.stringify({ entities, nextOffset: offset }, null, 2));
445
+ }
446
+ catch (err) {
447
+ return toolErr(err);
448
+ }
502
449
  },
503
450
  });
504
451
  server.addTool({
@@ -510,15 +457,13 @@ server.addTool({
510
457
  offset: z.string().optional(),
511
458
  }),
512
459
  execute: async (args) => {
513
- const { relations, offset } = await relationRepository.list(args.relationType, args.limit, args.offset);
514
- return {
515
- content: [
516
- {
517
- type: "text",
518
- text: JSON.stringify({ relations, nextOffset: offset }, null, 2),
519
- },
520
- ],
521
- };
460
+ try {
461
+ const { relations, offset } = await relationRepository.list(args.relationType, args.limit, args.offset);
462
+ return text(JSON.stringify({ relations, nextOffset: offset }, null, 2));
463
+ }
464
+ catch (err) {
465
+ return toolErr(err);
466
+ }
522
467
  },
523
468
  });
524
469
  // ── Initialize collections on startup ────────────────────────────────────────
@@ -530,12 +475,18 @@ async function init(retries = 10, delayMs = 3000) {
530
475
  await relationRepository.init();
531
476
  collectionsReady = true;
532
477
  console.error("Collections initialized");
478
+ try {
479
+ await warmup();
480
+ }
481
+ catch (err) {
482
+ console.warn("Embedding warmup failed (non-fatal):", err);
483
+ }
533
484
  return;
534
485
  }
535
486
  catch (err) {
536
487
  if (attempt === retries) {
537
488
  console.error(`Failed to initialize collections after ${retries} attempts:`, err);
538
- return;
489
+ process.exit(1);
539
490
  }
540
491
  console.error(`Collection init attempt ${attempt}/${retries} failed, retrying in ${delayMs / 1000}s...`);
541
492
  await new Promise((resolve) => setTimeout(resolve, delayMs));
@@ -577,4 +528,17 @@ if (config.transport === "http") {
577
528
  else {
578
529
  server.start({ transportType: "stdio" });
579
530
  }
531
+ function shutdown(signal) {
532
+ console.error(`[grove] Received ${signal}, shutting down...`);
533
+ server.stop().then(() => {
534
+ console.error("[grove] Server stopped");
535
+ process.exit(0);
536
+ });
537
+ setTimeout(() => {
538
+ console.error("[grove] Force exit after timeout");
539
+ process.exit(1);
540
+ }, 5000);
541
+ }
542
+ process.on("SIGTERM", () => shutdown("SIGTERM"));
543
+ process.on("SIGINT", () => shutdown("SIGINT"));
580
544
  //# sourceMappingURL=index.js.map