mcp-learning-memory 0.2.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 +394 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +424 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +8 -0
- package/dist/storage.d.ts +7 -0
- package/dist/storage.js +95 -0
- package/dist/tools.d.ts +12 -0
- package/dist/tools.js +559 -0
- package/dist/types.d.ts +49 -0
- package/dist/types.js +4 -0
- package/dist/validation.d.ts +31 -0
- package/dist/validation.js +153 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# mcp-learning-memory
|
|
2
|
+
|
|
3
|
+
> Memory that learns from your feedback.
|
|
4
|
+
|
|
5
|
+
[](https://github.com/nulone/mcp-learning-memory)
|
|
6
|
+
[]()
|
|
7
|
+
[]()
|
|
8
|
+
|
|
9
|
+
## What is this?
|
|
10
|
+
|
|
11
|
+
An MCP (Model Context Protocol) server that gives AI assistants persistent memory with learning capabilities. Save insights, track feedback, and let the system learn which information is valuable over time.
|
|
12
|
+
|
|
13
|
+
**Pattern: Index โ Detail**
|
|
14
|
+
- `list_index` returns titles and previews (cheap, fast, with filtering)
|
|
15
|
+
- `search_insights` finds relevant insights with contextual ranking
|
|
16
|
+
- `get_detail` loads full content only when needed (on-demand)
|
|
17
|
+
|
|
18
|
+
## Unique Features
|
|
19
|
+
|
|
20
|
+
### Trust Score
|
|
21
|
+
Insights are ranked by a computed trust score based on user feedback:
|
|
22
|
+
```
|
|
23
|
+
trustScore = (helpful - harmful ร 2) / (helpful + harmful + 1)
|
|
24
|
+
```
|
|
25
|
+
- Penalizes harmful feedback more heavily (ร2 weight)
|
|
26
|
+
- Insights with negative scores display a warning
|
|
27
|
+
- Boosts reliable information in search results
|
|
28
|
+
|
|
29
|
+
### Decay Factor
|
|
30
|
+
Older insights gradually lose ranking priority:
|
|
31
|
+
- Fresh insights (< 7 days): Full score + bonus
|
|
32
|
+
- Aging insights: Score decays linearly over 90 days
|
|
33
|
+
- Minimum decay: 10% (never fully forgotten)
|
|
34
|
+
|
|
35
|
+
### Auto-Deduplication
|
|
36
|
+
Prevents duplicate insights using Levenshtein distance:
|
|
37
|
+
- Detects typos: "Bug Fix" vs "Bux Fix" (distance=1)
|
|
38
|
+
- Case-insensitive comparison
|
|
39
|
+
- Offers overwrite option for intentional updates
|
|
40
|
+
|
|
41
|
+
## Features
|
|
42
|
+
|
|
43
|
+
- **8 MCP Tools**: add, list, search, get, delete, export, mark helpful/harmful
|
|
44
|
+
- **Smart Search**: Contextual ranking with trust score and time decay
|
|
45
|
+
- **Multi-tag Filtering**: Filter insights by tags, helpful count, and more
|
|
46
|
+
- **Persistent Storage**: JSON file survives restarts
|
|
47
|
+
- **Race-Safe**: Mutex protection for concurrent access
|
|
48
|
+
- **Atomic Writes**: No data corruption on crash
|
|
49
|
+
- **Auto-Recovery**: Graceful handling of corrupted data files
|
|
50
|
+
- **XDG Compliant**: Respects `$XDG_DATA_HOME`
|
|
51
|
+
- **Source Tracking**: Optional sourceUrl for traceability
|
|
52
|
+
|
|
53
|
+
## Architecture
|
|
54
|
+
|
|
55
|
+
```mermaid
|
|
56
|
+
flowchart TB
|
|
57
|
+
subgraph Client["๐ค AI Client"]
|
|
58
|
+
CLI[Claude CLI]
|
|
59
|
+
Desktop[Claude Desktop]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
subgraph Protocol["๐ก MCP Protocol"]
|
|
63
|
+
RPC[JSON-RPC over stdio]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
subgraph Server["โก mcp-learning-memory"]
|
|
67
|
+
Index[index.ts<br/>8 Tools]
|
|
68
|
+
Tools[tools.ts<br/>Business Logic]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
subgraph Features["โจ Unique Features"]
|
|
72
|
+
Trust[trustScore]
|
|
73
|
+
Decay[decay_factor]
|
|
74
|
+
Dedup[auto_dedup]
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
subgraph Storage["๐พ Storage"]
|
|
78
|
+
JSON[(memory.json)]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
CLI --> RPC
|
|
82
|
+
Desktop --> RPC
|
|
83
|
+
RPC --> Index
|
|
84
|
+
Index --> Tools
|
|
85
|
+
Tools --> Features
|
|
86
|
+
Tools --> JSON
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Installation
|
|
90
|
+
|
|
91
|
+
### Prerequisites
|
|
92
|
+
- Node.js 18+
|
|
93
|
+
- Claude CLI or Claude Desktop
|
|
94
|
+
|
|
95
|
+
### Build from source
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
git clone https://github.com/nulone/mcp-learning-memory
|
|
99
|
+
cd mcp-learning-memory
|
|
100
|
+
npm install
|
|
101
|
+
npm run build
|
|
102
|
+
npm test # 81 tests should pass
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Configuration
|
|
106
|
+
|
|
107
|
+
### Claude CLI
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Add MCP server
|
|
111
|
+
claude mcp add learning-memory node /path/to/mcp-learning-memory/dist/index.js
|
|
112
|
+
|
|
113
|
+
# Verify
|
|
114
|
+
claude
|
|
115
|
+
/mcp # Should show: learning-memory ยท โ connected
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Or manually edit `~/.claude.json`:
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"mcpServers": {
|
|
123
|
+
"learning-memory": {
|
|
124
|
+
"command": "node",
|
|
125
|
+
"args": ["/path/to/mcp-learning-memory/dist/index.js"]
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Claude Desktop
|
|
132
|
+
|
|
133
|
+
**macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
134
|
+
**Linux:** `~/.config/Claude/claude_desktop_config.json`
|
|
135
|
+
**Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
136
|
+
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
"mcpServers": {
|
|
140
|
+
"learning-memory": {
|
|
141
|
+
"command": "node",
|
|
142
|
+
"args": ["/path/to/mcp-learning-memory/dist/index.js"]
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Restart Claude Desktop after editing.
|
|
149
|
+
|
|
150
|
+
## Usage
|
|
151
|
+
|
|
152
|
+
### Natural language (via Claude)
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
Save an insight "React hooks tips" with tags react, hooks and content "Always call hooks at top level"
|
|
156
|
+
|
|
157
|
+
Show all my insights
|
|
158
|
+
|
|
159
|
+
Mark the React insight as helpful
|
|
160
|
+
|
|
161
|
+
Delete the outdated insight
|
|
162
|
+
|
|
163
|
+
Export my memory as markdown
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Direct tool calls
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
# Add new insight with source URL
|
|
170
|
+
add_insight: title="JWT Auth Pattern", tags=["auth","jwt"], content="Use refresh tokens...", sourceUrl="https://example.com/article"
|
|
171
|
+
|
|
172
|
+
# List with filters
|
|
173
|
+
list_index: tags=["auth"], sortBy="helpful", limit=10
|
|
174
|
+
|
|
175
|
+
# Search with ranking (uses trust score + decay)
|
|
176
|
+
search_insights: query="authentication", limit=5
|
|
177
|
+
|
|
178
|
+
# Get full content
|
|
179
|
+
get_detail: id="ace-000001"
|
|
180
|
+
|
|
181
|
+
# Provide feedback
|
|
182
|
+
mark_helpful: id="ace-000001"
|
|
183
|
+
mark_harmful: id="ace-000002"
|
|
184
|
+
|
|
185
|
+
# Delete insight
|
|
186
|
+
delete_insight: id="ace-000003"
|
|
187
|
+
|
|
188
|
+
# Export for backup
|
|
189
|
+
export_memory: format="markdown"
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## API Reference
|
|
193
|
+
|
|
194
|
+
### `add_insight`
|
|
195
|
+
|
|
196
|
+
Save a new insight to memory.
|
|
197
|
+
|
|
198
|
+
| Parameter | Type | Required | Description |
|
|
199
|
+
|-----------|------|----------|-------------|
|
|
200
|
+
| title | string | โ
| Short title (1-200 chars after trim) |
|
|
201
|
+
| tags | string[] | โ
| Category tags (1-10 items, normalized) |
|
|
202
|
+
| content | string | โ
| Full content (max 10,000 chars after trim) |
|
|
203
|
+
| overwrite | boolean | โ | Update existing insight with same title |
|
|
204
|
+
| sourceUrl | string | โ | Source URL for traceability (max 2,000 chars) |
|
|
205
|
+
|
|
206
|
+
**Auto-Deduplication:**
|
|
207
|
+
- Detects similar titles using Levenshtein distance (< 3)
|
|
208
|
+
- Case-insensitive comparison
|
|
209
|
+
- Returns existing insight ID when duplicate found
|
|
210
|
+
- Use `overwrite=true` to update intentionally
|
|
211
|
+
|
|
212
|
+
**Examples:**
|
|
213
|
+
```
|
|
214
|
+
# Basic insight
|
|
215
|
+
add_insight: title="React Tips", tags=["react"], content="Use memo for expensive renders"
|
|
216
|
+
|
|
217
|
+
# With source URL
|
|
218
|
+
add_insight: title="API Design", tags=["api","rest"], content="...", sourceUrl="https://docs.example.com"
|
|
219
|
+
|
|
220
|
+
# Overwrite existing
|
|
221
|
+
add_insight: title="React Tips", tags=["react","hooks"], content="Updated content", overwrite=true
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### `list_index`
|
|
225
|
+
|
|
226
|
+
List all insights with metadata and content preview.
|
|
227
|
+
|
|
228
|
+
| Parameter | Type | Required | Description |
|
|
229
|
+
|-----------|------|----------|-------------|
|
|
230
|
+
| tags | string[] | โ | Filter by tags (AND logic) |
|
|
231
|
+
| minHelpful | number | โ | Minimum helpful count (default: 0) |
|
|
232
|
+
| sortBy | string | โ | Sort: `created`, `lastUsed`, `helpful` (default: `lastUsed`) |
|
|
233
|
+
| limit | number | โ | Maximum results (default: 50) |
|
|
234
|
+
|
|
235
|
+
**Response includes:**
|
|
236
|
+
- Content preview (100 chars)
|
|
237
|
+
- Trust score (computed)
|
|
238
|
+
- Warning for low trust insights
|
|
239
|
+
- Source URL if present
|
|
240
|
+
|
|
241
|
+
### `get_detail`
|
|
242
|
+
|
|
243
|
+
Load full content of an insight. Updates `lastUsed` timestamp.
|
|
244
|
+
|
|
245
|
+
| Parameter | Type | Required | Description |
|
|
246
|
+
|-----------|------|----------|-------------|
|
|
247
|
+
| id | string | โ
| Insight ID (e.g., ace-000001) |
|
|
248
|
+
|
|
249
|
+
### `mark_helpful`
|
|
250
|
+
|
|
251
|
+
Increment helpful counter (+1). Updates `lastUsed` timestamp.
|
|
252
|
+
|
|
253
|
+
| Parameter | Type | Required | Description |
|
|
254
|
+
|-----------|------|----------|-------------|
|
|
255
|
+
| id | string | โ
| Insight ID |
|
|
256
|
+
|
|
257
|
+
### `mark_harmful`
|
|
258
|
+
|
|
259
|
+
Increment harmful counter (+1). Use for outdated/incorrect information.
|
|
260
|
+
|
|
261
|
+
| Parameter | Type | Required | Description |
|
|
262
|
+
|-----------|------|----------|-------------|
|
|
263
|
+
| id | string | โ
| Insight ID |
|
|
264
|
+
|
|
265
|
+
### `search_insights`
|
|
266
|
+
|
|
267
|
+
Search with contextual ranking using trust score and decay factor.
|
|
268
|
+
|
|
269
|
+
| Parameter | Type | Required | Description |
|
|
270
|
+
|-----------|------|----------|-------------|
|
|
271
|
+
| query | string | โ
| Search query (searches title, content, tags) |
|
|
272
|
+
| limit | number | โ | Maximum results (default: 5) |
|
|
273
|
+
|
|
274
|
+
**Scoring Algorithm:**
|
|
275
|
+
- Exact title match: +10 points
|
|
276
|
+
- Partial title match: +5 points
|
|
277
|
+
- Content match: +3 points
|
|
278
|
+
- Tag match: +2 points per tag
|
|
279
|
+
- Helpful count: +1 point per helpful
|
|
280
|
+
- Recent usage (7 days): +3 points
|
|
281
|
+
- Trust score bonus: +trustScore ร 5
|
|
282
|
+
- Decay factor: score ร max(0.1, 1 - daysOld/90)
|
|
283
|
+
|
|
284
|
+
### `delete_insight`
|
|
285
|
+
|
|
286
|
+
Delete an insight permanently.
|
|
287
|
+
|
|
288
|
+
| Parameter | Type | Required | Description |
|
|
289
|
+
|-----------|------|----------|-------------|
|
|
290
|
+
| id | string | โ
| Insight ID to delete |
|
|
291
|
+
|
|
292
|
+
### `export_memory`
|
|
293
|
+
|
|
294
|
+
Export all insights for backup or documentation.
|
|
295
|
+
|
|
296
|
+
| Parameter | Type | Required | Description |
|
|
297
|
+
|-----------|------|----------|-------------|
|
|
298
|
+
| format | string | โ | `json` (default) or `markdown` |
|
|
299
|
+
|
|
300
|
+
**Markdown format includes:**
|
|
301
|
+
- Trust scores for each insight
|
|
302
|
+
- Source URLs
|
|
303
|
+
- Statistics (helpful/harmful counts)
|
|
304
|
+
|
|
305
|
+
## Data Storage
|
|
306
|
+
|
|
307
|
+
**Location:** `$XDG_DATA_HOME/ace-flash-memory/memory.json`
|
|
308
|
+
- Linux/macOS default: `~/.local/share/ace-flash-memory/memory.json`
|
|
309
|
+
|
|
310
|
+
**Automatic Recovery:**
|
|
311
|
+
- Corrupted files are backed up with timestamp
|
|
312
|
+
- System continues with empty memory
|
|
313
|
+
- No data loss from temporary corruption
|
|
314
|
+
|
|
315
|
+
## Development
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
npm install
|
|
319
|
+
npm run build
|
|
320
|
+
npm test # 81 integration tests
|
|
321
|
+
|
|
322
|
+
# Verify no console.log (MCP requires stderr only)
|
|
323
|
+
grep -r "console.log" src/ # Should be empty
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Project Structure
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
mcp-learning-memory/
|
|
330
|
+
โโโ src/
|
|
331
|
+
โ โโโ index.ts # MCP server entry point
|
|
332
|
+
โ โโโ tools.ts # 8 tool implementations + Mutex
|
|
333
|
+
โ โโโ storage.ts # Atomic file I/O + recovery
|
|
334
|
+
โ โโโ validation.ts # Input validation & normalization
|
|
335
|
+
โ โโโ logger.ts # stderr-only logging
|
|
336
|
+
โ โโโ types.ts # TypeScript interfaces
|
|
337
|
+
โโโ tests/
|
|
338
|
+
โ โโโ integration.test.ts # 81 tests in isolated env
|
|
339
|
+
โโโ dist/ # Compiled JavaScript
|
|
340
|
+
โโโ package.json
|
|
341
|
+
โโโ tsconfig.json
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Safety Features
|
|
345
|
+
|
|
346
|
+
### No stdout pollution
|
|
347
|
+
MCP uses stdout for JSON-RPC. All logging goes to stderr.
|
|
348
|
+
|
|
349
|
+
### Mutex protection
|
|
350
|
+
Concurrent requests are serialized to prevent lost updates.
|
|
351
|
+
|
|
352
|
+
### Atomic writes
|
|
353
|
+
Writes use temp file + rename pattern for crash safety.
|
|
354
|
+
|
|
355
|
+
### Isolated testing
|
|
356
|
+
Tests run in temporary directories to protect user data.
|
|
357
|
+
|
|
358
|
+
## Troubleshooting
|
|
359
|
+
|
|
360
|
+
### MCP not connecting
|
|
361
|
+
|
|
362
|
+
```bash
|
|
363
|
+
# Check if server starts
|
|
364
|
+
node dist/index.js
|
|
365
|
+
# Should see: [INFO] server running
|
|
366
|
+
|
|
367
|
+
# Verify config path is absolute
|
|
368
|
+
cat ~/.claude.json
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Data not persisting
|
|
372
|
+
|
|
373
|
+
```bash
|
|
374
|
+
ls -la ~/.local/share/ace-flash-memory/
|
|
375
|
+
cat ~/.local/share/ace-flash-memory/memory.json
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Corrupted data
|
|
379
|
+
|
|
380
|
+
```bash
|
|
381
|
+
# List backups
|
|
382
|
+
ls ~/.local/share/ace-flash-memory/*.corrupt.*
|
|
383
|
+
|
|
384
|
+
# Restore if needed
|
|
385
|
+
cp memory.json.corrupt.TIMESTAMP memory.json
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
## License
|
|
389
|
+
|
|
390
|
+
MIT
|
|
391
|
+
|
|
392
|
+
## Credits
|
|
393
|
+
|
|
394
|
+
Built with [Model Context Protocol SDK](https://github.com/anthropics/mcp), [TypeScript](https://www.typescriptlang.org/), and [Vitest](https://vitest.dev/).
|