context-vault 2.0.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Felix Hellstrom
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,383 @@
1
+ # context-mcp
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@fellanh/context-mcp)](https://www.npmjs.com/package/@fellanh/context-mcp)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@fellanh/context-mcp)](https://www.npmjs.com/package/@fellanh/context-mcp)
5
+ [![license](https://img.shields.io/npm/l/@fellanh/context-mcp)](./LICENSE)
6
+ [![node](https://img.shields.io/node/v/@fellanh/context-mcp)](https://nodejs.org)
7
+
8
+ Personal context vault — an MCP server that connects any AI agent to your accumulated knowledge.
9
+
10
+ Your knowledge lives as markdown files in plain folders you own and can edit, version, or move freely. The SQLite database is a derived search index — rebuilt from those files at any time. The canonical flow is **files → DB** with a clean two-way mapping: disk structure determines folder placement, the DB stays flat and lightweight.
11
+
12
+ ## How It Works
13
+
14
+ ```
15
+ YOUR FILES (source of truth) SEARCH INDEX (derived)
16
+ ~/vault/ ~/.context-mcp/vault.db
17
+ ├── insights/ ┌───────────────────────────────┐
18
+ │ ├── react-query-caching.md │ vault table │
19
+ │ ├── sqlite-fts5-gotchas.md │ kind: insight │
20
+ │ └── react/ │ meta.folder: null (flat) │
21
+ │ └── hooks/ │ meta.folder: "react/hooks" │
22
+ │ └── use-query-gotcha.md │ kind: decision │
23
+ ├── decisions/ │ kind: pattern │
24
+ │ └── use-sqlite-over-pg.md │ kind: <any custom> │
25
+ ├── patterns/ │ + FTS5 full-text │
26
+ │ └── api-error-handler.md │ + vec0 embeddings │
27
+ └── references/ (custom kind) └───────────────────────────────┘
28
+ └── react-19-notes.md
29
+ Human-editable, git-versioned Fast hybrid search, RAG-ready
30
+ You own these files Rebuilt from files anytime
31
+ ```
32
+
33
+ The SQLite database is stored at `~/.context-mcp/vault.db` by default (configurable via `--db-path`, `CONTEXT_MCP_DB_PATH`, or `config.json`). It contains FTS5 full-text indexes and sqlite-vec embeddings (384-dim float32, all-MiniLM-L6-v2). The database is a derived index — delete it and the server rebuilds it automatically on next session.
34
+
35
+ Requires **Node.js 20** or later.
36
+
37
+ ## Install
38
+
39
+ ### Quick Start
40
+
41
+ ```bash
42
+ curl -fsSL https://raw.githubusercontent.com/fellanH/context-mcp/main/install.sh | sh
43
+ ```
44
+
45
+ ### npm (Recommended)
46
+
47
+ ```bash
48
+ npm install -g @fellanh/context-mcp
49
+ context-mcp setup
50
+ ```
51
+
52
+ The `setup` command auto-detects installed tools (Claude Code, Claude Desktop, Cursor, Windsurf, Cline), lets you pick which to configure, and writes the correct MCP config for each. Existing configs are preserved — only the `context-mcp` entry is added or updated.
53
+
54
+ ### Local Development
55
+
56
+ ```bash
57
+ git clone https://github.com/fellanH/context-mcp.git
58
+ cd context-mcp
59
+ npm install
60
+
61
+ # Interactive setup — detects your tools and configures them
62
+ node bin/cli.js setup
63
+ ```
64
+
65
+ For non-interactive environments (CI, scripts):
66
+
67
+ ```bash
68
+ context-mcp setup --yes
69
+ ```
70
+
71
+ ### Manual Configuration
72
+
73
+ If you prefer manual setup, add to your tool's MCP config. Pass `--vault-dir` to point at your vault folder (omit it to use the default `~/vault/`).
74
+
75
+ **npm install** (portable — survives upgrades):
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "context-mcp": {
81
+ "command": "context-mcp",
82
+ "args": ["serve", "--vault-dir", "/path/to/vault"]
83
+ }
84
+ }
85
+ }
86
+ ```
87
+
88
+ **Local dev clone** (absolute path to source):
89
+
90
+ ```json
91
+ {
92
+ "mcpServers": {
93
+ "context-mcp": {
94
+ "command": "node",
95
+ "args": ["/path/to/context-mcp/src/server/index.js", "--vault-dir", "/path/to/vault"]
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ You can also pass config via environment variables in the MCP config block:
102
+
103
+ ```json
104
+ {
105
+ "mcpServers": {
106
+ "context-mcp": {
107
+ "command": "context-mcp",
108
+ "args": ["serve"],
109
+ "env": {
110
+ "CONTEXT_MCP_VAULT_DIR": "/path/to/vault"
111
+ }
112
+ }
113
+ }
114
+ }
115
+ ```
116
+
117
+ ### How the Server Runs
118
+
119
+ The server is an MCP (Model Context Protocol) process — you don't start or stop it manually. Your AI client (Claude Code, Cursor, Cline, etc.) spawns it automatically as a child process when a session begins, based on the `mcpServers` config above. The server communicates over stdio and lives for the duration of the session. When the session ends, the client terminates the process and SQLite cleans up its WAL files.
120
+
121
+ This means:
122
+ - **No daemon, no port, no background service.** The server only runs while your AI client is active.
123
+ - **Multiple sessions** can run separate server instances concurrently — SQLite WAL mode handles concurrent access safely.
124
+ - **First launch** downloads the embedding model (~22MB, all-MiniLM-L6-v2) and creates the database. Subsequent starts are fast.
125
+ - **Auto-reindex** on first tool call per session ensures the search index is always in sync with your files on disk. No manual reindex needed.
126
+
127
+ ## Tools
128
+
129
+ The server exposes three tools. Your AI agent calls them automatically — you don't invoke them directly.
130
+
131
+ | Tool | Type | Description |
132
+ |------|------|-------------|
133
+ | `get_context` | Read | Hybrid FTS5 + vector search across all knowledge |
134
+ | `save_context` | Write | Save any kind of knowledge to the vault |
135
+ | `context_status` | Diag | Show resolved config, health, and per-kind file counts |
136
+
137
+ ### `get_context` — Search your vault
138
+
139
+ ```js
140
+ get_context({
141
+ query: "react query caching", // Natural language or keywords
142
+ kind: "insight", // Optional: filter by kind
143
+ tags: ["react"], // Optional: filter by tags
144
+ limit: 5 // Optional: max results (default 10)
145
+ })
146
+ ```
147
+
148
+ Returns entries ranked by combined full-text and semantic similarity, with recency weighting.
149
+
150
+ ### `save_context` — Save knowledge
151
+
152
+ ```js
153
+ save_context({
154
+ kind: "insight", // Determines folder: insights/
155
+ body: "React Query staleTime defaults to 0",
156
+ tags: ["react", "performance"],
157
+ title: "staleTime gotcha", // Optional
158
+ meta: { type: "gotcha" }, // Optional: any structured data
159
+ folder: "react/hooks", // Optional: subfolder organization
160
+ source: "debugging-session" // Optional: provenance
161
+ })
162
+ // → ~/vault/insights/react/hooks/staletime-gotcha.md
163
+ ```
164
+
165
+ The `kind` field accepts any string — `"insight"`, `"decision"`, `"pattern"`, `"reference"`, or any custom kind. The folder is auto-created from the pluralized kind name.
166
+
167
+ ### `context_status` — Diagnostics
168
+
169
+ Shows vault path, database size, file counts per kind, embedding coverage, and any issues.
170
+
171
+ ## Knowledge Organization
172
+
173
+ ### Folders and Kinds
174
+
175
+ Each top-level subdirectory in the vault maps to a `kind` value. The directory name is depluralized:
176
+
177
+ ```
178
+ insights/ → kind: "insight"
179
+ decisions/ → kind: "decision"
180
+ patterns/ → kind: "pattern"
181
+ references/ → kind: "reference"
182
+ ```
183
+
184
+ Within each kind directory, nested subfolders provide human-browsable organization. The subfolder path is stored in `meta.folder`:
185
+
186
+ ```
187
+ ON DISK IN DB (vault table)
188
+ insights/ kind: "insight", meta.folder: null
189
+ flat-file.md
190
+ insights/react/hooks/ kind: "insight", meta.folder: "react/hooks"
191
+ use-query-gotcha.md
192
+ ```
193
+
194
+ Tags are semantic (what the content is about). Folder structure is organizational (where it lives). These are separate concerns.
195
+
196
+ ### File Format
197
+
198
+ All knowledge files use YAML frontmatter:
199
+
200
+ ```markdown
201
+ ---
202
+ id: 01HXYZ...
203
+ tags: ["react", "performance"]
204
+ source: claude-code
205
+ created: 2026-02-17T12:00:00Z
206
+ ---
207
+ React Query's staleTime defaults to 0 — set it explicitly or every mount triggers a refetch.
208
+ ```
209
+
210
+ Standard keys: `id`, `tags`, `source`, `created`. Any extra frontmatter keys (`type`, `status`, `language`, `folder`, etc.) are stored in a `meta` JSON column automatically.
211
+
212
+ ### Custom Kinds
213
+
214
+ No code changes required:
215
+
216
+ 1. `mkdir ~/vault/references/`
217
+ 2. Add `.md` files with YAML frontmatter
218
+ 3. The next session auto-indexes them
219
+
220
+ The kind name comes from the directory: `references/` → kind `reference`.
221
+
222
+ ## Configuration
223
+
224
+ Works out of the box with zero config. All paths are overridable:
225
+
226
+ ```
227
+ CLI args > env vars > config file > convention defaults
228
+ ```
229
+
230
+ ### Defaults
231
+
232
+ | Setting | Default |
233
+ |---------|---------|
234
+ | Vault dir | `~/vault/` |
235
+ | Data dir | `~/.context-mcp/` |
236
+ | Database | `~/.context-mcp/vault.db` |
237
+ | Dev dir | `~/dev/` |
238
+
239
+ ### Config File (`~/.context-mcp/config.json`)
240
+
241
+ Lives in the data directory alongside the database. Created by `setup`, or create it manually:
242
+
243
+ ```json
244
+ {
245
+ "vaultDir": "/Users/you/vault/",
246
+ "dataDir": "/Users/you/.context-mcp",
247
+ "dbPath": "/Users/you/.context-mcp/vault.db",
248
+ "devDir": "/Users/you/dev"
249
+ }
250
+ ```
251
+
252
+ ### Environment Variables
253
+
254
+ | Variable | Overrides |
255
+ |----------|-----------|
256
+ | `CONTEXT_MCP_VAULT_DIR` | Vault directory (knowledge files) |
257
+ | `CONTEXT_MCP_DB_PATH` | Database path |
258
+ | `CONTEXT_MCP_DEV_DIR` | Dev directory |
259
+ | `CONTEXT_MCP_DATA_DIR` | Data directory (DB + config storage) |
260
+
261
+ ### CLI Arguments
262
+
263
+ ```bash
264
+ context-mcp serve --vault-dir /custom/vault --dev-dir /custom/dev
265
+ context-mcp serve --data-dir /custom/data --db-path /custom/data/vault.db
266
+ ```
267
+
268
+ ## CLI
269
+
270
+ ```bash
271
+ context-mcp <command> [options]
272
+ ```
273
+
274
+ | Command | Description |
275
+ |---------|-------------|
276
+ | `setup` | Interactive MCP installer — detects tools, writes configs |
277
+ | `serve` | Start the MCP server (used by AI clients in MCP configs) |
278
+ | `ui [--port 3141]` | Launch the web dashboard |
279
+ | `reindex` | Rebuild search index from knowledge files |
280
+ | `status` | Show vault diagnostics (paths, counts, health) |
281
+
282
+ If running from source without a global install, use `node bin/cli.js` instead of `context-mcp`.
283
+
284
+ ## Desktop App (macOS)
285
+
286
+ A macOS dock application that starts the UI server and opens the dashboard in your browser.
287
+
288
+ ```bash
289
+ osacompile -o "/Applications/Context.app" ui/Context.applescript
290
+ ```
291
+
292
+ The app checks if port 3141 is already in use, starts the server if not, and opens `http://localhost:3141`. Server logs are written to `/tmp/context-mcp.log`.
293
+
294
+ ## Troubleshooting
295
+
296
+ ### Native module build failures
297
+
298
+ `better-sqlite3` and `sqlite-vec` include native C code compiled for your platform. If install fails:
299
+
300
+ ```bash
301
+ npm rebuild better-sqlite3 sqlite-vec
302
+ ```
303
+
304
+ On Apple Silicon Macs, ensure you're running a native ARM Node.js (not Rosetta). Check with `node -p process.arch` — it should say `arm64`.
305
+
306
+ ### Vault directory not found
307
+
308
+ If `context_status` or `get_context` reports the vault directory doesn't exist:
309
+
310
+ ```bash
311
+ context-mcp status # Shows resolved paths
312
+ mkdir -p ~/vault # Create the default vault directory
313
+ ```
314
+
315
+ Or re-run `context-mcp setup` to reconfigure.
316
+
317
+ ### Embedding model download stalls
318
+
319
+ The first run downloads the all-MiniLM-L6-v2 embedding model (~22MB) from Hugging Face. This requires internet access and can take a moment. If it hangs, check your network or proxy settings.
320
+
321
+ ### Stale search index
322
+
323
+ If search results seem outdated or missing:
324
+
325
+ ```bash
326
+ context-mcp reindex
327
+ ```
328
+
329
+ This rebuilds the entire index from your vault files. Auto-reindex runs on every session start, but manual reindex can help diagnose issues.
330
+
331
+ ### Config path debugging
332
+
333
+ ```bash
334
+ context-mcp status
335
+ ```
336
+
337
+ Shows all resolved paths (vault dir, data dir, DB path, config file) and where each was resolved from (defaults, config file, env, or CLI args).
338
+
339
+ ## Architecture
340
+
341
+ ```
342
+ src/
343
+ ├── core/ Shared utilities (config, frontmatter, files, status)
344
+ ├── capture/ Write path — creates .md files in the vault
345
+ ├── index/ Sync layer — SQLite schema, embeddings, reindex
346
+ ├── retrieve/ Read path — hybrid FTS5 + vector search
347
+ └── server/ MCP server — wires layers into tool handlers
348
+
349
+ bin/
350
+ └── cli.js CLI entry point (setup, serve, ui, reindex, status)
351
+
352
+ ui/
353
+ ├── serve.js HTTP server for web dashboard
354
+ ├── index.html Single-page dashboard UI
355
+ └── Context.applescript macOS dock app launcher
356
+ ```
357
+
358
+ Each layer has a single responsibility and can be understood independently. The server is the only module that imports across layer boundaries.
359
+
360
+ ### Module Dependency Graph
361
+
362
+ ```
363
+ core/files.js, core/frontmatter.js ← capture/
364
+
365
+ core/config.js server/ ← bin/cli.js
366
+
367
+ index/embed.js ← retrieve/ ← ui/serve.js
368
+
369
+ index/db.js ←────────────────── (all consumers)
370
+ ```
371
+
372
+ ## Dependencies
373
+
374
+ | Package | Purpose |
375
+ |---------|---------|
376
+ | `@modelcontextprotocol/sdk` | MCP protocol (McpServer, StdioServerTransport) |
377
+ | `better-sqlite3` | SQLite driver |
378
+ | `sqlite-vec` | Vector search (384-dim float32) |
379
+ | `@huggingface/transformers` | Local embeddings (all-MiniLM-L6-v2, ~22MB) |
380
+
381
+ ## License
382
+
383
+ MIT