@lanonasis/mem-intel-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +490 -0
- package/dist/core/client.d.ts +43 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/errors.d.ts +24 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/index.cjs +310 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +300 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/types.d.ts +171 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/index-sdk.d.ts +8 -0
- package/dist/index-sdk.d.ts.map +1 -0
- package/dist/index.cjs +310 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +300 -0
- package/dist/index.js.map +1 -0
- package/dist/node/client.d.ts +22 -0
- package/dist/node/client.d.ts.map +1 -0
- package/dist/node/index.cjs +331 -0
- package/dist/node/index.cjs.map +1 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +321 -0
- package/dist/node/index.js.map +1 -0
- package/dist/react/context/MemoryIntelligenceProvider.d.ts +18 -0
- package/dist/react/context/MemoryIntelligenceProvider.d.ts.map +1 -0
- package/dist/react/hooks/useMemoryIntelligence.d.ts +115 -0
- package/dist/react/hooks/useMemoryIntelligence.d.ts.map +1 -0
- package/dist/react/index.cjs +399 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.ts +8 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +377 -0
- package/dist/react/index.js.map +1 -0
- package/dist/server/index.cjs +802 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +792 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/mcp-server.d.ts +7 -0
- package/dist/server/mcp-server.d.ts.map +1 -0
- package/dist/utils/embeddings.d.ts +13 -0
- package/dist/utils/embeddings.d.ts.map +1 -0
- package/dist/utils/formatting.d.ts +13 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/http-client.d.ts +31 -0
- package/dist/utils/http-client.d.ts.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/similarity.d.ts +8 -0
- package/dist/utils/similarity.d.ts.map +1 -0
- package/dist/vue/composables/useMemoryIntelligence.d.ts +24 -0
- package/dist/vue/composables/useMemoryIntelligence.d.ts.map +1 -0
- package/dist/vue/index.cjs +132 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +7 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/index.js +115 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +144 -0
|
@@ -0,0 +1,802 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mcp_js = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
// src/server/mcp-server.ts
|
|
7
|
+
|
|
8
|
+
// src/core/errors.ts
|
|
9
|
+
var MemoryIntelligenceError = class extends Error {
|
|
10
|
+
constructor(message) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "MemoryIntelligenceError";
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
var ConfigurationError = class extends MemoryIntelligenceError {
|
|
16
|
+
constructor(message) {
|
|
17
|
+
super(message);
|
|
18
|
+
this.name = "ConfigurationError";
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var MemoryNotFoundError = class extends MemoryIntelligenceError {
|
|
22
|
+
constructor(memoryId) {
|
|
23
|
+
super(`Memory not found: ${memoryId}`);
|
|
24
|
+
this.name = "MemoryNotFoundError";
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var DatabaseError = class extends MemoryIntelligenceError {
|
|
28
|
+
constructor(message, originalError) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.originalError = originalError;
|
|
31
|
+
this.name = "DatabaseError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var EmbeddingError = class extends MemoryIntelligenceError {
|
|
35
|
+
constructor(message, originalError) {
|
|
36
|
+
super(message);
|
|
37
|
+
this.originalError = originalError;
|
|
38
|
+
this.name = "EmbeddingError";
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var ValidationError = class extends MemoryIntelligenceError {
|
|
42
|
+
constructor(message) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = "ValidationError";
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/utils/http-client.ts
|
|
49
|
+
var HttpClient = class {
|
|
50
|
+
apiUrl;
|
|
51
|
+
apiKey;
|
|
52
|
+
timeout;
|
|
53
|
+
headers;
|
|
54
|
+
constructor(config) {
|
|
55
|
+
if (!config.apiKey) {
|
|
56
|
+
throw new ConfigurationError("API key is required");
|
|
57
|
+
}
|
|
58
|
+
if (!config.apiKey.startsWith("lano_")) {
|
|
59
|
+
throw new ConfigurationError(
|
|
60
|
+
"Invalid API key format. API key should start with 'lano_'"
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
this.apiUrl = config.apiUrl.replace(/\/$/, "");
|
|
64
|
+
this.apiKey = config.apiKey;
|
|
65
|
+
this.timeout = config.timeout || 3e4;
|
|
66
|
+
this.headers = {
|
|
67
|
+
"Content-Type": "application/json",
|
|
68
|
+
"X-API-Key": this.apiKey,
|
|
69
|
+
...config.headers
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async request(method, endpoint, data) {
|
|
73
|
+
const url = `${this.apiUrl}${endpoint}`;
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
76
|
+
try {
|
|
77
|
+
const options = {
|
|
78
|
+
method,
|
|
79
|
+
headers: this.headers,
|
|
80
|
+
signal: controller.signal
|
|
81
|
+
};
|
|
82
|
+
if (data && (method === "POST" || method === "PUT" || method === "PATCH")) {
|
|
83
|
+
options.body = JSON.stringify(data);
|
|
84
|
+
}
|
|
85
|
+
const response = await fetch(url, options);
|
|
86
|
+
clearTimeout(timeoutId);
|
|
87
|
+
const responseData = await response.json();
|
|
88
|
+
if (!response.ok) {
|
|
89
|
+
return {
|
|
90
|
+
status: response.status,
|
|
91
|
+
error: {
|
|
92
|
+
message: responseData?.message || responseData?.error || "Request failed",
|
|
93
|
+
code: responseData?.code
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
status: response.status,
|
|
99
|
+
data: responseData
|
|
100
|
+
};
|
|
101
|
+
} catch (error) {
|
|
102
|
+
clearTimeout(timeoutId);
|
|
103
|
+
if (error instanceof Error) {
|
|
104
|
+
if (error.name === "AbortError") {
|
|
105
|
+
return {
|
|
106
|
+
status: 408,
|
|
107
|
+
error: {
|
|
108
|
+
message: `Request timeout after ${this.timeout}ms`,
|
|
109
|
+
code: "TIMEOUT"
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
status: 0,
|
|
115
|
+
error: {
|
|
116
|
+
message: error.message,
|
|
117
|
+
code: "NETWORK_ERROR"
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
status: 0,
|
|
123
|
+
error: {
|
|
124
|
+
message: "Unknown error occurred",
|
|
125
|
+
code: "UNKNOWN_ERROR"
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async get(endpoint) {
|
|
131
|
+
return this.request("GET", endpoint);
|
|
132
|
+
}
|
|
133
|
+
async post(endpoint, data) {
|
|
134
|
+
return this.request("POST", endpoint, data);
|
|
135
|
+
}
|
|
136
|
+
async put(endpoint, data) {
|
|
137
|
+
return this.request("PUT", endpoint, data);
|
|
138
|
+
}
|
|
139
|
+
async patch(endpoint, data) {
|
|
140
|
+
return this.request("PATCH", endpoint, data);
|
|
141
|
+
}
|
|
142
|
+
async delete(endpoint) {
|
|
143
|
+
return this.request("DELETE", endpoint);
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// src/core/client.ts
|
|
148
|
+
var DEFAULT_API_URL = "https://api.lanonasis.com/api/v1";
|
|
149
|
+
var MemoryIntelligenceClient = class {
|
|
150
|
+
httpClient;
|
|
151
|
+
defaultResponseFormat;
|
|
152
|
+
constructor(config) {
|
|
153
|
+
if (!config.apiKey) {
|
|
154
|
+
throw new ConfigurationError(
|
|
155
|
+
"Missing required configuration: apiKey is required (format: lano_xxxxxxxxxx)"
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
this.httpClient = new HttpClient({
|
|
159
|
+
apiUrl: config.apiUrl || DEFAULT_API_URL,
|
|
160
|
+
apiKey: config.apiKey,
|
|
161
|
+
timeout: config.timeout,
|
|
162
|
+
headers: config.headers
|
|
163
|
+
});
|
|
164
|
+
this.defaultResponseFormat = config.responseFormat || "markdown";
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get HTTP client for direct API access
|
|
168
|
+
*/
|
|
169
|
+
getHttpClient() {
|
|
170
|
+
return this.httpClient;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Query memories from the API
|
|
174
|
+
*/
|
|
175
|
+
async queryMemories(userId, options = {}) {
|
|
176
|
+
const { type, limit = 100, offset = 0 } = options;
|
|
177
|
+
const params = new URLSearchParams({
|
|
178
|
+
user_id: userId,
|
|
179
|
+
limit: limit.toString(),
|
|
180
|
+
offset: offset.toString()
|
|
181
|
+
});
|
|
182
|
+
if (type) {
|
|
183
|
+
params.append("type", type);
|
|
184
|
+
}
|
|
185
|
+
const response = await this.httpClient.get(
|
|
186
|
+
`/intelligence/memories?${params.toString()}`
|
|
187
|
+
);
|
|
188
|
+
if (response.error) {
|
|
189
|
+
throw new DatabaseError(`Failed to query memories: ${response.error.message}`);
|
|
190
|
+
}
|
|
191
|
+
return response.data?.memories || [];
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Analyze usage patterns and trends in memory collection
|
|
195
|
+
*/
|
|
196
|
+
async analyzePatterns(params) {
|
|
197
|
+
const response = await this.httpClient.post(
|
|
198
|
+
"/intelligence/analyze-patterns",
|
|
199
|
+
{
|
|
200
|
+
...params,
|
|
201
|
+
responseFormat: params.responseFormat || this.defaultResponseFormat
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
if (response.error) {
|
|
205
|
+
throw new DatabaseError(`Failed to analyze patterns: ${response.error.message}`);
|
|
206
|
+
}
|
|
207
|
+
return response.data;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get AI-powered tag suggestions for a memory
|
|
211
|
+
*/
|
|
212
|
+
async suggestTags(params) {
|
|
213
|
+
const response = await this.httpClient.post(
|
|
214
|
+
"/intelligence/suggest-tags",
|
|
215
|
+
{
|
|
216
|
+
...params,
|
|
217
|
+
responseFormat: params.responseFormat || this.defaultResponseFormat
|
|
218
|
+
}
|
|
219
|
+
);
|
|
220
|
+
if (response.error) {
|
|
221
|
+
throw new DatabaseError(`Failed to suggest tags: ${response.error.message}`);
|
|
222
|
+
}
|
|
223
|
+
return response.data;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Find semantically related memories using vector similarity
|
|
227
|
+
*/
|
|
228
|
+
async findRelated(params) {
|
|
229
|
+
const response = await this.httpClient.post(
|
|
230
|
+
"/intelligence/find-related",
|
|
231
|
+
{
|
|
232
|
+
...params,
|
|
233
|
+
responseFormat: params.responseFormat || this.defaultResponseFormat
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
if (response.error) {
|
|
237
|
+
throw new DatabaseError(`Failed to find related memories: ${response.error.message}`);
|
|
238
|
+
}
|
|
239
|
+
return response.data;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Detect potential duplicate memories
|
|
243
|
+
*/
|
|
244
|
+
async detectDuplicates(params) {
|
|
245
|
+
const response = await this.httpClient.post(
|
|
246
|
+
"/intelligence/detect-duplicates",
|
|
247
|
+
{
|
|
248
|
+
...params,
|
|
249
|
+
responseFormat: params.responseFormat || this.defaultResponseFormat
|
|
250
|
+
}
|
|
251
|
+
);
|
|
252
|
+
if (response.error) {
|
|
253
|
+
throw new DatabaseError(`Failed to detect duplicates: ${response.error.message}`);
|
|
254
|
+
}
|
|
255
|
+
return response.data;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Extract insights and patterns from memories
|
|
259
|
+
*/
|
|
260
|
+
async extractInsights(params) {
|
|
261
|
+
const response = await this.httpClient.post(
|
|
262
|
+
"/intelligence/extract-insights",
|
|
263
|
+
{
|
|
264
|
+
...params,
|
|
265
|
+
responseFormat: params.responseFormat || this.defaultResponseFormat
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
if (response.error) {
|
|
269
|
+
throw new DatabaseError(`Failed to extract insights: ${response.error.message}`);
|
|
270
|
+
}
|
|
271
|
+
return response.data;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Check the health and organization quality of memories
|
|
275
|
+
*/
|
|
276
|
+
async healthCheck(params) {
|
|
277
|
+
const response = await this.httpClient.post(
|
|
278
|
+
"/intelligence/health-check",
|
|
279
|
+
{
|
|
280
|
+
...params,
|
|
281
|
+
responseFormat: params.responseFormat || this.defaultResponseFormat
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
if (response.error) {
|
|
285
|
+
throw new DatabaseError(`Failed to check health: ${response.error.message}`);
|
|
286
|
+
}
|
|
287
|
+
return response.data;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var ResponseFormat = {
|
|
291
|
+
JSON: "json",
|
|
292
|
+
MARKDOWN: "markdown"
|
|
293
|
+
};
|
|
294
|
+
var MemoryType = zod.z.enum([
|
|
295
|
+
"context",
|
|
296
|
+
"project",
|
|
297
|
+
"knowledge",
|
|
298
|
+
"reference",
|
|
299
|
+
"personal",
|
|
300
|
+
"workflow"
|
|
301
|
+
]);
|
|
302
|
+
|
|
303
|
+
// src/utils/formatting.ts
|
|
304
|
+
var CHARACTER_LIMIT = 5e4;
|
|
305
|
+
function formatResponse(data, format, markdownFormatter) {
|
|
306
|
+
if (format === ResponseFormat.JSON) {
|
|
307
|
+
return JSON.stringify(data, null, 2);
|
|
308
|
+
}
|
|
309
|
+
return markdownFormatter(data);
|
|
310
|
+
}
|
|
311
|
+
function truncateIfNeeded(text) {
|
|
312
|
+
if (text.length > CHARACTER_LIMIT) {
|
|
313
|
+
return text.substring(0, CHARACTER_LIMIT) + `
|
|
314
|
+
|
|
315
|
+
... (truncated, ${text.length - CHARACTER_LIMIT} characters omitted)`;
|
|
316
|
+
}
|
|
317
|
+
return text;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// src/server/mcp-server.ts
|
|
321
|
+
function createMCPServer(config) {
|
|
322
|
+
const client = new MemoryIntelligenceClient(config);
|
|
323
|
+
const server = new mcp_js.McpServer({
|
|
324
|
+
name: "memory-intelligence-mcp-server",
|
|
325
|
+
version: "1.0.0"
|
|
326
|
+
});
|
|
327
|
+
server.registerTool(
|
|
328
|
+
"memory_analyze_patterns",
|
|
329
|
+
{
|
|
330
|
+
title: "Analyze Memory Patterns",
|
|
331
|
+
description: `Analyze usage patterns and trends in the user's memory collection.`,
|
|
332
|
+
inputSchema: zod.z.object({
|
|
333
|
+
user_id: zod.z.string().uuid(),
|
|
334
|
+
time_range_days: zod.z.number().int().min(1).max(365).default(30),
|
|
335
|
+
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
336
|
+
}).strict(),
|
|
337
|
+
annotations: {
|
|
338
|
+
readOnlyHint: true,
|
|
339
|
+
destructiveHint: false,
|
|
340
|
+
idempotentHint: true,
|
|
341
|
+
openWorldHint: true
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
async (rawParams) => {
|
|
345
|
+
try {
|
|
346
|
+
const params = {
|
|
347
|
+
userId: rawParams.user_id,
|
|
348
|
+
timeRangeDays: rawParams.time_range_days,
|
|
349
|
+
responseFormat: rawParams.response_format
|
|
350
|
+
};
|
|
351
|
+
const analysis = await client.analyzePatterns(params);
|
|
352
|
+
const responseText = formatResponse(
|
|
353
|
+
analysis,
|
|
354
|
+
params.responseFormat || "markdown",
|
|
355
|
+
(data) => {
|
|
356
|
+
let md = `# Memory Pattern Analysis
|
|
357
|
+
|
|
358
|
+
`;
|
|
359
|
+
md += `**Time Range:** Last ${params.timeRangeDays || 30} days
|
|
360
|
+
`;
|
|
361
|
+
md += `**Total Memories:** ${data.total_memories}
|
|
362
|
+
|
|
363
|
+
`;
|
|
364
|
+
md += `## Distribution by Type
|
|
365
|
+
`;
|
|
366
|
+
for (const [type, count] of Object.entries(data.memories_by_type)) {
|
|
367
|
+
const percentage = (count / data.total_memories * 100).toFixed(1);
|
|
368
|
+
md += `- **${type}**: ${count} (${percentage}%)
|
|
369
|
+
`;
|
|
370
|
+
}
|
|
371
|
+
md += `
|
|
372
|
+
## Activity Patterns
|
|
373
|
+
`;
|
|
374
|
+
md += `- **Peak Hours (UTC):** ${data.peak_creation_hours.join(", ")}
|
|
375
|
+
`;
|
|
376
|
+
md += `- **Daily Average:** ${data.creation_velocity.daily_average} memories/day
|
|
377
|
+
`;
|
|
378
|
+
md += `- **Trend:** ${data.creation_velocity.trend}
|
|
379
|
+
`;
|
|
380
|
+
md += `
|
|
381
|
+
## Top Tags
|
|
382
|
+
`;
|
|
383
|
+
for (const { tag, count } of data.most_common_tags.slice(0, 5)) {
|
|
384
|
+
md += `- **${tag}**: ${count} uses
|
|
385
|
+
`;
|
|
386
|
+
}
|
|
387
|
+
md += `
|
|
388
|
+
## AI Insights
|
|
389
|
+
`;
|
|
390
|
+
for (const insight of data.insights) {
|
|
391
|
+
md += `${insight}
|
|
392
|
+
`;
|
|
393
|
+
}
|
|
394
|
+
return md;
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
return {
|
|
398
|
+
content: [{ type: "text", text: truncateIfNeeded(responseText) }]
|
|
399
|
+
};
|
|
400
|
+
} catch (error) {
|
|
401
|
+
return {
|
|
402
|
+
isError: true,
|
|
403
|
+
content: [
|
|
404
|
+
{
|
|
405
|
+
type: "text",
|
|
406
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
);
|
|
413
|
+
server.registerTool(
|
|
414
|
+
"memory_suggest_tags",
|
|
415
|
+
{
|
|
416
|
+
title: "Suggest Tags for Memory",
|
|
417
|
+
description: `AI-powered tag suggestions for a memory.`,
|
|
418
|
+
inputSchema: zod.z.object({
|
|
419
|
+
memory_id: zod.z.string().uuid(),
|
|
420
|
+
user_id: zod.z.string().uuid(),
|
|
421
|
+
max_suggestions: zod.z.number().int().min(1).max(20).default(5),
|
|
422
|
+
include_existing_tags: zod.z.boolean().default(true),
|
|
423
|
+
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
424
|
+
}).strict(),
|
|
425
|
+
annotations: {
|
|
426
|
+
readOnlyHint: true,
|
|
427
|
+
destructiveHint: false,
|
|
428
|
+
idempotentHint: false,
|
|
429
|
+
openWorldHint: true
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
async (rawParams) => {
|
|
433
|
+
try {
|
|
434
|
+
const params = {
|
|
435
|
+
memoryId: rawParams.memory_id,
|
|
436
|
+
userId: rawParams.user_id,
|
|
437
|
+
maxSuggestions: rawParams.max_suggestions,
|
|
438
|
+
includeExistingTags: rawParams.include_existing_tags,
|
|
439
|
+
responseFormat: rawParams.response_format
|
|
440
|
+
};
|
|
441
|
+
const result = await client.suggestTags(params);
|
|
442
|
+
const responseText = formatResponse(
|
|
443
|
+
result,
|
|
444
|
+
params.responseFormat || "markdown",
|
|
445
|
+
(data) => {
|
|
446
|
+
let md = `# Tag Suggestions
|
|
447
|
+
|
|
448
|
+
`;
|
|
449
|
+
md += `**Existing Tags:** ${data.existing_tags.join(", ") || "none"}
|
|
450
|
+
|
|
451
|
+
`;
|
|
452
|
+
md += `## Suggested Tags
|
|
453
|
+
`;
|
|
454
|
+
for (const suggestion of data.suggestions) {
|
|
455
|
+
md += `
|
|
456
|
+
### \`${suggestion.tag}\`
|
|
457
|
+
`;
|
|
458
|
+
md += `**Confidence:** ${(suggestion.confidence * 100).toFixed(0)}%
|
|
459
|
+
`;
|
|
460
|
+
md += `**Reason:** ${suggestion.reasoning}
|
|
461
|
+
`;
|
|
462
|
+
}
|
|
463
|
+
return md;
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
return {
|
|
467
|
+
content: [{ type: "text", text: truncateIfNeeded(responseText) }]
|
|
468
|
+
};
|
|
469
|
+
} catch (error) {
|
|
470
|
+
return {
|
|
471
|
+
isError: true,
|
|
472
|
+
content: [
|
|
473
|
+
{
|
|
474
|
+
type: "text",
|
|
475
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
476
|
+
}
|
|
477
|
+
]
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
);
|
|
482
|
+
server.registerTool(
|
|
483
|
+
"memory_find_related",
|
|
484
|
+
{
|
|
485
|
+
title: "Find Related Memories",
|
|
486
|
+
description: `Find semantically related memories using vector similarity.`,
|
|
487
|
+
inputSchema: zod.z.object({
|
|
488
|
+
memory_id: zod.z.string().uuid(),
|
|
489
|
+
user_id: zod.z.string().uuid(),
|
|
490
|
+
limit: zod.z.number().int().min(1).max(50).default(10),
|
|
491
|
+
similarity_threshold: zod.z.number().min(0).max(1).default(0.7),
|
|
492
|
+
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
493
|
+
}).strict(),
|
|
494
|
+
annotations: {
|
|
495
|
+
readOnlyHint: true,
|
|
496
|
+
destructiveHint: false,
|
|
497
|
+
idempotentHint: true,
|
|
498
|
+
openWorldHint: true
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
async (rawParams) => {
|
|
502
|
+
try {
|
|
503
|
+
const params = {
|
|
504
|
+
memoryId: rawParams.memory_id,
|
|
505
|
+
userId: rawParams.user_id,
|
|
506
|
+
limit: rawParams.limit,
|
|
507
|
+
similarityThreshold: rawParams.similarity_threshold,
|
|
508
|
+
responseFormat: rawParams.response_format
|
|
509
|
+
};
|
|
510
|
+
const result = await client.findRelated(params);
|
|
511
|
+
const responseText = formatResponse(
|
|
512
|
+
result,
|
|
513
|
+
params.responseFormat || "markdown",
|
|
514
|
+
(data) => {
|
|
515
|
+
let md = `# Related Memories
|
|
516
|
+
|
|
517
|
+
`;
|
|
518
|
+
md += `**Source:** ${data.source_memory.title}
|
|
519
|
+
`;
|
|
520
|
+
md += `**Found:** ${data.total_found} related memories
|
|
521
|
+
|
|
522
|
+
`;
|
|
523
|
+
for (const mem of data.related_memories) {
|
|
524
|
+
md += `## ${mem.title}
|
|
525
|
+
`;
|
|
526
|
+
md += `**Similarity:** ${(mem.similarity_score * 100).toFixed(1)}%
|
|
527
|
+
`;
|
|
528
|
+
if (mem.shared_tags.length > 0) {
|
|
529
|
+
md += `**Shared Tags:** ${mem.shared_tags.join(", ")}
|
|
530
|
+
`;
|
|
531
|
+
}
|
|
532
|
+
md += `**Preview:** ${mem.content_preview}
|
|
533
|
+
|
|
534
|
+
`;
|
|
535
|
+
}
|
|
536
|
+
return md;
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
return {
|
|
540
|
+
content: [{ type: "text", text: truncateIfNeeded(responseText) }]
|
|
541
|
+
};
|
|
542
|
+
} catch (error) {
|
|
543
|
+
return {
|
|
544
|
+
isError: true,
|
|
545
|
+
content: [
|
|
546
|
+
{
|
|
547
|
+
type: "text",
|
|
548
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
549
|
+
}
|
|
550
|
+
]
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
);
|
|
555
|
+
server.registerTool(
|
|
556
|
+
"memory_detect_duplicates",
|
|
557
|
+
{
|
|
558
|
+
title: "Detect Duplicate Memories",
|
|
559
|
+
description: `Find potential duplicate memories.`,
|
|
560
|
+
inputSchema: zod.z.object({
|
|
561
|
+
user_id: zod.z.string().uuid(),
|
|
562
|
+
similarity_threshold: zod.z.number().min(0.8).max(0.99).default(0.9),
|
|
563
|
+
max_pairs: zod.z.number().int().min(1).max(100).default(20),
|
|
564
|
+
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
565
|
+
}).strict(),
|
|
566
|
+
annotations: {
|
|
567
|
+
readOnlyHint: true,
|
|
568
|
+
destructiveHint: false,
|
|
569
|
+
idempotentHint: true,
|
|
570
|
+
openWorldHint: true
|
|
571
|
+
}
|
|
572
|
+
},
|
|
573
|
+
async (rawParams) => {
|
|
574
|
+
try {
|
|
575
|
+
const params = {
|
|
576
|
+
userId: rawParams.user_id,
|
|
577
|
+
similarityThreshold: rawParams.similarity_threshold,
|
|
578
|
+
maxPairs: rawParams.max_pairs,
|
|
579
|
+
responseFormat: rawParams.response_format
|
|
580
|
+
};
|
|
581
|
+
const result = await client.detectDuplicates(params);
|
|
582
|
+
const responseText = formatResponse(
|
|
583
|
+
result,
|
|
584
|
+
params.responseFormat || "markdown",
|
|
585
|
+
(data) => {
|
|
586
|
+
let md = `# Duplicate Detection
|
|
587
|
+
|
|
588
|
+
`;
|
|
589
|
+
md += `**Memories Analyzed:** ${data.total_memories_analyzed}
|
|
590
|
+
`;
|
|
591
|
+
md += `**Duplicate Pairs Found:** ${data.duplicate_pairs_found}
|
|
592
|
+
`;
|
|
593
|
+
md += `**Storage Savings:** ${data.estimated_storage_savings}
|
|
594
|
+
|
|
595
|
+
`;
|
|
596
|
+
for (const pair of data.duplicate_pairs) {
|
|
597
|
+
md += `### Similarity: ${(pair.similarity_score * 100).toFixed(1)}%
|
|
598
|
+
`;
|
|
599
|
+
md += `**Memory 1:** ${pair.memory_1.title}
|
|
600
|
+
`;
|
|
601
|
+
md += `**Memory 2:** ${pair.memory_2.title}
|
|
602
|
+
`;
|
|
603
|
+
md += `**Recommendation:** ${pair.recommendation}
|
|
604
|
+
|
|
605
|
+
`;
|
|
606
|
+
}
|
|
607
|
+
return md;
|
|
608
|
+
}
|
|
609
|
+
);
|
|
610
|
+
return {
|
|
611
|
+
content: [{ type: "text", text: truncateIfNeeded(responseText) }]
|
|
612
|
+
};
|
|
613
|
+
} catch (error) {
|
|
614
|
+
return {
|
|
615
|
+
isError: true,
|
|
616
|
+
content: [
|
|
617
|
+
{
|
|
618
|
+
type: "text",
|
|
619
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
620
|
+
}
|
|
621
|
+
]
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
);
|
|
626
|
+
server.registerTool(
|
|
627
|
+
"memory_extract_insights",
|
|
628
|
+
{
|
|
629
|
+
title: "Extract Insights from Memories",
|
|
630
|
+
description: `Extract key insights and patterns from memories.`,
|
|
631
|
+
inputSchema: zod.z.object({
|
|
632
|
+
user_id: zod.z.string().uuid(),
|
|
633
|
+
topic: zod.z.string().optional(),
|
|
634
|
+
memory_type: zod.z.string().optional(),
|
|
635
|
+
max_memories: zod.z.number().int().min(5).max(100).default(20),
|
|
636
|
+
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
637
|
+
}).strict(),
|
|
638
|
+
annotations: {
|
|
639
|
+
readOnlyHint: true,
|
|
640
|
+
destructiveHint: false,
|
|
641
|
+
idempotentHint: false,
|
|
642
|
+
openWorldHint: true
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
async (rawParams) => {
|
|
646
|
+
try {
|
|
647
|
+
const params = {
|
|
648
|
+
userId: rawParams.user_id,
|
|
649
|
+
topic: rawParams.topic,
|
|
650
|
+
memoryType: rawParams.memory_type,
|
|
651
|
+
maxMemories: rawParams.max_memories,
|
|
652
|
+
responseFormat: rawParams.response_format
|
|
653
|
+
};
|
|
654
|
+
const result = await client.extractInsights(params);
|
|
655
|
+
const responseText = formatResponse(
|
|
656
|
+
result,
|
|
657
|
+
params.responseFormat || "markdown",
|
|
658
|
+
(data) => {
|
|
659
|
+
let md = `# Memory Insights
|
|
660
|
+
|
|
661
|
+
`;
|
|
662
|
+
md += `**Memories Analyzed:** ${data.total_memories_analyzed}
|
|
663
|
+
`;
|
|
664
|
+
if (data.topic_filter) {
|
|
665
|
+
md += `**Topic:** ${data.topic_filter}
|
|
666
|
+
`;
|
|
667
|
+
}
|
|
668
|
+
md += `
|
|
669
|
+
## Summary
|
|
670
|
+
${data.summary}
|
|
671
|
+
|
|
672
|
+
`;
|
|
673
|
+
md += `## Insights
|
|
674
|
+
`;
|
|
675
|
+
for (const insight of data.insights) {
|
|
676
|
+
const icon = {
|
|
677
|
+
pattern: "\u{1F504}",
|
|
678
|
+
learning: "\u{1F4A1}",
|
|
679
|
+
opportunity: "\u{1F680}",
|
|
680
|
+
risk: "\u26A0\uFE0F",
|
|
681
|
+
action_item: "\u2705"
|
|
682
|
+
}[insight.category] || "\u{1F4CC}";
|
|
683
|
+
md += `
|
|
684
|
+
### ${icon} ${insight.title}
|
|
685
|
+
`;
|
|
686
|
+
md += `${insight.description}
|
|
687
|
+
`;
|
|
688
|
+
md += `**Confidence:** ${(insight.confidence * 100).toFixed(0)}%
|
|
689
|
+
`;
|
|
690
|
+
}
|
|
691
|
+
return md;
|
|
692
|
+
}
|
|
693
|
+
);
|
|
694
|
+
return {
|
|
695
|
+
content: [{ type: "text", text: truncateIfNeeded(responseText) }]
|
|
696
|
+
};
|
|
697
|
+
} catch (error) {
|
|
698
|
+
return {
|
|
699
|
+
isError: true,
|
|
700
|
+
content: [
|
|
701
|
+
{
|
|
702
|
+
type: "text",
|
|
703
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
704
|
+
}
|
|
705
|
+
]
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
server.registerTool(
|
|
711
|
+
"memory_health_check",
|
|
712
|
+
{
|
|
713
|
+
title: "Memory Health Check",
|
|
714
|
+
description: `Analyze the health and organization quality of memories.`,
|
|
715
|
+
inputSchema: zod.z.object({
|
|
716
|
+
user_id: zod.z.string().uuid(),
|
|
717
|
+
response_format: zod.z.enum([ResponseFormat.JSON, ResponseFormat.MARKDOWN]).default(ResponseFormat.MARKDOWN)
|
|
718
|
+
}).strict(),
|
|
719
|
+
annotations: {
|
|
720
|
+
readOnlyHint: true,
|
|
721
|
+
destructiveHint: false,
|
|
722
|
+
idempotentHint: true,
|
|
723
|
+
openWorldHint: true
|
|
724
|
+
}
|
|
725
|
+
},
|
|
726
|
+
async (rawParams) => {
|
|
727
|
+
try {
|
|
728
|
+
const params = {
|
|
729
|
+
userId: rawParams.user_id,
|
|
730
|
+
responseFormat: rawParams.response_format
|
|
731
|
+
};
|
|
732
|
+
const result = await client.healthCheck(params);
|
|
733
|
+
const responseText = formatResponse(
|
|
734
|
+
result,
|
|
735
|
+
params.responseFormat || "markdown",
|
|
736
|
+
(data) => {
|
|
737
|
+
let md = `# Memory Health Check
|
|
738
|
+
|
|
739
|
+
`;
|
|
740
|
+
md += `**Health Score:** ${data.health_score}/100
|
|
741
|
+
|
|
742
|
+
`;
|
|
743
|
+
md += `## Metrics
|
|
744
|
+
`;
|
|
745
|
+
md += `- **Total Memories:** ${data.metrics.total_memories}
|
|
746
|
+
`;
|
|
747
|
+
md += `- **Embedding Coverage:** ${data.metrics.embedding_coverage_percentage}%
|
|
748
|
+
`;
|
|
749
|
+
md += `- **Tagging Rate:** ${data.metrics.tagging_percentage}%
|
|
750
|
+
`;
|
|
751
|
+
md += `- **Avg Tags/Memory:** ${data.metrics.average_tags_per_memory}
|
|
752
|
+
|
|
753
|
+
`;
|
|
754
|
+
if (data.issues.length > 0) {
|
|
755
|
+
md += `## Issues
|
|
756
|
+
`;
|
|
757
|
+
for (const issue of data.issues) {
|
|
758
|
+
md += `- ${issue}
|
|
759
|
+
`;
|
|
760
|
+
}
|
|
761
|
+
md += `
|
|
762
|
+
`;
|
|
763
|
+
}
|
|
764
|
+
md += `## Recommendations
|
|
765
|
+
`;
|
|
766
|
+
for (const rec of data.recommendations) {
|
|
767
|
+
md += `- ${rec}
|
|
768
|
+
`;
|
|
769
|
+
}
|
|
770
|
+
return md;
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
return {
|
|
774
|
+
content: [{ type: "text", text: truncateIfNeeded(responseText) }]
|
|
775
|
+
};
|
|
776
|
+
} catch (error) {
|
|
777
|
+
return {
|
|
778
|
+
isError: true,
|
|
779
|
+
content: [
|
|
780
|
+
{
|
|
781
|
+
type: "text",
|
|
782
|
+
text: `Error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
783
|
+
}
|
|
784
|
+
]
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
);
|
|
789
|
+
return server;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
exports.ConfigurationError = ConfigurationError;
|
|
793
|
+
exports.DatabaseError = DatabaseError;
|
|
794
|
+
exports.EmbeddingError = EmbeddingError;
|
|
795
|
+
exports.MemoryIntelligenceError = MemoryIntelligenceError;
|
|
796
|
+
exports.MemoryNotFoundError = MemoryNotFoundError;
|
|
797
|
+
exports.MemoryType = MemoryType;
|
|
798
|
+
exports.ResponseFormat = ResponseFormat;
|
|
799
|
+
exports.ValidationError = ValidationError;
|
|
800
|
+
exports.createMCPServer = createMCPServer;
|
|
801
|
+
//# sourceMappingURL=index.cjs.map
|
|
802
|
+
//# sourceMappingURL=index.cjs.map
|