@cartisien/engram-mcp 0.2.0 → 0.3.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/LICENSE +21 -0
- package/dist/analysis/emotions.d.ts +16 -0
- package/dist/analysis/emotions.js +130 -0
- package/dist/analysis/emotions.js.map +1 -0
- package/dist/analysis/entities.d.ts +15 -0
- package/dist/analysis/entities.js +182 -0
- package/dist/analysis/entities.js.map +1 -0
- package/dist/analysis/themes.d.ts +11 -0
- package/dist/analysis/themes.js +151 -0
- package/dist/analysis/themes.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +31 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +13 -0
- package/dist/config.js +20 -0
- package/dist/config.js.map +1 -0
- package/dist/response.d.ts +17 -0
- package/dist/response.js +17 -0
- package/dist/response.js.map +1 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +104 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/consolidate.d.ts +41 -0
- package/dist/tools/consolidate.js +53 -0
- package/dist/tools/consolidate.js.map +1 -0
- package/dist/tools/context.d.ts +44 -0
- package/dist/tools/context.js +186 -0
- package/dist/tools/context.js.map +1 -0
- package/dist/tools/detect_changes.d.ts +35 -0
- package/dist/tools/detect_changes.js +178 -0
- package/dist/tools/detect_changes.js.map +1 -0
- package/dist/tools/forget.d.ts +38 -0
- package/dist/tools/forget.js +38 -0
- package/dist/tools/forget.js.map +1 -0
- package/dist/tools/graph.d.ts +40 -0
- package/dist/tools/graph.js +74 -0
- package/dist/tools/graph.js.map +1 -0
- package/dist/tools/impact.d.ts +39 -0
- package/dist/tools/impact.js +143 -0
- package/dist/tools/impact.js.map +1 -0
- package/dist/tools/process_detect.d.ts +49 -0
- package/dist/tools/process_detect.js +218 -0
- package/dist/tools/process_detect.js.map +1 -0
- package/dist/tools/recall.d.ts +81 -0
- package/dist/tools/recall.js +134 -0
- package/dist/tools/recall.js.map +1 -0
- package/dist/tools/remember.d.ts +47 -0
- package/dist/tools/remember.js +79 -0
- package/dist/tools/remember.js.map +1 -0
- package/dist/tools/search.d.ts +72 -0
- package/dist/tools/search.js +96 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/stats.d.ts +23 -0
- package/dist/tools/stats.js +47 -0
- package/dist/tools/stats.js.map +1 -0
- package/package.json +29 -14
- package/README.md +0 -114
- package/dist/engram.d.ts +0 -99
- package/dist/engram.js +0 -283
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.js +0 -322
- package/engram.ts +0 -385
- package/src/index.ts +0 -336
- package/tests/mcp.test.ts +0 -274
- package/tsconfig.json +0 -17
- package/tsconfig.test.json +0 -5
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Engram } from '@cartisien/engram';
|
|
2
|
+
export interface SearchInput {
|
|
3
|
+
query: string;
|
|
4
|
+
session_id?: string;
|
|
5
|
+
search_type?: 'hybrid' | 'semantic' | 'fts' | 'graph';
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
semantic_weight?: number;
|
|
9
|
+
filters?: {
|
|
10
|
+
role?: string[];
|
|
11
|
+
tier?: string[];
|
|
12
|
+
date_after?: string;
|
|
13
|
+
date_before?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export declare function toolSearch(engram: Engram, input: SearchInput): Promise<import("../response.js").McpResponse<unknown>>;
|
|
17
|
+
export declare const SEARCH_SCHEMA: {
|
|
18
|
+
readonly name: "search";
|
|
19
|
+
readonly description: "Raw hybrid search with pagination and filtering. Use for precise control over results.";
|
|
20
|
+
readonly inputSchema: {
|
|
21
|
+
readonly type: "object";
|
|
22
|
+
readonly properties: {
|
|
23
|
+
readonly query: {
|
|
24
|
+
readonly type: "string";
|
|
25
|
+
};
|
|
26
|
+
readonly session_id: {
|
|
27
|
+
readonly type: "string";
|
|
28
|
+
};
|
|
29
|
+
readonly search_type: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
readonly enum: readonly ["hybrid", "semantic", "fts", "graph"];
|
|
32
|
+
readonly default: "hybrid";
|
|
33
|
+
};
|
|
34
|
+
readonly limit: {
|
|
35
|
+
readonly type: "number";
|
|
36
|
+
readonly default: 10;
|
|
37
|
+
};
|
|
38
|
+
readonly offset: {
|
|
39
|
+
readonly type: "number";
|
|
40
|
+
readonly default: 0;
|
|
41
|
+
};
|
|
42
|
+
readonly semantic_weight: {
|
|
43
|
+
readonly type: "number";
|
|
44
|
+
readonly description: "0-1, weight for semantic vs BM25 (not yet configurable in v0.7)";
|
|
45
|
+
};
|
|
46
|
+
readonly filters: {
|
|
47
|
+
readonly type: "object";
|
|
48
|
+
readonly properties: {
|
|
49
|
+
readonly role: {
|
|
50
|
+
readonly type: "array";
|
|
51
|
+
readonly items: {
|
|
52
|
+
readonly type: "string";
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
readonly tier: {
|
|
56
|
+
readonly type: "array";
|
|
57
|
+
readonly items: {
|
|
58
|
+
readonly type: "string";
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
readonly date_after: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
};
|
|
64
|
+
readonly date_before: {
|
|
65
|
+
readonly type: "string";
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
readonly required: readonly ["query"];
|
|
71
|
+
};
|
|
72
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { extractEntities } from '../analysis/entities.js';
|
|
2
|
+
import { themeNames } from '../analysis/themes.js';
|
|
3
|
+
import { ok, fail } from '../response.js';
|
|
4
|
+
import { defaultSession } from '../client.js';
|
|
5
|
+
export async function toolSearch(engram, input) {
|
|
6
|
+
const start = Date.now();
|
|
7
|
+
const sessionId = input.session_id ?? defaultSession();
|
|
8
|
+
if (!input.query?.trim()) {
|
|
9
|
+
return fail('INVALID_INPUT', 'query is required', sessionId, start);
|
|
10
|
+
}
|
|
11
|
+
const limit = Math.min(input.limit ?? 10, 100);
|
|
12
|
+
const offset = input.offset ?? 0;
|
|
13
|
+
const tiers = input.filters?.tier
|
|
14
|
+
?? ['working', 'long_term'];
|
|
15
|
+
// Determine threshold by search type
|
|
16
|
+
const threshold = input.search_type === 'fts' ? 0 : 0.5;
|
|
17
|
+
try {
|
|
18
|
+
// Fetch enough to support offset
|
|
19
|
+
const all = await engram.recall(sessionId, input.query, {
|
|
20
|
+
limit: limit + offset + 20,
|
|
21
|
+
threshold,
|
|
22
|
+
tiers,
|
|
23
|
+
after: input.filters?.date_after ? new Date(input.filters.date_after) : undefined,
|
|
24
|
+
before: input.filters?.date_before ? new Date(input.filters.date_before) : undefined,
|
|
25
|
+
});
|
|
26
|
+
// Post-filter by role
|
|
27
|
+
let filtered = all;
|
|
28
|
+
if (input.filters?.role?.length) {
|
|
29
|
+
const roles = new Set(input.filters.role);
|
|
30
|
+
filtered = all.filter(m => roles.has(m.role));
|
|
31
|
+
}
|
|
32
|
+
const total = filtered.length;
|
|
33
|
+
const page = filtered.slice(offset, offset + limit);
|
|
34
|
+
// Analyze query
|
|
35
|
+
const queryEntities = extractEntities(input.query).map(e => e.name);
|
|
36
|
+
const queryThemes = themeNames(input.query, 2);
|
|
37
|
+
const results = page.map(m => ({
|
|
38
|
+
memory_id: m.id,
|
|
39
|
+
content: m.content,
|
|
40
|
+
role: m.role,
|
|
41
|
+
tier: m.tier,
|
|
42
|
+
timestamp: m.timestamp.toISOString(),
|
|
43
|
+
scores: {
|
|
44
|
+
semantic: m.similarity ?? 0,
|
|
45
|
+
final: m.similarity ?? 0,
|
|
46
|
+
},
|
|
47
|
+
}));
|
|
48
|
+
const suggestions = [];
|
|
49
|
+
if (queryThemes.length > 0) {
|
|
50
|
+
suggestions.push(`Try 'recall' with theme_filter: [\"${queryThemes[0]}\"] for contextual results`);
|
|
51
|
+
}
|
|
52
|
+
return ok({
|
|
53
|
+
results,
|
|
54
|
+
pagination: {
|
|
55
|
+
total,
|
|
56
|
+
returned: results.length,
|
|
57
|
+
offset,
|
|
58
|
+
has_more: offset + limit < total,
|
|
59
|
+
},
|
|
60
|
+
query_analysis: {
|
|
61
|
+
entities_detected: queryEntities.slice(0, 5),
|
|
62
|
+
themes_implied: queryThemes,
|
|
63
|
+
search_type_used: input.search_type ?? 'hybrid',
|
|
64
|
+
},
|
|
65
|
+
}, sessionId, start, suggestions);
|
|
66
|
+
}
|
|
67
|
+
catch (err) {
|
|
68
|
+
return fail('SEARCH_FAILED', String(err), sessionId, start);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export const SEARCH_SCHEMA = {
|
|
72
|
+
name: 'search',
|
|
73
|
+
description: 'Raw hybrid search with pagination and filtering. Use for precise control over results.',
|
|
74
|
+
inputSchema: {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
query: { type: 'string' },
|
|
78
|
+
session_id: { type: 'string' },
|
|
79
|
+
search_type: { type: 'string', enum: ['hybrid', 'semantic', 'fts', 'graph'], default: 'hybrid' },
|
|
80
|
+
limit: { type: 'number', default: 10 },
|
|
81
|
+
offset: { type: 'number', default: 0 },
|
|
82
|
+
semantic_weight: { type: 'number', description: '0-1, weight for semantic vs BM25 (not yet configurable in v0.7)' },
|
|
83
|
+
filters: {
|
|
84
|
+
type: 'object',
|
|
85
|
+
properties: {
|
|
86
|
+
role: { type: 'array', items: { type: 'string' } },
|
|
87
|
+
tier: { type: 'array', items: { type: 'string' } },
|
|
88
|
+
date_after: { type: 'string' },
|
|
89
|
+
date_before: { type: 'string' },
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
required: ['query'],
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAy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AAI,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;YACtC,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,EAAE;YACtC,eAAe,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,iEAAiE,EAAE;YACnH,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;oBAClD,IAAI,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE;oBAClD,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;oBAC9B,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;iBAChC;aACF;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB;CACO,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Engram } from '@cartisien/engram';
|
|
2
|
+
export interface StatsInput {
|
|
3
|
+
session_id?: string;
|
|
4
|
+
include_graph?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function toolStats(engram: Engram, input: StatsInput): Promise<import("../response.js").McpResponse<unknown>>;
|
|
7
|
+
export declare const STATS_SCHEMA: {
|
|
8
|
+
readonly name: "stats";
|
|
9
|
+
readonly description: "Get memory statistics for a session: counts by role/tier, embeddings coverage, importance scores, and graph metrics.";
|
|
10
|
+
readonly inputSchema: {
|
|
11
|
+
readonly type: "object";
|
|
12
|
+
readonly properties: {
|
|
13
|
+
readonly session_id: {
|
|
14
|
+
readonly type: "string";
|
|
15
|
+
};
|
|
16
|
+
readonly include_graph: {
|
|
17
|
+
readonly type: "boolean";
|
|
18
|
+
readonly default: true;
|
|
19
|
+
readonly description: "Include entity graph node/edge counts";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ok, fail } from '../response.js';
|
|
2
|
+
import { defaultSession } from '../client.js';
|
|
3
|
+
export async function toolStats(engram, input) {
|
|
4
|
+
const start = Date.now();
|
|
5
|
+
const sessionId = input.session_id ?? defaultSession();
|
|
6
|
+
try {
|
|
7
|
+
const stats = await engram.stats(sessionId);
|
|
8
|
+
const suggestions = [];
|
|
9
|
+
if (stats.byTier?.working > 80) {
|
|
10
|
+
suggestions.push(`${stats.byTier.working} working memories — consider running 'consolidate'`);
|
|
11
|
+
}
|
|
12
|
+
if (stats.total === 0) {
|
|
13
|
+
suggestions.push(`No memories in session '${sessionId}' — use 'remember' to start storing memories`);
|
|
14
|
+
}
|
|
15
|
+
return ok({
|
|
16
|
+
session_id: sessionId,
|
|
17
|
+
total_memories: stats.total,
|
|
18
|
+
by_role: stats.byRole,
|
|
19
|
+
by_tier: stats.byTier,
|
|
20
|
+
oldest: stats.oldest?.toISOString() ?? null,
|
|
21
|
+
newest: stats.newest?.toISOString() ?? null,
|
|
22
|
+
with_embeddings: stats.withEmbeddings,
|
|
23
|
+
avg_importance: stats.avgImportance != null
|
|
24
|
+
? Math.round(stats.avgImportance * 100) / 100
|
|
25
|
+
: null,
|
|
26
|
+
graph: input.include_graph !== false ? {
|
|
27
|
+
nodes: stats.graphNodes ?? 0,
|
|
28
|
+
edges: stats.graphEdges ?? 0,
|
|
29
|
+
} : undefined,
|
|
30
|
+
}, sessionId, start, suggestions);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
return fail('STATS_FAILED', String(err), sessionId, start);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const STATS_SCHEMA = {
|
|
37
|
+
name: 'stats',
|
|
38
|
+
description: 'Get memory statistics for a session: counts by role/tier, embeddings coverage, importance scores, and graph metrics.',
|
|
39
|
+
inputSchema: {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
session_id: { type: 'string' },
|
|
43
|
+
include_graph: { type: 'boolean', default: true, description: 'Include entity graph node/edge counts' },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=stats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/tools/stats.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAO9C,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc,EAAE,KAAiB;IAC/D,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,IAAI,cAAc,EAAE,CAAC;IAEvD,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAE5C,MAAM,WAAW,GAAa,EAAE,CAAC;QACjC,IAAI,KAAK,CAAC,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,CAAC;YAC/B,WAAW,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,oDAAoD,CAAC,CAAC;QAChG,CAAC;QACD,IAAI,KAAK,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;YACtB,WAAW,CAAC,IAAI,CAAC,2BAA2B,SAAS,8CAA8C,CAAC,CAAC;QACvG,CAAC;QAED,OAAO,EAAE,CAAC;YACR,UAAU,EAAE,SAAS;YACrB,cAAc,EAAE,KAAK,CAAC,KAAK;YAC3B,OAAO,EAAE,KAAK,CAAC,MAAM;YACrB,OAAO,EAAE,KAAK,CAAC,MAAM;YACrB,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,IAAI;YAC3C,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,WAAW,EAAE,IAAI,IAAI;YAC3C,eAAe,EAAE,KAAK,CAAC,cAAc;YACrC,cAAc,EAAE,KAAK,CAAC,aAAa,IAAI,IAAI;gBACzC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,aAAa,GAAG,GAAG,CAAC,GAAG,GAAG;gBAC7C,CAAC,CAAC,IAAI;YACR,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,KAAK,CAAC,CAAC,CAAC;gBACrC,KAAK,EAAE,KAAK,CAAC,UAAU,IAAI,CAAC;gBAC5B,KAAK,EAAE,KAAK,CAAC,UAAU,IAAI,CAAC;aAC7B,CAAC,CAAC,CAAC,SAAS;SACd,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAEpC,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,OAAO;IACb,WAAW,EAAE,sHAAsH;IACnI,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC9B,aAAa,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,uCAAuC,EAAE;SACxG;KACF;CACO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cartisien/engram-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "MCP server for
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "MCP server for Engram — structured agent memory as relational intelligence",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/
|
|
6
|
+
"main": "dist/server.js",
|
|
7
7
|
"bin": {
|
|
8
|
-
"engram-mcp": "dist/
|
|
9
|
-
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"start": "node dist/src/index.js"
|
|
8
|
+
"engram-mcp": "dist/server.js"
|
|
13
9
|
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
13
|
+
],
|
|
14
|
+
"keywords": [
|
|
15
|
+
"mcp",
|
|
16
|
+
"ai",
|
|
17
|
+
"memory",
|
|
18
|
+
"engram",
|
|
19
|
+
"agents"
|
|
20
|
+
],
|
|
21
|
+
"author": "Cartisien Interactive",
|
|
22
|
+
"license": "MIT",
|
|
14
23
|
"dependencies": {
|
|
15
|
-
"@cartisien/engram": "^0.6.1",
|
|
16
24
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
17
|
-
"
|
|
25
|
+
"@cartisien/engram": "2.0.0"
|
|
18
26
|
},
|
|
19
27
|
"devDependencies": {
|
|
20
|
-
"@types/node": "^20.
|
|
21
|
-
"typescript": "^5.
|
|
22
|
-
|
|
28
|
+
"@types/node": "^20.11.0",
|
|
29
|
+
"typescript": "^5.3.3"
|
|
30
|
+
},
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc",
|
|
36
|
+
"dev": "tsc --watch",
|
|
37
|
+
"start": "node dist/server.js"
|
|
23
38
|
}
|
|
24
|
-
}
|
|
39
|
+
}
|
package/README.md
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
# @cartisien/engram-mcp
|
|
2
|
-
|
|
3
|
-
> Persistent semantic memory for AI agents — MCP server powered by [@cartisien/engram](https://github.com/Cartisien/engram)
|
|
4
|
-
|
|
5
|
-
Give any MCP-compatible AI client (Claude Desktop, Cursor, Windsurf) persistent memory that survives across sessions.
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
npx -y @cartisien/engram-mcp
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## What it does
|
|
14
|
-
|
|
15
|
-
Exposes 5 tools to any MCP client:
|
|
16
|
-
|
|
17
|
-
| Tool | Description |
|
|
18
|
-
|------|-------------|
|
|
19
|
-
| `remember` | Store a memory with automatic embedding |
|
|
20
|
-
| `recall` | Semantic search across stored memories |
|
|
21
|
-
| `history` | Recent conversation history |
|
|
22
|
-
| `forget` | Delete one memory, a session, or entries before a date |
|
|
23
|
-
| `stats` | Memory statistics for a session |
|
|
24
|
-
|
|
25
|
-
Memories are stored in SQLite. Semantic search uses local Ollama embeddings (`nomic-embed-text`) — no API key, no cloud. Falls back to keyword search if Ollama isn't available.
|
|
26
|
-
|
|
27
|
-
---
|
|
28
|
-
|
|
29
|
-
## Quick Start
|
|
30
|
-
|
|
31
|
-
### Claude Desktop
|
|
32
|
-
|
|
33
|
-
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
34
|
-
|
|
35
|
-
```json
|
|
36
|
-
{
|
|
37
|
-
"mcpServers": {
|
|
38
|
-
"engram": {
|
|
39
|
-
"command": "npx",
|
|
40
|
-
"args": ["-y", "@cartisien/engram-mcp"],
|
|
41
|
-
"env": {
|
|
42
|
-
"ENGRAM_DB": "~/.engram/memory.db"
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Restart Claude Desktop. You'll see `remember`, `recall`, `history`, `forget`, and `stats` available as tools.
|
|
50
|
-
|
|
51
|
-
### Cursor / Windsurf
|
|
52
|
-
|
|
53
|
-
Add to your MCP config:
|
|
54
|
-
|
|
55
|
-
```json
|
|
56
|
-
{
|
|
57
|
-
"mcpServers": {
|
|
58
|
-
"engram": {
|
|
59
|
-
"command": "npx",
|
|
60
|
-
"args": ["-y", "@cartisien/engram-mcp"]
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
---
|
|
67
|
-
|
|
68
|
-
## Configuration
|
|
69
|
-
|
|
70
|
-
| Env Var | Default | Description |
|
|
71
|
-
|---------|---------|-------------|
|
|
72
|
-
| `ENGRAM_DB` | `~/.engram/memory.db` | SQLite database path |
|
|
73
|
-
| `ENGRAM_EMBEDDING_URL` | `http://localhost:11434` | Ollama base URL for embeddings |
|
|
74
|
-
|
|
75
|
-
### Local Embeddings (Recommended)
|
|
76
|
-
|
|
77
|
-
Install [Ollama](https://ollama.ai) and pull the embedding model:
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
ollama pull nomic-embed-text
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
Semantic search activates automatically. Without Ollama, keyword search is used.
|
|
84
|
-
|
|
85
|
-
---
|
|
86
|
-
|
|
87
|
-
## Example Usage
|
|
88
|
-
|
|
89
|
-
Once connected, your agent can:
|
|
90
|
-
|
|
91
|
-
```
|
|
92
|
-
remember(sessionId="myagent", content="User prefers TypeScript over JavaScript", role="user")
|
|
93
|
-
|
|
94
|
-
recall(sessionId="myagent", query="what are the user's coding preferences?", limit=5)
|
|
95
|
-
# Returns: [{ content: "User prefers TypeScript...", similarity: 0.82 }, ...]
|
|
96
|
-
|
|
97
|
-
history(sessionId="myagent", limit=10)
|
|
98
|
-
|
|
99
|
-
stats(sessionId="myagent")
|
|
100
|
-
# { total: 42, byRole: { user: 20, assistant: 22 }, withEmbeddings: 42 }
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## Part of the Cartisien Memory Suite
|
|
106
|
-
|
|
107
|
-
- [`@cartisien/engram`](https://github.com/Cartisien/engram) — core memory SDK
|
|
108
|
-
- `@cartisien/engram-mcp` — this package, MCP server
|
|
109
|
-
- `@cartisien/extensa` — vector infrastructure *(coming soon)*
|
|
110
|
-
- `@cartisien/cogito` — agent identity & lifecycle *(coming soon)*
|
|
111
|
-
|
|
112
|
-
---
|
|
113
|
-
|
|
114
|
-
MIT © [Cartisien Interactive](https://cartisien.com)
|
package/dist/engram.d.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
export interface MemoryEntry {
|
|
2
|
-
id: string;
|
|
3
|
-
sessionId: string;
|
|
4
|
-
content: string;
|
|
5
|
-
role: 'user' | 'assistant' | 'system';
|
|
6
|
-
timestamp: Date;
|
|
7
|
-
metadata?: Record<string, unknown>;
|
|
8
|
-
similarity?: number;
|
|
9
|
-
}
|
|
10
|
-
export interface RecallOptions {
|
|
11
|
-
limit?: number;
|
|
12
|
-
before?: Date;
|
|
13
|
-
after?: Date;
|
|
14
|
-
role?: 'user' | 'assistant' | 'system';
|
|
15
|
-
}
|
|
16
|
-
export interface EngramConfig {
|
|
17
|
-
dbPath?: string;
|
|
18
|
-
maxContextLength?: number;
|
|
19
|
-
embeddingUrl?: string;
|
|
20
|
-
embeddingModel?: string;
|
|
21
|
-
semanticSearch?: boolean;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Engram - Persistent memory for AI assistants
|
|
25
|
-
*
|
|
26
|
-
* A lightweight, SQLite-backed memory system that gives your AI assistants
|
|
27
|
-
* the ability to remember conversations across sessions.
|
|
28
|
-
* v0.2 adds semantic search via Ollama embeddings (nomic-embed-text).
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
* ```typescript
|
|
32
|
-
* import { Engram } from '@cartisien/engram';
|
|
33
|
-
*
|
|
34
|
-
* const memory = new Engram({ dbPath: './memory.db' });
|
|
35
|
-
*
|
|
36
|
-
* // Store a memory
|
|
37
|
-
* await memory.remember('user_123', 'User prefers dark mode and TypeScript', 'user');
|
|
38
|
-
*
|
|
39
|
-
* // Retrieve relevant memories semantically
|
|
40
|
-
* const context = await memory.recall('user_123', 'What are this user\'s preferences?', 5);
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare class Engram {
|
|
44
|
-
private db;
|
|
45
|
-
private maxContextLength;
|
|
46
|
-
private dbPath;
|
|
47
|
-
private initialized;
|
|
48
|
-
private embeddingUrl;
|
|
49
|
-
private embeddingModel;
|
|
50
|
-
private semanticSearch;
|
|
51
|
-
constructor(config?: EngramConfig);
|
|
52
|
-
private init;
|
|
53
|
-
/**
|
|
54
|
-
* Fetch embedding vector from Ollama
|
|
55
|
-
*/
|
|
56
|
-
private embed;
|
|
57
|
-
/**
|
|
58
|
-
* Cosine similarity between two vectors
|
|
59
|
-
*/
|
|
60
|
-
private cosineSimilarity;
|
|
61
|
-
/**
|
|
62
|
-
* Store a memory entry
|
|
63
|
-
*/
|
|
64
|
-
remember(sessionId: string, content: string, role?: 'user' | 'assistant' | 'system', metadata?: Record<string, unknown>): Promise<MemoryEntry>;
|
|
65
|
-
/**
|
|
66
|
-
* Recall memories for a session.
|
|
67
|
-
*
|
|
68
|
-
* With semantic search enabled (default), embeds the query and ranks
|
|
69
|
-
* results by cosine similarity. Falls back to keyword search if Ollama
|
|
70
|
-
* is unreachable or no embeddings are stored.
|
|
71
|
-
*/
|
|
72
|
-
recall(sessionId: string, query?: string, limit?: number, options?: RecallOptions): Promise<MemoryEntry[]>;
|
|
73
|
-
/**
|
|
74
|
-
* Get recent conversation history for a session
|
|
75
|
-
*/
|
|
76
|
-
history(sessionId: string, limit?: number): Promise<MemoryEntry[]>;
|
|
77
|
-
/**
|
|
78
|
-
* Forget (delete) memories
|
|
79
|
-
*/
|
|
80
|
-
forget(sessionId: string, options?: {
|
|
81
|
-
before?: Date;
|
|
82
|
-
id?: string;
|
|
83
|
-
}): Promise<number>;
|
|
84
|
-
/**
|
|
85
|
-
* Get memory statistics for a session
|
|
86
|
-
*/
|
|
87
|
-
stats(sessionId: string): Promise<{
|
|
88
|
-
total: number;
|
|
89
|
-
byRole: Record<string, number>;
|
|
90
|
-
oldest: Date | null;
|
|
91
|
-
newest: Date | null;
|
|
92
|
-
withEmbeddings: number;
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* Close the database connection
|
|
96
|
-
*/
|
|
97
|
-
close(): Promise<void>;
|
|
98
|
-
}
|
|
99
|
-
export default Engram;
|