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