@j0hanz/memory-mcp 1.3.0 → 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.
- package/README.md +8 -8
- package/dist/completions/index.d.ts +0 -1
- package/dist/completions/index.js +4 -3
- package/dist/db/index.d.ts +0 -1
- package/dist/db/index.js +14 -9
- package/dist/db/typed.d.ts +0 -1
- package/dist/db/typed.js +3 -7
- package/dist/index.d.ts +0 -1
- package/dist/index.js +29 -2
- package/dist/lib/errors.d.ts +2 -1
- package/dist/lib/errors.js +4 -2
- package/dist/lib/hash.d.ts +0 -1
- package/dist/lib/hash.js +2 -2
- package/dist/lib/instructions.d.ts +0 -1
- package/dist/lib/instructions.js +1 -5
- package/dist/lib/json-schema.d.ts +3 -0
- package/dist/lib/json-schema.js +9 -0
- package/dist/lib/mcp-utils.d.ts +0 -1
- package/dist/lib/mcp-utils.js +5 -3
- package/dist/lib/pagination.d.ts +0 -1
- package/dist/lib/pagination.js +4 -2
- package/dist/lib/search-cursor.d.ts +0 -1
- package/dist/lib/search-cursor.js +2 -2
- package/dist/lib/search.d.ts +0 -1
- package/dist/lib/search.js +12 -11
- package/dist/lib/sql.d.ts +1 -2
- package/dist/lib/sql.js +5 -2
- package/dist/lib/tool-contracts.d.ts +0 -1
- package/dist/lib/tool-contracts.js +15 -15
- package/dist/lib/tool-response.d.ts +0 -1
- package/dist/lib/tool-response.js +4 -3
- package/dist/lib/types.d.ts +0 -1
- package/dist/lib/types.js +2 -2
- package/dist/prompts/index.d.ts +0 -1
- package/dist/prompts/index.js +1 -2
- package/dist/resources/index.d.ts +0 -1
- package/dist/resources/index.js +59 -61
- package/dist/resources/instructions.d.ts +0 -1
- package/dist/resources/instructions.js +58 -60
- package/dist/resources/server-config.d.ts +0 -1
- package/dist/resources/server-config.js +11 -7
- package/dist/resources/tool-catalog.d.ts +0 -1
- package/dist/resources/tool-catalog.js +7 -18
- package/dist/resources/tool-info.d.ts +0 -1
- package/dist/resources/tool-info.js +12 -20
- package/dist/resources/workflows.d.ts +0 -1
- package/dist/resources/workflows.js +6 -4
- package/dist/schemas/index.d.ts +0 -1
- package/dist/schemas/index.js +1 -2
- package/dist/schemas/inputs.d.ts +17 -25
- package/dist/schemas/inputs.js +19 -7
- package/dist/schemas/outputs.d.ts +0 -1
- package/dist/schemas/outputs.js +3 -3
- package/dist/server.d.ts +0 -1
- package/dist/server.js +16 -13
- package/dist/tools/create-relationship.d.ts +0 -1
- package/dist/tools/create-relationship.js +26 -22
- package/dist/tools/delete-memories.d.ts +0 -1
- package/dist/tools/delete-memories.js +4 -12
- package/dist/tools/delete-memory.d.ts +0 -1
- package/dist/tools/delete-memory.js +4 -12
- package/dist/tools/delete-relationship.d.ts +0 -1
- package/dist/tools/delete-relationship.js +4 -12
- package/dist/tools/get-memory.d.ts +0 -1
- package/dist/tools/get-memory.js +4 -12
- package/dist/tools/get-relationships.d.ts +0 -1
- package/dist/tools/get-relationships.js +7 -13
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.js +2 -3
- package/dist/tools/memory-stats.d.ts +0 -1
- package/dist/tools/memory-stats.js +4 -12
- package/dist/tools/progress.d.ts +2 -2
- package/dist/tools/progress.js +2 -2
- package/dist/tools/recall.d.ts +0 -1
- package/dist/tools/recall.js +47 -49
- package/dist/tools/register-contract.d.ts +3 -0
- package/dist/tools/register-contract.js +11 -0
- package/dist/tools/result.d.ts +1 -1
- package/dist/tools/result.js +4 -1
- package/dist/tools/retrieve-context.d.ts +0 -1
- package/dist/tools/retrieve-context.js +6 -14
- package/dist/tools/search-memories.d.ts +0 -1
- package/dist/tools/search-memories.js +4 -12
- package/dist/tools/store-memories.d.ts +0 -1
- package/dist/tools/store-memories.js +4 -12
- package/dist/tools/store-memory.d.ts +0 -1
- package/dist/tools/store-memory.js +4 -12
- package/dist/tools/update-memory.d.ts +0 -1
- package/dist/tools/update-memory.js +4 -12
- package/package.json +9 -6
- package/dist/completions/index.d.ts.map +0 -1
- package/dist/completions/index.js.map +0 -1
- package/dist/db/index.d.ts.map +0 -1
- package/dist/db/index.js.map +0 -1
- package/dist/db/typed.d.ts.map +0 -1
- package/dist/db/typed.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/errors.d.ts.map +0 -1
- package/dist/lib/errors.js.map +0 -1
- package/dist/lib/hash.d.ts.map +0 -1
- package/dist/lib/hash.js.map +0 -1
- package/dist/lib/instructions.d.ts.map +0 -1
- package/dist/lib/instructions.js.map +0 -1
- package/dist/lib/mcp-utils.d.ts.map +0 -1
- package/dist/lib/mcp-utils.js.map +0 -1
- package/dist/lib/pagination.d.ts.map +0 -1
- package/dist/lib/pagination.js.map +0 -1
- package/dist/lib/search-cursor.d.ts.map +0 -1
- package/dist/lib/search-cursor.js.map +0 -1
- package/dist/lib/search.d.ts.map +0 -1
- package/dist/lib/search.js.map +0 -1
- package/dist/lib/sql.d.ts.map +0 -1
- package/dist/lib/sql.js.map +0 -1
- package/dist/lib/tool-contracts.d.ts.map +0 -1
- package/dist/lib/tool-contracts.js.map +0 -1
- package/dist/lib/tool-response.d.ts.map +0 -1
- package/dist/lib/tool-response.js.map +0 -1
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js.map +0 -1
- package/dist/resources/index.d.ts.map +0 -1
- package/dist/resources/index.js.map +0 -1
- package/dist/resources/instructions.d.ts.map +0 -1
- package/dist/resources/instructions.js.map +0 -1
- package/dist/resources/server-config.d.ts.map +0 -1
- package/dist/resources/server-config.js.map +0 -1
- package/dist/resources/tool-catalog.d.ts.map +0 -1
- package/dist/resources/tool-catalog.js.map +0 -1
- package/dist/resources/tool-info.d.ts.map +0 -1
- package/dist/resources/tool-info.js.map +0 -1
- package/dist/resources/workflows.d.ts.map +0 -1
- package/dist/resources/workflows.js.map +0 -1
- package/dist/schemas/index.d.ts.map +0 -1
- package/dist/schemas/index.js.map +0 -1
- package/dist/schemas/inputs.d.ts.map +0 -1
- package/dist/schemas/inputs.js.map +0 -1
- package/dist/schemas/outputs.d.ts.map +0 -1
- package/dist/schemas/outputs.js.map +0 -1
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/tools/create-relationship.d.ts.map +0 -1
- package/dist/tools/create-relationship.js.map +0 -1
- package/dist/tools/delete-memories.d.ts.map +0 -1
- package/dist/tools/delete-memories.js.map +0 -1
- package/dist/tools/delete-memory.d.ts.map +0 -1
- package/dist/tools/delete-memory.js.map +0 -1
- package/dist/tools/delete-relationship.d.ts.map +0 -1
- package/dist/tools/delete-relationship.js.map +0 -1
- package/dist/tools/get-memory.d.ts.map +0 -1
- package/dist/tools/get-memory.js.map +0 -1
- package/dist/tools/get-relationships.d.ts.map +0 -1
- package/dist/tools/get-relationships.js.map +0 -1
- package/dist/tools/index.d.ts.map +0 -1
- package/dist/tools/index.js.map +0 -1
- package/dist/tools/memory-stats.d.ts.map +0 -1
- package/dist/tools/memory-stats.js.map +0 -1
- package/dist/tools/progress.d.ts.map +0 -1
- package/dist/tools/progress.js.map +0 -1
- package/dist/tools/recall.d.ts.map +0 -1
- package/dist/tools/recall.js.map +0 -1
- package/dist/tools/result.d.ts.map +0 -1
- package/dist/tools/result.js.map +0 -1
- package/dist/tools/retrieve-context.d.ts.map +0 -1
- package/dist/tools/retrieve-context.js.map +0 -1
- package/dist/tools/search-memories.d.ts.map +0 -1
- package/dist/tools/search-memories.js.map +0 -1
- package/dist/tools/store-memories.d.ts.map +0 -1
- package/dist/tools/store-memories.js.map +0 -1
- package/dist/tools/store-memory.d.ts.map +0 -1
- package/dist/tools/store-memory.js.map +0 -1
- package/dist/tools/update-memory.d.ts.map +0 -1
- package/dist/tools/update-memory.js.map +0 -1
package/README.md
CHANGED
|
@@ -445,18 +445,18 @@ Returns:
|
|
|
445
445
|
|
|
446
446
|
### Environment Variables
|
|
447
447
|
|
|
448
|
-
| Variable | Description | Default
|
|
449
|
-
| -------------------------- | ------------------------------------------------------- |
|
|
450
|
-
| `MEMORY_DB_PATH` | SQLite database file path | `memory.db` | No |
|
|
451
|
-
| `RECALL_MAX_FRONTIER_SIZE` | Max BFS frontier nodes per hop (100–50000) | `1000`
|
|
452
|
-
| `RECALL_MAX_EDGE_ROWS` | Max relationship rows fetched per traversal (100–50000) | `5000`
|
|
453
|
-
| `RECALL_MAX_VISITED_NODES` | Max visited nodes across entire traversal (100–50000) | `5000`
|
|
448
|
+
| Variable | Description | Default | Required |
|
|
449
|
+
| -------------------------- | ------------------------------------------------------- | --------------------- | -------- |
|
|
450
|
+
| `MEMORY_DB_PATH` | SQLite database file path | `memory_db/memory.db` | No |
|
|
451
|
+
| `RECALL_MAX_FRONTIER_SIZE` | Max BFS frontier nodes per hop (100–50000) | `1000` | No |
|
|
452
|
+
| `RECALL_MAX_EDGE_ROWS` | Max relationship rows fetched per traversal (100–50000) | `5000` | No |
|
|
453
|
+
| `RECALL_MAX_VISITED_NODES` | Max visited nodes across entire traversal (100–50000) | `5000` | No |
|
|
454
454
|
|
|
455
455
|
> [!IMPORTANT]
|
|
456
|
-
> If `MEMORY_DB_PATH` is relative (including the default `memory.db`), it resolves from the process working directory.
|
|
456
|
+
> If `MEMORY_DB_PATH` is relative (including the default `memory_db/memory.db`), it resolves from the process working directory.
|
|
457
457
|
|
|
458
458
|
> [!TIP]
|
|
459
|
-
> Add `
|
|
459
|
+
> Add `memory_db/` to your `.gitignore` to keep the database out of version control — it contains local session data and should not be shared or committed.
|
|
460
460
|
|
|
461
461
|
### Limits and Constraints
|
|
462
462
|
|
|
@@ -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(
|
|
18
|
+
.all(toHashPrefixLikePattern(value))
|
|
17
19
|
.map((row) => row.hash);
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
|
-
//# sourceMappingURL=index.js.map
|
package/dist/db/index.d.ts
CHANGED
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
|
|
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
|
-
|
|
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
|
package/dist/db/typed.d.ts
CHANGED
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(...
|
|
14
|
-
get: (...params) => stmt.get(...
|
|
15
|
-
run: (...params) => stmt.run(...
|
|
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
package/dist/index.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { existsSync, mkdirSync, renameSync } from 'node:fs';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
3
5
|
import process from 'node:process';
|
|
4
6
|
import { initTypedDatabase } from './db/index.js';
|
|
5
7
|
import { getErrorMessage } from './lib/errors.js';
|
|
6
8
|
import { createServer } from './server.js';
|
|
7
|
-
const
|
|
9
|
+
const DEFAULT_DB_PATH = 'memory_db/memory.db';
|
|
10
|
+
const MEMORY_DB_PATH = process.env['MEMORY_DB_PATH'] ?? DEFAULT_DB_PATH;
|
|
8
11
|
const SHUTDOWN_SIGNALS = ['SIGINT', 'SIGTERM'];
|
|
9
12
|
const SHUTDOWN_TIMEOUT_MS = 3000;
|
|
10
13
|
const FORCED_EXIT_CODE = 1;
|
|
11
14
|
const CLEAN_EXIT_CODE = 0;
|
|
15
|
+
const LEGACY_DB_BASENAME = 'memory.db';
|
|
16
|
+
const DEFAULT_DB_DIR = 'memory_db';
|
|
12
17
|
function registerShutdownHandlers(shutdown) {
|
|
13
18
|
for (const signal of SHUTDOWN_SIGNALS) {
|
|
14
19
|
process.on(signal, shutdown);
|
|
@@ -50,7 +55,30 @@ function createShutdownHandler(server, db) {
|
|
|
50
55
|
void runShutdown(server, db);
|
|
51
56
|
};
|
|
52
57
|
}
|
|
58
|
+
function migrateLegacyDatabase() {
|
|
59
|
+
if (process.env['MEMORY_DB_PATH'])
|
|
60
|
+
return;
|
|
61
|
+
if (!existsSync(LEGACY_DB_BASENAME) || existsSync(DEFAULT_DB_PATH))
|
|
62
|
+
return;
|
|
63
|
+
try {
|
|
64
|
+
mkdirSync(dirname(DEFAULT_DB_PATH), { recursive: true });
|
|
65
|
+
const filesToMove = [
|
|
66
|
+
LEGACY_DB_BASENAME,
|
|
67
|
+
`${LEGACY_DB_BASENAME}-shm`,
|
|
68
|
+
`${LEGACY_DB_BASENAME}-wal`,
|
|
69
|
+
];
|
|
70
|
+
for (const file of filesToMove) {
|
|
71
|
+
if (existsSync(file)) {
|
|
72
|
+
renameSync(file, `${DEFAULT_DB_DIR}/${file}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
process.stderr.write(`Warning: Failed to migrate legacy database: ${getErrorMessage(err)}\n`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
53
80
|
async function main() {
|
|
81
|
+
migrateLegacyDatabase();
|
|
54
82
|
const db = initTypedDatabase(MEMORY_DB_PATH);
|
|
55
83
|
const server = createServer(db);
|
|
56
84
|
const transport = new StdioServerTransport();
|
|
@@ -62,4 +90,3 @@ main().catch((err) => {
|
|
|
62
90
|
process.stderr.write(`Fatal error: ${getErrorMessage(err)}\n`);
|
|
63
91
|
process.exit(FORCED_EXIT_CODE);
|
|
64
92
|
});
|
|
65
|
-
//# sourceMappingURL=index.js.map
|
package/dist/lib/errors.d.ts
CHANGED
|
@@ -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
|
package/dist/lib/errors.js
CHANGED
|
@@ -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
|
|
20
|
+
if (isMcpError(err))
|
|
18
21
|
throw err;
|
|
19
22
|
}
|
|
20
|
-
//# sourceMappingURL=errors.js.map
|
package/dist/lib/hash.d.ts
CHANGED
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
|
-
|
|
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
|
package/dist/lib/instructions.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { buildServerInstructions } from '../resources/instructions.js';
|
|
2
2
|
let cachedInstructions;
|
|
3
3
|
export function loadInstructions() {
|
|
4
|
-
|
|
5
|
-
return cachedInstructions;
|
|
6
|
-
}
|
|
7
|
-
cachedInstructions = buildServerInstructions();
|
|
4
|
+
cachedInstructions ??= buildServerInstructions();
|
|
8
5
|
return cachedInstructions;
|
|
9
6
|
}
|
|
10
|
-
//# sourceMappingURL=instructions.js.map
|
package/dist/lib/mcp-utils.d.ts
CHANGED
|
@@ -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
|
package/dist/lib/mcp-utils.js
CHANGED
|
@@ -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 (!
|
|
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 (!
|
|
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
|
package/dist/lib/pagination.d.ts
CHANGED
|
@@ -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
|
package/dist/lib/pagination.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
package/dist/lib/search.d.ts
CHANGED
package/dist/lib/search.js
CHANGED
|
@@ -33,7 +33,7 @@ export function buildAndWhereClause(clauses) {
|
|
|
33
33
|
if (clauses.length === 0) {
|
|
34
34
|
return '';
|
|
35
35
|
}
|
|
36
|
-
return
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
|
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 =
|
|
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
|
|
@@ -5,7 +5,7 @@ export const TOOL_CONTRACTS = [
|
|
|
5
5
|
{
|
|
6
6
|
name: 'store_memory',
|
|
7
7
|
title: 'Store Memory',
|
|
8
|
-
description: 'Store
|
|
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
|
|
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
|
|
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: '
|
|
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
|
|
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
|
|
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: '
|
|
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
|
|
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
|
|
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
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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 =
|
|
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: [
|
|
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(
|
|
20
|
+
content: [toTextContent(errorPayload)],
|
|
19
21
|
isError: true,
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
//# sourceMappingURL=tool-response.js.map
|
package/dist/lib/types.d.ts
CHANGED
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
|
|
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
|
package/dist/prompts/index.d.ts
CHANGED