@j0hanz/memory-mcp 1.3.1 → 1.4.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 (173) hide show
  1. package/dist/completions/index.d.ts +0 -1
  2. package/dist/completions/index.js +4 -3
  3. package/dist/db/index.d.ts +0 -1
  4. package/dist/db/index.js +14 -9
  5. package/dist/db/typed.d.ts +0 -1
  6. package/dist/db/typed.js +3 -7
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.js +9 -5
  9. package/dist/lib/errors.d.ts +2 -1
  10. package/dist/lib/errors.js +4 -2
  11. package/dist/lib/hash.d.ts +0 -1
  12. package/dist/lib/hash.js +2 -2
  13. package/dist/lib/instructions.d.ts +0 -1
  14. package/dist/lib/instructions.js +1 -5
  15. package/dist/lib/json-schema.d.ts +3 -0
  16. package/dist/lib/json-schema.js +9 -0
  17. package/dist/lib/mcp-utils.d.ts +0 -1
  18. package/dist/lib/mcp-utils.js +5 -3
  19. package/dist/lib/pagination.d.ts +0 -1
  20. package/dist/lib/pagination.js +4 -2
  21. package/dist/lib/search-cursor.d.ts +0 -1
  22. package/dist/lib/search-cursor.js +2 -2
  23. package/dist/lib/search.d.ts +0 -1
  24. package/dist/lib/search.js +12 -11
  25. package/dist/lib/sql.d.ts +1 -2
  26. package/dist/lib/sql.js +5 -2
  27. package/dist/lib/tool-contracts.d.ts +0 -1
  28. package/dist/lib/tool-contracts.js +15 -15
  29. package/dist/lib/tool-response.d.ts +0 -1
  30. package/dist/lib/tool-response.js +4 -3
  31. package/dist/lib/types.d.ts +0 -1
  32. package/dist/lib/types.js +2 -2
  33. package/dist/prompts/index.d.ts +0 -1
  34. package/dist/prompts/index.js +1 -2
  35. package/dist/resources/index.d.ts +0 -1
  36. package/dist/resources/index.js +59 -61
  37. package/dist/resources/instructions.d.ts +0 -1
  38. package/dist/resources/instructions.js +58 -60
  39. package/dist/resources/server-config.d.ts +0 -1
  40. package/dist/resources/server-config.js +10 -6
  41. package/dist/resources/tool-catalog.d.ts +0 -1
  42. package/dist/resources/tool-catalog.js +7 -18
  43. package/dist/resources/tool-info.d.ts +0 -1
  44. package/dist/resources/tool-info.js +12 -20
  45. package/dist/resources/workflows.d.ts +0 -1
  46. package/dist/resources/workflows.js +6 -4
  47. package/dist/schemas/index.d.ts +0 -1
  48. package/dist/schemas/index.js +1 -2
  49. package/dist/schemas/inputs.d.ts +17 -25
  50. package/dist/schemas/inputs.js +19 -7
  51. package/dist/schemas/outputs.d.ts +0 -1
  52. package/dist/schemas/outputs.js +3 -3
  53. package/dist/server.d.ts +0 -1
  54. package/dist/server.js +16 -13
  55. package/dist/tools/create-relationship.d.ts +0 -1
  56. package/dist/tools/create-relationship.js +26 -22
  57. package/dist/tools/delete-memories.d.ts +0 -1
  58. package/dist/tools/delete-memories.js +4 -12
  59. package/dist/tools/delete-memory.d.ts +0 -1
  60. package/dist/tools/delete-memory.js +4 -12
  61. package/dist/tools/delete-relationship.d.ts +0 -1
  62. package/dist/tools/delete-relationship.js +4 -12
  63. package/dist/tools/get-memory.d.ts +0 -1
  64. package/dist/tools/get-memory.js +4 -12
  65. package/dist/tools/get-relationships.d.ts +0 -1
  66. package/dist/tools/get-relationships.js +7 -13
  67. package/dist/tools/index.d.ts +0 -1
  68. package/dist/tools/index.js +2 -3
  69. package/dist/tools/memory-stats.d.ts +0 -1
  70. package/dist/tools/memory-stats.js +4 -12
  71. package/dist/tools/progress.d.ts +2 -2
  72. package/dist/tools/progress.js +2 -2
  73. package/dist/tools/recall.d.ts +0 -1
  74. package/dist/tools/recall.js +47 -49
  75. package/dist/tools/register-contract.d.ts +3 -0
  76. package/dist/tools/register-contract.js +11 -0
  77. package/dist/tools/result.d.ts +1 -1
  78. package/dist/tools/result.js +4 -1
  79. package/dist/tools/retrieve-context.d.ts +0 -1
  80. package/dist/tools/retrieve-context.js +6 -14
  81. package/dist/tools/search-memories.d.ts +0 -1
  82. package/dist/tools/search-memories.js +4 -12
  83. package/dist/tools/store-memories.d.ts +0 -1
  84. package/dist/tools/store-memories.js +4 -12
  85. package/dist/tools/store-memory.d.ts +0 -1
  86. package/dist/tools/store-memory.js +4 -12
  87. package/dist/tools/update-memory.d.ts +0 -1
  88. package/dist/tools/update-memory.js +4 -12
  89. package/package.json +9 -6
  90. package/dist/completions/index.d.ts.map +0 -1
  91. package/dist/completions/index.js.map +0 -1
  92. package/dist/db/index.d.ts.map +0 -1
  93. package/dist/db/index.js.map +0 -1
  94. package/dist/db/typed.d.ts.map +0 -1
  95. package/dist/db/typed.js.map +0 -1
  96. package/dist/index.d.ts.map +0 -1
  97. package/dist/index.js.map +0 -1
  98. package/dist/lib/errors.d.ts.map +0 -1
  99. package/dist/lib/errors.js.map +0 -1
  100. package/dist/lib/hash.d.ts.map +0 -1
  101. package/dist/lib/hash.js.map +0 -1
  102. package/dist/lib/instructions.d.ts.map +0 -1
  103. package/dist/lib/instructions.js.map +0 -1
  104. package/dist/lib/mcp-utils.d.ts.map +0 -1
  105. package/dist/lib/mcp-utils.js.map +0 -1
  106. package/dist/lib/pagination.d.ts.map +0 -1
  107. package/dist/lib/pagination.js.map +0 -1
  108. package/dist/lib/search-cursor.d.ts.map +0 -1
  109. package/dist/lib/search-cursor.js.map +0 -1
  110. package/dist/lib/search.d.ts.map +0 -1
  111. package/dist/lib/search.js.map +0 -1
  112. package/dist/lib/sql.d.ts.map +0 -1
  113. package/dist/lib/sql.js.map +0 -1
  114. package/dist/lib/tool-contracts.d.ts.map +0 -1
  115. package/dist/lib/tool-contracts.js.map +0 -1
  116. package/dist/lib/tool-response.d.ts.map +0 -1
  117. package/dist/lib/tool-response.js.map +0 -1
  118. package/dist/lib/types.d.ts.map +0 -1
  119. package/dist/lib/types.js.map +0 -1
  120. package/dist/prompts/index.d.ts.map +0 -1
  121. package/dist/prompts/index.js.map +0 -1
  122. package/dist/resources/index.d.ts.map +0 -1
  123. package/dist/resources/index.js.map +0 -1
  124. package/dist/resources/instructions.d.ts.map +0 -1
  125. package/dist/resources/instructions.js.map +0 -1
  126. package/dist/resources/server-config.d.ts.map +0 -1
  127. package/dist/resources/server-config.js.map +0 -1
  128. package/dist/resources/tool-catalog.d.ts.map +0 -1
  129. package/dist/resources/tool-catalog.js.map +0 -1
  130. package/dist/resources/tool-info.d.ts.map +0 -1
  131. package/dist/resources/tool-info.js.map +0 -1
  132. package/dist/resources/workflows.d.ts.map +0 -1
  133. package/dist/resources/workflows.js.map +0 -1
  134. package/dist/schemas/index.d.ts.map +0 -1
  135. package/dist/schemas/index.js.map +0 -1
  136. package/dist/schemas/inputs.d.ts.map +0 -1
  137. package/dist/schemas/inputs.js.map +0 -1
  138. package/dist/schemas/outputs.d.ts.map +0 -1
  139. package/dist/schemas/outputs.js.map +0 -1
  140. package/dist/server.d.ts.map +0 -1
  141. package/dist/server.js.map +0 -1
  142. package/dist/tools/create-relationship.d.ts.map +0 -1
  143. package/dist/tools/create-relationship.js.map +0 -1
  144. package/dist/tools/delete-memories.d.ts.map +0 -1
  145. package/dist/tools/delete-memories.js.map +0 -1
  146. package/dist/tools/delete-memory.d.ts.map +0 -1
  147. package/dist/tools/delete-memory.js.map +0 -1
  148. package/dist/tools/delete-relationship.d.ts.map +0 -1
  149. package/dist/tools/delete-relationship.js.map +0 -1
  150. package/dist/tools/get-memory.d.ts.map +0 -1
  151. package/dist/tools/get-memory.js.map +0 -1
  152. package/dist/tools/get-relationships.d.ts.map +0 -1
  153. package/dist/tools/get-relationships.js.map +0 -1
  154. package/dist/tools/index.d.ts.map +0 -1
  155. package/dist/tools/index.js.map +0 -1
  156. package/dist/tools/memory-stats.d.ts.map +0 -1
  157. package/dist/tools/memory-stats.js.map +0 -1
  158. package/dist/tools/progress.d.ts.map +0 -1
  159. package/dist/tools/progress.js.map +0 -1
  160. package/dist/tools/recall.d.ts.map +0 -1
  161. package/dist/tools/recall.js.map +0 -1
  162. package/dist/tools/result.d.ts.map +0 -1
  163. package/dist/tools/result.js.map +0 -1
  164. package/dist/tools/retrieve-context.d.ts.map +0 -1
  165. package/dist/tools/retrieve-context.js.map +0 -1
  166. package/dist/tools/search-memories.d.ts.map +0 -1
  167. package/dist/tools/search-memories.js.map +0 -1
  168. package/dist/tools/store-memories.d.ts.map +0 -1
  169. package/dist/tools/store-memories.js.map +0 -1
  170. package/dist/tools/store-memory.d.ts.map +0 -1
  171. package/dist/tools/store-memory.js.map +0 -1
  172. package/dist/tools/update-memory.d.ts.map +0 -1
  173. package/dist/tools/update-memory.js.map +0 -1
@@ -1,3 +1,2 @@
1
1
  import type { TypedDb } from '../db/typed.js';
2
2
  export declare function createHashCompletionCallback(db: TypedDb): (value: string) => string[];
3
- //# sourceMappingURL=index.d.ts.map
@@ -7,14 +7,15 @@ function escapeLikePattern(value) {
7
7
  function normalizeHashPrefix(value) {
8
8
  return escapeLikePattern(value.slice(0, HASH_MAX_LENGTH));
9
9
  }
10
+ function toHashPrefixLikePattern(value) {
11
+ return `${normalizeHashPrefix(value)}%`;
12
+ }
10
13
  // Returns a completion callback for the `hash` URI variable.
11
14
  export function createHashCompletionCallback(db) {
12
15
  return (value) => {
13
- const escapedPrefix = normalizeHashPrefix(value);
14
16
  return db
15
17
  .prepareOnce(HASH_COMPLETION_SQL)
16
- .all(`${escapedPrefix}%`)
18
+ .all(toHashPrefixLikePattern(value))
17
19
  .map((row) => row.hash);
18
20
  };
19
21
  }
20
- //# sourceMappingURL=index.js.map
@@ -2,4 +2,3 @@ import { DatabaseSync } from 'node:sqlite';
2
2
  import { type TypedDb } from './typed.js';
3
3
  export declare function initDatabase(path: string): DatabaseSync;
4
4
  export declare function initTypedDatabase(path: string): TypedDb;
5
- //# sourceMappingURL=index.d.ts.map
package/dist/db/index.js CHANGED
@@ -63,6 +63,18 @@ const SCHEMA_SQL = `
63
63
  CREATE INDEX IF NOT EXISTS idx_relationships_to
64
64
  ON relationships(to_hash);
65
65
  `;
66
+ function runImmediateTransaction(db, action) {
67
+ db.exec('BEGIN IMMEDIATE');
68
+ try {
69
+ const result = action();
70
+ db.exec('COMMIT');
71
+ return result;
72
+ }
73
+ catch (err) {
74
+ db.exec('ROLLBACK');
75
+ throw err;
76
+ }
77
+ }
66
78
  function assertFts5Available(db) {
67
79
  try {
68
80
  db.exec(FTS5_CHECK_SQL);
@@ -105,8 +117,7 @@ function needsRelationshipsCascadeUpdateMigration(db) {
105
117
  return false;
106
118
  }
107
119
  function migrateRelationshipsCascadeUpdate(db) {
108
- db.exec('BEGIN IMMEDIATE');
109
- try {
120
+ runImmediateTransaction(db, () => {
110
121
  db.exec('ALTER TABLE relationships RENAME TO relationships_old');
111
122
  db.exec(RELATIONSHIPS_TABLE_SQL.replace(' IF NOT EXISTS', ''));
112
123
  db.exec(`
@@ -117,12 +128,7 @@ function migrateRelationshipsCascadeUpdate(db) {
117
128
  db.exec('DROP TABLE relationships_old');
118
129
  db.exec('CREATE INDEX IF NOT EXISTS idx_relationships_from ON relationships(from_hash)');
119
130
  db.exec('CREATE INDEX IF NOT EXISTS idx_relationships_to ON relationships(to_hash)');
120
- db.exec('COMMIT');
121
- }
122
- catch (err) {
123
- db.exec('ROLLBACK');
124
- throw err;
125
- }
131
+ });
126
132
  }
127
133
  function applyMigrations(db) {
128
134
  const currentVersion = readUserVersion(db);
@@ -157,4 +163,3 @@ export function initTypedDatabase(path) {
157
163
  const db = initDatabase(path);
158
164
  return createTypedDb(db);
159
165
  }
160
- //# sourceMappingURL=index.js.map
@@ -18,4 +18,3 @@ export declare class TypedDb {
18
18
  }
19
19
  export declare function createTypedDb(db: DatabaseSync): TypedDb;
20
20
  export {};
21
- //# sourceMappingURL=typed.d.ts.map
package/dist/db/typed.js CHANGED
@@ -6,13 +6,10 @@ export class TypedDb {
6
6
  }
7
7
  makeStatement(sql) {
8
8
  const stmt = this.db.prepare(sql);
9
- const materializeParams = (...params) => [
10
- ...params,
11
- ];
12
9
  return {
13
- all: (...params) => stmt.all(...materializeParams(...params)),
14
- get: (...params) => stmt.get(...materializeParams(...params)),
15
- run: (...params) => stmt.run(...materializeParams(...params)),
10
+ all: (...params) => stmt.all(...params),
11
+ get: (...params) => stmt.get(...params),
12
+ run: (...params) => stmt.run(...params),
16
13
  };
17
14
  }
18
15
  prepare(sql) {
@@ -50,4 +47,3 @@ export class TypedDb {
50
47
  export function createTypedDb(db) {
51
48
  return new TypedDb(db);
52
49
  }
53
- //# sourceMappingURL=typed.js.map
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  #!/usr/bin/env node
2
2
  export {};
3
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -12,6 +12,8 @@ const SHUTDOWN_SIGNALS = ['SIGINT', 'SIGTERM'];
12
12
  const SHUTDOWN_TIMEOUT_MS = 3000;
13
13
  const FORCED_EXIT_CODE = 1;
14
14
  const CLEAN_EXIT_CODE = 0;
15
+ const LEGACY_DB_BASENAME = 'memory.db';
16
+ const DEFAULT_DB_DIR = 'memory_db';
15
17
  function registerShutdownHandlers(shutdown) {
16
18
  for (const signal of SHUTDOWN_SIGNALS) {
17
19
  process.on(signal, shutdown);
@@ -56,15 +58,18 @@ function createShutdownHandler(server, db) {
56
58
  function migrateLegacyDatabase() {
57
59
  if (process.env['MEMORY_DB_PATH'])
58
60
  return;
59
- const legacyPath = 'memory.db';
60
- if (!existsSync(legacyPath) || existsSync(DEFAULT_DB_PATH))
61
+ if (!existsSync(LEGACY_DB_BASENAME) || existsSync(DEFAULT_DB_PATH))
61
62
  return;
62
63
  try {
63
64
  mkdirSync(dirname(DEFAULT_DB_PATH), { recursive: true });
64
- const filesToMove = [legacyPath, `${legacyPath}-shm`, `${legacyPath}-wal`];
65
+ const filesToMove = [
66
+ LEGACY_DB_BASENAME,
67
+ `${LEGACY_DB_BASENAME}-shm`,
68
+ `${LEGACY_DB_BASENAME}-wal`,
69
+ ];
65
70
  for (const file of filesToMove) {
66
71
  if (existsSync(file)) {
67
- renameSync(file, `memory_db/${file}`);
72
+ renameSync(file, `${DEFAULT_DB_DIR}/${file}`);
68
73
  }
69
74
  }
70
75
  }
@@ -85,4 +90,3 @@ main().catch((err) => {
85
90
  process.stderr.write(`Fatal error: ${getErrorMessage(err)}\n`);
86
91
  process.exit(FORCED_EXIT_CODE);
87
92
  });
88
- //# sourceMappingURL=index.js.map
@@ -1,3 +1,4 @@
1
+ import { McpError } from '@modelcontextprotocol/sdk/types.js';
1
2
  export declare const E_NOT_FOUND = "E_NOT_FOUND";
2
3
  export declare const E_INVALID_CURSOR = "E_INVALID_CURSOR";
3
4
  export declare const E_DB_ERROR = "E_DB_ERROR";
@@ -5,5 +6,5 @@ export declare const E_CONFLICT = "E_CONFLICT";
5
6
  export declare const E_CANCELLED = "E_CANCELLED";
6
7
  export declare const E_UNKNOWN = "E_UNKNOWN";
7
8
  export declare function getErrorMessage(err: unknown): string;
9
+ export declare function isMcpError(err: unknown): err is McpError;
8
10
  export declare function rethrowMcpError(err: unknown): void;
9
- //# sourceMappingURL=errors.d.ts.map
@@ -13,8 +13,10 @@ export function getErrorMessage(err) {
13
13
  return err;
14
14
  return UNKNOWN_ERROR_MESSAGE;
15
15
  }
16
+ export function isMcpError(err) {
17
+ return err instanceof McpError;
18
+ }
16
19
  export function rethrowMcpError(err) {
17
- if (err instanceof McpError)
20
+ if (isMcpError(err))
18
21
  throw err;
19
22
  }
20
- //# sourceMappingURL=errors.js.map
@@ -1,2 +1 @@
1
1
  export declare function computeMemoryHash(content: string, tags: readonly string[]): string;
2
- //# sourceMappingURL=hash.d.ts.map
package/dist/lib/hash.js CHANGED
@@ -7,7 +7,8 @@ function normalizeTags(tags) {
7
7
  return [...tags].sort();
8
8
  }
9
9
  function stableTagsJson(tags) {
10
- return JSON.stringify(normalizeTags(tags));
10
+ const normalizedTags = normalizeTags(tags);
11
+ return JSON.stringify(normalizedTags);
11
12
  }
12
13
  export function computeMemoryHash(content, tags) {
13
14
  return createHash(MEMORY_HASH_ALGORITHM)
@@ -15,4 +16,3 @@ export function computeMemoryHash(content, tags) {
15
16
  .update(stableTagsJson(tags))
16
17
  .digest('hex');
17
18
  }
18
- //# sourceMappingURL=hash.js.map
@@ -1,2 +1 @@
1
1
  export declare function loadInstructions(): string;
2
- //# sourceMappingURL=instructions.d.ts.map
@@ -1,10 +1,6 @@
1
1
  import { buildServerInstructions } from '../resources/instructions.js';
2
2
  let cachedInstructions;
3
3
  export function loadInstructions() {
4
- if (cachedInstructions !== undefined) {
5
- return cachedInstructions;
6
- }
7
- cachedInstructions = buildServerInstructions();
4
+ cachedInstructions ??= buildServerInstructions();
8
5
  return cachedInstructions;
9
6
  }
10
- //# sourceMappingURL=instructions.js.map
@@ -0,0 +1,3 @@
1
+ import { z } from 'zod/v4';
2
+ export type JsonSchemaObject = Record<string, unknown>;
3
+ export declare function extractJsonSchema(schema: z.ZodType): JsonSchemaObject;
@@ -0,0 +1,9 @@
1
+ import { z } from 'zod/v4';
2
+ export function extractJsonSchema(schema) {
3
+ try {
4
+ return z.toJSONSchema(schema);
5
+ }
6
+ catch {
7
+ return {};
8
+ }
9
+ }
@@ -3,4 +3,3 @@ type LogLevel = 'debug' | 'info' | 'notice' | 'warning' | 'error';
3
3
  export declare function logToolEvent(server: McpServer, logger: string, data: unknown, level?: LogLevel): Promise<void>;
4
4
  export declare function notifyMemoryResourceUpdated(server: McpServer, hash: string): Promise<void>;
5
5
  export {};
6
- //# sourceMappingURL=mcp-utils.d.ts.map
@@ -1,5 +1,8 @@
1
+ function isConnected(server) {
2
+ return server.isConnected();
3
+ }
1
4
  export async function logToolEvent(server, logger, data, level = 'info') {
2
- if (!server.isConnected()) {
5
+ if (!isConnected(server)) {
3
6
  return;
4
7
  }
5
8
  try {
@@ -11,7 +14,7 @@ export async function logToolEvent(server, logger, data, level = 'info') {
11
14
  }
12
15
  const MEMORY_RESOURCE_URI_PREFIX = 'memory://memories/';
13
16
  export async function notifyMemoryResourceUpdated(server, hash) {
14
- if (!server.isConnected()) {
17
+ if (!isConnected(server)) {
15
18
  return;
16
19
  }
17
20
  try {
@@ -23,4 +26,3 @@ export async function notifyMemoryResourceUpdated(server, hash) {
23
26
  // best-effort notification
24
27
  }
25
28
  }
26
- //# sourceMappingURL=mcp-utils.js.map
@@ -5,4 +5,3 @@ export interface PageSlice<T> {
5
5
  export declare function encodeCursor(offset: number): string;
6
6
  export declare function decodeCursor(cursor: string): number;
7
7
  export declare function splitPage<T>(rows: readonly T[], limit: number): PageSlice<T>;
8
- //# sourceMappingURL=pagination.d.ts.map
@@ -26,6 +26,9 @@ function parseCursorPayload(cursor) {
26
26
  }
27
27
  return parsed;
28
28
  }
29
+ function invalidCursor() {
30
+ return new McpError(ErrorCode.InvalidParams, `${E_INVALID_CURSOR}: malformed cursor`);
31
+ }
29
32
  export function encodeCursor(offset) {
30
33
  const payload = { offset };
31
34
  return Buffer.from(JSON.stringify(payload)).toString(CURSOR_ENCODING);
@@ -35,7 +38,7 @@ export function decodeCursor(cursor) {
35
38
  return parseCursorPayload(cursor).offset;
36
39
  }
37
40
  catch {
38
- throw new McpError(ErrorCode.InvalidParams, `${E_INVALID_CURSOR}: malformed cursor`);
41
+ throw invalidCursor();
39
42
  }
40
43
  }
41
44
  export function splitPage(rows, limit) {
@@ -44,4 +47,3 @@ export function splitPage(rows, limit) {
44
47
  }
45
48
  return { page: rows.slice(), hasMore: false };
46
49
  }
47
- //# sourceMappingURL=pagination.js.map
@@ -10,4 +10,3 @@ export type DecodedSearchCursor = {
10
10
  export declare function buildSearchCursorScope(query: string, filters: MemoryFilters): string;
11
11
  export declare function encodeSearchCursor(scope: string, rank: number, hash: string): string;
12
12
  export declare function decodeSearchCursor(cursor: string, expectedScope: string): DecodedSearchCursor;
13
- //# sourceMappingURL=search-cursor.d.ts.map
@@ -5,6 +5,7 @@ const CURSOR_ENCODING = 'base64url';
5
5
  const CURSOR_VERSION = 2;
6
6
  const CURSOR_KIND = 'fts-keyset';
7
7
  const CURSOR_SCOPE_HASH_LENGTH = 24;
8
+ const HASH_64_REGEX = /^[a-f0-9]{64}$/;
8
9
  function invalidCursor(reason) {
9
10
  return new McpError(ErrorCode.InvalidParams, `${E_INVALID_CURSOR}: ${reason}`);
10
11
  }
@@ -21,7 +22,7 @@ function isKeysetCursorPayload(value) {
21
22
  typeof value['rank'] === 'number' &&
22
23
  Number.isFinite(value['rank']) &&
23
24
  typeof value['hash'] === 'string' &&
24
- /^[a-f0-9]{64}$/.test(value['hash']));
25
+ HASH_64_REGEX.test(value['hash']));
25
26
  }
26
27
  function isLegacyOffsetCursorPayload(value) {
27
28
  if (!isRecord(value)) {
@@ -86,4 +87,3 @@ export function decodeSearchCursor(cursor, expectedScope) {
86
87
  }
87
88
  throw invalidCursor('malformed cursor');
88
89
  }
89
- //# sourceMappingURL=search-cursor.js.map
@@ -27,4 +27,3 @@ export declare function toMemoryFilters(params: {
27
27
  max_importance?: number | undefined;
28
28
  memory_type?: string | undefined;
29
29
  }): MemoryFilters;
30
- //# sourceMappingURL=search.d.ts.map
@@ -33,7 +33,7 @@ export function buildAndWhereClause(clauses) {
33
33
  if (clauses.length === 0) {
34
34
  return '';
35
35
  }
36
- return clauses.map((clause) => ` AND ${clause}`).join('');
36
+ return ` AND ${clauses.join(' AND ')}`;
37
37
  }
38
38
  function buildRankedSearchSql(whereExtra, cursor) {
39
39
  if (!cursor || cursor.mode === 'offset') {
@@ -64,14 +64,15 @@ export function loadRankedSearchRows(db, query, limit, cursor, filters) {
64
64
  return stmt.all(ftsQuery, ...filter.params, cursor.rank, cursor.rank, cursor.hash, limit + 1);
65
65
  }
66
66
  export function toMemoryFilters(params) {
67
- return {
68
- ...(params.min_importance != null
69
- ? { min_importance: params.min_importance }
70
- : {}),
71
- ...(params.max_importance != null
72
- ? { max_importance: params.max_importance }
73
- : {}),
74
- ...(params.memory_type != null ? { memory_type: params.memory_type } : {}),
75
- };
67
+ const filters = {};
68
+ if (params.min_importance != null) {
69
+ filters.min_importance = params.min_importance;
70
+ }
71
+ if (params.max_importance != null) {
72
+ filters.max_importance = params.max_importance;
73
+ }
74
+ if (params.memory_type != null) {
75
+ filters.memory_type = params.memory_type;
76
+ }
77
+ return filters;
76
78
  }
77
- //# sourceMappingURL=search.js.map
package/dist/lib/sql.d.ts CHANGED
@@ -9,9 +9,8 @@ export declare const SELECT_MEMORY_BY_HASH_SQL = "SELECT * FROM memories WHERE h
9
9
  /** Check existence: returns only the hash column to minimise data transfer. */
10
10
  export declare const SELECT_MEMORY_HASH_SQL = "SELECT hash FROM memories WHERE hash = ?";
11
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";
12
+ export declare const MEMORY_AGGREGATE_SQL = "SELECT COUNT(*) AS total,\n MIN(created_at) AS oldest,\n MAX(created_at) AS newest,\n AVG(importance) AS avg_importance\n FROM memories";
13
13
  /** Total relationship count. */
14
14
  export declare const RELATIONSHIP_COUNT_SQL = "SELECT COUNT(*) AS total FROM relationships";
15
15
  /** Per-type memory breakdown. */
16
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
package/dist/lib/sql.js CHANGED
@@ -10,9 +10,12 @@ export const SELECT_MEMORY_BY_HASH_SQL = 'SELECT * FROM memories WHERE hash = ?'
10
10
  /** Check existence: returns only the hash column to minimise data transfer. */
11
11
  export const SELECT_MEMORY_HASH_SQL = 'SELECT hash FROM memories WHERE hash = ?';
12
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';
13
+ export const MEMORY_AGGREGATE_SQL = `SELECT COUNT(*) AS total,
14
+ MIN(created_at) AS oldest,
15
+ MAX(created_at) AS newest,
16
+ AVG(importance) AS avg_importance
17
+ FROM memories`;
14
18
  /** Total relationship count. */
15
19
  export const RELATIONSHIP_COUNT_SQL = 'SELECT COUNT(*) AS total FROM relationships';
16
20
  /** Per-type memory breakdown. */
17
21
  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
@@ -15,4 +15,3 @@ export interface ToolContract {
15
15
  export declare const TOOL_CONTRACTS: ToolContract[];
16
16
  export declare function getToolContracts(): ToolContract[];
17
17
  export declare function getToolContract(name: string): ToolContract;
18
- //# sourceMappingURL=tool-contracts.d.ts.map
@@ -5,7 +5,7 @@ export const TOOL_CONTRACTS = [
5
5
  {
6
6
  name: 'store_memory',
7
7
  title: 'Store Memory',
8
- description: 'Store a single memory. Returns SHA-256 hash. Idempotent: existing content+tags returns `created: false`. Prefer `store_memories` for batch.',
8
+ description: 'Store single memory. Returns hash. Idempotent (created: false if exists). Prefer store_memories.',
9
9
  inputSchema: StoreMemoryInputSchema,
10
10
  outputSchema: StoreResultSchema,
11
11
  annotations: {
@@ -18,7 +18,7 @@ export const TOOL_CONTRACTS = [
18
18
  {
19
19
  name: 'store_memories',
20
20
  title: 'Store Memories (Batch)',
21
- description: 'Store up to 50 memories atomically. Idempotent per item. Returns per-item results. Rolls back entirely on error.',
21
+ description: 'Store 1-50 memories atomically. Idempotent. Rolls back on error.',
22
22
  inputSchema: StoreMemoriesInputSchema,
23
23
  outputSchema: BatchResultSchema,
24
24
  annotations: {
@@ -31,7 +31,7 @@ export const TOOL_CONTRACTS = [
31
31
  {
32
32
  name: 'get_memory',
33
33
  title: 'Get Memory',
34
- description: 'Retrieve a single memory by exact SHA-256 hash. Returns memory object or E_NOT_FOUND. Use `search_memories` or `recall` if hash is unknown.',
34
+ description: 'Retrieve memory by SHA-256 hash. Returns E_NOT_FOUND if missing.',
35
35
  inputSchema: GetMemoryInputSchema,
36
36
  outputSchema: MemoryResultSchema,
37
37
  annotations: {
@@ -43,7 +43,7 @@ export const TOOL_CONTRACTS = [
43
43
  {
44
44
  name: 'search_memories',
45
45
  title: 'Search Memories',
46
- description: 'FTS5 full-text search over content and tags. Returns ranked results with cursor pagination. Matches alphanumeric/underscore only (all-OR logic). Use `recall` to follow relationships.',
46
+ description: 'Full-text search (content+tags). Ranked, paginated. Alphanumeric/underscore only. Implicit AND.',
47
47
  inputSchema: SearchMemoriesInputSchema,
48
48
  outputSchema: SearchResultSchema,
49
49
  annotations: {
@@ -55,7 +55,7 @@ export const TOOL_CONTRACTS = [
55
55
  {
56
56
  name: 'retrieve_context',
57
57
  title: 'Retrieve Context',
58
- description: 'FTS search with token-budget management. Returns memories up to `token_budget`. Sort `strategy`: `relevance` (default), `importance`, or `recency`. Returns `truncated: true` if budget reached. Matches alphanumeric/underscore only.',
58
+ description: 'FTS search within token budget. Sorts by relevance/importance/recency. Returns truncated: true if limit hit.',
59
59
  inputSchema: RetrieveContextInputSchema,
60
60
  outputSchema: RetrieveContextResultSchema,
61
61
  annotations: {
@@ -67,7 +67,7 @@ export const TOOL_CONTRACTS = [
67
67
  {
68
68
  name: 'recall',
69
69
  title: 'Recall (BFS Graph Traversal)',
70
- description: 'FTS search then BFS graph traversal up to `depth` hops. Returns discovered memories and edges. Emits progress. Returns `aborted: true` if safety limits hit.',
70
+ description: 'FTS search + BFS traversal (depth hops). Returns memories+edges. Emits progress. Aborts on limit.',
71
71
  inputSchema: RecallInputSchema,
72
72
  outputSchema: RecallResultSchema,
73
73
  annotations: {
@@ -79,7 +79,7 @@ export const TOOL_CONTRACTS = [
79
79
  {
80
80
  name: 'update_memory',
81
81
  title: 'Update Memory',
82
- description: 'Replace content/tags of an existing memory. Returns old and new SHA-256 hashes. Returns E_NOT_FOUND if missing, E_CONFLICT if new content+tags already exists.',
82
+ description: 'Update content/tags. Returns old+new hash. Cascade updates relationships.',
83
83
  inputSchema: UpdateMemoryInputSchema,
84
84
  outputSchema: UpdateResultSchema,
85
85
  annotations: {
@@ -91,7 +91,7 @@ export const TOOL_CONTRACTS = [
91
91
  {
92
92
  name: 'delete_memory',
93
93
  title: 'Delete Memory',
94
- description: 'Delete a single memory by SHA-256 hash. Cascade-deletes relationships. Returns `{deleted: false}` if not found (idempotent).',
94
+ description: 'Delete memory by hash. Cascade deletes relationships. Idempotent.',
95
95
  inputSchema: DeleteMemoryInputSchema,
96
96
  outputSchema: DeleteResultSchema,
97
97
  annotations: {
@@ -104,7 +104,7 @@ export const TOOL_CONTRACTS = [
104
104
  {
105
105
  name: 'delete_memories',
106
106
  title: 'Delete Memories (Batch)',
107
- description: 'Delete up to 50 memories atomically. Cascade-deletes relationships. Per-item `deleted: false` if not found. Rolls back entirely on error.',
107
+ description: 'Delete 1-50 memories atomically. Cascade deletes. Rolls back on error.',
108
108
  inputSchema: DeleteMemoriesInputSchema,
109
109
  outputSchema: BatchResultSchema,
110
110
  annotations: {
@@ -116,7 +116,7 @@ export const TOOL_CONTRACTS = [
116
116
  {
117
117
  name: 'create_relationship',
118
118
  title: 'Create Relationship',
119
- description: 'Create directed labeled edge between two memories. Idempotent: existing edge returns `created: false`. Returns E_NOT_FOUND if endpoints missing.',
119
+ description: 'Create directed edge. Idempotent. Errors if endpoints missing.',
120
120
  inputSchema: CreateRelationshipInputSchema,
121
121
  outputSchema: CreateRelationshipResultSchema,
122
122
  annotations: {
@@ -129,7 +129,7 @@ export const TOOL_CONTRACTS = [
129
129
  {
130
130
  name: 'delete_relationship',
131
131
  title: 'Delete Relationship',
132
- description: 'Remove a single directed relationship edge. Exact match required (from_hash, to_hash, relation_type). Returns E_NOT_FOUND if missing.',
132
+ description: 'Delete edge. Exact match required. Errors if missing.',
133
133
  inputSchema: DeleteRelationshipInputSchema,
134
134
  outputSchema: DeleteRelationshipResultSchema,
135
135
  annotations: {
@@ -141,7 +141,7 @@ export const TOOL_CONTRACTS = [
141
141
  {
142
142
  name: 'get_relationships',
143
143
  title: 'Get Relationships',
144
- description: 'Retrieve all relationships for a memory, with related memory inlined. Filter by direction (outgoing|incoming|both). Returns E_NOT_FOUND if source missing.',
144
+ description: 'Get relationships for memory. Filter direction. Inlines related memory.',
145
145
  inputSchema: GetRelationshipsInputSchema,
146
146
  outputSchema: RelationshipResultSchema,
147
147
  annotations: {
@@ -153,7 +153,7 @@ export const TOOL_CONTRACTS = [
153
153
  {
154
154
  name: 'memory_stats',
155
155
  title: 'Memory Stats',
156
- description: 'Return aggregate statistics: total memories, relationships, oldest/newest timestamps, average importance, and per-type counts.',
156
+ description: 'Get global stats: counts, timestamps, importance.',
157
157
  inputSchema: MemoryStatsInputSchema,
158
158
  outputSchema: StatsResultSchema,
159
159
  annotations: {
@@ -163,14 +163,14 @@ export const TOOL_CONTRACTS = [
163
163
  },
164
164
  },
165
165
  ];
166
+ const TOOL_CONTRACTS_BY_NAME = new Map(TOOL_CONTRACTS.map((contract) => [contract.name, contract]));
166
167
  export function getToolContracts() {
167
168
  return TOOL_CONTRACTS;
168
169
  }
169
170
  export function getToolContract(name) {
170
- const contract = TOOL_CONTRACTS.find((c) => c.name === name);
171
+ const contract = TOOL_CONTRACTS_BY_NAME.get(name);
171
172
  if (!contract) {
172
173
  throw new Error(`Tool contract not found: ${name}`);
173
174
  }
174
175
  return contract;
175
176
  }
176
- //# sourceMappingURL=tool-contracts.js.map
@@ -1,4 +1,3 @@
1
1
  import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
2
  export declare function createToolResponse(payload: Record<string, unknown>): CallToolResult;
3
3
  export declare function createErrorResponse(code: string, message: string): CallToolResult;
4
- //# sourceMappingURL=tool-response.d.ts.map
@@ -8,15 +8,16 @@ function createStructuredError(code, message) {
8
8
  };
9
9
  }
10
10
  export function createToolResponse(payload) {
11
+ const textContent = toTextContent(payload);
11
12
  return {
12
- content: [toTextContent(payload)],
13
+ content: [textContent],
13
14
  structuredContent: payload,
14
15
  };
15
16
  }
16
17
  export function createErrorResponse(code, message) {
18
+ const errorPayload = createStructuredError(code, message);
17
19
  return {
18
- content: [toTextContent(createStructuredError(code, message))],
20
+ content: [toTextContent(errorPayload)],
19
21
  isError: true,
20
22
  };
21
23
  }
22
- //# sourceMappingURL=tool-response.js.map
@@ -72,4 +72,3 @@ export interface HashRow {
72
72
  }
73
73
  export declare function parseTags(tagsJson: string): string[];
74
74
  export declare function parseMemoryRow(row: MemoryRow): Memory;
75
- //# sourceMappingURL=types.d.ts.map
package/dist/lib/types.js CHANGED
@@ -12,10 +12,11 @@ export function parseTags(tagsJson) {
12
12
  }
13
13
  export function parseMemoryRow(row) {
14
14
  const relevance = row.rank != null ? -row.rank : undefined;
15
+ const tags = parseTags(row.tags);
15
16
  return {
16
17
  hash: row.hash,
17
18
  content: row.content,
18
- tags: parseTags(row.tags),
19
+ tags,
19
20
  memory_type: row.memory_type,
20
21
  importance: row.importance,
21
22
  created_at: row.created_at,
@@ -23,4 +24,3 @@ export function parseMemoryRow(row) {
23
24
  ...(relevance != null ? { relevance } : {}),
24
25
  };
25
26
  }
26
- //# sourceMappingURL=types.js.map
@@ -1,3 +1,2 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  export declare function registerAllPrompts(server: McpServer): void;
3
- //# sourceMappingURL=index.d.ts.map
@@ -19,14 +19,13 @@ function createHelpMessages(instructions) {
19
19
  ];
20
20
  }
21
21
  const HELP_MESSAGES = createHelpMessages(INSTRUCTIONS_CONTENT);
22
+ const GET_HELP_PROMPT_NAME = 'get-help';
22
23
  const GET_HELP_PROMPT_CONFIG = {
23
24
  title: 'Get Help',
24
25
  description: 'Return full usage instructions.',
25
26
  };
26
- const GET_HELP_PROMPT_NAME = 'get-help';
27
27
  export function registerAllPrompts(server) {
28
28
  server.registerPrompt(GET_HELP_PROMPT_NAME, GET_HELP_PROMPT_CONFIG, () => ({
29
29
  messages: HELP_MESSAGES,
30
30
  }));
31
31
  }
32
- //# sourceMappingURL=index.js.map
@@ -1,4 +1,3 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { TypedDb } from '../db/typed.js';
3
3
  export declare function registerAllResources(server: McpServer, db: TypedDb): void;
4
- //# sourceMappingURL=index.d.ts.map