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