Skip to content

Commit 0cf8f10

Browse files
committed
full Claude Code Recipe
1 parent bf2647c commit 0cf8f10

8 files changed

Lines changed: 2956 additions & 19 deletions

File tree

.claude/mcp.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"mcpServers": {
33
"logosdb": {
4-
"command": "npx",
5-
"args": ["-y", "logosdb-mcp-server"],
4+
"command": "node",
5+
"args": ["./mcp/dist/index.js"],
66
"env": {
77
"LOGOSDB_PATH": "./.logosdb"
88
}

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ logosdb change log
1010
`search_top_k` and `match_rank` (closes #96).
1111
* README: Claude Code slash-commands table and `.claude/commands/` in repository contents (closes #95).
1212
* `.claude/commands/search.md` and `forget.md` updated for the new tool parameters.
13+
* Root npm workspace (`package.json` / `package-lock.json`): `npm install` at repo root builds MCP;
14+
`.claude/mcp.json` runs **`node ./mcp/dist/index.js`** for Claude Code in this clone.
1315

1416
0.7.7 (2026-05-11)
1517
-------------------

CONTRIBUTING.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Thank you for your interest in contributing to LogosDB. This document outlines t
1010
- C++17-capable compiler (GCC 9+, Clang 12+, Apple Clang 13+, MSVC 2019+)
1111
- Python 3.9+ (for Python bindings and tests)
1212
- Git with submodule support
13+
- Node.js 18+ (optional — only for building **logosdb-mcp-server** / Claude Code `.claude/mcp.json` in this repo)
1314

1415
### Building
1516

@@ -28,6 +29,16 @@ cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
2829
ninja
2930
```
3031

32+
### Claude Code (optional)
33+
34+
This repo’s [`.claude/mcp.json`](.claude/mcp.json) points at **`./mcp/dist/index.js`**. From the repo root:
35+
36+
```bash
37+
npm install
38+
```
39+
40+
That builds the MCP server (`mcp` workspace `prepare``tsc`). Use `npm run mcp:build` after MCP TypeScript changes.
41+
3142
Build targets:
3243
- `logosdb` — static library (`liblogosdb.a`)
3344
- `logosdb-cli` — command-line tool

README.md

Lines changed: 162 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Target versions and issue assignment match **[GitHub milestones](https://github.
6666
### [0.7.7](https://github.com/jose-compu/logosdb/milestone/7) — patch (`0.x.Z`)
6767

6868
* [#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)
7070

7171
### [0.7.8](https://github.com/jose-compu/logosdb/milestone/14) — patch (`0.x.Z`)
7272

@@ -489,9 +489,57 @@ logosdb-cli search /tmp/mydb --query-file q.bin --top-k 5
489489
exposes LogosDB to **Claude Code** (and any other MCP client) over stdio. It lets Claude index
490490
files, persist knowledge across sessions, and do semantic search without leaving the conversation.
491491

492-
### Quick start
492+
### Claude Code: complete recipe
493493

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`:
495543

496544
```json
497545
{
@@ -507,30 +555,73 @@ files, persist knowledge across sessions, and do semantic search without leaving
507555
}
508556
```
509557

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).
511559

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`
513561

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)).
515563

516-
**3. Use it in conversation:**
564+
#### 5. Reload Claude Code and verify
517565

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).
523592

524593
### Claude Code slash commands
525594

526595
This repo ships **project slash commands** under [.claude/commands/](.claude/commands/) (in addition to [`.claude/mcp.json`](.claude/mcp.json) for the MCP server):
527596

528597
| Command | Role |
529598
|---------|------|
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) |
531600
| `/search` | Semantic search; optional ISO `ts_from` / `ts_to` on the MCP tool (`commands/search.md`) |
532601
| `/forget` | Delete by row `id` **or** by natural-language `query` (`commands/forget.md`) |
533602

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+
534625
### Environment variables
535626

536627
| Variable | Default | Description |
@@ -566,17 +657,68 @@ Voyage AI (`voyage-3`, dim=1024) is Anthropic's recommended cloud embedding mode
566657

567658
### Installing locally (without npx)
568659

660+
**Option A — global CLI on your machine**
661+
569662
```bash
570663
npm install -g logosdb-mcp-server
571664
```
572665

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:
574697

575698
```json
576-
"command": "logosdb-mcp-server",
577-
"args": []
699+
"command": "node",
700+
"args": ["./node_modules/logosdb-mcp-server/dist/index.js"],
701+
"env": { "LOGOSDB_PATH": "./.logosdb" }
578702
```
579703

704+
**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`:
711+
712+
```json
713+
"logosdb": {
714+
"command": "node",
715+
"args": ["/absolute/path/to/logosdb/mcp/dist/index.js"],
716+
"env": { "LOGOSDB_PATH": "./.logosdb" }
717+
}
718+
```
719+
720+
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+
580722
# Performance
581723

582724
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
585727

586728
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.
587729

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+
588732
LogosDB: version 0.5.0
589733
CPU: Apple M-series (ARM64)
590734
Dim: 2048
@@ -647,8 +791,9 @@ LogosDB uses the same HNSW implementation as ChromaDB (hnswlib) but eliminates P
647791
examples/python/ Python usage examples
648792
pyproject.toml Python build/config (scikit-build-core)
649793
third_party/hnswlib/ Vendored hnswlib (header-only)
794+
package.json / package-lock.json Root npm workspace (builds MCP for Claude Code)
650795
mcp/ MCP server (logosdb-mcp-server npm package)
651-
.claude/mcp.json Example Claude Code MCP configuration
796+
.claude/mcp.json Claude Code MCP config (local `node ./mcp/dist/index.js`)
652797
.claude/commands/ Slash command prompts (/index, /search, /forget)
653798
CHANGELOG Release history
654799
LICENSE MIT license text

mcp/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,79 @@ npm install -g logosdb-mcp-server
1111

1212
Or run without installing via `npx -y logosdb-mcp-server`.
1313

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. |
86+
1487
## Configure
1588

1689
### Default: local embeddings (Transformers.js)

mcp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"logosdb-mcp-server": "dist/index.js"
99
},
1010
"scripts": {
11+
"prepare": "npm run build",
1112
"build": "tsc",
1213
"dev": "tsc --watch",
1314
"start": "node dist/index.js",

0 commit comments

Comments
 (0)