@j0hanz/memory-mcp 1.0.1 → 1.2.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/dist/completions/index.d.ts.map +1 -1
- package/dist/completions/index.js +3 -3
- package/dist/completions/index.js.map +1 -1
- package/dist/lib/errors.d.ts +1 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +1 -0
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/instructions.d.ts.map +1 -1
- package/dist/lib/instructions.js +2 -19
- package/dist/lib/instructions.js.map +1 -1
- package/dist/lib/sql.d.ts +17 -0
- package/dist/lib/sql.d.ts.map +1 -0
- package/dist/lib/sql.js +18 -0
- package/dist/lib/sql.js.map +1 -0
- package/dist/lib/tool-contracts.d.ts +18 -0
- package/dist/lib/tool-contracts.d.ts.map +1 -0
- package/dist/lib/tool-contracts.js +175 -0
- package/dist/lib/tool-contracts.js.map +1 -0
- package/dist/lib/tool-response.d.ts.map +1 -1
- package/dist/lib/tool-response.js +7 -8
- package/dist/lib/tool-response.js.map +1 -1
- package/dist/prompts/index.js +2 -2
- package/dist/prompts/index.js.map +1 -1
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +74 -10
- package/dist/resources/index.js.map +1 -1
- package/dist/resources/instructions.d.ts +2 -0
- package/dist/resources/instructions.d.ts.map +1 -0
- package/dist/resources/instructions.js +106 -0
- package/dist/resources/instructions.js.map +1 -0
- package/dist/resources/server-config.d.ts +2 -0
- package/dist/resources/server-config.d.ts.map +1 -0
- package/dist/resources/server-config.js +72 -0
- package/dist/resources/server-config.js.map +1 -0
- package/dist/resources/tool-catalog.d.ts +2 -0
- package/dist/resources/tool-catalog.d.ts.map +1 -0
- package/dist/resources/tool-catalog.js +64 -0
- package/dist/resources/tool-catalog.js.map +1 -0
- package/dist/resources/tool-info.d.ts +5 -0
- package/dist/resources/tool-info.d.ts.map +1 -0
- package/dist/resources/tool-info.js +129 -0
- package/dist/resources/tool-info.js.map +1 -0
- package/dist/resources/workflows.d.ts +2 -0
- package/dist/resources/workflows.d.ts.map +1 -0
- package/dist/resources/workflows.js +55 -0
- package/dist/resources/workflows.js.map +1 -0
- package/dist/schemas/inputs.d.ts +1 -1
- package/dist/schemas/inputs.d.ts.map +1 -1
- package/dist/schemas/inputs.js +55 -27
- package/dist/schemas/inputs.js.map +1 -1
- package/dist/schemas/outputs.d.ts.map +1 -1
- package/dist/schemas/outputs.js +144 -91
- package/dist/schemas/outputs.js.map +1 -1
- package/dist/tools/create-relationship.d.ts.map +1 -1
- package/dist/tools/create-relationship.js +10 -8
- package/dist/tools/create-relationship.js.map +1 -1
- package/dist/tools/delete-memories.d.ts.map +1 -1
- package/dist/tools/delete-memories.js +19 -15
- package/dist/tools/delete-memories.js.map +1 -1
- package/dist/tools/delete-memory.js +11 -9
- package/dist/tools/delete-memory.js.map +1 -1
- package/dist/tools/delete-relationship.d.ts.map +1 -1
- package/dist/tools/delete-relationship.js +10 -8
- package/dist/tools/delete-relationship.js.map +1 -1
- package/dist/tools/get-memory.d.ts.map +1 -1
- package/dist/tools/get-memory.js +11 -9
- package/dist/tools/get-memory.js.map +1 -1
- package/dist/tools/get-relationships.d.ts.map +1 -1
- package/dist/tools/get-relationships.js +46 -26
- package/dist/tools/get-relationships.js.map +1 -1
- package/dist/tools/memory-stats.d.ts.map +1 -1
- package/dist/tools/memory-stats.js +19 -35
- package/dist/tools/memory-stats.js.map +1 -1
- package/dist/tools/progress.d.ts.map +1 -1
- package/dist/tools/progress.js +13 -8
- package/dist/tools/progress.js.map +1 -1
- package/dist/tools/recall.js +15 -15
- package/dist/tools/recall.js.map +1 -1
- package/dist/tools/result.d.ts +2 -0
- package/dist/tools/result.d.ts.map +1 -1
- package/dist/tools/result.js +5 -0
- package/dist/tools/result.js.map +1 -1
- package/dist/tools/retrieve-context.d.ts.map +1 -1
- package/dist/tools/retrieve-context.js +38 -26
- package/dist/tools/retrieve-context.js.map +1 -1
- package/dist/tools/search-memories.d.ts.map +1 -1
- package/dist/tools/search-memories.js +10 -8
- package/dist/tools/search-memories.js.map +1 -1
- package/dist/tools/store-memories.d.ts.map +1 -1
- package/dist/tools/store-memories.js +19 -15
- package/dist/tools/store-memories.js.map +1 -1
- package/dist/tools/store-memory.js +11 -10
- package/dist/tools/store-memory.js.map +1 -1
- package/dist/tools/update-memory.d.ts.map +1 -1
- package/dist/tools/update-memory.js +47 -32
- package/dist/tools/update-memory.js.map +1 -1
- package/package.json +1 -2
- package/dist/instructions.md +0 -169
|
@@ -2,18 +2,20 @@ import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
|
|
|
2
2
|
import { splitPage } from '../lib/pagination.js';
|
|
3
3
|
import { buildSearchCursorScope, decodeSearchCursor, encodeSearchCursor, } from '../lib/search-cursor.js';
|
|
4
4
|
import { loadRankedSearchRows, toMemoryFilters } from '../lib/search.js';
|
|
5
|
+
import { getToolContract } from '../lib/tool-contracts.js';
|
|
5
6
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
6
7
|
import { parseMemoryRow } from '../lib/types.js';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
8
|
+
import {} from '../schemas/inputs.js';
|
|
9
|
+
import {} from '../schemas/outputs.js';
|
|
9
10
|
import { wrapToolHandler } from './progress.js';
|
|
10
11
|
export function registerSearchMemories(server, db) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
const contract = getToolContract('search_memories');
|
|
13
|
+
server.registerTool(contract.name, {
|
|
14
|
+
title: contract.title,
|
|
15
|
+
description: contract.description,
|
|
16
|
+
inputSchema: contract.inputSchema,
|
|
17
|
+
outputSchema: contract.outputSchema,
|
|
18
|
+
annotations: contract.annotations,
|
|
17
19
|
}, wrapToolHandler((params) => {
|
|
18
20
|
try {
|
|
19
21
|
const { limit, cursor } = params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-memories.js","sourceRoot":"","sources":["../../src/tools/search-memories.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,
|
|
1
|
+
{"version":3,"file":"search-memories.js","sourceRoot":"","sources":["../../src/tools/search-memories.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAkC,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAA2B,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD,MAAM,UAAU,sBAAsB,CAAC,MAAiB,EAAE,EAAW;IACnE,MAAM,QAAQ,GAAG,eAAe,CAAC,iBAAiB,CAAC,C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,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;gBAC7D,CAAC;YACH,CAAC;YAED,OAAO,kBAAkB,CAAC;gBACxB,QAAQ;gBACR,cAAc,EAAE,QAAQ,CAAC,MAAM;gBAC/B,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,eAAe,CAAC,GAAG,CAAC,CAAC;YACrB,OAAO,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,EACD;QACE,eAAe,EAAE,CAAC,MAAmB,EAAE,EAAE,CACvC,sBAAsB,MAAM,CAAC,KAAK,WAAW,MAAM,CAAC,KAAK,GAAG;KAC/D,CACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-memories.d.ts","sourceRoot":"","sources":["../../src/tools/store-memories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"store-memories.d.ts","sourceRoot":"","sources":["../../src/tools/store-memories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA2B9C,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAoE1E"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
|
|
2
2
|
import { computeMemoryHash } from '../lib/hash.js';
|
|
3
3
|
import { logToolEvent, notifyMemoryResourceUpdated } from '../lib/mcp-utils.js';
|
|
4
|
+
import { INSERT_MEMORY_SQL } from '../lib/sql.js';
|
|
5
|
+
import { getToolContract } from '../lib/tool-contracts.js';
|
|
4
6
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
+
import {} from '../schemas/inputs.js';
|
|
8
|
+
import {} from '../schemas/outputs.js';
|
|
7
9
|
import { wrapToolHandler } from './progress.js';
|
|
8
|
-
const INSERT_MEMORY_SQL = `INSERT OR IGNORE INTO memories (hash, content, tags, memory_type, importance, created_at, updated_at)
|
|
9
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`;
|
|
10
|
-
function countCreated(items) {
|
|
11
|
-
return items.reduce((count, item) => (item.created ? count + 1 : count), 0);
|
|
12
|
-
}
|
|
13
10
|
async function notifyCreatedResources(server, items) {
|
|
14
11
|
const notifications = items
|
|
15
12
|
.filter((item) => item.created)
|
|
@@ -17,12 +14,13 @@ async function notifyCreatedResources(server, items) {
|
|
|
17
14
|
await Promise.allSettled(notifications);
|
|
18
15
|
}
|
|
19
16
|
export function registerStoreMemories(server, db) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
const contract = getToolContract('store_memories');
|
|
18
|
+
server.registerTool(contract.name, {
|
|
19
|
+
title: contract.title,
|
|
20
|
+
description: contract.description,
|
|
21
|
+
inputSchema: contract.inputSchema,
|
|
22
|
+
outputSchema: contract.outputSchema,
|
|
23
|
+
annotations: contract.annotations,
|
|
26
24
|
}, wrapToolHandler(async (params) => {
|
|
27
25
|
try {
|
|
28
26
|
const now = new Date().toISOString();
|
|
@@ -43,8 +41,14 @@ export function registerStoreMemories(server, db) {
|
|
|
43
41
|
}
|
|
44
42
|
return items;
|
|
45
43
|
});
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
let created = 0;
|
|
45
|
+
let succeeded = 0;
|
|
46
|
+
for (const item of results) {
|
|
47
|
+
if (item.ok)
|
|
48
|
+
succeeded += 1;
|
|
49
|
+
if (item.created)
|
|
50
|
+
created += 1;
|
|
51
|
+
}
|
|
48
52
|
const failed = results.length - succeeded;
|
|
49
53
|
await logToolEvent(server, 'store_memories', {
|
|
50
54
|
total: results.length,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-memories.js","sourceRoot":"","sources":["../../src/tools/store-memories.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,
|
|
1
|
+
{"version":3,"file":"store-memories.js","sourceRoot":"","sources":["../../src/tools/store-memories.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAiC,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAA0B,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD,KAAK,UAAU,sBAAsB,CACnC,MAAiB,EACjB,KAAiC;IAEjC,MAAM,aAAa,GAAG,KAAK;SACxB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE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CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
|
|
2
2
|
import { computeMemoryHash } from '../lib/hash.js';
|
|
3
3
|
import { logToolEvent, notifyMemoryResourceUpdated } from '../lib/mcp-utils.js';
|
|
4
|
+
import { INSERT_MEMORY_SQL } from '../lib/sql.js';
|
|
5
|
+
import { getToolContract } from '../lib/tool-contracts.js';
|
|
4
6
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
+
import {} from '../schemas/inputs.js';
|
|
8
|
+
import {} from '../schemas/outputs.js';
|
|
7
9
|
import { wrapToolHandler } from './progress.js';
|
|
8
|
-
const INSERT_MEMORY_SQL = `INSERT OR IGNORE INTO memories (hash, content, tags, memory_type, importance, created_at, updated_at)
|
|
9
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`;
|
|
10
10
|
function toInsertParams(params, hash, memoryType, now) {
|
|
11
11
|
return [
|
|
12
12
|
hash,
|
|
@@ -25,12 +25,13 @@ function insertMemory(db, params, hash, memoryType, now) {
|
|
|
25
25
|
return insertResult.changes > 0;
|
|
26
26
|
}
|
|
27
27
|
export function registerStoreMemory(server, db) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
const contract = getToolContract('store_memory');
|
|
29
|
+
server.registerTool(contract.name, {
|
|
30
|
+
title: contract.title,
|
|
31
|
+
description: contract.description,
|
|
32
|
+
inputSchema: contract.inputSchema,
|
|
33
|
+
outputSchema: contract.outputSchema,
|
|
34
|
+
annotations: contract.annotations,
|
|
34
35
|
}, wrapToolHandler(async (params) => {
|
|
35
36
|
try {
|
|
36
37
|
const memoryType = params.memory_type ?? 'general';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store-memory.js","sourceRoot":"","sources":["../../src/tools/store-memory.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,
|
|
1
|
+
{"version":3,"file":"store-memory.js","sourceRoot":"","sources":["../../src/tools/store-memory.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAA+B,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAA0B,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD,SAAS,cAAc,CACrB,MAA2D,EAC3D,IAAY,EACZ,UAAkB,EAClB,GAAW;IAEX,OAAO;QACL,IAAI;QACJ,MAAM,CAAC,OAAO;QACd,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC;QAC3B,UAAU;QACV,MAAM,CAAC,UAAU;QACjB,GAAG;QACH,GAAG;KACJ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,EAAW,EACX,MAAkB,EAClB,IAAY,EACZ,UAAkB,EAClB,GAAW;IAEX,MAAM,YAAY,GAAG,EAAE;SACpB,WAA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e,CAAC,GAAG,CAAC,CAAC;YACrB,OAAO,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,EACD;QACE,eAAe,EAAE,CAAC,MAAkB,EAAE,EAAE,CACtC,mBAAmB,MAAM,CAAC,IAAI,CAAC,MAAM,gBAAgB;KACxD,CACF,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-memory.d.ts","sourceRoot":"","sources":["../../src/tools/update-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"update-memory.d.ts","sourceRoot":"","sources":["../../src/tools/update-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA8C9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAsFzE"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { E_CONFLICT, E_NOT_FOUND, E_UNKNOWN, getErrorMessage, rethrowMcpError, } from '../lib/errors.js';
|
|
2
2
|
import { computeMemoryHash } from '../lib/hash.js';
|
|
3
3
|
import { logToolEvent, notifyMemoryResourceUpdated } from '../lib/mcp-utils.js';
|
|
4
|
+
import { SELECT_MEMORY_BY_HASH_SQL, SELECT_MEMORY_HASH_SQL, } from '../lib/sql.js';
|
|
5
|
+
import { getToolContract } from '../lib/tool-contracts.js';
|
|
4
6
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
5
7
|
import { parseTags } from '../lib/types.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
+
import {} from '../schemas/inputs.js';
|
|
9
|
+
import {} from '../schemas/outputs.js';
|
|
8
10
|
import { wrapToolHandler } from './progress.js';
|
|
9
11
|
const UPDATE_MEMORY_SQL = `UPDATE memories
|
|
10
12
|
SET hash = ?, content = ?, tags = ?, updated_at = ?
|
|
11
13
|
WHERE hash = ?`;
|
|
12
|
-
const SELECT_MEMORY_BY_HASH_SQL = 'SELECT * FROM memories WHERE hash = ?';
|
|
13
|
-
const SELECT_MEMORY_HASH_SQL = 'SELECT hash FROM memories WHERE hash = ?';
|
|
14
14
|
async function notifyUpdatedMemoryResources(server, oldHash, newHash) {
|
|
15
15
|
const notifications = [notifyMemoryResourceUpdated(server, oldHash)];
|
|
16
16
|
if (newHash !== oldHash) {
|
|
@@ -19,42 +19,57 @@ async function notifyUpdatedMemoryResources(server, oldHash, newHash) {
|
|
|
19
19
|
await Promise.allSettled(notifications);
|
|
20
20
|
}
|
|
21
21
|
export function registerUpdateMemory(server, db) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
const contract = getToolContract('update_memory');
|
|
23
|
+
server.registerTool(contract.name, {
|
|
24
|
+
title: contract.title,
|
|
25
|
+
description: contract.description,
|
|
26
|
+
inputSchema: contract.inputSchema,
|
|
27
|
+
outputSchema: contract.outputSchema,
|
|
28
|
+
annotations: contract.annotations,
|
|
28
29
|
}, wrapToolHandler(async (params) => {
|
|
29
30
|
try {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (collision) {
|
|
43
|
-
return createErrorResponse(E_CONFLICT, `Memory already exists for target content/tags: ${newHash}`);
|
|
31
|
+
// All reads and the write are inside a single IMMEDIATE transaction
|
|
32
|
+
// to prevent TOCTOU between existence/collision checks and UPDATE.
|
|
33
|
+
const txResult = db.transaction(() => {
|
|
34
|
+
const existing = db
|
|
35
|
+
.prepareOnce(SELECT_MEMORY_BY_HASH_SQL)
|
|
36
|
+
.get(params.hash);
|
|
37
|
+
if (!existing) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
code: E_NOT_FOUND,
|
|
41
|
+
message: `Memory not found: ${params.hash}`,
|
|
42
|
+
};
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
const newTags = params.tags ?? parseTags(existing.tags);
|
|
45
|
+
const newHash = computeMemoryHash(params.content, newTags);
|
|
46
|
+
if (newHash !== params.hash) {
|
|
47
|
+
const collision = db
|
|
48
|
+
.prepareOnce(SELECT_MEMORY_HASH_SQL)
|
|
49
|
+
.get(newHash);
|
|
50
|
+
if (collision) {
|
|
51
|
+
return {
|
|
52
|
+
ok: false,
|
|
53
|
+
code: E_CONFLICT,
|
|
54
|
+
message: `Memory already exists for target content/tags: ${newHash}`,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const now = new Date().toISOString();
|
|
48
59
|
db.prepareOnce(UPDATE_MEMORY_SQL).run(newHash, params.content, JSON.stringify(newTags), now, params.hash);
|
|
60
|
+
return { ok: true, oldHash: params.hash, newHash };
|
|
49
61
|
});
|
|
62
|
+
if (!txResult.ok) {
|
|
63
|
+
return createErrorResponse(txResult.code, txResult.message);
|
|
64
|
+
}
|
|
50
65
|
await logToolEvent(server, 'update', {
|
|
51
|
-
oldHash:
|
|
52
|
-
newHash,
|
|
66
|
+
oldHash: txResult.oldHash,
|
|
67
|
+
newHash: txResult.newHash,
|
|
53
68
|
});
|
|
54
|
-
await notifyUpdatedMemoryResources(server,
|
|
69
|
+
await notifyUpdatedMemoryResources(server, txResult.oldHash, txResult.newHash);
|
|
55
70
|
return createToolResponse({
|
|
56
|
-
old_hash:
|
|
57
|
-
new_hash: newHash,
|
|
71
|
+
old_hash: txResult.oldHash,
|
|
72
|
+
new_hash: txResult.newHash,
|
|
58
73
|
});
|
|
59
74
|
}
|
|
60
75
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-memory.js","sourceRoot":"","sources":["../../src/tools/update-memory.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAkB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"update-memory.js","sourceRoot":"","sources":["../../src/tools/update-memory.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,UAAU,EACV,WAAW,EACX,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAChF,OAAO,EACL,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAkB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAgC,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAA2B,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIhD,MAAM,iBAAiB,GAAG;;iBAET,CAAC;AAMlB,K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BAC1B,QAAQ,EAAE,QAAQ,CAAC,OAAO;aAC3B,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,eAAe,CAAC,GAAG,CAAC,CAAC;YACrB,OAAO,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,CAAC;IACH,CAAC,EACD;QACE,eAAe,EAAE,CAAC,MAAmB,EAAE,EAAE,CACvC,oBAAoB,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAuB;KACtE,CACF,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@j0hanz/memory-mcp",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"mcpName": "io.github.j0hanz/memory-mcp",
|
|
5
5
|
"author": "Johanz",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
],
|
|
38
38
|
"scripts": {
|
|
39
39
|
"clean": "node scripts/tasks.mjs clean",
|
|
40
|
-
"validate:instructions": "node scripts/tasks.mjs validate:instructions",
|
|
41
40
|
"build": "node scripts/tasks.mjs build",
|
|
42
41
|
"copy:assets": "node scripts/tasks.mjs copy:assets",
|
|
43
42
|
"prepare": "npm run build",
|
package/dist/instructions.md
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
# MEMORY-MCP INSTRUCTIONS
|
|
2
|
-
|
|
3
|
-
These instructions are available as a resource (`internal://instructions`) or prompt (`get-help`). Load them when unsure about tool usage.
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
## CORE CAPABILITY
|
|
8
|
-
|
|
9
|
-
- **Domain:** SQLite-backed persistent memory storage, full-text search, and graph recall for LLM agents.
|
|
10
|
-
- **Primary Resources:** Memory entries (content + tags + metadata), directed labeled relationships between memories.
|
|
11
|
-
- **Tools:**
|
|
12
|
-
- READ: `get_memory`, `search_memories`, `recall`, `retrieve_context`, `get_relationships`, `memory_stats`
|
|
13
|
-
- WRITE: `store_memory`, `store_memories`, `update_memory`, `delete_memory`, `delete_memories`, `create_relationship`, `delete_relationship`
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## PROMPTS
|
|
18
|
-
|
|
19
|
-
- `get-help`: Returns these instructions for quick recall.
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## RESOURCES & RESOURCE LINKS
|
|
24
|
-
|
|
25
|
-
- `internal://instructions`: This document.
|
|
26
|
-
- `memory://memories/{hash}`: Retrieve a single memory by its SHA-256 hash (JSON). Supports hash auto-completion.
|
|
27
|
-
|
|
28
|
-
---
|
|
29
|
-
|
|
30
|
-
## THE "GOLDEN PATH" WORKFLOWS (CRITICAL)
|
|
31
|
-
|
|
32
|
-
### WORKFLOW A: STORE AND RETRIEVE
|
|
33
|
-
|
|
34
|
-
1. Call `store_memory` with `content`, `tags`, and optional `importance`/`memory_type` to persist a memory. Note the returned `hash`.
|
|
35
|
-
2. Call `get_memory` with `hash` to retrieve it later.
|
|
36
|
-
3. For bulk ingestion, call `store_memories` with up to 50 items in one atomic transaction.
|
|
37
|
-
NOTE: Storing identical content+tags is idempotent — returns the existing hash with `created: false`.
|
|
38
|
-
|
|
39
|
-
### WORKFLOW B: SEARCH AND DISCOVER
|
|
40
|
-
|
|
41
|
-
1. Call `search_memories` with a `query` string to full-text search across content and tags.
|
|
42
|
-
2. Use `cursor` from the response's `nextCursor` to paginate through results.
|
|
43
|
-
3. Apply filters: `min_importance`, `max_importance`, `memory_type` to narrow results.
|
|
44
|
-
NOTE: Query terms are matched individually. FTS5 phrase operators and negation are **not** supported.
|
|
45
|
-
|
|
46
|
-
### WORKFLOW C: GRAPH RECALL (BFS)
|
|
47
|
-
|
|
48
|
-
1. Call `recall` with a `query` and `depth` (0–3) to search memories and traverse relationships via BFS.
|
|
49
|
-
2. Inspect the returned `memories` (all discovered nodes) and `graph` (edges connecting them).
|
|
50
|
-
3. Use `depth: 0` for search-only (no traversal), `depth: 1–3` for progressively wider graph exploration.
|
|
51
|
-
NOTE: If `aborted: true` is returned, the traversal hit a safety limit. Results are still valid but incomplete.
|
|
52
|
-
|
|
53
|
-
### WORKFLOW D: CONTEXT WINDOW MANAGEMENT
|
|
54
|
-
|
|
55
|
-
1. Call `retrieve_context` with a `query` and `token_budget` to get relevance-ranked memories that fit within a token limit.
|
|
56
|
-
2. Choose `strategy`: `relevance` (FTS rank, default), `importance` (highest first), or `recency` (newest first).
|
|
57
|
-
3. Check `truncated: true` to know if more memories matched but were excluded by the budget.
|
|
58
|
-
NOTE: Eliminates manual pagination and token counting. Use this when filling an LLM context window.
|
|
59
|
-
|
|
60
|
-
### WORKFLOW E: BUILD KNOWLEDGE GRAPHS
|
|
61
|
-
|
|
62
|
-
1. Call `store_memory` (or `store_memories`) to create memories and note their hashes.
|
|
63
|
-
2. Call `create_relationship` with `from_hash`, `to_hash`, and `relation_type` to link them.
|
|
64
|
-
3. Call `get_relationships` to inspect edges for a memory (filter by `direction`: outgoing, incoming, or both).
|
|
65
|
-
4. Call `recall` with `depth: 1–3` to traverse the graph from a search query.
|
|
66
|
-
NOTE: Both endpoint memories must exist before creating a relationship.
|
|
67
|
-
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
## TOOL NUANCES & GOTCHAS
|
|
71
|
-
|
|
72
|
-
`store_memory`
|
|
73
|
-
|
|
74
|
-
- Purpose: Store a single memory. Returns its SHA-256 hash.
|
|
75
|
-
- Gotcha: Hash is deterministic — computed from `content` + sorted `tags`. Same content+tags always produces the same hash.
|
|
76
|
-
- Gotcha: `importance` defaults to `0` if omitted. `memory_type` defaults to `general`.
|
|
77
|
-
|
|
78
|
-
`store_memories`
|
|
79
|
-
|
|
80
|
-
- Purpose: Batch store up to 50 memories in one atomic transaction.
|
|
81
|
-
- Gotcha: If the transaction fails, all items roll back. Per-item results indicate `created: true/false`.
|
|
82
|
-
|
|
83
|
-
`update_memory`
|
|
84
|
-
|
|
85
|
-
- Purpose: Replace content (and optionally tags) of an existing memory. Returns old and new hashes.
|
|
86
|
-
- Gotcha: The hash changes when content or tags change. Relationships automatically cascade to the new hash.
|
|
87
|
-
- Gotcha: Returns `E_CONFLICT` if a memory already exists with the new content+tags combination.
|
|
88
|
-
|
|
89
|
-
`search_memories`
|
|
90
|
-
|
|
91
|
-
- Purpose: Full-text search over content and tags using SQLite FTS5.
|
|
92
|
-
- Input: `limit` defaults to 20, max 100. `cursor` from previous `nextCursor` for pagination.
|
|
93
|
-
- Gotcha: Only alphanumeric tokens are indexed. Special characters and FTS5 operators are stripped from queries.
|
|
94
|
-
|
|
95
|
-
`recall`
|
|
96
|
-
|
|
97
|
-
- Purpose: FTS search + BFS graph traversal up to 3 hops.
|
|
98
|
-
- Input: `depth` defaults to 1, max 3. `limit` defaults to 10 (seed memories), max 50.
|
|
99
|
-
- Gotcha: Traversal is bounded by frontier size (default 1,000), edge count (default 5,000), and visited nodes (default 5,000). Override via `RECALL_MAX_FRONTIER_SIZE`, `RECALL_MAX_EDGE_ROWS`, `RECALL_MAX_VISITED_NODES` env vars.
|
|
100
|
-
|
|
101
|
-
`retrieve_context`
|
|
102
|
-
|
|
103
|
-
- Purpose: Token-budgeted memory retrieval — fills a token budget with ranked results.
|
|
104
|
-
- Input: `token_budget` defaults to 4,000, max 200,000. `strategy` defaults to `relevance`.
|
|
105
|
-
- Gotcha: Token estimation uses ~4 characters per token. Internal candidate cap is 200 rows.
|
|
106
|
-
|
|
107
|
-
`get_relationships`
|
|
108
|
-
|
|
109
|
-
- Purpose: Retrieve all relationships for a memory with the linked memory content inlined.
|
|
110
|
-
- Input: `direction` defaults to `both`. Options: `outgoing`, `incoming`, `both`.
|
|
111
|
-
- Gotcha: Returns `E_NOT_FOUND` if the source memory does not exist.
|
|
112
|
-
|
|
113
|
-
`create_relationship`
|
|
114
|
-
|
|
115
|
-
- Purpose: Create a directed labeled edge between two memories.
|
|
116
|
-
- Input: `relation_type` is free-form. Suggested types: `related_to`, `causes`, `depends_on`, `parent_of`, `child_of`, `supersedes`, `contradicts`, `supports`, `references`.
|
|
117
|
-
- Gotcha: Idempotent — re-creating an existing relationship is a no-op. Both memories must exist.
|
|
118
|
-
|
|
119
|
-
`delete_memory`
|
|
120
|
-
|
|
121
|
-
- Purpose: Delete a single memory and all its relationships.
|
|
122
|
-
- Side effects: Cascade-deletes all relationships involving this memory.
|
|
123
|
-
|
|
124
|
-
`delete_memories`
|
|
125
|
-
|
|
126
|
-
- Purpose: Batch delete up to 50 memories in one atomic transaction.
|
|
127
|
-
- Side effects: Cascade-deletes all relationships involving deleted memories.
|
|
128
|
-
|
|
129
|
-
`memory_stats`
|
|
130
|
-
|
|
131
|
-
- Purpose: Return aggregate statistics (total counts, oldest/newest timestamps, average importance, breakdown by type).
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
## CROSS-FEATURE RELATIONSHIPS
|
|
136
|
-
|
|
137
|
-
- `store_memory` / `store_memories` produce hashes required by `get_memory`, `update_memory`, `delete_memory`, `create_relationship`, and `get_relationships`.
|
|
138
|
-
- `search_memories` and `recall` share the same FTS5 index, query sanitization, and cursor pagination.
|
|
139
|
-
- `recall` combines `search_memories`-style FTS seeding with BFS graph traversal from `get_relationships`-style edge queries.
|
|
140
|
-
- `retrieve_context` uses the same FTS5 index but adds token budgeting and sort strategies on top.
|
|
141
|
-
- `update_memory` changes a memory's hash — relationships cascade automatically via foreign keys.
|
|
142
|
-
- `delete_memory` / `delete_memories` cascade-delete relationships via foreign keys.
|
|
143
|
-
|
|
144
|
-
---
|
|
145
|
-
|
|
146
|
-
## CONSTRAINTS & LIMITATIONS
|
|
147
|
-
|
|
148
|
-
- **Transport:** stdio only.
|
|
149
|
-
- **Runtime:** Node.js >= 24 with FTS5-enabled SQLite.
|
|
150
|
-
- **Database path:** Set via `MEMORY_DB_PATH` env var (default: `memory.db`).
|
|
151
|
-
- **Content size:** Max 100,000 characters per memory.
|
|
152
|
-
- **Tags:** 1–100 tags per memory, each max 50 characters, no whitespace.
|
|
153
|
-
- **Importance:** Integer 0–10 (0 = lowest, 10 = critical).
|
|
154
|
-
- **Memory types:** `general`, `fact`, `plan`, `decision`, `reflection`, `lesson`, `error`, `gradient`.
|
|
155
|
-
- **Search limit:** Max 100 results per query (default 20).
|
|
156
|
-
- **Recall depth:** Max 3 hops (default 1). Seed limit max 50 (default 10).
|
|
157
|
-
- **Retrieve context budget:** Max 200,000 tokens (default 4,000). Internal candidate cap: 200 rows.
|
|
158
|
-
- **Batch operations:** Max 50 items per `store_memories` / `delete_memories` call.
|
|
159
|
-
- **BFS safety limits:** Configurable via `RECALL_MAX_FRONTIER_SIZE` (default 1,000), `RECALL_MAX_EDGE_ROWS` (default 5,000), `RECALL_MAX_VISITED_NODES` (default 5,000).
|
|
160
|
-
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
## ERROR HANDLING STRATEGY
|
|
164
|
-
|
|
165
|
-
- `E_NOT_FOUND`: Memory or relationship does not exist. → Call `search_memories` to find the correct hash, or verify the hash with `get_memory`.
|
|
166
|
-
- `E_INVALID_CURSOR`: Pagination cursor is malformed or does not match the current query/filters. → Drop the cursor and restart pagination from the beginning.
|
|
167
|
-
- `E_CONFLICT`: `update_memory` target content+tags already exists as another memory. → Call `get_memory` with the conflicting hash or choose different content/tags.
|
|
168
|
-
- `E_DB_ERROR`: Database operation failed. → Check that the database file is accessible and not corrupted. Retry the operation.
|
|
169
|
-
- `E_UNKNOWN`: Unexpected internal error. → Retry the operation. If persistent, inspect server logs.
|