@j0hanz/memdb 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -19,9 +19,24 @@ const readPackageVersion = async () => {
19
19
  const version = Reflect.get(parsed, 'version');
20
20
  return typeof version === 'string' ? version : undefined;
21
21
  };
22
+ const readServerInstructions = async () => {
23
+ try {
24
+ const text = await readFile(new URL('./instructions.md', import.meta.url), {
25
+ encoding: 'utf-8',
26
+ signal: AbortSignal.timeout(5000),
27
+ });
28
+ const trimmed = text.trim();
29
+ return trimmed.length > 0 ? trimmed : undefined;
30
+ }
31
+ catch {
32
+ return undefined;
33
+ }
34
+ };
22
35
  const packageVersion = await readPackageVersion();
36
+ const serverInstructions = (await readServerInstructions()) ??
37
+ 'A Memory MCP Server for AI Assistants using node:sqlite';
23
38
  const server = new McpServer({ name: 'memdb', version: packageVersion ?? '0.0.0' }, {
24
- instructions: 'A Memory MCP Server for AI Assistants using node:sqlite',
39
+ instructions: serverInstructions,
25
40
  capabilities: { tools: {} },
26
41
  });
27
42
  const patchToolErrorResults = (target) => {
@@ -0,0 +1,204 @@
1
+ # memdb MCP Server — AI Usage Instructions
2
+
3
+ Use this server to store and retrieve persistent memories (facts, decisions, lessons, plans) in a local SQLite database. Prefer using these tools over "remembering" state in chat.
4
+
5
+ ## Operating Rules
6
+
7
+ - Use tools only when the operation changes or verifies memory state.
8
+ - Prefer `search_memories` or `memory_stats` to establish state before updating/deleting.
9
+ - Operate by stable identifiers (`hash`, 32-char hex MD5) rather than ambiguous user text.
10
+ - Batch operations when available: use `store_memories` / `delete_memories` for multiple items.
11
+ - Treat destructive tools (`delete_memory`, `delete_memories`, `delete_relationship`) as destructive: require explicit user confirmation unless the user clearly requested deletion.
12
+ - Keep operations atomic; if a request is vague, ask a clarifying question before calling tools.
13
+
14
+ ### Quick Decision Rules
15
+
16
+ - If unsure what exists → call `search_memories` or `memory_stats` before mutation.
17
+ - If the user provides multiple items → use `store_memories` (up to 50) or `delete_memories`.
18
+ - If the user asks to delete without a specific target → list matches first and ask which hash.
19
+ - Prefer `update_memory` over delete+recreate when correcting an existing memory.
20
+
21
+ ### Client UX Notes (VS Code)
22
+
23
+ - Non-read-only tools typically require user confirmation.
24
+ - Tool lists can be cached; users can reset via **MCP: Reset Cached Tools**.
25
+ - Only run MCP servers from trusted sources.
26
+
27
+ ## Data Model (What the Server Operates On)
28
+
29
+ ### Memory
30
+
31
+ | Field | Type | Description |
32
+ | ------------- | ---------- | --------------------------------------------------------------------------- |
33
+ | `id` | int | Auto-generated row ID |
34
+ | `hash` | string | MD5 of content (32 hex chars); primary lookup key |
35
+ | `content` | string | 1–100,000 chars; the stored text |
36
+ | `tags` | string[] | 1–100 tags; no whitespace; max 50 chars each; use `kebab-case` |
37
+ | `importance` | int (0–10) | Priority (0=low, 10=critical); higher surfaces first in search |
38
+ | `memory_type` | enum | `general` `fact` `plan` `decision` `reflection` `lesson` `error` `gradient` |
39
+ | `created_at` | ISO 8601 | Creation timestamp |
40
+ | `accessed_at` | ISO 8601 | Last access timestamp |
41
+
42
+ ### Relationship (Knowledge Graph Edge)
43
+
44
+ | Field | Type | Description |
45
+ | --------------- | ------ | ----------------------------------------------------------------- |
46
+ | `from_hash` | string | Source memory hash |
47
+ | `to_hash` | string | Target memory hash |
48
+ | `relation_type` | string | No whitespace; e.g., `depends_on`, `causes`, `part_of`, `follows` |
49
+
50
+ ### Constraints
51
+
52
+ - Changing content changes the hash (content-addressed).
53
+ - Tags and `relation_type` must not contain whitespace.
54
+ - Search query: 1–1,000 chars, max 50 terms.
55
+ - Batch limits: 50 items for `store_memories` and `delete_memories`.
56
+
57
+ ## Response Shape
58
+
59
+ All tools return JSON in `structuredContent`:
60
+
61
+ ```json
62
+ // Success
63
+ { "ok": true, "result": { ... } }
64
+
65
+ // Error
66
+ { "ok": false, "error": { "code": "E_CODE", "message": "..." } }
67
+ ```
68
+
69
+ Error responses also set `isError: true` on the top-level tool result.
70
+
71
+ ## Workflows (Recommended)
72
+
73
+ ### 1) Capture a new memory
74
+
75
+ 1. Prepare content (crisp, 1–3 sentences).
76
+ 2. Choose 2–6 tags: domain tags (`auth`, `postgres`) + intent tags (`decision`, `bug`).
77
+ 3. Call `store_memory`. Record the returned `hash` if you need to reference it later.
78
+
79
+ ### 2) Retrieve context for a task
80
+
81
+ 1. Call `search_memories` with a focused query (include relevant tag text in the query).
82
+ 2. If you need related context, call `recall` with `depth: 1` or `2`.
83
+ 3. For verbatim content of a specific hash, call `get_memory`.
84
+
85
+ ### 3) Maintain quality over time
86
+
87
+ 1. Prefer `update_memory` over creating duplicates when correcting content.
88
+ 2. Use `create_relationship` to link durable facts/decisions in the knowledge graph.
89
+ 3. Use `delete_memory` / `delete_memories` only with explicit user intent.
90
+
91
+ ## Tools (What to Use, When)
92
+
93
+ ### store_memory
94
+
95
+ Store a single memory with tags.
96
+
97
+ - **Use when:** You have one clear item to persist.
98
+ - **Args:** `content` (req), `tags` (req, 1–100), `importance` (opt, 0–10), `memory_type` (opt).
99
+ - **Returns:** `{ id, hash, isNew }`.
100
+ - **Notes:** Idempotent (same content → same hash, `isNew: false`).
101
+
102
+ ### store_memories
103
+
104
+ Batch store up to 50 memories.
105
+
106
+ - **Use when:** Importing multiple items at once.
107
+ - **Args:** `items[]` (each has `content`, `tags`, optional `importance`, `memory_type`).
108
+ - **Returns:** `{ results, succeeded, failed }`.
109
+ - **Notes:** Partial success supported.
110
+
111
+ ### search_memories
112
+
113
+ Full-text + tag search.
114
+
115
+ - **Use when:** Discovering what exists; start here before mutating.
116
+ - **Args:** `query` (1–1,000 chars, max 50 terms).
117
+ - **Returns:** Array of `Memory` + `relevance`, up to 100 results.
118
+ - **Notes:** Read-only. Content matches rank higher than tag matches.
119
+
120
+ ### get_memory
121
+
122
+ Fetch a single memory by hash.
123
+
124
+ - **Use when:** You need verbatim content after search identified a hash.
125
+ - **Args:** `hash` (32 hex chars).
126
+ - **Returns:** `Memory`.
127
+ - **Notes:** Read-only. Returns `E_NOT_FOUND` if missing.
128
+
129
+ ### update_memory
130
+
131
+ Update content (and optionally replace tags).
132
+
133
+ - **Use when:** Correcting or refining an existing memory.
134
+ - **Args:** `hash` (req), `content` (req), `tags` (opt, replaces all if provided).
135
+ - **Returns:** `{ updated: true, oldHash, newHash }`.
136
+ - **Notes:** Hash changes because content changes. Idempotent.
137
+
138
+ ### delete_memory
139
+
140
+ Delete a single memory by hash.
141
+
142
+ - **Use when:** User explicitly wants removal.
143
+ - **Args:** `hash`.
144
+ - **Returns:** `{ deleted: true }` or `E_NOT_FOUND`.
145
+ - **Notes:** Destructive. Confirm before calling.
146
+
147
+ ### delete_memories
148
+
149
+ Batch delete up to 50 hashes.
150
+
151
+ - **Use when:** Bulk cleanup with explicit user intent.
152
+ - **Args:** `hashes[]`.
153
+ - **Returns:** `{ results, succeeded, failed }`.
154
+ - **Notes:** Destructive. Partial success supported.
155
+
156
+ ### create_relationship
157
+
158
+ Link two memories with a typed edge.
159
+
160
+ - **Use when:** Building a knowledge graph (e.g., `depends_on`, `causes`, `part_of`).
161
+ - **Args:** `from_hash`, `to_hash`, `relation_type`.
162
+ - **Returns:** `{ id, isNew }`.
163
+ - **Notes:** Idempotent.
164
+
165
+ ### get_relationships
166
+
167
+ List relationships for a memory.
168
+
169
+ - **Use when:** Inspecting local graph around one memory.
170
+ - **Args:** `hash`, `direction` (opt: `outgoing`, `incoming`, `both`; default `both`).
171
+ - **Returns:** Array of `Relationship`.
172
+ - **Notes:** Read-only.
173
+
174
+ ### delete_relationship
175
+
176
+ Remove a relationship edge.
177
+
178
+ - **Use when:** An edge is wrong or outdated.
179
+ - **Args:** `from_hash`, `to_hash`, `relation_type`.
180
+ - **Returns:** `{ deleted: true }` or `E_NOT_FOUND`.
181
+ - **Notes:** Destructive. Confirm before calling.
182
+
183
+ ### recall
184
+
185
+ Search + traverse relationships to return a connected cluster.
186
+
187
+ - **Use when:** You need broader context beyond keyword matches.
188
+ - **Args:** `query`, `depth` (opt, 0–3; default 1).
189
+ - **Returns:** `{ memories, relationships, depth }`.
190
+ - **Notes:** Read-only. Use `depth: 1–2` by default.
191
+
192
+ ### memory_stats
193
+
194
+ Database statistics and health.
195
+
196
+ - **Use when:** Sanity-checking the DB or reporting status.
197
+ - **Args:** (none).
198
+ - **Returns:** `{ memoryCount, tagCount, oldestMemory, newestMemory }`.
199
+ - **Notes:** Read-only.
200
+
201
+ ## Safety
202
+
203
+ - **Do not store secrets** (API keys, passwords, tokens, private keys) in memory content.
204
+ - **Confirm destructive operations** (`delete_memory`, `delete_memories`, `delete_relationship`) before calling.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@j0hanz/memdb",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "mcpName": "io.github.j0hanz/memdb",
5
5
  "description": "A SQLite-backed MCP memory server with local workspace storage.",
6
6
  "type": "module",
@@ -18,7 +18,7 @@
18
18
  "README.md"
19
19
  ],
20
20
  "scripts": {
21
- "build": "tsc -p tsconfig.build.json && node -e \"require('fs').chmodSync('dist/index.js', '755')\"",
21
+ "build": "tsc -p tsconfig.build.json && node -e \"const fs=require('fs');fs.copyFileSync('src/instructions.md','dist/instructions.md');fs.chmodSync('dist/index.js','755');\"",
22
22
  "prepare": "npm run build",
23
23
  "dev": "tsx watch src/index.ts",
24
24
  "start": "node dist/index.js",