mcp-kb-server 1.1.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/LICENSE +21 -0
- package/README.md +692 -0
- package/config/discovery.json +14 -0
- package/package.json +39 -0
- package/src/server.js +326 -0
- package/src/storage/db.js +138 -0
- package/src/tools/dashboard.js +939 -0
- package/src/tools/kb.js +394 -0
- package/src/tools/memory.js +500 -0
- package/src/tools/summary.js +112 -0
- package/src/tools/summaryDelta.js +128 -0
- package/src/utils/config.js +58 -0
- package/src/utils/errors.js +106 -0
- package/src/utils/fileDiscovery.js +218 -0
- package/src/utils/logger.js +23 -0
- package/src/utils/metrics.js +192 -0
- package/src/utils/performance.js +153 -0
- package/src/utils/projectId.js +144 -0
- package/src/utils/validation.js +119 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mcp-kb-server contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
# MCP Knowledge Base Server
|
|
2
|
+
|
|
3
|
+
A Model Context Protocol (MCP) server providing persistent memory, knowledge base, and project summary capabilities with automatic project detection and interactive dashboards.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
9
|
+
│ AI Assistant (Kiro, Claude, etc.) │
|
|
10
|
+
│ │
|
|
11
|
+
│ "Remember we use JWT" "What do I know about auth?" │
|
|
12
|
+
│ "Show all my memories" "What changed since last summary?" │
|
|
13
|
+
└──────────────┬───────────────────────────┬───────────────────┘
|
|
14
|
+
│ MCP Protocol (stdio) │
|
|
15
|
+
▼ ▼
|
|
16
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
17
|
+
│ mcp-kb-server │
|
|
18
|
+
│ │
|
|
19
|
+
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌──────────┐ │
|
|
20
|
+
│ │ memory │ │ kb │ │ summary │ │dashboard │ │
|
|
21
|
+
│ │ .store │ │ .add │ │.project │ │.projects │ │
|
|
22
|
+
│ │ .search │ │ .search │ │ .delta │ └──────────┘ │
|
|
23
|
+
│ │ .list │ └─────────┘ └─────────┘ │
|
|
24
|
+
│ │ .delete │ │
|
|
25
|
+
│ │ .update │ Auto-detect project_id from project_root │
|
|
26
|
+
│ └─────────┘ package.json → git remote → directory name │
|
|
27
|
+
│ │
|
|
28
|
+
│ ┌────────────────────┐ ┌────────────────────┐ │
|
|
29
|
+
│ │ memory.sqlite │ │ kb.sqlite │ │
|
|
30
|
+
│ │ + memory_fts(FTS5)│ │ + kb_fts (FTS5) │ │
|
|
31
|
+
│ │ + expires/TTL │ │ + kb_meta (scoping) │ │
|
|
32
|
+
│ └────────────────────┘ └────────────────────┘ │
|
|
33
|
+
└──────────────────────────────────────────────────────────────┘
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Agent Workflow
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
Store knowledge Recall knowledge Maintain knowledge
|
|
40
|
+
───────────── ──────────────── ──────────────────
|
|
41
|
+
|
|
42
|
+
memory.store ──┐ memory.search -──┐ memory.update ──┐
|
|
43
|
+
(decisions, │ (query + tags, │ (correct info, │
|
|
44
|
+
patterns, │ FTS5 ranking) │ refine tags) │
|
|
45
|
+
bug fixes) │ │ │
|
|
46
|
+
│ memory.list ─────┤ memory.delete ──┤
|
|
47
|
+
kb.add ────────┤ (paginated, │ (remove stale) │
|
|
48
|
+
(docs, specs, │ total_count) │ │
|
|
49
|
+
references) │ │ TTL/expiry ─────┘
|
|
50
|
+
│ kb.search ───────┤ (auto-purge)
|
|
51
|
+
│ (FTS5 + optional │
|
|
52
|
+
│ project scoping)│
|
|
53
|
+
│ │
|
|
54
|
+
▼ ▼
|
|
55
|
+
┌──────────┐ ┌──────────────┐
|
|
56
|
+
│ SQLite │ │ summary │
|
|
57
|
+
│ (WAL) │◄───────────│ .project │
|
|
58
|
+
└──────────┘ │ .delta │
|
|
59
|
+
└──────┬───────┘
|
|
60
|
+
│
|
|
61
|
+
▼
|
|
62
|
+
┌──────────────┐
|
|
63
|
+
│ dashboard │
|
|
64
|
+
│ .projects │
|
|
65
|
+
│ (HTML view) │
|
|
66
|
+
└──────────────┘
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Features
|
|
70
|
+
|
|
71
|
+
### 🧠 Memory Management
|
|
72
|
+
- **Long-term Memory**: Store, search, list, update, and delete project-specific memory entries
|
|
73
|
+
- **Full-Text Search**: FTS5 with BM25 ranking via `use_fts` flag, plus substring fallback
|
|
74
|
+
- **Tag Filtering**: Filter memories by tag name, combine with text queries
|
|
75
|
+
- **Pagination**: `memory.list` with `total_count`, `offset`, `has_more` for browsing all memories
|
|
76
|
+
- **TTL / Expiry**: Optional `expires_at` on entries, auto-purged on access
|
|
77
|
+
- **Automatic Project Detection**: Auto-detect project_id from package.json, git, or directory name
|
|
78
|
+
- **Project Isolation**: Complete data isolation between projects
|
|
79
|
+
- **Scoped Storage**: Organize entries by custom scopes
|
|
80
|
+
|
|
81
|
+
### 📚 Knowledge Base
|
|
82
|
+
- **Document Storage**: Add and search documents with full-text search (FTS5)
|
|
83
|
+
- **Project Scoping**: Optional `project_id` on kb.add/kb.search to isolate docs per project
|
|
84
|
+
- **Vector Search**: Optional Qdrant integration for semantic search
|
|
85
|
+
- **Source Tracking**: Track document sources and metadata
|
|
86
|
+
|
|
87
|
+
### 📊 Project Summaries
|
|
88
|
+
- **Snapshot Generation**: Create comprehensive project summaries from files, memory, and KB
|
|
89
|
+
- **Delta Summaries**: Compare current state vs. last summary to see changes
|
|
90
|
+
- **Auto-Discovery**: Automatically find instruction files (README, ARCHITECTURE, etc.)
|
|
91
|
+
|
|
92
|
+
### 🎨 Interactive Dashboards
|
|
93
|
+
- **Visual Overview**: Beautiful HTML dashboards showing all projects
|
|
94
|
+
- **Real-time Search**: Filter projects and entries interactively
|
|
95
|
+
- **Activity Tracking**: See recent activity across all projects
|
|
96
|
+
- **Self-Contained**: No external dependencies, works offline
|
|
97
|
+
|
|
98
|
+
### 🔒 Safety Features
|
|
99
|
+
- **Path Validation**: Validates project_root paths exist and are accessible
|
|
100
|
+
- **Mismatch Detection**: Warns when explicit project_id differs from detected
|
|
101
|
+
- **XSS Protection**: All user content is HTML-escaped
|
|
102
|
+
- **Path Normalization**: Consistent absolute paths across platforms
|
|
103
|
+
- **Cache Invalidation**: Query cache cleared on all mutations
|
|
104
|
+
|
|
105
|
+
## Installation
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npm install
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Testing
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm run test
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Usage
|
|
118
|
+
|
|
119
|
+
### As MCP Server
|
|
120
|
+
|
|
121
|
+
Configure in your MCP client (e.g., Kiro, Claude Desktop):
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"mcpServers": {
|
|
126
|
+
"kb-server": {
|
|
127
|
+
"command": "node",
|
|
128
|
+
"args": ["/path/to/mcp-kb-server/src/server.js"],
|
|
129
|
+
"env": {}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Available Tools
|
|
136
|
+
|
|
137
|
+
#### Memory Tools
|
|
138
|
+
Requires either `project_root` or `project_id`.
|
|
139
|
+
|
|
140
|
+
**memory.store** - Store long-term memory
|
|
141
|
+
```javascript
|
|
142
|
+
{
|
|
143
|
+
"project_root": "/path/to/project", // Auto-detects project_id
|
|
144
|
+
"content": "Important information",
|
|
145
|
+
"scope": "default", // Optional
|
|
146
|
+
"tags": ["feature", "auth"], // Optional
|
|
147
|
+
"expires_at": "2026-12-31T00:00:00Z" // Optional TTL
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**memory.search** - Search memory
|
|
152
|
+
```javascript
|
|
153
|
+
{
|
|
154
|
+
"project_root": "/path/to/project",
|
|
155
|
+
"query": "authentication",
|
|
156
|
+
"tag": "decision", // Optional — filter by tag
|
|
157
|
+
"use_fts": true, // Optional — FTS5 with BM25 ranking
|
|
158
|
+
"scope": "default", // Optional
|
|
159
|
+
"limit": 5 // Optional
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**memory.list** - List all memories with pagination
|
|
164
|
+
```javascript
|
|
165
|
+
{
|
|
166
|
+
"project_root": "/path/to/project",
|
|
167
|
+
"limit": 50, // Optional (1-500, default 50)
|
|
168
|
+
"offset": 0, // Optional — for pagination
|
|
169
|
+
"scope": "decisions" // Optional — filter by scope
|
|
170
|
+
}
|
|
171
|
+
// Returns: { total_count, offset, limit, has_more, entries }
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**memory.delete** - Delete a memory entry
|
|
175
|
+
```javascript
|
|
176
|
+
{
|
|
177
|
+
"project_root": "/path/to/project",
|
|
178
|
+
"id": "uuid-of-entry"
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**memory.update** - Update an existing memory entry
|
|
183
|
+
```javascript
|
|
184
|
+
{
|
|
185
|
+
"project_root": "/path/to/project",
|
|
186
|
+
"id": "uuid-of-entry",
|
|
187
|
+
"content": "Updated information", // Optional
|
|
188
|
+
"tags": ["updated", "auth"], // Optional — replaces existing
|
|
189
|
+
"expires_at": "" // Optional — empty string removes expiry
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
#### Knowledge Base Tools
|
|
194
|
+
|
|
195
|
+
**kb.add** - Add document to knowledge base
|
|
196
|
+
```javascript
|
|
197
|
+
{
|
|
198
|
+
"title": "API Documentation",
|
|
199
|
+
"content": "Complete API reference...",
|
|
200
|
+
"source": "docs/api.md", // Optional
|
|
201
|
+
"project_id": "my-project" // Optional — scope to project
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**kb.search** - Search knowledge base
|
|
206
|
+
```javascript
|
|
207
|
+
{
|
|
208
|
+
"query": "authentication",
|
|
209
|
+
"project_id": "my-project", // Optional — search only this project's docs
|
|
210
|
+
"limit": 5 // Optional
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
#### Summary Tools
|
|
215
|
+
|
|
216
|
+
**summary.project** - Generate project snapshot
|
|
217
|
+
```javascript
|
|
218
|
+
{
|
|
219
|
+
"project_root": "/path/to/project",
|
|
220
|
+
"auto_discover": true, // Auto-find instruction files
|
|
221
|
+
"include_memory": true, // Include memory entries
|
|
222
|
+
"include_kb": true // Include KB documents
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
**summary.delta** - Generate change summary
|
|
227
|
+
```javascript
|
|
228
|
+
{
|
|
229
|
+
"project_root": "/path/to/project",
|
|
230
|
+
"auto_discover": true
|
|
231
|
+
}
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
#### Dashboard Tool
|
|
235
|
+
|
|
236
|
+
**dashboard.projects** - Generate and serve interactive HTML dashboard
|
|
237
|
+
```javascript
|
|
238
|
+
{
|
|
239
|
+
"limit": 10 // Recent entries per project
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Generates a dashboard file (in `./temp`) and starts a local server. Returns the local URL and file path.
|
|
244
|
+
|
|
245
|
+
## Automatic Project Detection
|
|
246
|
+
|
|
247
|
+
The server automatically detects `project_id` from `project_root` using:
|
|
248
|
+
|
|
249
|
+
1. **package.json** - Uses the "name" field
|
|
250
|
+
2. **Git remote** - Extracts repository name from origin URL
|
|
251
|
+
3. **Directory name** - Falls back to directory basename
|
|
252
|
+
|
|
253
|
+
All project IDs are sanitized to valid identifiers (lowercase, alphanumeric + hyphens).
|
|
254
|
+
|
|
255
|
+
### Example
|
|
256
|
+
|
|
257
|
+
```javascript
|
|
258
|
+
// Auto-detection
|
|
259
|
+
memory.store({
|
|
260
|
+
project_root: "/Users/me/my-awesome-project",
|
|
261
|
+
content: "test"
|
|
262
|
+
})
|
|
263
|
+
// Detects project_id: "my-awesome-project"
|
|
264
|
+
|
|
265
|
+
// Explicit (still works)
|
|
266
|
+
memory.store({
|
|
267
|
+
project_id: "custom-id",
|
|
268
|
+
project_root: "/Users/me/my-awesome-project",
|
|
269
|
+
content: "test"
|
|
270
|
+
})
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Safety Features
|
|
274
|
+
|
|
275
|
+
### Path Validation
|
|
276
|
+
|
|
277
|
+
All `project_root` paths are validated:
|
|
278
|
+
- ✅ Path exists
|
|
279
|
+
- ✅ Path is a directory
|
|
280
|
+
- ✅ Path is accessible
|
|
281
|
+
- ✅ Path is normalized to absolute
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
// ❌ Error: project_root does not exist
|
|
285
|
+
memory.store({ project_root: "/nonexistent", content: "test" })
|
|
286
|
+
|
|
287
|
+
// ❌ Error: project_root is not a directory
|
|
288
|
+
memory.store({ project_root: "/path/to/file.txt", content: "test" })
|
|
289
|
+
|
|
290
|
+
// ✅ Success: Valid path
|
|
291
|
+
memory.store({ project_root: "/path/to/project", content: "test" })
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Mismatch Detection
|
|
295
|
+
|
|
296
|
+
Warns when explicit `project_id` differs from auto-detected:
|
|
297
|
+
|
|
298
|
+
```javascript
|
|
299
|
+
// package.json has name: "actual-project"
|
|
300
|
+
memory.store({
|
|
301
|
+
project_id: "wrong-name",
|
|
302
|
+
project_root: "/path/to/actual-project",
|
|
303
|
+
content: "test"
|
|
304
|
+
})
|
|
305
|
+
// Console: [SAFETY WARNING] Explicit project_id "wrong-name"
|
|
306
|
+
// differs from detected "actual-project" (package.json)
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## Dashboard
|
|
310
|
+
|
|
311
|
+
Generate beautiful HTML dashboards:
|
|
312
|
+
|
|
313
|
+
```javascript
|
|
314
|
+
const result = dashboard.projects({ limit: 20 });
|
|
315
|
+
|
|
316
|
+
console.log(result.dashboard_url);
|
|
317
|
+
// Open the URL in your browser
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
**Dashboard Features**:
|
|
321
|
+
- 📊 Overview statistics (projects, entries, summaries)
|
|
322
|
+
- 🔍 Real-time search and filtering
|
|
323
|
+
- ✏️ Interactive KB management (Add/Edit/Delete)
|
|
324
|
+
- 📝 Markdown rendering support
|
|
325
|
+
- 📋 Latest project summaries
|
|
326
|
+
- 🎨 Clean, theme-aware UI (Dark/Light mode)
|
|
327
|
+
- 📱 Responsive design
|
|
328
|
+
- 🔒 XSS protection
|
|
329
|
+
- 📦 Self-contained (no external dependencies)
|
|
330
|
+
|
|
331
|
+
## Project Structure
|
|
332
|
+
|
|
333
|
+
```
|
|
334
|
+
mcp-kb-server/
|
|
335
|
+
├── src/
|
|
336
|
+
│ ├── server.js # MCP server entry point
|
|
337
|
+
│ ├── storage/
|
|
338
|
+
│ │ └── db.js # Database initialization
|
|
339
|
+
│ ├── tools/
|
|
340
|
+
│ │ ├── memory.js # Memory storage/search
|
|
341
|
+
│ │ ├── kb.js # Knowledge base
|
|
342
|
+
│ │ ├── summary.js # Project summaries
|
|
343
|
+
│ │ ├── summaryDelta.js # Delta summaries
|
|
344
|
+
│ │ └── dashboard.js # Dashboard generation
|
|
345
|
+
│ └── utils/
|
|
346
|
+
│ └── projectId.js # Project ID detection
|
|
347
|
+
├── data/ # SQLite databases (auto-created)
|
|
348
|
+
├── test/ # Test suite
|
|
349
|
+
├── config/
|
|
350
|
+
│ └── discovery.json # Auto-discovery patterns
|
|
351
|
+
└── package.json
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## Database
|
|
355
|
+
|
|
356
|
+
Uses SQLite for persistent storage:
|
|
357
|
+
|
|
358
|
+
- **memory.sqlite** - Memory entries with project scoping
|
|
359
|
+
- **kb.sqlite** - Knowledge base documents with FTS5
|
|
360
|
+
|
|
361
|
+
Databases are automatically created in the `data/` directory on first run.
|
|
362
|
+
|
|
363
|
+
## Development
|
|
364
|
+
|
|
365
|
+
### Run Tests
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
npm test
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
All 66 tests should pass:
|
|
372
|
+
- ✅ Memory tools — store, search, list, delete, update, tags, FTS5, expiry (15 tests)
|
|
373
|
+
- ✅ KB tools — add, search, vector, rollback, project scoping (4 tests)
|
|
374
|
+
- ✅ Project ID detection (6 tests)
|
|
375
|
+
- ✅ Project safety (11 tests)
|
|
376
|
+
- ✅ Project scoping (5 tests)
|
|
377
|
+
- ✅ Summary tools (4 tests)
|
|
378
|
+
- ✅ Dashboard (7 tests)
|
|
379
|
+
- ✅ Config, errors, performance, validation (14 tests)
|
|
380
|
+
|
|
381
|
+
### Project Detection
|
|
382
|
+
|
|
383
|
+
Test detection logic:
|
|
384
|
+
|
|
385
|
+
```javascript
|
|
386
|
+
import { detectProjectId } from './src/utils/projectId.js';
|
|
387
|
+
|
|
388
|
+
const result = detectProjectId('/path/to/project');
|
|
389
|
+
console.log(result);
|
|
390
|
+
// {
|
|
391
|
+
// project_id: "my-project",
|
|
392
|
+
// project_root: "/absolute/path/to/project",
|
|
393
|
+
// detection_method: "package.json",
|
|
394
|
+
// explicit_mismatch: false,
|
|
395
|
+
// explicit_project_id: null
|
|
396
|
+
// }
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
## Configuration
|
|
400
|
+
|
|
401
|
+
### Auto-Discovery Patterns
|
|
402
|
+
|
|
403
|
+
Edit `config/discovery.json` to customize which files are auto-discovered:
|
|
404
|
+
|
|
405
|
+
```json
|
|
406
|
+
{
|
|
407
|
+
"instructionFiles": [
|
|
408
|
+
"README.md",
|
|
409
|
+
"README",
|
|
410
|
+
"ARCHITECTURE.md",
|
|
411
|
+
"DESIGN.md",
|
|
412
|
+
".kiro/resources/*.md",
|
|
413
|
+
"docs/**/*.md"
|
|
414
|
+
]
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
Supports glob patterns with `*` and `**`.
|
|
419
|
+
|
|
420
|
+
## Requirements
|
|
421
|
+
|
|
422
|
+
- **Node.js**: ≥18
|
|
423
|
+
- **Dependencies**: better-sqlite3, dotenv, joi, winston
|
|
424
|
+
|
|
425
|
+
## Architecture
|
|
426
|
+
|
|
427
|
+
### Memory Scoping
|
|
428
|
+
|
|
429
|
+
All memory entries are scoped by `project_id`:
|
|
430
|
+
|
|
431
|
+
```sql
|
|
432
|
+
CREATE TABLE memory (
|
|
433
|
+
id TEXT PRIMARY KEY,
|
|
434
|
+
scope TEXT NOT NULL,
|
|
435
|
+
content TEXT NOT NULL,
|
|
436
|
+
tags TEXT,
|
|
437
|
+
created_at TEXT NOT NULL,
|
|
438
|
+
updated_at TEXT,
|
|
439
|
+
expires_at TEXT,
|
|
440
|
+
project_id TEXT NOT NULL DEFAULT 'legacy'
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
-- FTS5 for full-text search with BM25 ranking
|
|
444
|
+
CREATE VIRTUAL TABLE memory_fts USING fts5(content, tags);
|
|
445
|
+
|
|
446
|
+
CREATE INDEX idx_memory_project_id ON memory(project_id);
|
|
447
|
+
CREATE INDEX idx_memory_expires_at ON memory(expires_at);
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Knowledge Base
|
|
451
|
+
|
|
452
|
+
Full-text search with FTS5, optional project scoping:
|
|
453
|
+
|
|
454
|
+
```sql
|
|
455
|
+
CREATE VIRTUAL TABLE kb_fts USING fts5(title, content, source);
|
|
456
|
+
|
|
457
|
+
-- Project scoping metadata
|
|
458
|
+
CREATE TABLE kb_meta (
|
|
459
|
+
rowid INTEGER PRIMARY KEY,
|
|
460
|
+
project_id TEXT DEFAULT NULL
|
|
461
|
+
);
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
## Security
|
|
465
|
+
|
|
466
|
+
- **Project Isolation**: Complete data isolation between projects
|
|
467
|
+
- **Path Validation**: Prevents directory traversal and invalid paths
|
|
468
|
+
- **XSS Protection**: All user content is HTML-escaped in dashboards
|
|
469
|
+
- **No External Resources**: Dashboards work offline, no CDN dependencies
|
|
470
|
+
- **Parameterized Queries**: SQL injection prevention
|
|
471
|
+
|
|
472
|
+
## Performance
|
|
473
|
+
|
|
474
|
+
- **Indexed Queries**: All project_id queries use indexes
|
|
475
|
+
- **FTS5 Search**: BM25-ranked full-text search on both memory and KB
|
|
476
|
+
- **LRU Query Cache**: 50-entry cache with 5-minute TTL, auto-invalidated on mutations
|
|
477
|
+
- **Throttled Maintenance**: Expired entry purge runs at most once per 60s per project
|
|
478
|
+
- **Efficient Aggregation**: Dashboard uses single query for stats
|
|
479
|
+
- **Configurable Limits**: Control result set sizes
|
|
480
|
+
- **Synchronous API**: better-sqlite3 is faster than async alternatives
|
|
481
|
+
|
|
482
|
+
## Error Handling
|
|
483
|
+
|
|
484
|
+
All errors include JSON-RPC error codes:
|
|
485
|
+
|
|
486
|
+
```javascript
|
|
487
|
+
{
|
|
488
|
+
"error": {
|
|
489
|
+
"code": -32602,
|
|
490
|
+
"message": "project_root does not exist: /nonexistent"
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
Common error codes:
|
|
496
|
+
- `-32602`: Invalid params (missing required fields, invalid paths)
|
|
497
|
+
- `-32601`: Method not found
|
|
498
|
+
- `-32000`: Server error
|
|
499
|
+
|
|
500
|
+
## Migration
|
|
501
|
+
|
|
502
|
+
### From v0.x (No Project Scoping)
|
|
503
|
+
|
|
504
|
+
Legacy entries are automatically assigned `project_id = 'legacy'`:
|
|
505
|
+
|
|
506
|
+
```javascript
|
|
507
|
+
// Access legacy data
|
|
508
|
+
memory.search({ project_id: "legacy", query: "" })
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### Updating to Project Scoping
|
|
512
|
+
|
|
513
|
+
Simply provide `project_root` and the server will auto-detect:
|
|
514
|
+
|
|
515
|
+
```javascript
|
|
516
|
+
// Old (still works)
|
|
517
|
+
memory.store({ project_id: "my-project", content: "test" })
|
|
518
|
+
|
|
519
|
+
// New (recommended)
|
|
520
|
+
memory.store({ project_root: "/path/to/project", content: "test" })
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
## Documentation
|
|
524
|
+
|
|
525
|
+
- **README.md** - Main documentation (you are here)
|
|
526
|
+
- **EXAMPLES.md** - Practical prompts and usage examples for AI assistants
|
|
527
|
+
- **AUTOMATIC_PROJECT_ID.md** - Auto-detection feature guide
|
|
528
|
+
- **PROJECT_SAFETY_RULES.md** - Safety features documentation
|
|
529
|
+
- **DASHBOARD_FEATURE.md** - Dashboard usage guide
|
|
530
|
+
- **PROJECT_SCOPING.md** - Project scoping implementation details
|
|
531
|
+
- **IMPLEMENTATION_SUMMARY.md** - Recent changes summary
|
|
532
|
+
|
|
533
|
+
## Quick Start with AI Assistants
|
|
534
|
+
|
|
535
|
+
See **EXAMPLES.md** for practical prompts like:
|
|
536
|
+
|
|
537
|
+
```
|
|
538
|
+
"Store a memory that we're using JWT for authentication"
|
|
539
|
+
"Search my project memory for anything about the database"
|
|
540
|
+
"Generate a dashboard showing all my projects"
|
|
541
|
+
"What changed in my project since the last summary?"
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
The EXAMPLES.md file includes:
|
|
545
|
+
- Common usage patterns
|
|
546
|
+
- Workflow examples
|
|
547
|
+
- Prompt templates
|
|
548
|
+
- Best practices
|
|
549
|
+
- Troubleshooting tips
|
|
550
|
+
|
|
551
|
+
## Examples
|
|
552
|
+
|
|
553
|
+
### Store and Search Memory
|
|
554
|
+
|
|
555
|
+
```javascript
|
|
556
|
+
// Store
|
|
557
|
+
memory.store({
|
|
558
|
+
project_root: "/path/to/project",
|
|
559
|
+
content: "Implemented user authentication with JWT",
|
|
560
|
+
tags: ["feature", "auth", "security"]
|
|
561
|
+
})
|
|
562
|
+
|
|
563
|
+
// Search
|
|
564
|
+
memory.search({
|
|
565
|
+
project_root: "/path/to/project",
|
|
566
|
+
query: "authentication"
|
|
567
|
+
})
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
### Generate Project Summary
|
|
571
|
+
|
|
572
|
+
```javascript
|
|
573
|
+
// Create snapshot
|
|
574
|
+
summary.project({
|
|
575
|
+
project_root: "/path/to/project",
|
|
576
|
+
auto_discover: true,
|
|
577
|
+
include_memory: true,
|
|
578
|
+
include_kb: true
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
// Store the summary
|
|
582
|
+
memory.store({
|
|
583
|
+
project_root: "/path/to/project",
|
|
584
|
+
scope: "project-summary",
|
|
585
|
+
content: JSON.stringify(summaryResult),
|
|
586
|
+
tags: ["project-summary"]
|
|
587
|
+
})
|
|
588
|
+
|
|
589
|
+
// Later, check what changed
|
|
590
|
+
summary.delta({
|
|
591
|
+
project_root: "/path/to/project"
|
|
592
|
+
})
|
|
593
|
+
```
|
|
594
|
+
|
|
595
|
+
### Create Dashboard
|
|
596
|
+
|
|
597
|
+
```javascript
|
|
598
|
+
// Generate dashboard
|
|
599
|
+
const result = dashboard.projects({ limit: 20 });
|
|
600
|
+
|
|
601
|
+
console.log(`Dashboard URL: ${result.dashboard_url}`);
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
## Troubleshooting
|
|
605
|
+
|
|
606
|
+
### Database Locked
|
|
607
|
+
|
|
608
|
+
If you see `SQLITE_BUSY` errors:
|
|
609
|
+
|
|
610
|
+
```javascript
|
|
611
|
+
// The server uses WAL mode by default
|
|
612
|
+
// Ensure only one server instance is running
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### Path Not Found
|
|
616
|
+
|
|
617
|
+
```javascript
|
|
618
|
+
// Use absolute paths or ensure current directory is correct
|
|
619
|
+
const path = require('path');
|
|
620
|
+
const absolutePath = path.resolve('./my-project');
|
|
621
|
+
|
|
622
|
+
memory.store({
|
|
623
|
+
project_root: absolutePath,
|
|
624
|
+
content: "test"
|
|
625
|
+
})
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
### Mismatch Warnings
|
|
629
|
+
|
|
630
|
+
If you see mismatch warnings:
|
|
631
|
+
|
|
632
|
+
```javascript
|
|
633
|
+
// Check your package.json name matches your expected project_id
|
|
634
|
+
// Or provide explicit project_id to override detection
|
|
635
|
+
memory.store({
|
|
636
|
+
project_id: "my-preferred-id",
|
|
637
|
+
project_root: "/path/to/project",
|
|
638
|
+
content: "test"
|
|
639
|
+
})
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
## Contributing
|
|
643
|
+
|
|
644
|
+
1. Fork the repository
|
|
645
|
+
2. Create a feature branch
|
|
646
|
+
3. Add tests for new features
|
|
647
|
+
4. Ensure all tests pass: `npm test`
|
|
648
|
+
5. Submit a pull request
|
|
649
|
+
|
|
650
|
+
## License
|
|
651
|
+
|
|
652
|
+
MIT
|
|
653
|
+
|
|
654
|
+
## Version History
|
|
655
|
+
|
|
656
|
+
### v1.1.0 (Current)
|
|
657
|
+
- ✅ memory.delete — remove outdated memories
|
|
658
|
+
- ✅ memory.update — upsert content, tags, expiry
|
|
659
|
+
- ✅ memory.list — paginated listing with total_count
|
|
660
|
+
- ✅ Tag-based filtering on memory.search
|
|
661
|
+
- ✅ FTS5 full-text search on memory (BM25 ranking)
|
|
662
|
+
- ✅ KB project scoping (optional project_id)
|
|
663
|
+
- ✅ TTL / expiry on memory entries (auto-purge)
|
|
664
|
+
- ✅ LRU query cache with mutation invalidation
|
|
665
|
+
- ✅ 66 comprehensive tests
|
|
666
|
+
|
|
667
|
+
### v1.0.0
|
|
668
|
+
- ✅ Automatic project_id detection
|
|
669
|
+
- ✅ Project switching safety rules
|
|
670
|
+
- ✅ Interactive HTML dashboards with Dark/Light mode
|
|
671
|
+
- ✅ Interactive Knowledge Base management
|
|
672
|
+
- ✅ Markdown rendering support
|
|
673
|
+
- ✅ Complete project scoping
|
|
674
|
+
- ✅ Path validation and normalization
|
|
675
|
+
- ✅ Mismatch detection and warnings
|
|
676
|
+
- ✅ 42 comprehensive tests
|
|
677
|
+
|
|
678
|
+
### v0.x (Legacy)
|
|
679
|
+
- Basic memory and KB functionality
|
|
680
|
+
- No project scoping
|
|
681
|
+
- Manual project_id required
|
|
682
|
+
|
|
683
|
+
## Support
|
|
684
|
+
|
|
685
|
+
For issues, questions, or contributions, please open an issue on GitHub.
|
|
686
|
+
|
|
687
|
+
## Acknowledgments
|
|
688
|
+
|
|
689
|
+
Built with:
|
|
690
|
+
- [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) - Fast SQLite driver
|
|
691
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/) - MCP specification
|
|
692
|
+
- D.E.R.E.K workflow - Structured development methodology
|