@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/dist/prompts/index.js
CHANGED
|
@@ -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
|
package/dist/resources/index.js
CHANGED
|
@@ -18,6 +18,7 @@ const MEMORY_RESOURCE_URI_TEMPLATE = 'memory://memories/{hash}';
|
|
|
18
18
|
const MEMORY_RESOURCE_LIST_LIMIT = 100;
|
|
19
19
|
const RECENT_MEMORY_HASHES_SQL = `SELECT hash FROM memories ORDER BY updated_at DESC LIMIT ${MEMORY_RESOURCE_LIST_LIMIT}`;
|
|
20
20
|
const RESOURCE_LAST_MODIFIED = new Date().toISOString();
|
|
21
|
+
const TOOL_NAMES = getToolNames();
|
|
21
22
|
function createMarkdownContent(uri, text) {
|
|
22
23
|
return { uri, mimeType: 'text/markdown', text };
|
|
23
24
|
}
|
|
@@ -33,15 +34,39 @@ function createErrorResourceContents(uri, error, hash) {
|
|
|
33
34
|
contents: [createJsonContent(uri, { error, ...(hash ? { hash } : {}) })],
|
|
34
35
|
};
|
|
35
36
|
}
|
|
37
|
+
function createResourceAnnotations(audience, priority) {
|
|
38
|
+
return {
|
|
39
|
+
audience: [...audience],
|
|
40
|
+
priority,
|
|
41
|
+
lastModified: RESOURCE_LAST_MODIFIED,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
36
44
|
function getSingleVariable(value) {
|
|
37
45
|
return Array.isArray(value) ? value[0] : value;
|
|
38
46
|
}
|
|
47
|
+
function requireSingleVariable(variables, key, errorMessage) {
|
|
48
|
+
const value = getSingleVariable(variables[key]);
|
|
49
|
+
if (!value) {
|
|
50
|
+
throw new McpError(ErrorCode.InvalidParams, errorMessage);
|
|
51
|
+
}
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
function registerStaticMarkdownResource(server, config) {
|
|
55
|
+
server.registerResource(config.name, config.uri, {
|
|
56
|
+
title: config.title,
|
|
57
|
+
description: config.description,
|
|
58
|
+
mimeType: 'text/markdown',
|
|
59
|
+
annotations: createResourceAnnotations(config.audience, config.priority),
|
|
60
|
+
}, () => ({
|
|
61
|
+
contents: [createMarkdownContent(config.uri, config.content)],
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
39
64
|
function readMemoryByHash(db, hash) {
|
|
40
65
|
return db.prepareOnce(SELECT_MEMORY_BY_HASH_SQL).get(hash);
|
|
41
66
|
}
|
|
42
67
|
function listToolInfoResources() {
|
|
43
68
|
return {
|
|
44
|
-
resources:
|
|
69
|
+
resources: TOOL_NAMES.map((toolName) => ({
|
|
45
70
|
uri: `internal://tool-info/${toolName}`,
|
|
46
71
|
name: 'tool-info',
|
|
47
72
|
title: `Tool Info: ${toolName}`,
|
|
@@ -68,51 +93,38 @@ const SERVER_CONFIG_CONTENT = buildServerConfig();
|
|
|
68
93
|
// --- Registration ---
|
|
69
94
|
export function registerAllResources(server, db) {
|
|
70
95
|
// internal://instructions
|
|
71
|
-
server
|
|
96
|
+
registerStaticMarkdownResource(server, {
|
|
97
|
+
name: 'instructions',
|
|
98
|
+
uri: INSTRUCTIONS_URI,
|
|
72
99
|
title: 'Memory Instructions',
|
|
73
100
|
description: 'Complete usage guide: tool inventory, routing decisions, error codes, data model, and workflow patterns. Read this first.',
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
lastModified: RESOURCE_LAST_MODIFIED,
|
|
79
|
-
},
|
|
80
|
-
}, () => ({
|
|
81
|
-
contents: [createMarkdownContent(INSTRUCTIONS_URI, INSTRUCTIONS_CONTENT)],
|
|
82
|
-
}));
|
|
101
|
+
audience: ['assistant'],
|
|
102
|
+
priority: 0.9,
|
|
103
|
+
content: INSTRUCTIONS_CONTENT,
|
|
104
|
+
});
|
|
83
105
|
// internal://tool-catalog
|
|
84
|
-
server
|
|
106
|
+
registerStaticMarkdownResource(server, {
|
|
107
|
+
name: 'tool-catalog',
|
|
108
|
+
uri: TOOL_CATALOG_URI,
|
|
85
109
|
title: 'Tool Catalog',
|
|
86
110
|
description: 'Tool reference table, optional parameter matrix, and cross-tool data flow.',
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
lastModified: RESOURCE_LAST_MODIFIED,
|
|
92
|
-
},
|
|
93
|
-
}, () => ({
|
|
94
|
-
contents: [createMarkdownContent(TOOL_CATALOG_URI, TOOL_CATALOG_CONTENT)],
|
|
95
|
-
}));
|
|
111
|
+
audience: ['assistant'],
|
|
112
|
+
priority: 0.7,
|
|
113
|
+
content: TOOL_CATALOG_CONTENT,
|
|
114
|
+
});
|
|
96
115
|
// internal://tool-info/{toolName}
|
|
97
116
|
server.registerResource('tool-info', new ResourceTemplate(TOOL_INFO_URI_TEMPLATE, {
|
|
98
117
|
list: () => listToolInfoResources(),
|
|
99
118
|
complete: {
|
|
100
|
-
toolName: (value) =>
|
|
119
|
+
toolName: (value) => TOOL_NAMES.filter((n) => n.startsWith(value)),
|
|
101
120
|
},
|
|
102
121
|
}), {
|
|
103
122
|
title: 'Tool Info',
|
|
104
123
|
description: 'Per-tool detail: parameters, behavior, and output shape. Supports toolName auto-completion.',
|
|
105
124
|
mimeType: 'text/markdown',
|
|
106
|
-
annotations:
|
|
107
|
-
audience: ['assistant'],
|
|
108
|
-
priority: 0.6,
|
|
109
|
-
lastModified: RESOURCE_LAST_MODIFIED,
|
|
110
|
-
},
|
|
125
|
+
annotations: createResourceAnnotations(['assistant'], 0.6),
|
|
111
126
|
}, (uri, variables) => {
|
|
112
|
-
const toolName =
|
|
113
|
-
if (!toolName) {
|
|
114
|
-
throw new McpError(ErrorCode.InvalidParams, 'Missing toolName parameter');
|
|
115
|
-
}
|
|
127
|
+
const toolName = requireSingleVariable(variables, 'toolName', 'Missing toolName parameter');
|
|
116
128
|
const info = getToolInfo(toolName);
|
|
117
129
|
if (!info) {
|
|
118
130
|
throw new McpError(ErrorCode.InvalidParams, `Unknown tool: ${toolName}`);
|
|
@@ -122,33 +134,25 @@ export function registerAllResources(server, db) {
|
|
|
122
134
|
};
|
|
123
135
|
});
|
|
124
136
|
// internal://workflows
|
|
125
|
-
server
|
|
137
|
+
registerStaticMarkdownResource(server, {
|
|
138
|
+
name: 'workflows',
|
|
139
|
+
uri: WORKFLOWS_URI,
|
|
126
140
|
title: 'Workflow Guide',
|
|
127
141
|
description: 'Recommended multi-step workflow sequences with guardrails and tool reference.',
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
lastModified: RESOURCE_LAST_MODIFIED,
|
|
133
|
-
},
|
|
134
|
-
}, () => ({
|
|
135
|
-
contents: [createMarkdownContent(WORKFLOWS_URI, WORKFLOW_GUIDE_CONTENT)],
|
|
136
|
-
}));
|
|
142
|
+
audience: ['assistant'],
|
|
143
|
+
priority: 0.7,
|
|
144
|
+
content: WORKFLOW_GUIDE_CONTENT,
|
|
145
|
+
});
|
|
137
146
|
// internal://server-config
|
|
138
|
-
|
|
147
|
+
registerStaticMarkdownResource(server, {
|
|
148
|
+
name: 'server-config',
|
|
149
|
+
uri: SERVER_CONFIG_URI,
|
|
139
150
|
title: 'Server Configuration',
|
|
140
151
|
description: 'Runtime configuration, environment variables, capabilities, and data limits.',
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
lastModified: RESOURCE_LAST_MODIFIED,
|
|
146
|
-
},
|
|
147
|
-
}, () => ({
|
|
148
|
-
contents: [
|
|
149
|
-
createMarkdownContent(SERVER_CONFIG_URI, SERVER_CONFIG_CONTENT),
|
|
150
|
-
],
|
|
151
|
-
}));
|
|
152
|
+
audience: ['user', 'assistant'],
|
|
153
|
+
priority: 0.5,
|
|
154
|
+
content: SERVER_CONFIG_CONTENT,
|
|
155
|
+
});
|
|
152
156
|
// memory://memories/{hash}
|
|
153
157
|
const hashCompletion = createHashCompletionCallback(db);
|
|
154
158
|
server.registerResource('memory', new ResourceTemplate(MEMORY_RESOURCE_URI_TEMPLATE, {
|
|
@@ -158,14 +162,9 @@ export function registerAllResources(server, db) {
|
|
|
158
162
|
title: 'Memory',
|
|
159
163
|
description: 'Fetch a single memory object by exact SHA-256 hash. Supports hash auto-completion. Returns { error } if the hash does not exist.',
|
|
160
164
|
mimeType: 'application/json',
|
|
161
|
-
annotations:
|
|
162
|
-
audience: ['assistant'],
|
|
163
|
-
priority: 0.7,
|
|
164
|
-
lastModified: RESOURCE_LAST_MODIFIED,
|
|
165
|
-
},
|
|
165
|
+
annotations: createResourceAnnotations(['assistant'], 0.7),
|
|
166
166
|
}, (uri, variables) => {
|
|
167
|
-
const
|
|
168
|
-
const hash = getSingleVariable(rawHash);
|
|
167
|
+
const hash = getSingleVariable(variables['hash']);
|
|
169
168
|
if (!hash || !HASH_REGEX.test(hash)) {
|
|
170
169
|
throw new McpError(ErrorCode.InvalidParams, 'Invalid hash: must be a 64-character hex string');
|
|
171
170
|
}
|
|
@@ -178,4 +177,3 @@ export function registerAllResources(server, db) {
|
|
|
178
177
|
};
|
|
179
178
|
});
|
|
180
179
|
}
|
|
181
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -17,90 +17,88 @@ const ERROR_CODES = [
|
|
|
17
17
|
'| `E_CANCELLED` | Request was cancelled |',
|
|
18
18
|
'| `E_UNKNOWN` | Unexpected internal error — retry once |',
|
|
19
19
|
];
|
|
20
|
-
const
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
const ERROR_RESULT_CONVENTIONS = [
|
|
21
|
+
'- Tool failures return `isError: true` with JSON text in `content[0].text`.',
|
|
22
|
+
'- Error payload shape: `{ ok: false, error: { code, message } }`.',
|
|
23
|
+
'- On error, do not expect `structuredContent`; parse the JSON text payload instead.',
|
|
24
|
+
'- Successful responses include both `structuredContent` and JSON text in `content[0].text`.',
|
|
25
|
+
];
|
|
26
|
+
const DATA_MODEL = `Memory:
|
|
27
|
+
- hash: SHA-256(content + sorted tags). Deterministic.
|
|
28
|
+
- content: 1-100k chars.
|
|
29
|
+
- tags: 1-100 items, 1-50 chars each.
|
|
30
|
+
- type: general|fact|plan|decision|reflection|lesson|error|gradient.
|
|
31
|
+
- importance: 0-10.
|
|
27
32
|
|
|
28
|
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
\`\`\`
|
|
37
|
-
store_memories({ items: [...] }) → { items[].hash, succeeded, failed }
|
|
38
|
-
create_relationship({ from_hash, to_hash, relation_type }) × N
|
|
39
|
-
\`\`\`
|
|
33
|
+
Relationship:
|
|
34
|
+
- Edge: from_hash -[relation_type]-> to_hash.
|
|
35
|
+
- type: 1-50 chars.
|
|
36
|
+
- Constraint: Endpoints must exist. Cascade delete/update.`;
|
|
37
|
+
const WORKFLOWS = `
|
|
38
|
+
1. Store and Link:
|
|
39
|
+
store_memories({ items: [...] }) -> { items[].hash }
|
|
40
|
+
create_relationship({ from_hash, to_hash, relation_type })
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
# or, for relationship navigation:
|
|
45
|
-
recall({ query, depth: 1 }) → { memories[], graph[] }
|
|
46
|
-
\`\`\`
|
|
42
|
+
2. Search and Read:
|
|
43
|
+
search_memories({ query, limit }) -> { memories[], nextCursor }
|
|
44
|
+
recall({ query, depth: 1 }) -> { memories[], graph[] }
|
|
47
45
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
retrieve_context({ query, token_budget: 4000, strategy: 'relevance' })
|
|
51
|
-
→ { memories[], estimated_tokens, truncated }
|
|
52
|
-
\`\`\`
|
|
46
|
+
3. Fill Context:
|
|
47
|
+
retrieve_context({ query, token_budget: 4000 }) -> { memories[], truncated }
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
update_memory({ hash, content }) → { old_hash, new_hash }
|
|
57
|
-
# Existing relationships auto-update to new_hash via CASCADE
|
|
58
|
-
\`\`\`
|
|
49
|
+
4. Update:
|
|
50
|
+
update_memory({ hash, content }) -> { new_hash }
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
delete_memories({ hashes: [...] }) → { items[].{ hash, deleted }, succeeded, failed }
|
|
63
|
-
# deleted: false means hash not found — not an error
|
|
64
|
-
\`\`\``;
|
|
52
|
+
5. Delete:
|
|
53
|
+
delete_memories({ hashes: [...] }) -> { items[].deleted }`;
|
|
65
54
|
function buildToolRouting() {
|
|
66
|
-
const
|
|
67
|
-
const rows = contracts.map((c) => {
|
|
55
|
+
const rows = getToolContracts().map((c) => {
|
|
68
56
|
const purpose = c.description.split('.')[0] ?? '';
|
|
69
57
|
return `| \`${c.name}\` | ${purpose} |`;
|
|
70
58
|
});
|
|
71
|
-
return [
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
].join('\n');
|
|
59
|
+
return ['| Tool | Purpose |', '| --- | --- |', ...rows].join('\n');
|
|
60
|
+
}
|
|
61
|
+
function renderSharedConstraints() {
|
|
62
|
+
return getSharedConstraints()
|
|
63
|
+
.map((c) => `- ${c}`)
|
|
64
|
+
.join('\n');
|
|
78
65
|
}
|
|
79
66
|
export function buildServerInstructions() {
|
|
80
67
|
return [
|
|
81
|
-
'
|
|
68
|
+
'<role>',
|
|
69
|
+
'Memory MCP: Persistent memory storage, full-text retrieval, and relationship graph traversal.',
|
|
70
|
+
'</role>',
|
|
82
71
|
'',
|
|
72
|
+
'<capabilities>',
|
|
83
73
|
buildToolRouting(),
|
|
74
|
+
'</capabilities>',
|
|
84
75
|
'',
|
|
85
|
-
'
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.join('\n'),
|
|
76
|
+
'<constraints>',
|
|
77
|
+
renderSharedConstraints(),
|
|
78
|
+
'</constraints>',
|
|
89
79
|
'',
|
|
90
|
-
'
|
|
80
|
+
'<error_codes>',
|
|
91
81
|
ERROR_CODES.join('\n'),
|
|
82
|
+
'</error_codes>',
|
|
83
|
+
'',
|
|
84
|
+
'<error_result_conventions>',
|
|
85
|
+
ERROR_RESULT_CONVENTIONS.join('\n'),
|
|
86
|
+
'</error_result_conventions>',
|
|
92
87
|
'',
|
|
93
|
-
'
|
|
88
|
+
'<data_model>',
|
|
94
89
|
DATA_MODEL,
|
|
90
|
+
'</data_model>',
|
|
95
91
|
'',
|
|
96
|
-
'
|
|
92
|
+
'<workflows>',
|
|
97
93
|
WORKFLOWS,
|
|
94
|
+
'</workflows>',
|
|
98
95
|
'',
|
|
99
|
-
'
|
|
96
|
+
'<prompts>',
|
|
100
97
|
PROMPTS_INVENTORY.join('\n'),
|
|
98
|
+
'</prompts>',
|
|
101
99
|
'',
|
|
102
|
-
'
|
|
100
|
+
'<resources>',
|
|
103
101
|
RESOURCES_INVENTORY.join('\n'),
|
|
102
|
+
'</resources>',
|
|
104
103
|
].join('\n');
|
|
105
104
|
}
|
|
106
|
-
//# sourceMappingURL=instructions.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const ENV_VARS = [
|
|
2
2
|
{
|
|
3
3
|
name: 'MEMORY_DB_PATH',
|
|
4
|
-
default: 'memory.db',
|
|
4
|
+
default: 'memory_db/memory.db',
|
|
5
5
|
range: '—',
|
|
6
6
|
purpose: 'SQLite database file path',
|
|
7
7
|
},
|
|
@@ -38,16 +38,21 @@ const DATA_LIMITS = [
|
|
|
38
38
|
];
|
|
39
39
|
const CAPABILITIES = [
|
|
40
40
|
{ capability: 'tools', status: 'enabled' },
|
|
41
|
-
{ capability: 'resources', status: 'enabled (
|
|
41
|
+
{ capability: 'resources', status: 'enabled (list/read + listChanged)' },
|
|
42
42
|
{ capability: 'prompts', status: 'enabled' },
|
|
43
43
|
{ capability: 'completions', status: 'enabled' },
|
|
44
44
|
{ capability: 'logging', status: 'enabled' },
|
|
45
|
-
{ capability: 'tasks', status: 'enabled' },
|
|
46
45
|
];
|
|
46
|
+
function toEnvVarRow(v) {
|
|
47
|
+
return `| \`${v.name}\` | ${v.default} | ${v.range} | ${v.purpose} |`;
|
|
48
|
+
}
|
|
49
|
+
function toRangeRow(label, range) {
|
|
50
|
+
return `| ${label} | ${range} |`;
|
|
51
|
+
}
|
|
47
52
|
export function buildServerConfig() {
|
|
48
|
-
const envRows = ENV_VARS.map(
|
|
49
|
-
const limitRows = DATA_LIMITS.map((l) =>
|
|
50
|
-
const capRows = CAPABILITIES.map((c) =>
|
|
53
|
+
const envRows = ENV_VARS.map(toEnvVarRow);
|
|
54
|
+
const limitRows = DATA_LIMITS.map((l) => toRangeRow(l.dimension, l.range));
|
|
55
|
+
const capRows = CAPABILITIES.map((c) => toRangeRow(c.capability, c.status));
|
|
51
56
|
return [
|
|
52
57
|
'# Server Configuration',
|
|
53
58
|
'',
|
|
@@ -70,4 +75,3 @@ export function buildServerConfig() {
|
|
|
70
75
|
...limitRows,
|
|
71
76
|
].join('\n');
|
|
72
77
|
}
|
|
73
|
-
//# sourceMappingURL=server-config.js.map
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { extractJsonSchema, } from '../lib/json-schema.js';
|
|
2
2
|
import { getToolContracts } from '../lib/tool-contracts.js';
|
|
3
3
|
import { buildCoreContextPack } from './tool-info.js';
|
|
4
|
-
function extractJsonSchema(schema) {
|
|
5
|
-
try {
|
|
6
|
-
return z.toJSONSchema(schema);
|
|
7
|
-
}
|
|
8
|
-
catch {
|
|
9
|
-
return {};
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
4
|
function extractOptionalParams(toolName, schema) {
|
|
13
5
|
const jsonSchema = extractJsonSchema(schema);
|
|
14
6
|
const properties = (jsonSchema['properties'] ?? {});
|
|
@@ -26,10 +18,7 @@ function extractOptionalParams(toolName, schema) {
|
|
|
26
18
|
}
|
|
27
19
|
return rows;
|
|
28
20
|
}
|
|
29
|
-
const CROSS_TOOL_DATA_FLOW =
|
|
30
|
-
|
|
31
|
-
\`\`\`
|
|
32
|
-
store_memory.hash ──→ get_memory.hash
|
|
21
|
+
const CROSS_TOOL_DATA_FLOW = `store_memory.hash ──→ get_memory.hash
|
|
33
22
|
store_memory.hash ──→ create_relationship.from_hash / to_hash
|
|
34
23
|
store_memory.hash ──→ update_memory.hash
|
|
35
24
|
store_memory.hash ──→ delete_memory.hash
|
|
@@ -39,18 +28,17 @@ search_memories.nextCursor ──→ search_memories.cursor
|
|
|
39
28
|
recall.memories[].hash ──→ get_memory.hash
|
|
40
29
|
recall.nextCursor ──→ recall.cursor
|
|
41
30
|
update_memory.new_hash ──→ get_memory.hash
|
|
42
|
-
get_relationships.relationships[].linked_hash ──→ get_memory.hash
|
|
43
|
-
\`\`\``;
|
|
31
|
+
get_relationships.relationships[].linked_hash ──→ get_memory.hash`;
|
|
44
32
|
export function buildToolCatalog() {
|
|
45
33
|
const contracts = getToolContracts();
|
|
46
34
|
const optionalRows = contracts.flatMap((c) => extractOptionalParams(c.name, c.inputSchema));
|
|
47
35
|
const optionalParamSection = optionalRows.length > 0
|
|
48
36
|
? [
|
|
49
|
-
'
|
|
50
|
-
'',
|
|
37
|
+
'<optional_params>',
|
|
51
38
|
'| Tool | Parameter | Default | Purpose |',
|
|
52
39
|
'|------|-----------|---------|---------|',
|
|
53
40
|
...optionalRows,
|
|
41
|
+
'</optional_params>',
|
|
54
42
|
].join('\n')
|
|
55
43
|
: '';
|
|
56
44
|
return [
|
|
@@ -58,7 +46,8 @@ export function buildToolCatalog() {
|
|
|
58
46
|
'',
|
|
59
47
|
optionalParamSection,
|
|
60
48
|
'',
|
|
49
|
+
'<data_flow>',
|
|
61
50
|
CROSS_TOOL_DATA_FLOW,
|
|
51
|
+
'</data_flow>',
|
|
62
52
|
].join('\n');
|
|
63
53
|
}
|
|
64
|
-
//# sourceMappingURL=tool-catalog.js.map
|
|
@@ -2,4 +2,3 @@ export declare function getSharedConstraints(): readonly string[];
|
|
|
2
2
|
export declare function buildCoreContextPack(): string;
|
|
3
3
|
export declare function getToolInfo(name: string): string | undefined;
|
|
4
4
|
export declare function getToolNames(): string[];
|
|
5
|
-
//# sourceMappingURL=tool-info.d.ts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { extractJsonSchema, } from '../lib/json-schema.js';
|
|
2
2
|
import { getToolContracts } from '../lib/tool-contracts.js';
|
|
3
3
|
// --- Shared Constraints (Single Source of Truth) ---
|
|
4
4
|
const SHARED_CONSTRAINTS = [
|
|
5
5
|
'Idempotence: `store_memory` and `store_memories` return `created: false` if content+tags exist.',
|
|
6
6
|
'Atomic Transactions: `store_memories` and `delete_memories` roll back on error.',
|
|
7
7
|
'Hash Changes: `update_memory` changes hash on content/tags change. Relationships survive via CASCADE.',
|
|
8
|
-
'FTS Search Limits: Query terms
|
|
9
|
-
'Recall Limits: BFS traversal bounded by env vars. Returns `aborted: true` with partial results
|
|
8
|
+
'FTS Search Limits: Query is tokenized to alphanumeric/underscore terms and uses implicit AND matching. No phrase/negation support.',
|
|
9
|
+
'Recall Limits: BFS traversal bounded by env vars. Returns `aborted: true` with partial results only when limits are hit.',
|
|
10
10
|
];
|
|
11
11
|
export function getSharedConstraints() {
|
|
12
12
|
return SHARED_CONSTRAINTS;
|
|
@@ -35,22 +35,14 @@ export function buildCoreContextPack() {
|
|
|
35
35
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
36
36
|
const rows = entries.map((e) => `| \`${e.name}\` | ${e.purpose} | ${e.behavior} |`);
|
|
37
37
|
return [
|
|
38
|
-
'
|
|
39
|
-
'',
|
|
38
|
+
'<core_tools>',
|
|
40
39
|
'| Tool | Purpose | Behavior |',
|
|
41
40
|
'|------|---------|----------|',
|
|
42
41
|
...rows,
|
|
42
|
+
'</core_tools>',
|
|
43
43
|
].join('\n');
|
|
44
44
|
}
|
|
45
45
|
// --- Per-Tool Info ---
|
|
46
|
-
function extractJsonSchema(schema) {
|
|
47
|
-
try {
|
|
48
|
-
return z.toJSONSchema(schema);
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
46
|
function formatParamConstraints(prop) {
|
|
55
47
|
const parts = [];
|
|
56
48
|
if (typeof prop['minimum'] === 'number')
|
|
@@ -106,13 +98,14 @@ export function getToolInfo(name) {
|
|
|
106
98
|
const behaviorLine = formatBehavior(contract.annotations);
|
|
107
99
|
const outputShape = formatOutputShape(contract.outputSchema);
|
|
108
100
|
return [
|
|
109
|
-
|
|
110
|
-
contract.description
|
|
111
|
-
|
|
112
|
-
'
|
|
101
|
+
`<tool_info name="${contract.name}">`,
|
|
102
|
+
`<description>${contract.description}</description>`,
|
|
103
|
+
`<behavior>${behaviorLine}</behavior>`,
|
|
104
|
+
'<params>',
|
|
113
105
|
paramLines.length > 0 ? paramLines.join('\n') : 'None',
|
|
114
|
-
'',
|
|
115
|
-
|
|
106
|
+
'</params>',
|
|
107
|
+
`<output>${outputShape}</output>`,
|
|
108
|
+
'</tool_info>',
|
|
116
109
|
].join('\n');
|
|
117
110
|
}
|
|
118
111
|
export function getToolNames() {
|
|
@@ -120,4 +113,3 @@ export function getToolNames() {
|
|
|
120
113
|
.map((c) => c.name)
|
|
121
114
|
.sort((a, b) => a.localeCompare(b));
|
|
122
115
|
}
|
|
123
|
-
//# sourceMappingURL=tool-info.js.map
|
|
@@ -38,6 +38,11 @@ const WORKFLOW_TRACKS = `## Workflow A: Store and Link
|
|
|
38
38
|
2. \`get_relationships({ hash, direction: 'both' })\` for a specific memory's edges
|
|
39
39
|
|
|
40
40
|
> BFS traversal emits progress per hop. Use \`depth: 0\` to skip traversal.`;
|
|
41
|
+
function renderSharedConstraintsSection() {
|
|
42
|
+
return getSharedConstraints()
|
|
43
|
+
.map((c) => `- ${c}`)
|
|
44
|
+
.join('\n');
|
|
45
|
+
}
|
|
41
46
|
export function buildWorkflowGuide() {
|
|
42
47
|
return [
|
|
43
48
|
'# Workflow Reference',
|
|
@@ -45,11 +50,8 @@ export function buildWorkflowGuide() {
|
|
|
45
50
|
WORKFLOW_TRACKS,
|
|
46
51
|
'',
|
|
47
52
|
'## Shared Constraints',
|
|
48
|
-
|
|
49
|
-
.map((c) => `- ${c}`)
|
|
50
|
-
.join('\n'),
|
|
53
|
+
renderSharedConstraintsSection(),
|
|
51
54
|
'',
|
|
52
55
|
'> See `internal://tool-catalog` for complete tool reference and cross-tool data flow.',
|
|
53
56
|
].join('\n');
|
|
54
57
|
}
|
|
55
|
-
//# sourceMappingURL=workflows.js.map
|
package/dist/schemas/index.d.ts
CHANGED
package/dist/schemas/index.js
CHANGED
package/dist/schemas/inputs.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
2
|
export declare const HASH_SCHEMA: z.ZodString;
|
|
3
|
+
declare const MEMORY_TYPE_SCHEMA: z.ZodEnum<{
|
|
4
|
+
error: "error";
|
|
5
|
+
general: "general";
|
|
6
|
+
fact: "fact";
|
|
7
|
+
plan: "plan";
|
|
8
|
+
decision: "decision";
|
|
9
|
+
reflection: "reflection";
|
|
10
|
+
lesson: "lesson";
|
|
11
|
+
gradient: "gradient";
|
|
12
|
+
}>;
|
|
3
13
|
export declare const SUGGESTED_RELATION_TYPES: readonly ["related_to", "causes", "depends_on", "parent_of", "child_of", "supersedes", "contradicts", "supports", "references"];
|
|
4
14
|
export declare const StoreMemoryInputSchema: z.ZodObject<{
|
|
5
15
|
content: z.ZodString;
|
|
@@ -63,39 +73,21 @@ export declare const DeleteMemoriesInputSchema: z.ZodObject<{
|
|
|
63
73
|
hashes: z.ZodArray<z.ZodString>;
|
|
64
74
|
}, z.core.$strict>;
|
|
65
75
|
export declare const SearchMemoriesInputSchema: z.ZodObject<{
|
|
76
|
+
min_importance: z.ZodOptional<z.ZodNumber>;
|
|
77
|
+
max_importance: z.ZodOptional<z.ZodNumber>;
|
|
78
|
+
memory_type: z.ZodOptional<typeof MEMORY_TYPE_SCHEMA>;
|
|
66
79
|
query: z.ZodString;
|
|
67
80
|
limit: z.ZodPrefault<z.ZodOptional<z.ZodInt>>;
|
|
68
81
|
cursor: z.ZodOptional<z.ZodString>;
|
|
69
|
-
min_importance: z.ZodOptional<z.ZodNumber>;
|
|
70
|
-
max_importance: z.ZodOptional<z.ZodNumber>;
|
|
71
|
-
memory_type: z.ZodOptional<z.ZodEnum<{
|
|
72
|
-
error: "error";
|
|
73
|
-
general: "general";
|
|
74
|
-
fact: "fact";
|
|
75
|
-
plan: "plan";
|
|
76
|
-
decision: "decision";
|
|
77
|
-
reflection: "reflection";
|
|
78
|
-
lesson: "lesson";
|
|
79
|
-
gradient: "gradient";
|
|
80
|
-
}>>;
|
|
81
82
|
}, z.core.$strict>;
|
|
82
83
|
export declare const RecallInputSchema: z.ZodObject<{
|
|
84
|
+
min_importance: z.ZodOptional<z.ZodNumber>;
|
|
85
|
+
max_importance: z.ZodOptional<z.ZodNumber>;
|
|
86
|
+
memory_type: z.ZodOptional<typeof MEMORY_TYPE_SCHEMA>;
|
|
83
87
|
query: z.ZodString;
|
|
84
88
|
depth: z.ZodPrefault<z.ZodOptional<z.ZodInt>>;
|
|
85
89
|
limit: z.ZodPrefault<z.ZodOptional<z.ZodInt>>;
|
|
86
90
|
cursor: z.ZodOptional<z.ZodString>;
|
|
87
|
-
min_importance: z.ZodOptional<z.ZodNumber>;
|
|
88
|
-
max_importance: z.ZodOptional<z.ZodNumber>;
|
|
89
|
-
memory_type: z.ZodOptional<z.ZodEnum<{
|
|
90
|
-
error: "error";
|
|
91
|
-
general: "general";
|
|
92
|
-
fact: "fact";
|
|
93
|
-
plan: "plan";
|
|
94
|
-
decision: "decision";
|
|
95
|
-
reflection: "reflection";
|
|
96
|
-
lesson: "lesson";
|
|
97
|
-
gradient: "gradient";
|
|
98
|
-
}>>;
|
|
99
91
|
}, z.core.$strict>;
|
|
100
92
|
export declare const RetrieveContextInputSchema: z.ZodObject<{
|
|
101
93
|
query: z.ZodString;
|
|
@@ -125,4 +117,4 @@ export declare const DeleteRelationshipInputSchema: z.ZodObject<{
|
|
|
125
117
|
relation_type: z.ZodString;
|
|
126
118
|
}, z.core.$strict>;
|
|
127
119
|
export declare const MemoryStatsInputSchema: z.ZodObject<{}, z.core.$strict>;
|
|
128
|
-
|
|
120
|
+
export {};
|