@j0hanz/memory-mcp 1.0.1 → 1.1.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.
Files changed (69) hide show
  1. package/dist/completions/index.d.ts.map +1 -1
  2. package/dist/completions/index.js +3 -3
  3. package/dist/completions/index.js.map +1 -1
  4. package/dist/lib/errors.d.ts +1 -0
  5. package/dist/lib/errors.d.ts.map +1 -1
  6. package/dist/lib/errors.js +1 -0
  7. package/dist/lib/errors.js.map +1 -1
  8. package/dist/lib/instructions.d.ts.map +1 -1
  9. package/dist/lib/instructions.js +87 -18
  10. package/dist/lib/instructions.js.map +1 -1
  11. package/dist/lib/sql.d.ts +17 -0
  12. package/dist/lib/sql.d.ts.map +1 -0
  13. package/dist/lib/sql.js +18 -0
  14. package/dist/lib/sql.js.map +1 -0
  15. package/dist/lib/tool-contracts.d.ts +18 -0
  16. package/dist/lib/tool-contracts.d.ts.map +1 -0
  17. package/dist/lib/tool-contracts.js +120 -0
  18. package/dist/lib/tool-contracts.js.map +1 -0
  19. package/dist/prompts/index.js +2 -2
  20. package/dist/prompts/index.js.map +1 -1
  21. package/dist/resources/index.d.ts.map +1 -1
  22. package/dist/resources/index.js +4 -5
  23. package/dist/resources/index.js.map +1 -1
  24. package/dist/schemas/inputs.d.ts +1 -1
  25. package/dist/tools/create-relationship.d.ts.map +1 -1
  26. package/dist/tools/create-relationship.js +10 -8
  27. package/dist/tools/create-relationship.js.map +1 -1
  28. package/dist/tools/delete-memories.d.ts.map +1 -1
  29. package/dist/tools/delete-memories.js +19 -15
  30. package/dist/tools/delete-memories.js.map +1 -1
  31. package/dist/tools/delete-memory.js +11 -9
  32. package/dist/tools/delete-memory.js.map +1 -1
  33. package/dist/tools/delete-relationship.d.ts.map +1 -1
  34. package/dist/tools/delete-relationship.js +10 -8
  35. package/dist/tools/delete-relationship.js.map +1 -1
  36. package/dist/tools/get-memory.d.ts.map +1 -1
  37. package/dist/tools/get-memory.js +11 -9
  38. package/dist/tools/get-memory.js.map +1 -1
  39. package/dist/tools/get-relationships.d.ts.map +1 -1
  40. package/dist/tools/get-relationships.js +46 -26
  41. package/dist/tools/get-relationships.js.map +1 -1
  42. package/dist/tools/memory-stats.d.ts.map +1 -1
  43. package/dist/tools/memory-stats.js +19 -35
  44. package/dist/tools/memory-stats.js.map +1 -1
  45. package/dist/tools/progress.d.ts.map +1 -1
  46. package/dist/tools/progress.js +15 -8
  47. package/dist/tools/progress.js.map +1 -1
  48. package/dist/tools/recall.js +15 -15
  49. package/dist/tools/recall.js.map +1 -1
  50. package/dist/tools/result.d.ts +2 -0
  51. package/dist/tools/result.d.ts.map +1 -1
  52. package/dist/tools/result.js +5 -0
  53. package/dist/tools/result.js.map +1 -1
  54. package/dist/tools/retrieve-context.d.ts.map +1 -1
  55. package/dist/tools/retrieve-context.js +40 -26
  56. package/dist/tools/retrieve-context.js.map +1 -1
  57. package/dist/tools/search-memories.d.ts.map +1 -1
  58. package/dist/tools/search-memories.js +10 -8
  59. package/dist/tools/search-memories.js.map +1 -1
  60. package/dist/tools/store-memories.d.ts.map +1 -1
  61. package/dist/tools/store-memories.js +19 -15
  62. package/dist/tools/store-memories.js.map +1 -1
  63. package/dist/tools/store-memory.js +11 -10
  64. package/dist/tools/store-memory.js.map +1 -1
  65. package/dist/tools/update-memory.d.ts.map +1 -1
  66. package/dist/tools/update-memory.js +47 -32
  67. package/dist/tools/update-memory.js.map +1 -1
  68. package/package.json +1 -2
  69. package/dist/instructions.md +0 -169
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/completions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAY9C,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,OAAO,GACV,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAQ7B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/completions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAgB9C,wBAAgB,4BAA4B,CAC1C,EAAE,EAAE,OAAO,GACV,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EAAE,CAQ7B"}
@@ -1,6 +1,9 @@
1
1
  const HASH_MAX_LENGTH = 64;
2
2
  const HASH_COMPLETION_LIMIT = 101;
3
3
  const HASH_COMPLETION_SQL = `SELECT hash FROM memories WHERE hash LIKE ? ESCAPE '\\' ORDER BY hash LIMIT ${HASH_COMPLETION_LIMIT}`;
4
+ function escapeLikePattern(value) {
5
+ return value.replace(/[%_\\]/g, '\\$&');
6
+ }
4
7
  function normalizeHashPrefix(value) {
5
8
  return escapeLikePattern(value.slice(0, HASH_MAX_LENGTH));
6
9
  }
@@ -14,7 +17,4 @@ export function createHashCompletionCallback(db) {
14
17
  .map((row) => row.hash);
15
18
  };
16
19
  }
17
- function escapeLikePattern(value) {
18
- return value.replace(/[%_\\]/g, '\\$&');
19
- }
20
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/completions/index.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,mBAAmB,GAAG,+EAA+E,qBAAqB,EAAE,CAAC;AAEnI,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,4BAA4B,CAC1C,EAAW;IAEX,OAAO,CAAC,KAAa,EAAY,EAAE;QACjC,MAAM,aAAa,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,EAAE;aACN,WAAW,CAAU,mBAAmB,CAAC;aACzC,GAAG,CAAC,GAAG,aAAa,GAAG,CAAC;aACxB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/completions/index.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,mBAAmB,GAAG,+EAA+E,qBAAqB,EAAE,CAAC;AAEnI,SAAS,iBAAiB,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,4BAA4B,CAC1C,EAAW;IAEX,OAAO,CAAC,KAAa,EAAY,EAAE;QACjC,MAAM,aAAa,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACjD,OAAO,EAAE;aACN,WAAW,CAAU,mBAAmB,CAAC;aACzC,GAAG,CAAC,GAAG,aAAa,GAAG,CAAC;aACxB,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC"}
@@ -2,6 +2,7 @@ export declare const E_NOT_FOUND = "E_NOT_FOUND";
2
2
  export declare const E_INVALID_CURSOR = "E_INVALID_CURSOR";
3
3
  export declare const E_DB_ERROR = "E_DB_ERROR";
4
4
  export declare const E_CONFLICT = "E_CONFLICT";
5
+ export declare const E_CANCELLED = "E_CANCELLED";
5
6
  export declare const E_UNKNOWN = "E_UNKNOWN";
6
7
  export declare function getErrorMessage(err: unknown): string;
7
8
  export declare function rethrowMcpError(err: unknown): void;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,SAAS,cAAc,CAAC;AAGrC,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAIpD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAElD"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AACnD,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,WAAW,gBAAgB,CAAC;AACzC,eAAO,MAAM,SAAS,cAAc,CAAC;AAGrC,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAIpD;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAElD"}
@@ -3,6 +3,7 @@ export const E_NOT_FOUND = 'E_NOT_FOUND';
3
3
  export const E_INVALID_CURSOR = 'E_INVALID_CURSOR';
4
4
  export const E_DB_ERROR = 'E_DB_ERROR';
5
5
  export const E_CONFLICT = 'E_CONFLICT';
6
+ export const E_CANCELLED = 'E_CANCELLED';
6
7
  export const E_UNKNOWN = 'E_UNKNOWN';
7
8
  const UNKNOWN_ERROR_MESSAGE = 'Unknown error occurred';
8
9
  export function getErrorMessage(err) {
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAEvD,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IAC7C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,GAAG,YAAY,QAAQ;QAAE,MAAM,GAAG,CAAC;AACzC,CAAC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAE9D,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AACnD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,qBAAqB,GAAG,wBAAwB,CAAC;AAEvD,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,GAAG,YAAY,KAAK;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IAC7C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,GAAG,CAAC;IACxC,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,GAAG,YAAY,QAAQ;QAAE,MAAM,GAAG,CAAC;AACzC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAaA,wBAAgB,gBAAgB,IAAI,MAAM,CAgBzC"}
1
+ {"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAwEA,wBAAgB,gBAAgB,IAAI,MAAM,CA+BzC"}
@@ -1,27 +1,96 @@
1
- import { readFileSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { fileURLToPath } from 'node:url';
4
- const BASE_DIR = fileURLToPath(new URL('.', import.meta.url));
5
- const FALLBACK_INSTRUCTIONS = '# Memory instructions\n\nSee the README for usage details.';
6
- const INSTRUCTION_PATHS = [
7
- join(BASE_DIR, '..', 'instructions.md'),
8
- join(BASE_DIR, '..', '..', 'src', 'instructions.md'),
1
+ import { getToolContracts } from './tool-contracts.js';
2
+ const SHARED_CONSTRAINTS = [
3
+ 'Idempotence: `store_memory` and `store_memories` return `created: false` if content+tags already exist.',
4
+ 'Atomic Transactions: `store_memories` and `delete_memories` roll back entirely on unexpected errors.',
5
+ 'Hash Changes: `update_memory` changes the hash when content or tags change. Relationships survive via CASCADE.',
6
+ 'FTS Search Limits: Query terms matched individually (all-OR logic). Phrase operators and negation not supported.',
7
+ 'Recall Limits: BFS traversal is bounded by env vars (RECALL_MAX_FRONTIER_SIZE, RECALL_MAX_EDGE_ROWS, RECALL_MAX_VISITED_NODES). Returns `aborted: true` with partial results when limits are hit.',
9
8
  ];
9
+ const ERROR_CODES = [
10
+ '| Code | Meaning |',
11
+ '| --- | --- |',
12
+ '| `E_NOT_FOUND` | Hash or relationship does not exist |',
13
+ '| `E_CONFLICT` | `update_memory` target content+tags already maps to an existing hash |',
14
+ '| `E_CANCELLED` | Request was cancelled |',
15
+ '| `E_UNKNOWN` | Unexpected internal error — retry once |',
16
+ ];
17
+ const DATA_MODEL = `
18
+ ### Memory
19
+ - \`hash\` — SHA-256 of \`(content + sorted tags)\`; deterministic; changes when content or tags change
20
+ - \`content\` — Text; 1–100,000 chars
21
+ - \`tags\` — Array; 1–100 tags; each 1–50 chars, no whitespace; minimum 1 required
22
+ - \`memory_type\` — \`general\` | \`fact\` | \`plan\` | \`decision\` | \`reflection\` | \`lesson\` | \`error\` | \`gradient\` (default \`general\`)
23
+ - \`importance\` — Integer 0–10 (default 0; 10 = critical)
24
+ - \`created_at\`, \`updated_at\` — ISO 8601 timestamps
25
+
26
+ ### Relationship
27
+ - Directed edge: \`from_hash -[relation_type]-> to_hash\`
28
+ - \`relation_type\` — Free-form string, 1–50 chars, no whitespace
29
+ - Suggested types: \`related_to\`, \`causes\`, \`depends_on\`, \`parent_of\`, \`child_of\`, \`supersedes\`, \`contradicts\`, \`supports\`, \`references\`
30
+ - Both endpoints must exist before creating a relationship
31
+ - Cascade-deleted when either endpoint memory is deleted
32
+ - Cascade-updated when either endpoint hash changes (ON UPDATE CASCADE)
33
+ `;
34
+ const WORKFLOWS = `
35
+ ### Store and Link
36
+ \`\`\`
37
+ store_memories({ items: [...] }) → { items[].hash, succeeded, failed }
38
+ create_relationship({ from_hash, to_hash, relation_type }) × N
39
+ \`\`\`
40
+
41
+ ### Search and Read
42
+ \`\`\`
43
+ search_memories({ query, limit }) → { memories[], nextCursor }
44
+ # or, for relationship navigation:
45
+ recall({ query, depth: 1 }) → { memories[], graph[] }
46
+ \`\`\`
47
+
48
+ ### Fill Context Window
49
+ \`\`\`
50
+ retrieve_context({ query, token_budget: 4000, strategy: 'relevance' })
51
+ → { memories[], estimated_tokens, truncated }
52
+ \`\`\`
53
+
54
+ ### Update a Memory
55
+ \`\`\`
56
+ update_memory({ hash, content }) → { old_hash, new_hash }
57
+ # Existing relationships auto-update to new_hash via CASCADE
58
+ \`\`\`
59
+
60
+ ### Batch Delete
61
+ \`\`\`
62
+ delete_memories({ hashes: [...] }) → { items[].{ hash, deleted }, succeeded, failed }
63
+ # deleted: false means hash not found — not an error
64
+ \`\`\`
65
+ `;
10
66
  let cachedInstructions;
11
67
  export function loadInstructions() {
12
68
  if (cachedInstructions !== undefined) {
13
69
  return cachedInstructions;
14
70
  }
15
- for (const p of INSTRUCTION_PATHS) {
16
- try {
17
- cachedInstructions = readFileSync(p, 'utf8');
18
- return cachedInstructions;
19
- }
20
- catch {
21
- // try next path
22
- }
23
- }
24
- cachedInstructions = FALLBACK_INSTRUCTIONS;
71
+ const contracts = getToolContracts();
72
+ const toolRows = contracts.map((c) => {
73
+ return `| \`${c.name}\` | ${c.description.split('.')[0] ?? ''} |`;
74
+ });
75
+ cachedInstructions = [
76
+ '# Memory MCP — Usage Guide',
77
+ '## Tool Routing',
78
+ '| Tool | Purpose |',
79
+ '| --- | --- |',
80
+ ...toolRows,
81
+ '',
82
+ '## Shared Constraints',
83
+ SHARED_CONSTRAINTS.map((c) => `- ${c}`).join('\n'),
84
+ '## Error Codes',
85
+ ERROR_CODES.join('\n'),
86
+ '## Data Model',
87
+ DATA_MODEL,
88
+ '## Common Workflows',
89
+ WORKFLOWS,
90
+ '## Resources',
91
+ '- `internal://instructions` — This document. Read for tool routing, error codes, and workflows.',
92
+ '- `memory://memories/{hash}` — Fetch a single memory by URI with hash auto-completion.',
93
+ ].join('\n\n');
25
94
  return cachedInstructions;
26
95
  }
27
96
  //# sourceMappingURL=instructions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/lib/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC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MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;CAgBlB,CAAC;AAEF,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BjB,CAAC;AAEF,IAAI,kBAAsC,CAAC;AAE3C,MAAM,UAAU,gBAAgB;IAC9B,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED,MAAM,SAAS,GAAG,gBAAgB,EAAE,CAAC;IACrC,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACnC,OAAO,OAAO,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,kBAAkB,GAAG;QACnB,4BAA4B;QAC5B,iBAAiB;QACjB,oBAAoB;QACpB,eAAe;QACf,GAAG,QAAQ;QACX,EAAE;QACF,uBAAuB;QACvB,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAClD,gBAAgB;QAChB,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QACtB,eAAe;QACf,UAAU;QACV,qBAAqB;QACrB,SAAS;QACT,cAAc;QACd,iGAAiG;QACjG,wFAAwF;KACzF,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEf,OAAO,kBAAkB,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,17 @@
1
+ /** Shared SQL statement constants. Centralised here to ensure all callers
2
+ * cache the same string key via `prepareOnce`. */
3
+ /** Insert or silently ignore a duplicate memory (content+tags hash is PK). */
4
+ export declare const INSERT_MEMORY_SQL = "INSERT OR IGNORE INTO memories (hash, content, tags, memory_type, importance, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, ?)";
5
+ /** Delete one memory row by hash. Relationships cascade via FK. */
6
+ export declare const DELETE_MEMORY_SQL = "DELETE FROM memories WHERE hash = ?";
7
+ /** Fetch a full memory row by hash. */
8
+ export declare const SELECT_MEMORY_BY_HASH_SQL = "SELECT * FROM memories WHERE hash = ?";
9
+ /** Check existence: returns only the hash column to minimise data transfer. */
10
+ export declare const SELECT_MEMORY_HASH_SQL = "SELECT hash FROM memories WHERE hash = ?";
11
+ /** Aggregate memory store stats in a single scan. */
12
+ export declare const MEMORY_AGGREGATE_SQL = "SELECT COUNT(*) AS total, MIN(created_at) AS oldest, MAX(created_at) AS newest, AVG(importance) AS avg_importance FROM memories";
13
+ /** Total relationship count. */
14
+ export declare const RELATIONSHIP_COUNT_SQL = "SELECT COUNT(*) AS total FROM relationships";
15
+ /** Per-type memory breakdown. */
16
+ export declare const TYPE_COUNTS_SQL = "SELECT memory_type, COUNT(*) AS count FROM memories GROUP BY memory_type ORDER BY count DESC";
17
+ //# sourceMappingURL=sql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../../src/lib/sql.ts"],"names":[],"mappings":"AAAA;mDACmD;AAEnD,8EAA8E;AAC9E,eAAO,MAAM,iBAAiB,0IACC,CAAC;AAEhC,mEAAmE;AACnE,eAAO,MAAM,iBAAiB,wCAAwC,CAAC;AAEvE,uCAAuC;AACvC,eAAO,MAAM,yBAAyB,0CACG,CAAC;AAE1C,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,6CACS,CAAC;AAE7C,qDAAqD;AACrD,eAAO,MAAM,oBAAoB,oIACkG,CAAC;AAEpI,gCAAgC;AAChC,eAAO,MAAM,sBAAsB,gDACY,CAAC;AAEhD,iCAAiC;AACjC,eAAO,MAAM,eAAe,iGACoE,CAAC"}
@@ -0,0 +1,18 @@
1
+ /** Shared SQL statement constants. Centralised here to ensure all callers
2
+ * cache the same string key via `prepareOnce`. */
3
+ /** Insert or silently ignore a duplicate memory (content+tags hash is PK). */
4
+ export const INSERT_MEMORY_SQL = `INSERT OR IGNORE INTO memories (hash, content, tags, memory_type, importance, created_at, updated_at)
5
+ VALUES (?, ?, ?, ?, ?, ?, ?)`;
6
+ /** Delete one memory row by hash. Relationships cascade via FK. */
7
+ export const DELETE_MEMORY_SQL = 'DELETE FROM memories WHERE hash = ?';
8
+ /** Fetch a full memory row by hash. */
9
+ export const SELECT_MEMORY_BY_HASH_SQL = 'SELECT * FROM memories WHERE hash = ?';
10
+ /** Check existence: returns only the hash column to minimise data transfer. */
11
+ export const SELECT_MEMORY_HASH_SQL = 'SELECT hash FROM memories WHERE hash = ?';
12
+ /** Aggregate memory store stats in a single scan. */
13
+ export const MEMORY_AGGREGATE_SQL = 'SELECT COUNT(*) AS total, MIN(created_at) AS oldest, MAX(created_at) AS newest, AVG(importance) AS avg_importance FROM memories';
14
+ /** Total relationship count. */
15
+ export const RELATIONSHIP_COUNT_SQL = 'SELECT COUNT(*) AS total FROM relationships';
16
+ /** Per-type memory breakdown. */
17
+ export const TYPE_COUNTS_SQL = 'SELECT memory_type, COUNT(*) AS count FROM memories GROUP BY memory_type ORDER BY count DESC';
18
+ //# sourceMappingURL=sql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql.js","sourceRoot":"","sources":["../../src/lib/sql.ts"],"names":[],"mappings":"AAAA;mDACmD;AAEnD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,iBAAiB,GAAG;+BACF,CAAC;AAEhC,mEAAmE;AACnE,MAAM,CAAC,MAAM,iBAAiB,GAAG,qCAAqC,CAAC;AAEvE,uCAAuC;AACvC,MAAM,CAAC,MAAM,yBAAyB,GACpC,uCAAuC,CAAC;AAE1C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GACjC,0CAA0C,CAAC;AAE7C,qDAAqD;AACrD,MAAM,CAAC,MAAM,oBAAoB,GAC/B,iIAAiI,CAAC;AAEpI,gCAAgC;AAChC,MAAM,CAAC,MAAM,sBAAsB,GACjC,6CAA6C,CAAC;AAEhD,iCAAiC;AACjC,MAAM,CAAC,MAAM,eAAe,GAC1B,8FAA8F,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type z } from 'zod/v4';
2
+ export interface ToolContract {
3
+ name: string;
4
+ title: string;
5
+ description: string;
6
+ inputSchema: z.ZodType;
7
+ outputSchema: z.ZodType;
8
+ annotations: {
9
+ readOnlyHint?: boolean;
10
+ idempotentHint?: boolean;
11
+ destructiveHint?: boolean;
12
+ openWorldHint?: boolean;
13
+ };
14
+ }
15
+ export declare const TOOL_CONTRACTS: ToolContract[];
16
+ export declare function getToolContracts(): ToolContract[];
17
+ export declare function getToolContract(name: string): ToolContract;
18
+ //# sourceMappingURL=tool-contracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-contracts.d.ts","sourceRoot":"","sources":["../../src/lib/tool-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,QAAQ,CAAC;AAgChC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC;IACvB,YAAY,EAAE,CAAC,CAAC,OAAO,CAAC;IACxB,WAAW,EAAE;QACX,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,OAAO,CAAC;QACzB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;CACH;AAED,eAAO,MAAM,cAAc,EAAE,YAAY,EAsHxC,CAAC;AAEF,wBAAgB,gBAAgB,IAAI,YAAY,EAAE,CAEjD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAM1D"}
@@ -0,0 +1,120 @@
1
+ import {} from 'zod/v4';
2
+ import { CreateRelationshipInputSchema, DeleteMemoriesInputSchema, DeleteMemoryInputSchema, DeleteRelationshipInputSchema, GetMemoryInputSchema, GetRelationshipsInputSchema, MemoryStatsInputSchema, RecallInputSchema, RetrieveContextInputSchema, SearchMemoriesInputSchema, StoreMemoriesInputSchema, StoreMemoryInputSchema, UpdateMemoryInputSchema, } from '../schemas/inputs.js';
3
+ import { BatchResultSchema, CreateRelationshipResultSchema, DeleteRelationshipResultSchema, DeleteResultSchema, MemoryResultSchema, RecallResultSchema, RelationshipResultSchema, RetrieveContextResultSchema, SearchResultSchema, StatsResultSchema, StoreResultSchema, UpdateResultSchema, } from '../schemas/outputs.js';
4
+ export const TOOL_CONTRACTS = [
5
+ {
6
+ name: 'store_memory',
7
+ title: 'Store Memory',
8
+ description: 'Store a single memory with content, tags, and optional type/importance. Returns the SHA-256 hash. Idempotent — storing the same content+tags returns the existing hash with `created: false`. For storing multiple memories at once, prefer `store_memories`.',
9
+ inputSchema: StoreMemoryInputSchema,
10
+ outputSchema: StoreResultSchema,
11
+ annotations: { idempotentHint: true, openWorldHint: false },
12
+ },
13
+ {
14
+ name: 'store_memories',
15
+ title: 'Store Memories (Batch)',
16
+ description: 'Store up to 50 memories atomically. Each item is independently idempotent — same content+tags returns existing hash with `created: false`. Returns per-item results. Transaction rolls back entirely on unexpected error.',
17
+ inputSchema: StoreMemoriesInputSchema,
18
+ outputSchema: BatchResultSchema,
19
+ annotations: { idempotentHint: true, openWorldHint: false },
20
+ },
21
+ {
22
+ name: 'get_memory',
23
+ title: 'Get Memory',
24
+ description: 'Retrieve a single memory by its exact SHA-256 hash. Returns the full memory object or E_NOT_FOUND. Use `search_memories` or `recall` when you do not know the exact hash.',
25
+ inputSchema: GetMemoryInputSchema,
26
+ outputSchema: MemoryResultSchema,
27
+ annotations: { readOnlyHint: true, openWorldHint: false },
28
+ },
29
+ {
30
+ name: 'search_memories',
31
+ title: 'Search Memories',
32
+ description: 'Full-text search over memory content and tags using FTS5. Returns ranked results with cursor pagination. Query terms are individually matched (all-OR logic; FTS5 phrase operators and negation are not supported). Use `recall` when you need to follow relationships between memories after the search.',
33
+ inputSchema: SearchMemoriesInputSchema,
34
+ outputSchema: SearchResultSchema,
35
+ annotations: { readOnlyHint: true, openWorldHint: false },
36
+ },
37
+ {
38
+ name: 'retrieve_context',
39
+ title: 'Retrieve Context',
40
+ description: 'FTS search with automatic token-budget management. Returns relevance-ranked memories totalling at most `token_budget` tokens. `strategy` controls sort: `relevance` (FTS rank, default), `importance` (highest first), or `recency` (newest first). Returns `truncated: true` when budget was reached before all candidates were included.',
41
+ inputSchema: RetrieveContextInputSchema,
42
+ outputSchema: RetrieveContextResultSchema,
43
+ annotations: { readOnlyHint: true, openWorldHint: false },
44
+ },
45
+ {
46
+ name: 'recall',
47
+ title: 'Recall (BFS Graph Traversal)',
48
+ description: 'Search for memories and explore their connections (knowledge graph). FTS search then BFS graph traversal up to `depth` hops. Returns all discovered memories and edges. Use when exploring memory relationships or understanding context. Emits progress per hop. Returns `aborted: true` with partial results when safety limits are hit (env: RECALL_MAX_FRONTIER_SIZE, RECALL_MAX_EDGE_ROWS, RECALL_MAX_VISITED_NODES).',
49
+ inputSchema: RecallInputSchema,
50
+ outputSchema: RecallResultSchema,
51
+ annotations: { readOnlyHint: true, openWorldHint: false },
52
+ },
53
+ {
54
+ name: 'update_memory',
55
+ title: 'Update Memory',
56
+ description: 'Replace the content (and optionally tags) of an existing memory. Returns both old and new SHA-256 hashes, since content changes alter the hash. Returns E_NOT_FOUND if the memory does not exist; E_CONFLICT if the new content+tags already maps to an existing hash.',
57
+ inputSchema: UpdateMemoryInputSchema,
58
+ outputSchema: UpdateResultSchema,
59
+ annotations: { destructiveHint: true, openWorldHint: false },
60
+ },
61
+ {
62
+ name: 'delete_memory',
63
+ title: 'Delete Memory',
64
+ description: 'Delete a single memory by its SHA-256 hash. Cascade-deletes all relationships involving it. Returns E_NOT_FOUND if the hash does not exist.',
65
+ inputSchema: DeleteMemoryInputSchema,
66
+ outputSchema: DeleteResultSchema,
67
+ annotations: { destructiveHint: true, openWorldHint: false },
68
+ },
69
+ {
70
+ name: 'delete_memories',
71
+ title: 'Delete Memories (Batch)',
72
+ description: 'Delete up to 50 memories atomically. Cascade-deletes all relationships for each hash. Per-item `deleted: false` means the hash was not found — not an error, the batch still succeeds. Transaction rolls back entirely on unexpected error.',
73
+ inputSchema: DeleteMemoriesInputSchema,
74
+ outputSchema: BatchResultSchema,
75
+ annotations: { destructiveHint: true, openWorldHint: false },
76
+ },
77
+ {
78
+ name: 'create_relationship',
79
+ title: 'Create Relationship',
80
+ description: 'Create a directed labeled edge between two memories. Idempotent — re-creating an existing relationship is a no-op and returns `created: false`. Both endpoint memories must already exist, otherwise returns E_NOT_FOUND for the missing endpoint.',
81
+ inputSchema: CreateRelationshipInputSchema,
82
+ outputSchema: CreateRelationshipResultSchema,
83
+ annotations: { idempotentHint: true, openWorldHint: false },
84
+ },
85
+ {
86
+ name: 'delete_relationship',
87
+ title: 'Delete Relationship',
88
+ description: 'Remove a single directed relationship edge between two memories. All three fields (from_hash, to_hash, relation_type) must match exactly. Returns E_NOT_FOUND if the exact relationship does not exist.',
89
+ inputSchema: DeleteRelationshipInputSchema,
90
+ outputSchema: DeleteRelationshipResultSchema,
91
+ annotations: { destructiveHint: true, openWorldHint: false },
92
+ },
93
+ {
94
+ name: 'get_relationships',
95
+ title: 'Get Relationships',
96
+ description: 'Retrieve all relationships for a memory, with the related memory inlined. Filter by direction (outgoing | incoming | both). Returns E_NOT_FOUND if the source memory does not exist.',
97
+ inputSchema: GetRelationshipsInputSchema,
98
+ outputSchema: RelationshipResultSchema,
99
+ annotations: { readOnlyHint: true, openWorldHint: false },
100
+ },
101
+ {
102
+ name: 'memory_stats',
103
+ title: 'Memory Stats',
104
+ description: 'Return aggregate statistics: total memories, total relationships, oldest/newest timestamps, average importance, and per-type counts. No input required.',
105
+ inputSchema: MemoryStatsInputSchema,
106
+ outputSchema: StatsResultSchema,
107
+ annotations: { readOnlyHint: true, openWorldHint: false },
108
+ },
109
+ ];
110
+ export function getToolContracts() {
111
+ return TOOL_CONTRACTS;
112
+ }
113
+ export function getToolContract(name) {
114
+ const contract = TOOL_CONTRACTS.find((c) => c.name === name);
115
+ if (!contract) {
116
+ throw new Error(`Tool contract not found: ${name}`);
117
+ }
118
+ return contract;
119
+ }
120
+ //# sourceMappingURL=tool-contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-contracts.js","sourceRoot":"","sources":["../../src/lib/tool-contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,QAAQ,CAAC;AAEhC,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,EACzB,uBAAuB,EACvB,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,8BAA8B,EAC9B,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,2BAA2B,EAC3B,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAgB/B,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,EAAE,cAAc;QACrB,WAAW,EACT,+PAA+P;QACjQ,WAAW,EAAE,sBAAsB;QACnC,YAAY,EAAE,iBAAiB;QAC/B,WAAW,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE;KAC5D;IACD;QACE,IAAI,EAAE,gBAAgB;QACtB,KAAK,EAAE,wBAAwB;QAC/B,WAAW,EACT,2NAA2N;QAC7N,WAAW,EAAE,wBAAwB;QACrC,YAAY,EAAE,iBAAiB;QAC/B,WAAW,EAAE,EAAE,cAAc,EAAE,IAAI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AC;AACxB,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC7D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -6,7 +6,7 @@ function createHelpMessages(instructions) {
6
6
  role: 'user',
7
7
  content: {
8
8
  type: 'text',
9
- text: 'Show me the memory usage instructions.',
9
+ text: 'How do I use the memory tools?',
10
10
  },
11
11
  },
12
12
  {
@@ -21,7 +21,7 @@ function createHelpMessages(instructions) {
21
21
  const HELP_MESSAGES = createHelpMessages(INSTRUCTIONS_CONTENT);
22
22
  const GET_HELP_PROMPT_CONFIG = {
23
23
  title: 'Get Help',
24
- description: 'Return the full usage instructions for all memory tools and workflows.',
24
+ description: 'Return full usage instructions: tool inventory, routing decisions, error codes, data model limits, and workflow patterns.',
25
25
  };
26
26
  const GET_HELP_PROMPT_NAME = 'get-help';
27
27
  export function registerAllPrompts(server) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/prompts/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,oBAAoB,GAAG,gBAAgB,EAAE,CAAC;AAEhD,SAAS,kBAAkB,CAAC,YAAoB;IAC9C,OAAO;QACL;YACE,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,wCAAwC;aAC/C;SACF;QACD;YACE,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE;gBACP,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,YAAY;aACnB;SACF;KACF,CAAC;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"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA+C9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAyDzE"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAKzE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AA8C9C,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CA2DzE"}
@@ -2,6 +2,7 @@ import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { createHashCompletionCallback } from '../completions/index.js';
4
4
  import { loadInstructions } from '../lib/instructions.js';
5
+ import { SELECT_MEMORY_BY_HASH_SQL } from '../lib/sql.js';
5
6
  import { parseMemoryRow } from '../lib/types.js';
6
7
  const HASH_REGEX = /^[a-f0-9]{64}$/;
7
8
  const INSTRUCTIONS_URI = 'internal://instructions';
@@ -22,15 +23,13 @@ function getSingleVariable(value) {
22
23
  return Array.isArray(value) ? value[0] : value;
23
24
  }
24
25
  function readMemoryByHash(db, hash) {
25
- return db
26
- .prepareOnce('SELECT * FROM memories WHERE hash = ?')
27
- .get(hash);
26
+ return db.prepareOnce(SELECT_MEMORY_BY_HASH_SQL).get(hash);
28
27
  }
29
28
  const INSTRUCTIONS_CONTENT = loadInstructions();
30
29
  export function registerAllResources(server, db) {
31
30
  server.registerResource('instructions', INSTRUCTIONS_URI, {
32
31
  title: 'Memory Instructions',
33
- description: 'Usage guide for all memory tools and workflows.',
32
+ description: 'Complete usage guide: tool inventory, routing decisions, error codes, data model, and workflow patterns. Read this first.',
34
33
  mimeType: 'text/markdown',
35
34
  annotations: { audience: ['assistant'], priority: 0.9 },
36
35
  }, () => ({
@@ -48,7 +47,7 @@ export function registerAllResources(server, db) {
48
47
  complete: { hash: hashCompletion },
49
48
  }), {
50
49
  title: 'Memory',
51
- description: 'Retrieve a memory by its SHA-256 hash.',
50
+ description: 'Fetch a single memory object by exact SHA-256 hash. Supports hash auto-completion. Returns { error } if the hash does not exist.',
52
51
  mimeType: 'application/json',
53
52
  annotations: { audience: ['assistant'], priority: 0.7 },
54
53
  }, (uri, variables) => {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resources/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAG3E,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AAEzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,UAAU,GAAG,gBAAgB,CAAC;AACpC,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,4BAA4B,GAAG,0BAA0B,CAAC;AAQhE,SAAS,iBAAiB,CAAC,GAAW,EAAE,OAAgB;IACtD,OAAO;QACL,GAAG;QACH,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;KAC9B,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,GAAW,EACX,KAAa,EACb,IAAa;IAEb,OAAO;QACL,QAAQ,EAAE,CAAC,iBAAiB,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,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>;
103
103
  strategy: z.ZodPrefault<z.ZodOptional<z.ZodEnum<{
104
- relevance: "relevance";
105
104
  importance: "importance";
106
105
  recency: "recency";
106
+ relevance: "relevance";
107
107
  }>>>;
108
108
  }, z.core.$strict>;
109
109
  export declare const GetRelationshipsInputSchema: z.ZodObject<{
@@ -1 +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;AA8C9C,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,OAAO,GACV,IAAI,CAgDN"}
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;AA+C9C,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,SAAS,EACjB,EAAE,EAAE,OAAO,GACV,IAAI,CAiDN"}
@@ -1,8 +1,9 @@
1
1
  import { E_NOT_FOUND, E_UNKNOWN, getErrorMessage, rethrowMcpError, } from '../lib/errors.js';
2
2
  import { logToolEvent } from '../lib/mcp-utils.js';
3
+ import { getToolContract } from '../lib/tool-contracts.js';
3
4
  import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
4
- import { CreateRelationshipInputSchema } from '../schemas/inputs.js';
5
- import { CreateRelationshipResultSchema } from '../schemas/outputs.js';
5
+ import {} from '../schemas/inputs.js';
6
+ import {} from '../schemas/outputs.js';
6
7
  import { wrapToolHandler } from './progress.js';
7
8
  const INSERT_RELATIONSHIP_SQL = `INSERT OR IGNORE INTO relationships (from_hash, to_hash, relation_type, created_at)
8
9
  VALUES (?, ?, ?, ?)`;
@@ -24,12 +25,13 @@ function getMissingEndpoint(db, params) {
24
25
  return undefined;
25
26
  }
26
27
  export function registerCreateRelationship(server, db) {
27
- server.registerTool('create_relationship', {
28
- title: 'Create Relationship',
29
- description: 'Create a directed labeled edge between two memories. Idempotent — re-creating an existing relationship is a no-op.',
30
- inputSchema: CreateRelationshipInputSchema,
31
- outputSchema: CreateRelationshipResultSchema,
32
- annotations: { idempotentHint: true, openWorldHint: false },
28
+ const contract = getToolContract('create_relationship');
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,
33
35
  }, wrapToolHandler(async (params) => {
34
36
  try {
35
37
  const missing = getMissingEndpoint(db, params);
@@ -1 +1 @@
1
- {"version":3,"file":"create-relationship.js","sourceRoot":"","sources":["../../src/tools/create-relationship.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGhD,MAAM,uBAAuB,GAAG;sBACV,CAAC;AACvB,MAAM,iBAAiB,GACrB,wDAAwD,CAAC;AAE3D,SAAS,oBAAoB,CAAC,IAAyB,EAAE,IAAY;IACnE,OAAO,GAAG,IAAI,sBAAsB,IAAI,EAAE,CAAC;AAC7C,CAAC;AAED,SAAS,kBAAkB,CACzB,EAAW,EACX,MAAqD;IAErD,MAAM,IAAI,GAAG,EAAE;SACZ,WAAW,CAAmB,iBAAiB,C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AA0B,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,MAAM,CAAC,aAAa,GAAG;KAC5H,CACF,CACF,CAAC;AACJ,CAAC"}
@@ -1 +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;AA8B9C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAsD3E"}
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;AA0B9C,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO,GAAG,IAAI,CAsD3E"}
@@ -1,13 +1,11 @@
1
1
  import { E_UNKNOWN, getErrorMessage, rethrowMcpError } from '../lib/errors.js';
2
2
  import { logToolEvent, notifyMemoryResourceUpdated } from '../lib/mcp-utils.js';
3
+ import { DELETE_MEMORY_SQL } from '../lib/sql.js';
4
+ import { getToolContract } from '../lib/tool-contracts.js';
3
5
  import { createErrorResponse, createToolResponse, } from '../lib/tool-response.js';
4
- import { DeleteMemoriesInputSchema } from '../schemas/inputs.js';
5
- import { BatchResultSchema } from '../schemas/outputs.js';
6
+ import {} from '../schemas/inputs.js';
7
+ import {} from '../schemas/outputs.js';
6
8
  import { wrapToolHandler } from './progress.js';
7
- const DELETE_MEMORY_SQL = 'DELETE FROM memories WHERE hash = ?';
8
- function countDeleted(items) {
9
- return items.reduce((count, item) => (item.deleted ? count + 1 : count), 0);
10
- }
11
9
  async function notifyDeletedResources(server, items) {
12
10
  const notifications = items
13
11
  .filter((item) => item.deleted)
@@ -15,12 +13,13 @@ async function notifyDeletedResources(server, items) {
15
13
  await Promise.allSettled(notifications);
16
14
  }
17
15
  export function registerDeleteMemories(server, db) {
18
- server.registerTool('delete_memories', {
19
- title: 'Delete Memories (Batch)',
20
- description: 'Delete multiple memories by hash in a single atomic transaction. Returns per-item results indicating which hashes were deleted.',
21
- inputSchema: DeleteMemoriesInputSchema,
22
- outputSchema: BatchResultSchema,
23
- annotations: { destructiveHint: true, openWorldHint: false },
16
+ const contract = getToolContract('delete_memories');
17
+ server.registerTool(contract.name, {
18
+ title: contract.title,
19
+ description: contract.description,
20
+ inputSchema: contract.inputSchema,
21
+ outputSchema: contract.outputSchema,
22
+ annotations: contract.annotations,
24
23
  }, wrapToolHandler(async (params) => {
25
24
  try {
26
25
  const results = db.transaction(() => {
@@ -31,14 +30,19 @@ export function registerDeleteMemories(server, db) {
31
30
  items.push({
32
31
  hash,
33
32
  ok: true,
34
- created: false,
35
33
  deleted: result.changes > 0,
36
34
  });
37
35
  }
38
36
  return items;
39
37
  });
40
- const deleted = countDeleted(results);
41
- const succeeded = results.reduce((count, item) => (item.ok ? count + 1 : count), 0);
38
+ let deleted = 0;
39
+ let succeeded = 0;
40
+ for (const item of results) {
41
+ if (item.ok)
42
+ succeeded += 1;
43
+ if (item.deleted)
44
+ deleted += 1;
45
+ }
42
46
  const failed = results.length - succeeded;
43
47
  await logToolEvent(server, 'delete_memories', {
44
48
  total: params.hashes.length,