You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[#74](https://github.com/jose-compu/logosdb/issues/74) — security: harden encoding and injection surfaces across MCP, CLI, and integrations
69
-
*[#9](https://github.com/jose-compu/logosdb/issues/9) — Sanitizer builds (ASan/UBSan/TSan) and a libFuzzer target
69
+
*[#9](https://github.com/jose-compu/logosdb/issues/9) — libFuzzer JSON harness in CI; local ASan/UBSan builds possible; full-tree sanitizer CI not enabled (vendored hnswlib noise)
exposes LogosDB to **Claude Code** (and any other MCP client) over stdio. It lets Claude index
490
490
files, persist knowledge across sessions, and do semantic search without leaving the conversation.
491
491
492
-
### Quick start
492
+
### Claude Code: complete recipe
493
493
494
-
**1. Add to `.claude/mcp.json`** in your project (or to `~/.claude.json` for global use):
494
+
Follow these steps in order. Claude Code spawns the MCP server with **working directory = your project root** (the folder you opened); paths in `mcp.json` and `LOGOSDB_PATH` are resolved relative to that cwd unless you use absolute paths.
495
+
496
+
#### 1. Prerequisites
497
+
498
+
-**Node.js** 18 or newer on your `PATH` (`node -v`, `npm -v`). For the published package you also need **`npx`**.
499
+
-**Claude Code** installed and signed in ([overview](https://docs.anthropic.com/en/docs/claude-code/overview)).
500
+
- Decide **where the DB lives**: `LOGOSDB_PATH` (default `./.logosdb`) is created under the project root; add the directory to `.gitignore` if you do not want it committed.
501
+
502
+
#### 2. Install the server (pick one)
503
+
504
+
**Option A — This repository (local `node`, no `npx`).** From the **repository root**:
505
+
506
+
```bash
507
+
npm install
508
+
```
509
+
510
+
That installs the `mcp` workspace and runs **`prepare`**, which compiles TypeScript to [`mcp/dist/index.js`](mcp/dist/index.js). After you change MCP sources, run `npm run mcp:build` at the root or `npm run build` inside `mcp/`.
511
+
512
+
**Option B — Any other project (published [`logosdb-mcp-server`](https://www.npmjs.com/package/logosdb-mcp-server)).** In your app’s root:
513
+
514
+
```bash
515
+
npm install logosdb-mcp-server
516
+
```
517
+
518
+
You can still invoke it without a project dependency via `npx -y logosdb-mcp-server` (see Option C).
519
+
520
+
#### 3. Register the MCP server in Claude Code
521
+
522
+
Project-local config lives in **`.claude/mcp.json`** at the repository root. User-wide config is **`~/.claude.json`** (same `mcpServers` shape). Only one definition named `logosdb` is needed.
523
+
524
+
**If you use Option A (this clone):** the repo already contains [`.claude/mcp.json`](.claude/mcp.json):
525
+
526
+
```json
527
+
{
528
+
"mcpServers": {
529
+
"logosdb": {
530
+
"command": "node",
531
+
"args": ["./mcp/dist/index.js"],
532
+
"env": {
533
+
"LOGOSDB_PATH": "./.logosdb"
534
+
}
535
+
}
536
+
}
537
+
}
538
+
```
539
+
540
+
Open **this folder** as the Claude Code project so `./mcp/dist/index.js` resolves. If the client’s cwd is **not** the repo root, set `"args"` to an **absolute** path to `mcp/dist/index.js` (see [Installing locally — Option C](#installing-locally-without-npx)).
541
+
542
+
**If you use Option B or prefer always-latest from npm (Option C):** create or merge `.claude/mcp.json`:
495
543
496
544
```json
497
545
{
@@ -507,30 +555,73 @@ files, persist knowledge across sessions, and do semantic search without leaving
507
555
}
508
556
```
509
557
510
-
By default the MCP server uses **local Transformers.js**embeddings (no API keys). Add `EMBEDDING_PROVIDER` / keys only if you want cloud or [Ollama](https://ollama.com) — see `mcp/README.md`.
558
+
Default embeddings are **local Transformers.js** (no API keys); first run may download model weights. Optional **Ollama / OpenAI / Voyage** env vars are documented in [`mcp/README.md`](mcp/README.md#configure).
511
559
512
-
**Google Antigravity:** same stdio + `npx` setup; step-by-step is in [`mcp/README.md` — Google Antigravity](mcp/README.md#google-antigravity).
560
+
#### 4. Path rules for `logosdb_index_file`
513
561
514
-
**2. Start Claude Code** — the server is launched automatically on first tool call.
562
+
The server only indexes files that resolve under **`process.cwd()`** or **`LOGOSDB_INDEX_ROOT`** (if set). Symlinks that escape those roots are rejected. Keep indexing paths inside the project you opened, or set `LOGOSDB_INDEX_ROOT` to an absolute allowed root (details in [`mcp/README.md` — Path confinement](mcp/README.md#path-confinement-logosdb_index_file)).
515
563
516
-
**3. Use it in conversation:**
564
+
#### 5. Reload Claude Code and verify
517
565
518
-
```
519
-
> Index the src/ directory into a "code" namespace
520
-
> Find where JWT tokens are validated
521
-
> Remember that we decided to use UUIDs for all primary keys
522
-
```
566
+
-**Restart** Claude Code or reload MCP configuration after editing `mcp.json`.
567
+
- The **logosdb** server starts on **first tool use** (stdio).
568
+
- Ask the agent to run **`logosdb_list`** (or check the MCP tools panel). You should see namespaces (possibly empty) rather than a spawn error.
569
+
570
+
#### 6. Index, search, delete
571
+
572
+
-**Natural language:** e.g. “Index `src/` into the `code` namespace”, “Search the codebase for JWT validation”.
573
+
-**Slash commands (optional):** if `.claude/commands/` is present in the project (this repo ships them), use `/index`, `/search`, `/forget` — see the table below.
574
+
-**Snippet memory:** the agent can call **`logosdb_index`** for short text; **`logosdb_index_file`** chunks files and directories.
575
+
576
+
Use **one embedding backend consistently** per namespace on disk (do not change model dimension on existing data). See [Environment variables](#environment-variables) and [`mcp/README.md`](mcp/README.md).
577
+
578
+
#### 7. Optional: agent instructions
579
+
580
+
Copy the **`CLAUDE.md`** template block from [Agent instructions (`CLAUDE.md` and similar)](#agent-instructions-claudemd-and-similar) into your project so the agent indexes and searches without being reminded every session.
581
+
582
+
#### 8. Troubleshooting
583
+
584
+
| Symptom | What to try |
585
+
|--------|----------------|
586
+
| MCP fails to start / “Cannot find module” | From the same cwd Claude uses, run `node ./mcp/dist/index.js` (Option A) or `npx -y logosdb-mcp-server` (Option C) in a terminal; fix missing `npm install` or broken path. |
587
+
| Relative `./mcp/dist/index.js` not found | Use an **absolute**`args` path to `index.js`, or open the correct folder as the project root. |
588
+
|`logosdb_index_file` rejects a path | Path is outside cwd / `LOGOSDB_INDEX_ROOT`; use a path inside the project or set `LOGOSDB_INDEX_ROOT`. |
589
+
| Search looks wrong after changing model | New embeddings must use a **fresh**`LOGOSDB_PATH` or new namespace; dimensions must match. |
590
+
591
+
**Google Antigravity:** same stdio MCP pattern (`node` + local script, or `npx` + package). Step-by-step: [`mcp/README.md` — Google Antigravity](mcp/README.md#google-antigravity).
523
592
524
593
### Claude Code slash commands
525
594
526
595
This repo ships **project slash commands** under [.claude/commands/](.claude/commands/) (in addition to [`.claude/mcp.json`](.claude/mcp.json) for the MCP server):
527
596
528
597
| Command | Role |
529
598
|---------|------|
530
-
|`/index`| Index paths or text into a namespace (`commands/index.md`) |
599
+
|`/index`| Index a **file or directory** into a namespace via `logosdb_index_file`(`commands/index.md`; arbitrary text uses the `logosdb_index` tool in chat) |
531
600
|`/search`| Semantic search; optional ISO `ts_from` / `ts_to` on the MCP tool (`commands/search.md`) |
532
601
|`/forget`| Delete by row `id`**or** by natural-language `query` (`commands/forget.md`) |
533
602
603
+
### Agent instructions (`CLAUDE.md` and similar)
604
+
605
+
The MCP server does not index the repository by itself: **the agent must call the tools** (or you rely on slash commands / hooks). To make LogosDB feel automatic without typing `/index` every time, add a block like the following to your project’s **`CLAUDE.md`** (or any instructions file your agent reads on every session). Adjust namespaces and paths to your repo.
606
+
607
+
````markdown
608
+
## LogosDB (semantic memory via MCP)
609
+
610
+
The **logosdb** MCP server is configured. Data lives on disk under `LOGOSDB_PATH` (see `.claude/mcp.json`); it **persists across sessions**.
611
+
612
+
**Namespaces:** Use separate namespaces for different concerns (e.g. `code` for `src/`, `docs` for `docs/`, `decisions` for short architectural notes). Search only the namespace that matches the user’s task.
613
+
614
+
**When starting substantive work on this codebase:**
615
+
1. If the user has not indexed recently and you need broad code context, call **`logosdb_index_file`** on the smallest useful path (e.g. `src/` or a package directory), not the whole monorepo unless asked.
616
+
2. Before answering “where is X implemented?” or similar, call **`logosdb_search`** with a tight natural-language `query`, `namespace` set appropriately, and `top_k` between **3** and **8**. Do not paste entire trees into the chat—retrieve, then read only the cited files.
617
+
3. For “what did we decide recently?” style questions, use **`logosdb_search`** with optional **`ts_from` / `ts_to`** (ISO 8601 inclusive bounds) on the `decisions` or `docs` namespace when timestamps matter.
618
+
4. When the user states a durable fact worth remembering (API contract, policy, workaround), call **`logosdb_index`** into the right namespace with concise text (timestamps are stored automatically; optional **`metadata`** can label the source).
619
+
620
+
**After large refactors or dependency upgrades:** Re-run **`logosdb_index_file`** on affected paths so search stays aligned with the tree.
621
+
622
+
**Deletion:** Use **`logosdb_delete`** with **`id`** from a prior search hit, or with **`query`** + optional **`match_rank`** / **`search_top_k`** to remove a semantically matched row when the user asks to forget something.
623
+
````
624
+
534
625
### Environment variables
535
626
536
627
| Variable | Default | Description |
@@ -566,17 +657,68 @@ Voyage AI (`voyage-3`, dim=1024) is Anthropic's recommended cloud embedding mode
566
657
567
658
### Installing locally (without npx)
568
659
660
+
**Option A — global CLI on your machine**
661
+
569
662
```bash
570
663
npm install -g logosdb-mcp-server
571
664
```
572
665
573
-
Then replace the `command`/`args` in `mcp.json` with:
666
+
In `.claude/mcp.json`, point the server at the global binary:
667
+
668
+
```json
669
+
"logosdb": {
670
+
"command": "logosdb-mcp-server",
671
+
"args": [],
672
+
"env": { "LOGOSDB_PATH": "./.logosdb" }
673
+
}
674
+
```
675
+
676
+
Ensure the directory containing the global npm binaries is on your `PATH` when Claude Code spawns the process (same shell you use for `npm install -g`).
677
+
678
+
**Option B — project-local `node_modules` (no global install)**
679
+
680
+
From your app repo:
681
+
682
+
```bash
683
+
npm install logosdb-mcp-server
684
+
```
685
+
686
+
Then use `npx` so the binary resolves from `./node_modules`:
687
+
688
+
```json
689
+
"logosdb": {
690
+
"command": "npx",
691
+
"args": ["-y", "logosdb-mcp-server"],
692
+
"env": { "LOGOSDB_PATH": "./.logosdb" }
693
+
}
694
+
```
695
+
696
+
Omit `-y` if you prefer a fixed local install only. You can also call the entry script explicitly:
**Option C — development build from a LogosDB clone**
705
+
706
+
```bash
707
+
cd mcp && npm install && npm run build
708
+
```
709
+
710
+
This repository’s checked-in [`.claude/mcp.json`](.claude/mcp.json) uses a **relative** path `./mcp/dist/index.js` after **`npm install` from the repo root** (workspace `prepare`). For **other** clients or if the process cwd is not the repo root, use an **absolute** path to `mcp/dist/index.js`:
The same `env` block (`LOGOSDB_PATH`, embedding variables) applies to every option. Restart Claude Code or reload MCP config after editing `.claude/mcp.json`.
721
+
580
722
# Performance
581
723
582
724
Here is a performance report from the included `logosdb-bench` program. The results are somewhat noisy, but should be enough to get a ballpark performance estimate.
@@ -585,6 +727,8 @@ Here is a performance report from the included `logosdb-bench` program. The resu
585
727
586
728
We use databases with 1K, 10K, and 100K vectors. Each vector has 2048 dimensions (matching typical LLM embedding sizes). Vectors are L2-normalized random unit vectors.
587
729
730
+
*(Report below was produced with an older `logosdb-bench` binary labeled 0.5.0; scaling and relative HNSW vs brute-force behavior are still representative of current builds.)*
731
+
588
732
LogosDB: version 0.5.0
589
733
CPU: Apple M-series (ARM64)
590
734
Dim: 2048
@@ -647,8 +791,9 @@ LogosDB uses the same HNSW implementation as ChromaDB (hnswlib) but eliminates P
Or run without installing via `npx -y logosdb-mcp-server`.
13
13
14
+
## Claude Code: complete recipe
15
+
16
+
These steps assume your **Claude Code project root** is the directory where you want `./.logosdb` (or your chosen `LOGOSDB_PATH`) to live. The MCP child process **`cwd`** is normally that same folder, so relative paths in `.claude/mcp.json` resolve there.
17
+
18
+
### 1. Prerequisites
19
+
20
+
-**Node.js** 18+ (`node -v`), **`npm`**, and for the recipes below **`npx`** on `PATH`.
21
+
-**Claude Code** installed and authenticated.
22
+
- Add **`.logosdb`** (or whatever you set in `LOGOSDB_PATH`) to **`.gitignore`** if you do not want vector data in version control.
23
+
24
+
### 2. Install the package (pick one)
25
+
26
+
**Published server (typical):** no project `package.json` is required if Claude Code will run `npx` for you. Optional registry check:
27
+
28
+
```bash
29
+
npm view logosdb-mcp-server version
30
+
```
31
+
32
+
Alternatively add a dependency:
33
+
34
+
```bash
35
+
npm install logosdb-mcp-server
36
+
```
37
+
38
+
**Develop from a LogosDB git clone:** from the monorepo root run `npm install` so `mcp/dist/index.js` is built; then point `mcp.json` at that file with `node` (see the main [README — Claude Code recipe](https://github.com/jose-compu/logosdb/blob/main/README.md#claude-code-complete-recipe)).
39
+
40
+
### 3. Create `.claude/mcp.json`
41
+
42
+
In your **project root**, create `.claude/mcp.json` (or merge into **`~/.claude.json`** for all projects) with a `logosdb` entry.
43
+
44
+
**Recommended (always run the published server):**
45
+
46
+
```json
47
+
{
48
+
"mcpServers": {
49
+
"logosdb": {
50
+
"command": "npx",
51
+
"args": ["-y", "logosdb-mcp-server"],
52
+
"env": {
53
+
"LOGOSDB_PATH": "./.logosdb"
54
+
}
55
+
}
56
+
}
57
+
}
58
+
```
59
+
60
+
**Project-local install (pin a version in `package.json`):** same `mcpServers` block, or point `node` at `./node_modules/logosdb-mcp-server/dist/index.js` with empty `args` — see [Configure](#configure).
61
+
62
+
**Optional env:** Ollama, OpenAI, Voyage, chunk size, and index root are in [Configure](#configure) and [Environment variables](#environment-variables).
63
+
64
+
### 4. Path confinement for indexing
65
+
66
+
`logosdb_index_file` only accepts paths under **`process.cwd()`** or **`LOGOSDB_INDEX_ROOT`**. Read [Path confinement (`logosdb_index_file`)](#path-confinement-logosdb_index_file) before indexing parent directories or using symlinks.
67
+
68
+
### 5. Restart and verify
69
+
70
+
- Restart **Claude Code** or reload MCP after editing JSON.
71
+
- Ask the agent to run **`logosdb_list`**. If the server fails to spawn, run the same `command` + `args` in a shell from your project root and fix errors (missing Node, network for `npx`, etc.).
72
+
73
+
### 6. Use it
74
+
75
+
- Ask in natural language to index `src/` (or a file), search semantically, or store a short decision via **`logosdb_index`**.
76
+
-**Slash commands:** copy [`.claude/commands/`](https://github.com/jose-compu/logosdb/tree/main/.claude/commands) from the LogosDB repo into your project for `/index`, `/search`, `/forget` (optional).
77
+
-**Agent habits:** add a `CLAUDE.md` snippet so the agent indexes and searches without reminders — see the main [README — Agent instructions](https://github.com/jose-compu/logosdb/blob/main/README.md#agent-instructions-claudemd-and-similar).
78
+
79
+
### 7. Troubleshooting
80
+
81
+
| Issue | Action |
82
+
|-------|--------|
83
+
|`npx` cannot download or run the package | Check network, Node version, and corporate proxy; try `npm install logosdb-mcp-server` + `node ./node_modules/logosdb-mcp-server/dist/index.js` in `args` via `node` command. |
84
+
| Wrong embedding size / garbage search | Use one backend and dimension per namespace; use a fresh `LOGOSDB_PATH` or new namespace when changing models ([Environment variables](#environment-variables)). |
85
+
| Path rejected on index | Stay inside cwd or set `LOGOSDB_INDEX_ROOT` to an absolute allowed directory. |
0 commit comments