@j0hanz/memory-mcp 1.5.0 → 1.6.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 +1 -0
- package/dist/completions/index.d.ts.map +1 -0
- package/dist/db/index.d.ts +1 -0
- package/dist/db/index.d.ts.map +1 -0
- package/dist/db/index.js +10 -8
- package/dist/db/typed.d.ts +1 -0
- package/dist/db/typed.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib/errors.d.ts +1 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/hash.d.ts +1 -0
- package/dist/lib/hash.d.ts.map +1 -0
- package/dist/lib/instructions.d.ts +1 -0
- package/dist/lib/instructions.d.ts.map +1 -0
- package/dist/lib/json-schema.d.ts +1 -0
- package/dist/lib/json-schema.d.ts.map +1 -0
- package/dist/lib/mcp-utils.d.ts +1 -0
- package/dist/lib/mcp-utils.d.ts.map +1 -0
- package/dist/lib/pagination.d.ts +1 -0
- package/dist/lib/pagination.d.ts.map +1 -0
- package/dist/lib/search-cursor.d.ts +1 -0
- package/dist/lib/search-cursor.d.ts.map +1 -0
- package/dist/lib/search.d.ts +1 -0
- package/dist/lib/search.d.ts.map +1 -0
- package/dist/lib/search.js +31 -23
- package/dist/lib/sql.d.ts +1 -0
- package/dist/lib/sql.d.ts.map +1 -0
- package/dist/lib/tool-contracts.d.ts +1 -0
- package/dist/lib/tool-contracts.d.ts.map +1 -0
- package/dist/lib/tool-contracts.js +65 -93
- package/dist/lib/tool-execution.d.ts +13 -0
- package/dist/lib/tool-execution.d.ts.map +1 -0
- package/dist/lib/tool-execution.js +28 -0
- package/dist/lib/tool-response.d.ts +1 -0
- package/dist/lib/tool-response.d.ts.map +1 -0
- package/dist/lib/types.d.ts +1 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/prompts/index.d.ts +1 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +12 -8
- package/dist/resources/index.d.ts +1 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +65 -38
- package/dist/resources/instructions.d.ts +1 -0
- package/dist/resources/instructions.d.ts.map +1 -0
- package/dist/resources/instructions.js +44 -37
- package/dist/resources/server-config.d.ts +1 -0
- package/dist/resources/server-config.d.ts.map +1 -0
- package/dist/resources/server-config.js +33 -22
- package/dist/resources/tool-catalog.d.ts +1 -0
- package/dist/resources/tool-catalog.d.ts.map +1 -0
- package/dist/resources/tool-catalog.js +10 -5
- package/dist/resources/tool-info.d.ts +1 -0
- package/dist/resources/tool-info.d.ts.map +1 -0
- package/dist/resources/tool-info.js +17 -8
- package/dist/resources/workflows.d.ts +1 -0
- package/dist/resources/workflows.d.ts.map +1 -0
- package/dist/resources/workflows.js +69 -40
- package/dist/schemas/index.d.ts +1 -0
- package/dist/schemas/index.d.ts.map +1 -0
- package/dist/schemas/inputs.d.ts +1 -0
- package/dist/schemas/inputs.d.ts.map +1 -0
- package/dist/schemas/inputs.js +14 -10
- package/dist/schemas/outputs.d.ts +7 -6
- package/dist/schemas/outputs.d.ts.map +1 -0
- package/dist/schemas/outputs.js +7 -6
- package/dist/server.d.ts +1 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +11 -4
- package/dist/tools/create-relationship.d.ts +1 -0
- package/dist/tools/create-relationship.d.ts.map +1 -0
- package/dist/tools/create-relationship.js +14 -19
- package/dist/tools/delete-memories.d.ts +1 -0
- package/dist/tools/delete-memories.d.ts.map +1 -0
- package/dist/tools/delete-memories.js +27 -37
- package/dist/tools/delete-memory.d.ts +1 -0
- package/dist/tools/delete-memory.d.ts.map +1 -0
- package/dist/tools/delete-memory.js +9 -15
- package/dist/tools/delete-relationship.d.ts +1 -0
- package/dist/tools/delete-relationship.d.ts.map +1 -0
- package/dist/tools/delete-relationship.js +7 -12
- package/dist/tools/get-memory.d.ts +1 -0
- package/dist/tools/get-memory.d.ts.map +1 -0
- package/dist/tools/get-memory.js +9 -14
- package/dist/tools/get-relationships.d.ts +1 -0
- package/dist/tools/get-relationships.d.ts.map +1 -0
- package/dist/tools/get-relationships.js +12 -17
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/memory-stats.d.ts +1 -0
- package/dist/tools/memory-stats.d.ts.map +1 -0
- package/dist/tools/memory-stats.js +22 -28
- package/dist/tools/progress.d.ts +1 -0
- package/dist/tools/progress.d.ts.map +1 -0
- package/dist/tools/progress.js +30 -23
- package/dist/tools/recall.d.ts +1 -0
- package/dist/tools/recall.d.ts.map +1 -0
- package/dist/tools/recall.js +77 -48
- package/dist/tools/register-contract.d.ts +1 -0
- package/dist/tools/register-contract.d.ts.map +1 -0
- package/dist/tools/result.d.ts +1 -0
- package/dist/tools/result.d.ts.map +1 -0
- package/dist/tools/retrieve-context.d.ts +1 -0
- package/dist/tools/retrieve-context.d.ts.map +1 -0
- package/dist/tools/retrieve-context.js +47 -33
- package/dist/tools/search-memories.d.ts +1 -0
- package/dist/tools/search-memories.d.ts.map +1 -0
- package/dist/tools/search-memories.js +24 -30
- package/dist/tools/store-memories.d.ts +1 -0
- package/dist/tools/store-memories.d.ts.map +1 -0
- package/dist/tools/store-memories.js +32 -42
- package/dist/tools/store-memory.d.ts +1 -0
- package/dist/tools/store-memory.d.ts.map +1 -0
- package/dist/tools/store-memory.js +12 -18
- package/dist/tools/update-memory.d.ts +1 -0
- package/dist/tools/update-memory.d.ts.map +1 -0
- package/dist/tools/update-memory.js +41 -46
- package/package.json +1 -1
|
@@ -73,23 +73,23 @@ export declare const RelationshipEdgeSchema: z.ZodObject<{
|
|
|
73
73
|
relation_type: z.ZodString;
|
|
74
74
|
}, z.core.$strict>;
|
|
75
75
|
export declare const RelationshipWithMemorySchema: z.ZodObject<{
|
|
76
|
-
from_hash: z.ZodString;
|
|
77
|
-
to_hash: z.ZodString;
|
|
78
|
-
relation_type: z.ZodString;
|
|
79
76
|
created_at: z.ZodString;
|
|
80
77
|
linked_hash: z.ZodString;
|
|
81
78
|
linked_content: z.ZodString;
|
|
82
79
|
linked_tags: z.ZodArray<z.ZodString>;
|
|
80
|
+
from_hash: z.ZodString;
|
|
81
|
+
to_hash: z.ZodString;
|
|
82
|
+
relation_type: z.ZodString;
|
|
83
83
|
}, z.core.$strict>;
|
|
84
84
|
export declare const RelationshipResultSchema: z.ZodObject<{
|
|
85
85
|
relationships: z.ZodArray<z.ZodObject<{
|
|
86
|
-
from_hash: z.ZodString;
|
|
87
|
-
to_hash: z.ZodString;
|
|
88
|
-
relation_type: z.ZodString;
|
|
89
86
|
created_at: z.ZodString;
|
|
90
87
|
linked_hash: z.ZodString;
|
|
91
88
|
linked_content: z.ZodString;
|
|
92
89
|
linked_tags: z.ZodArray<z.ZodString>;
|
|
90
|
+
from_hash: z.ZodString;
|
|
91
|
+
to_hash: z.ZodString;
|
|
92
|
+
relation_type: z.ZodString;
|
|
93
93
|
}, z.core.$strict>>;
|
|
94
94
|
count: z.ZodNumber;
|
|
95
95
|
}, z.core.$strict>;
|
|
@@ -145,3 +145,4 @@ export declare const RetrieveContextResultSchema: z.ZodObject<{
|
|
|
145
145
|
estimated_tokens: z.ZodNumber;
|
|
146
146
|
truncated: z.ZodBoolean;
|
|
147
147
|
}, z.core.$strict>;
|
|
148
|
+
//# sourceMappingURL=outputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outputs.d.ts","sourceRoot":"","sources":["../../src/schemas/outputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAa3B,eAAO,MAAM,iBAAiB;;;kBAKQ,CAAC;AAEvC,eAAO,MAAM,YAAY;;;;;;;;;kBAWG,CAAC;AAE7B,eAAO,MAAM,kBAAkB;;;;;;;;;kBAAe,CAAC;AAE/C,eAAO,MAAM,iBAAiB;;;kBAKI,CAAC;AAEnC,eAAO,MAAM,kBAAkB;;;kBAKI,CAAC;AAEpC,eAAO,MAAM,kBAAkB;;;kBAKI,CAAC;AAEpC,eAAO,MAAM,qBAAqB;;;;;;kBAQF,CAAC;AAEjC,eAAO,MAAM,iBAAiB;;;;;;;;;;kBAMO,CAAC;AAEtC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;kBAMH,CAAC;AAE7B,eAAO,MAAM,sBAAsB;;;;kBAIH,CAAC;AAEjC,eAAO,MAAM,4BAA4B;;;;;;;;kBAQU,CAAC;AAEpD,eAAO,MAAM,wBAAwB;;;;;;;;;;;kBAOY,CAAC;AAElD,eAAO,MAAM,8BAA8B;;kBAIF,CAAC;AAE1C,eAAO,MAAM,8BAA8B;;kBAIF,CAAC;AAE1C,eAAO,MAAM,iBAAiB;;;;;;;;;;;kBAiBS,CAAC;AAExC,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;kBAQH,CAAC;AAE7B,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;kBAMF,CAAC"}
|
package/dist/schemas/outputs.js
CHANGED
|
@@ -3,6 +3,11 @@ const STRING_SCHEMA = z.string();
|
|
|
3
3
|
const NUMBER_SCHEMA = z.number();
|
|
4
4
|
const BOOLEAN_SCHEMA = z.boolean();
|
|
5
5
|
const STRING_ARRAY_SCHEMA = z.array(STRING_SCHEMA);
|
|
6
|
+
const RELATIONSHIP_FIELDS = {
|
|
7
|
+
from_hash: STRING_SCHEMA.describe('Source hash'),
|
|
8
|
+
to_hash: STRING_SCHEMA.describe('Target hash'),
|
|
9
|
+
relation_type: STRING_SCHEMA.describe('Relationship type'),
|
|
10
|
+
};
|
|
6
11
|
export const ErrorResultSchema = z
|
|
7
12
|
.strictObject({
|
|
8
13
|
code: STRING_SCHEMA.describe('Error code'),
|
|
@@ -65,16 +70,12 @@ export const SearchResultSchema = z
|
|
|
65
70
|
.describe('Search result');
|
|
66
71
|
export const RelationshipEdgeSchema = z
|
|
67
72
|
.strictObject({
|
|
68
|
-
|
|
69
|
-
to_hash: z.string().describe('Target hash'),
|
|
70
|
-
relation_type: z.string().describe('Relationship type'),
|
|
73
|
+
...RELATIONSHIP_FIELDS,
|
|
71
74
|
})
|
|
72
75
|
.describe('Relationship edge');
|
|
73
76
|
export const RelationshipWithMemorySchema = z
|
|
74
77
|
.strictObject({
|
|
75
|
-
|
|
76
|
-
to_hash: z.string().describe('Target hash'),
|
|
77
|
-
relation_type: z.string().describe('Relationship type'),
|
|
78
|
+
...RELATIONSHIP_FIELDS,
|
|
78
79
|
created_at: z.string().describe('Created at'),
|
|
79
80
|
linked_hash: z.string().describe('Linked memory hash'),
|
|
80
81
|
linked_content: z.string().describe('Linked memory content'),
|
package/dist/server.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAMpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AA0G7C,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,GAAG,SAAS,CAanD"}
|
package/dist/server.js
CHANGED
|
@@ -63,15 +63,22 @@ function createIconDescriptors() {
|
|
|
63
63
|
return undefined;
|
|
64
64
|
return [{ src, mimeType: ICON_MIME, sizes: ICON_SIZES }];
|
|
65
65
|
}
|
|
66
|
-
|
|
66
|
+
function buildServerIdentity() {
|
|
67
67
|
const { version } = loadPackageManifest();
|
|
68
68
|
const icons = createIconDescriptors();
|
|
69
|
-
|
|
70
|
-
const server = new McpServer({
|
|
69
|
+
return {
|
|
71
70
|
name: SERVER_NAME,
|
|
72
71
|
version,
|
|
73
72
|
...(icons ? { icons } : {}),
|
|
74
|
-
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function buildServerInstructions() {
|
|
76
|
+
return loadInstructions();
|
|
77
|
+
}
|
|
78
|
+
export function createServer(db) {
|
|
79
|
+
const identity = buildServerIdentity();
|
|
80
|
+
const instructions = buildServerInstructions();
|
|
81
|
+
const server = new McpServer(identity, {
|
|
75
82
|
capabilities: SERVER_CAPABILITIES,
|
|
76
83
|
instructions,
|
|
77
84
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-relationship.d.ts","sourceRoot":"","sources":["../../src/tools/create-relationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAqE9C,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,OAAO,GACV,IAAI,CA6BN"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { E_NOT_FOUND
|
|
1
|
+
import { E_NOT_FOUND } from '../lib/errors.js';
|
|
2
2
|
import { logToolEvent } from '../lib/mcp-utils.js';
|
|
3
|
+
import { executeToolSafely } from '../lib/tool-execution.js';
|
|
3
4
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
4
5
|
import { CreateRelationshipInputSchema } from '../schemas/inputs.js';
|
|
5
6
|
import { CreateRelationshipResultSchema } from '../schemas/outputs.js';
|
|
@@ -42,25 +43,19 @@ function createRelationshipTx(db, params) {
|
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
export function registerCreateRelationship(server, db) {
|
|
45
|
-
registerToolWithContract(server, 'create_relationship', CreateRelationshipInputSchema, CreateRelationshipResultSchema, wrapToolHandler(async (params) => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return createErrorResponse(txResult.code, txResult.message);
|
|
50
|
-
}
|
|
51
|
-
await logToolEvent(server, 'create_relationship', {
|
|
52
|
-
fromHash: params.from_hash,
|
|
53
|
-
toHash: params.to_hash,
|
|
54
|
-
relationType: params.relation_type,
|
|
55
|
-
created: txResult.created,
|
|
56
|
-
});
|
|
57
|
-
return createToolResponse({ created: txResult.created });
|
|
46
|
+
registerToolWithContract(server, 'create_relationship', CreateRelationshipInputSchema, CreateRelationshipResultSchema, wrapToolHandler(async (params) => executeToolSafely(async () => {
|
|
47
|
+
const txResult = createRelationshipTx(db, params);
|
|
48
|
+
if (!txResult.ok) {
|
|
49
|
+
return createErrorResponse(txResult.code, txResult.message);
|
|
58
50
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
51
|
+
await logToolEvent(server, 'create_relationship', {
|
|
52
|
+
fromHash: params.from_hash,
|
|
53
|
+
toHash: params.to_hash,
|
|
54
|
+
relationType: params.relation_type,
|
|
55
|
+
created: txResult.created,
|
|
56
|
+
});
|
|
57
|
+
return createToolResponse({ created: txResult.created });
|
|
58
|
+
}), {
|
|
64
59
|
progressMessage: (params) => `⊕ create_relationship: ${params.from_hash.slice(0, 8)}... -> ${params.to_hash.slice(0, 8)}... [${params.relation_type}]`,
|
|
65
60
|
}));
|
|
66
61
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-memories.d.ts","sourceRoot":"","sources":["../../src/tools/delete-memories.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAuB9C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CA6C3E"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
|
|
2
1
|
import { logToolEvent, notifyMemoryResourceUpdated } from '../lib/mcp-utils.js';
|
|
3
2
|
import { DELETE_MEMORY_SQL } from '../lib/sql.js';
|
|
4
|
-
import {
|
|
3
|
+
import { executeToolSafely, summarizeBatch } from '../lib/tool-execution.js';
|
|
4
|
+
import { createToolResponse } from '../lib/tool-response.js';
|
|
5
5
|
import { DeleteMemoriesInputSchema } from '../schemas/inputs.js';
|
|
6
6
|
import { BatchResultSchema } from '../schemas/outputs.js';
|
|
7
7
|
import { wrapToolHandler } from './progress.js';
|
|
@@ -13,42 +13,32 @@ async function notifyDeletedResources(server, items) {
|
|
|
13
13
|
await Promise.allSettled(notifications);
|
|
14
14
|
}
|
|
15
15
|
export function registerDeleteMemories(server, db) {
|
|
16
|
-
registerToolWithContract(server, 'delete_memories', DeleteMemoriesInputSchema, BatchResultSchema, wrapToolHandler(async (params) => {
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return items;
|
|
30
|
-
});
|
|
31
|
-
let deleted = 0;
|
|
32
|
-
let succeeded = 0;
|
|
33
|
-
for (const item of results) {
|
|
34
|
-
if (item.ok)
|
|
35
|
-
succeeded += 1;
|
|
36
|
-
if (item.deleted)
|
|
37
|
-
deleted += 1;
|
|
16
|
+
registerToolWithContract(server, 'delete_memories', DeleteMemoriesInputSchema, BatchResultSchema, wrapToolHandler(async (params) => executeToolSafely(async () => {
|
|
17
|
+
const results = db.transaction(() => {
|
|
18
|
+
const items = [];
|
|
19
|
+
const stmt = db.prepareOnce(DELETE_MEMORY_SQL);
|
|
20
|
+
for (const hash of params.hashes) {
|
|
21
|
+
const result = stmt.run(hash);
|
|
22
|
+
items.push({
|
|
23
|
+
hash,
|
|
24
|
+
ok: true,
|
|
25
|
+
deleted: result.changes > 0,
|
|
26
|
+
});
|
|
38
27
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
28
|
+
return items;
|
|
29
|
+
});
|
|
30
|
+
const summary = summarizeBatch(results, (item) => item.deleted === true);
|
|
31
|
+
await logToolEvent(server, 'delete_memories', {
|
|
32
|
+
total: params.hashes.length,
|
|
33
|
+
deleted: summary.matched,
|
|
34
|
+
});
|
|
35
|
+
await notifyDeletedResources(server, results);
|
|
36
|
+
return createToolResponse({
|
|
37
|
+
items: results,
|
|
38
|
+
succeeded: summary.succeeded,
|
|
39
|
+
failed: summary.failed,
|
|
40
|
+
});
|
|
41
|
+
}), {
|
|
52
42
|
progressMessage: (params) => `⊖ delete_memories: ${params.hashes.length} hashes [batch]`,
|
|
53
43
|
}));
|
|
54
44
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-memory.d.ts","sourceRoot":"","sources":["../../src/tools/delete-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAgB9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAwBzE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
|
|
2
1
|
import { logToolEvent, notifyMemoryResourceUpdated } from '../lib/mcp-utils.js';
|
|
3
2
|
import { DELETE_MEMORY_SQL } from '../lib/sql.js';
|
|
4
|
-
import {
|
|
3
|
+
import { executeToolSafely } from '../lib/tool-execution.js';
|
|
4
|
+
import { createToolResponse } from '../lib/tool-response.js';
|
|
5
5
|
import { DeleteMemoryInputSchema } from '../schemas/inputs.js';
|
|
6
6
|
import { DeleteResultSchema } from '../schemas/outputs.js';
|
|
7
7
|
import { wrapToolHandler } from './progress.js';
|
|
@@ -10,20 +10,14 @@ function deleteByHash(db, hash) {
|
|
|
10
10
|
return db.prepareOnce(DELETE_MEMORY_SQL).run(hash).changes > 0;
|
|
11
11
|
}
|
|
12
12
|
export function registerDeleteMemory(server, db) {
|
|
13
|
-
registerToolWithContract(server, 'delete_memory', DeleteMemoryInputSchema, DeleteResultSchema, wrapToolHandler(async (params) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
await notifyMemoryResourceUpdated(server, params.hash);
|
|
19
|
-
}
|
|
20
|
-
return createToolResponse({ deleted, hash: params.hash });
|
|
13
|
+
registerToolWithContract(server, 'delete_memory', DeleteMemoryInputSchema, DeleteResultSchema, wrapToolHandler(async (params) => executeToolSafely(async () => {
|
|
14
|
+
const deleted = deleteByHash(db, params.hash);
|
|
15
|
+
if (deleted) {
|
|
16
|
+
await logToolEvent(server, 'delete', { hash: params.hash });
|
|
17
|
+
await notifyMemoryResourceUpdated(server, params.hash);
|
|
21
18
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return createErrorResponse(E_UNKNOWN, getErrorMessage(err));
|
|
25
|
-
}
|
|
26
|
-
}, {
|
|
19
|
+
return createToolResponse({ deleted, hash: params.hash });
|
|
20
|
+
}), {
|
|
27
21
|
progressMessage: (params) => `⊖ delete_memory: ${params.hash.slice(0, 12)}... [single]`,
|
|
28
22
|
}));
|
|
29
23
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-relationship.d.ts","sourceRoot":"","sources":["../../src/tools/delete-relationship.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAyC9C,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,OAAO,GACV,IAAI,CAwBN"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { E_NOT_FOUND
|
|
1
|
+
import { E_NOT_FOUND } from '../lib/errors.js';
|
|
2
|
+
import { executeToolSafely } from '../lib/tool-execution.js';
|
|
2
3
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
3
4
|
import { DeleteRelationshipInputSchema } from '../schemas/inputs.js';
|
|
4
5
|
import { DeleteRelationshipResultSchema } from '../schemas/outputs.js';
|
|
@@ -18,18 +19,12 @@ function deleteRelationship(db, params) {
|
|
|
18
19
|
.run(params.from_hash, params.to_hash, params.relation_type).changes > 0);
|
|
19
20
|
}
|
|
20
21
|
export function registerDeleteRelationship(server, db) {
|
|
21
|
-
registerToolWithContract(server, 'delete_relationship', DeleteRelationshipInputSchema, DeleteRelationshipResultSchema, wrapToolHandler((params) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return createErrorResponse(E_NOT_FOUND, createNotFoundRelationshipMessage(params));
|
|
25
|
-
}
|
|
26
|
-
return createToolResponse(DELETE_RELATIONSHIP_RESULT);
|
|
22
|
+
registerToolWithContract(server, 'delete_relationship', DeleteRelationshipInputSchema, DeleteRelationshipResultSchema, wrapToolHandler((params) => executeToolSafely(() => {
|
|
23
|
+
if (!deleteRelationship(db, params)) {
|
|
24
|
+
return createErrorResponse(E_NOT_FOUND, createNotFoundRelationshipMessage(params));
|
|
27
25
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return createErrorResponse(E_UNKNOWN, getErrorMessage(err));
|
|
31
|
-
}
|
|
32
|
-
}, {
|
|
26
|
+
return createToolResponse(DELETE_RELATIONSHIP_RESULT);
|
|
27
|
+
}), {
|
|
33
28
|
progressMessage: (params) => `⊖ delete_relationship: ${params.from_hash.slice(0, 8)}... -> ${params.to_hash.slice(0, 8)}... [${params.relation_type}]`,
|
|
34
29
|
}));
|
|
35
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-memory.d.ts","sourceRoot":"","sources":["../../src/tools/get-memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAwB9C,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAwBtE"}
|
package/dist/tools/get-memory.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { E_NOT_FOUND
|
|
1
|
+
import { E_NOT_FOUND } from '../lib/errors.js';
|
|
2
2
|
import { SELECT_MEMORY_BY_HASH_SQL } from '../lib/sql.js';
|
|
3
|
+
import { executeToolSafely } from '../lib/tool-execution.js';
|
|
3
4
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
4
5
|
import { parseMemoryRow } from '../lib/types.js';
|
|
5
6
|
import { GetMemoryInputSchema } from '../schemas/inputs.js';
|
|
@@ -13,20 +14,14 @@ function notFound(hash) {
|
|
|
13
14
|
return createErrorResponse(E_NOT_FOUND, `Memory not found: ${hash}`);
|
|
14
15
|
}
|
|
15
16
|
export function registerGetMemory(server, db) {
|
|
16
|
-
registerToolWithContract(server, 'get_memory', GetMemoryInputSchema, MemoryResultSchema, wrapToolHandler((params) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return notFound(params.hash);
|
|
21
|
-
}
|
|
22
|
-
const memory = parseMemoryRow(row);
|
|
23
|
-
return createToolResponse({ ...memory });
|
|
17
|
+
registerToolWithContract(server, 'get_memory', GetMemoryInputSchema, MemoryResultSchema, wrapToolHandler((params) => executeToolSafely(() => {
|
|
18
|
+
const row = getMemoryRow(db, params.hash);
|
|
19
|
+
if (!row) {
|
|
20
|
+
return notFound(params.hash);
|
|
24
21
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}, {
|
|
22
|
+
const memory = parseMemoryRow(row);
|
|
23
|
+
return createToolResponse({ ...memory });
|
|
24
|
+
}), {
|
|
30
25
|
progressMessage: (params) => `⊙ get_memory: ${params.hash.slice(0, 12)}... [single]`,
|
|
31
26
|
}));
|
|
32
27
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-relationships.d.ts","sourceRoot":"","sources":["../../src/tools/get-relationships.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAIzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA2F9C,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAgC7E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { E_NOT_FOUND
|
|
1
|
+
import { E_NOT_FOUND } from '../lib/errors.js';
|
|
2
2
|
import { SELECT_MEMORY_HASH_SQL } from '../lib/sql.js';
|
|
3
|
+
import { executeToolSafely } from '../lib/tool-execution.js';
|
|
3
4
|
import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
|
|
4
5
|
import { parseTags } from '../lib/types.js';
|
|
5
6
|
import { GetRelationshipsInputSchema } from '../schemas/inputs.js';
|
|
@@ -60,23 +61,17 @@ function toRelationshipWithMemory(row) {
|
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
export function registerGetRelationships(server, db) {
|
|
63
|
-
registerToolWithContract(server, 'get_relationships', GetRelationshipsInputSchema, RelationshipResultSchema, wrapToolHandler((params) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return createErrorResponse(E_NOT_FOUND, `Memory not found: ${params.hash}`);
|
|
67
|
-
}
|
|
68
|
-
const rows = loadRelationships(db, params.hash, params.direction);
|
|
69
|
-
const relationships = rows.map(toRelationshipWithMemory);
|
|
70
|
-
return createToolResponse({
|
|
71
|
-
relationships,
|
|
72
|
-
count: relationships.length,
|
|
73
|
-
});
|
|
64
|
+
registerToolWithContract(server, 'get_relationships', GetRelationshipsInputSchema, RelationshipResultSchema, wrapToolHandler((params) => executeToolSafely(() => {
|
|
65
|
+
if (!memoryExists(db, params.hash)) {
|
|
66
|
+
return createErrorResponse(E_NOT_FOUND, `Memory not found: ${params.hash}`);
|
|
74
67
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
const rows = loadRelationships(db, params.hash, params.direction);
|
|
69
|
+
const relationships = rows.map(toRelationshipWithMemory);
|
|
70
|
+
return createToolResponse({
|
|
71
|
+
relationships,
|
|
72
|
+
count: relationships.length,
|
|
73
|
+
});
|
|
74
|
+
}), {
|
|
80
75
|
progressMessage: (params) => `⊙ get_relationships: ${params.hash.slice(0, 12)}... [${params.direction}]`,
|
|
81
76
|
}));
|
|
82
77
|
}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAe9C,KAAK,aAAa,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,KAAK,IAAI,CAAC;AAE9D,eAAO,MAAM,eAAe,EAAE,SAAS,aAAa,EAcnD,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAIrE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-stats.d.ts","sourceRoot":"","sources":["../../src/tools/memory-stats.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA6B9C,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAmCxE"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
|
|
2
1
|
import { MEMORY_AGGREGATE_SQL, RELATIONSHIP_COUNT_SQL, TYPE_COUNTS_SQL, } from '../lib/sql.js';
|
|
3
|
-
import {
|
|
2
|
+
import { executeToolSafely } from '../lib/tool-execution.js';
|
|
3
|
+
import { createToolResponse } from '../lib/tool-response.js';
|
|
4
4
|
import { MemoryStatsInputSchema } from '../schemas/inputs.js';
|
|
5
5
|
import { StatsResultSchema } from '../schemas/outputs.js';
|
|
6
6
|
import { wrapToolHandler } from './progress.js';
|
|
@@ -13,30 +13,24 @@ function toTypeCounts(rows) {
|
|
|
13
13
|
return byType;
|
|
14
14
|
}
|
|
15
15
|
export function registerMemoryStats(server, db) {
|
|
16
|
-
registerToolWithContract(server, 'memory_stats', MemoryStatsInputSchema, StatsResultSchema, wrapToolHandler(() => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
catch (err) {
|
|
38
|
-
rethrowMcpError(err);
|
|
39
|
-
return createErrorResponse(E_UNKNOWN, getErrorMessage(err));
|
|
40
|
-
}
|
|
41
|
-
}, { progressMessage: () => '⊙ memory_stats: [aggregate]' }));
|
|
16
|
+
registerToolWithContract(server, 'memory_stats', MemoryStatsInputSchema, StatsResultSchema, wrapToolHandler(() => executeToolSafely(() => {
|
|
17
|
+
const aggregate = db
|
|
18
|
+
.prepareOnce(MEMORY_AGGREGATE_SQL)
|
|
19
|
+
.get();
|
|
20
|
+
const totalRelationships = db.prepareOnce(RELATIONSHIP_COUNT_SQL).get()?.total ?? 0;
|
|
21
|
+
const typeRows = db.prepareOnce(TYPE_COUNTS_SQL).all();
|
|
22
|
+
const byType = toTypeCounts(typeRows);
|
|
23
|
+
return createToolResponse({
|
|
24
|
+
memories: {
|
|
25
|
+
total: aggregate?.total ?? 0,
|
|
26
|
+
oldest: aggregate?.oldest ?? null,
|
|
27
|
+
newest: aggregate?.newest ?? null,
|
|
28
|
+
avg_importance: aggregate?.avg_importance ?? null,
|
|
29
|
+
},
|
|
30
|
+
relationships: {
|
|
31
|
+
total: totalRelationships,
|
|
32
|
+
},
|
|
33
|
+
by_type: byType,
|
|
34
|
+
});
|
|
35
|
+
}), { progressMessage: () => '⊙ memory_stats: [aggregate]' }));
|
|
42
36
|
}
|
package/dist/tools/progress.d.ts
CHANGED
|
@@ -32,3 +32,4 @@ export declare function createProgressReporter(extra: ProgressContext, options?:
|
|
|
32
32
|
export declare function progressWithMessage(reporter: ProgressReporter, getMessage: (progress: ProgressSnapshot) => string): ProgressReporter<ProgressSnapshot>;
|
|
33
33
|
export declare function wrapToolHandler<TArgs>(handler: ToolHandler<TArgs>, options: WrappedHandlerOptions<TArgs>): ToolHandler<TArgs>;
|
|
34
34
|
export {};
|
|
35
|
+
//# sourceMappingURL=progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress.d.ts","sourceRoot":"","sources":["../../src/tools/progress.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,oCAAoC,CAAC;AAO5C,UAAU,YAAY;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,gBAAgB,CAAC,EAAE,CAAC,YAAY,EAAE,oBAAoB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1E;AAED,UAAU,cAAc;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,uBAAuB;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,UAAU,gBAAgB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,gBAAgB,CAC1B,SAAS,SAAS,gBAAgB,GAAG,cAAc,IACjD,CAAC,CAAC,QAAQ,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG;IACpC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B,CAAC;AAEF,UAAU,qBAAqB,CAAC,KAAK;IACnC,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,KAAK,MAAM,CAAC;IACpE,eAAe,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC;CAC1C;AAED,KAAK,WAAW,CAAC,KAAK,IAAI,CACxB,IAAI,EAAE,KAAK,EACX,KAAK,EAAE,eAAe,KACnB,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAAC;AA0F9C,wBAAsB,cAAc,CAClC,KAAK,EAAE,eAAe,EACtB,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,uBAA4B,GACpC,gBAAgB,CAyClB;AAED,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,UAAU,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,MAAM,GACjD,gBAAgB,CAAC,gBAAgB,CAAC,CAepC;AAED,wBAAgB,eAAe,CAAC,KAAK,EACnC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAC3B,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,GACpC,WAAW,CAAC,KAAK,CAAC,CAoDpB"}
|