mcp-kb 0.3.1__tar.gz → 0.3.3__tar.gz

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.
Files changed (41) hide show
  1. mcp_kb-0.3.3/PKG-INFO +338 -0
  2. mcp_kb-0.3.3/README.md +319 -0
  3. mcp_kb-0.3.3/mcp_kb/cli/__init__.py +1 -0
  4. mcp_kb-0.3.3/mcp_kb/cli/args.py +175 -0
  5. mcp_kb-0.3.3/mcp_kb/cli/main.py +181 -0
  6. mcp_kb-0.3.3/mcp_kb/cli/reindex.py +113 -0
  7. mcp_kb-0.3.3/mcp_kb/cli/runtime_config.py +421 -0
  8. mcp_kb-0.3.3/mcp_kb/data/KNOWLEDBASE_DOC.md +151 -0
  9. mcp_kb-0.3.3/mcp_kb/data/__init__.py +1 -0
  10. mcp_kb-0.3.3/mcp_kb/ingest/__init__.py +1 -0
  11. mcp_kb-0.3.3/mcp_kb/ingest/chroma.py +1287 -0
  12. mcp_kb-0.3.3/mcp_kb/knowledge/__init__.py +1 -0
  13. mcp_kb-0.3.3/mcp_kb/knowledge/bootstrap.py +44 -0
  14. mcp_kb-0.3.3/mcp_kb/knowledge/events.py +105 -0
  15. mcp_kb-0.3.3/mcp_kb/knowledge/search.py +177 -0
  16. mcp_kb-0.3.3/mcp_kb/knowledge/store.py +294 -0
  17. mcp_kb-0.3.3/mcp_kb/security/__init__.py +1 -0
  18. mcp_kb-0.3.3/mcp_kb/security/path_validation.py +108 -0
  19. mcp_kb-0.3.3/mcp_kb/server/__init__.py +1 -0
  20. mcp_kb-0.3.3/mcp_kb/server/app.py +201 -0
  21. mcp_kb-0.3.3/mcp_kb/ui/__init__.py +17 -0
  22. mcp_kb-0.3.3/mcp_kb/ui/api.py +377 -0
  23. mcp_kb-0.3.3/mcp_kb/ui/assets/assets/index.css +1 -0
  24. mcp_kb-0.3.3/mcp_kb/ui/assets/index.html +62 -0
  25. mcp_kb-0.3.3/mcp_kb/ui/server.py +332 -0
  26. mcp_kb-0.3.3/mcp_kb/utils/__init__.py +1 -0
  27. mcp_kb-0.3.3/mcp_kb/utils/filesystem.py +128 -0
  28. mcp_kb-0.3.3/mcp_kb.egg-info/PKG-INFO +338 -0
  29. mcp_kb-0.3.3/mcp_kb.egg-info/SOURCES.txt +35 -0
  30. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/pyproject.toml +4 -2
  31. mcp_kb-0.3.1/PKG-INFO +0 -181
  32. mcp_kb-0.3.1/README.md +0 -162
  33. mcp_kb-0.3.1/mcp_kb.egg-info/PKG-INFO +0 -181
  34. mcp_kb-0.3.1/mcp_kb.egg-info/SOURCES.txt +0 -10
  35. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/mcp_kb/__init__.py +0 -0
  36. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/mcp_kb/config.py +0 -0
  37. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/mcp_kb.egg-info/dependency_links.txt +0 -0
  38. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/mcp_kb.egg-info/entry_points.txt +0 -0
  39. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/mcp_kb.egg-info/requires.txt +0 -0
  40. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/mcp_kb.egg-info/top_level.txt +0 -0
  41. {mcp_kb-0.3.1 → mcp_kb-0.3.3}/setup.cfg +0 -0
mcp_kb-0.3.3/PKG-INFO ADDED
@@ -0,0 +1,338 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-kb
3
+ Version: 0.3.3
4
+ Summary: MCP server exposing a local markdown knowledge base
5
+ Author: LLM Maintainer
6
+ Requires-Python: >=3.11
7
+ Description-Content-Type: text/markdown
8
+ Requires-Dist: httpx>=0.28.1
9
+ Requires-Dist: mcp[cli]>=1.15.0
10
+ Requires-Dist: pydantic>=2.11.9
11
+ Provides-Extra: vector
12
+ Requires-Dist: chromadb>=1.1.0; extra == "vector"
13
+ Requires-Dist: tiktoken>=0.11.0; extra == "vector"
14
+ Requires-Dist: langchain-text-splitters>=0.3.11; extra == "vector"
15
+ Requires-Dist: umap-learn>=0.5.9.post2; extra == "vector"
16
+ Provides-Extra: sentence-transformer
17
+ Requires-Dist: mcp-kb[vector]; extra == "sentence-transformer"
18
+ Requires-Dist: sentence-transformers>=5.1.1; extra == "sentence-transformer"
19
+
20
+ # MCP Knowledge Base Server
21
+
22
+ A local, text‑only knowledge base exposed as an MCP server with optional HTTP/SSE transports and a built‑in web UI. Supports creating, reading, updating, searching, and soft‑deleting UTF‑8 text files. Optionally mirrors content to Chroma for semantic search and 2D/3D vector visualization.
23
+
24
+ ## Highlights
25
+
26
+ - **MCP tools** for file lifecycle + search
27
+ - **HTTP/SSE transports** and a minimal **built‑in UI**
28
+ - **Deterministic path validation** and **soft deletes**
29
+ - **Optional Chroma mirroring** for semantic search and vector plotting
30
+ - **No lock‑in**: works with any Python toolchain (pip/pipx/Poetry/PDM/Rye/etc.)
31
+
32
+ ---
33
+
34
+ ## Table of contents
35
+
36
+ - [Quick start](#quick-start)
37
+ - [How it works](#how-it-works)
38
+ - [CLI usage](#cli-usage)
39
+ - [MCP tools](#mcp-tools)
40
+ - [Human UI](#human-ui)
41
+ - [UI HTTP API](#ui-http-api)
42
+ - [Optional: ChromaDB mirroring](#optional-chromadb-mirroring)
43
+ - [Reindexing CLI](#reindexing-cli)
44
+ - [Persistent CLI defaults](#persistent-cli-defaults)
45
+ - [Path rules & safety](#path-rules--safety)
46
+ - [Testing](#testing)
47
+ - [Integrating with LLM clients](#integrating-with-llm-clients)
48
+ - [Troubleshooting](#troubleshooting)
49
+
50
+ ---
51
+
52
+ ## Quick start
53
+
54
+ **Prereqs:** Python 3.11+ is required. :contentReference[oaicite:1]{index=1}
55
+
56
+ **Install (choose one):**
57
+
58
+ - From PyPI:
59
+
60
+ ```bash
61
+ python -m pip install mcp-kb
62
+ ```
63
+
64
+ **Run the server (HTTP transport + UI):**
65
+
66
+ ```bash
67
+ mcp-kb-server --root /path/to/knowledgebase --transport http
68
+ # Alternative if entry points aren't on PATH:
69
+ python -m mcp_kb.cli.main --root /path/to/knowledgebase --transport http
70
+ ```
71
+
72
+ On first launch, a documentation file is installed at `.data/KNOWLEDBASE_DOC.md`. The UI binds to port **8765** by default and increments until free, logging a URL like:
73
+
74
+ ```
75
+ UI available at http://127.0.0.1:8765
76
+ ```
77
+
78
+ > **Note:** The server defaults to `stdio` only. Add `--transport sse` and/or `--transport http` to enable network transports.
79
+
80
+ ---
81
+
82
+ ## How it works
83
+
84
+ - **KnowledgeBase**: safe, validated file operations (create/read/append/regex/soft‑delete).
85
+ - **MCP server**: exposes the operations as MCP tools over chosen transports.
86
+ - **Human UI**: small web UI for browsing, editing, and searching files.
87
+ - **Optional vector layer**: if Chroma is configured, semantic search and a 3D scatter of embeddings appear in the UI.
88
+
89
+ ---
90
+
91
+ ## CLI usage
92
+
93
+ The package exposes these entry points: `mcp-kb` / `mcp-kb-server` (run server) and `mcp-kb-reindex` (offline reindex).
94
+
95
+ Common flags (server):
96
+
97
+ - `--root <path>`: KB root directory (relative paths are enforced internally)
98
+ - `--transport {stdio|sse|http}` (repeatable; default: `stdio`)
99
+ - `--host <ip>` / `--port <int>`: apply to HTTP/SSE transports
100
+ - `--ui-port <int>`: starting port for UI (default 8765; auto‑increments if busy)
101
+ - `--no-ui`: disable the UI even if HTTP/SSE is active
102
+
103
+ Examples:
104
+
105
+ ```bash
106
+ # stdio only (default):
107
+ mcp-kb-server --root /path/to/kb
108
+
109
+ # HTTP + SSE + stdio:
110
+ mcp-kb-server --root /path/to/kb \
111
+ --transport stdio --transport sse --transport http \
112
+ --host 0.0.0.0 --port 9000
113
+ ```
114
+
115
+ ---
116
+
117
+ ## MCP tools
118
+
119
+ All tools operate on **relative** paths inside the KB root and respect soft‑deletes.
120
+
121
+ - `create_file(path, content) -> str`
122
+ - `read_file(path, start_line?, end_line?) -> {path, start_line, end_line, content}`
123
+ - `append_file(path, content) -> str`
124
+ - `regex_replace(path, pattern, replacement) -> {replacements}`
125
+ - `delete(path) -> str` _(soft delete; renames file with sentinel)_
126
+ - `search(query, limit=5) -> [FileSegment...]` _(semantic first if Chroma is on; otherwise literal scan)_
127
+ - `overview() -> str`
128
+ - `documentation() -> str`
129
+
130
+ `read_file` and `search` return **FileSegment** objects with `start_line`, `end_line`, and `content`. Line indices are **0‑based inclusive** in the JSON the server emits.
131
+
132
+ ---
133
+
134
+ ## Human UI
135
+
136
+ - Menu: **Browse** (always) and **Vectors** (when a vector store is available).
137
+ - Browse: left tree, right editor, Save/Cancel/Delete, and **New File**.
138
+ - Search: sidebar search filters the tree; clicking a result opens the file and highlights the matched lines. When vectors are available, the plot highlights results and the query point.
139
+
140
+ ---
141
+
142
+ ## UI HTTP API
143
+
144
+ Base path is the UI origin.
145
+
146
+ - `GET /api/tree` → file tree (nested `{name, path, type, children}`)
147
+ - `GET /api/file?path=<rel>` → `{path, start_line, end_line, content}`
148
+ - `PUT /api/file` (JSON `{path, content}`) → `204` on success
149
+ - `DELETE /api/file?path=<rel>` → `204` on success
150
+ - `GET /api/search?query=<text>&limit=<int>` →
151
+
152
+ ```json
153
+ {
154
+ "results": [
155
+ { "path": "notes/a.md", "start_line": 10, "end_line": 12, "content": "..." }
156
+ ],
157
+ "meta": {
158
+ "query_embeddings": [ ... ],
159
+ "query_embeddings_umap2d": [x, y],
160
+ "query_embeddings_umap3d": [x, y, z]
161
+ }
162
+ }
163
+ ```
164
+
165
+ _(Meta fields appear when Chroma is enabled.)_
166
+
167
+ **Vector endpoints** (visible when Chroma is configured):
168
+
169
+ - `GET /api/vector/status` → `{ "available": bool, "dimensions": int|null, "count": int|null }`
170
+ - `GET /api/vector/embeddings?limit=<int>&offset=<int>&path=<rel?>` → `[ { id, document_id, path, chunk, embedding, umap2d?, umap3d? } ]`
171
+ - `GET /api/vector/query_embedding?query=<text>` → `{ embedding: number[], used_model: string|null }`
172
+ - `POST /api/vector/reindex` → `{ status: "queued"|"running"|"unavailable"|"error" }`
173
+ - `POST /api/vector/refit` → `{ status: "queued"|"unavailable"|"error" }`
174
+
175
+ ---
176
+
177
+ ## Optional: ChromaDB mirroring
178
+
179
+ Install the vector extras (pick what you need):
180
+
181
+ ```bash
182
+ # core vector support (Chroma, UMAP integration, splitters)
183
+ python -m pip install 'mcp-kb[vector]'
184
+
185
+ # add Sentence Transformers embedding support
186
+ python -m pip install 'mcp-kb[sentence-transformer]'
187
+ ```
188
+
189
+ Enable via CLI flags (examples):
190
+
191
+ ```bash
192
+ mcp-kb-server \
193
+ --root /path/to/kb \
194
+ --transport http \
195
+ --chroma-client ephemeral \
196
+ --chroma-collection local-kb \
197
+ --chroma-embedding default
198
+ ```
199
+
200
+ Supported clients: `off`, `ephemeral`, `persistent`, `http`, `cloud`. All `--chroma-*` flags have `MCP_KB_CHROMA_*` env var equivalents (e.g., `MCP_KB_CHROMA_CLIENT=http`, `MCP_KB_CHROMA_HOST=...`). Chunking can be tuned with `--chroma-chunk-size` and `--chroma-chunk-overlap`.
201
+
202
+ ---
203
+
204
+ ## Reindexing CLI
205
+
206
+ Rebuild the Chroma index from disk without running the MCP transports:
207
+
208
+ ```bash
209
+ mcp-kb-reindex --root /path/to/kb \
210
+ --chroma-client persistent \
211
+ --chroma-data-dir /path/to/chroma \
212
+ --chroma-collection knowledge-base \
213
+ --chroma-embedding default
214
+ ```
215
+
216
+ This processes all active text files and updates the collection; some tests assert the reindex path mirrors content exactly.
217
+
218
+ ---
219
+
220
+ ## Persistent CLI defaults
221
+
222
+ Resolved CLI/environment settings are persisted per KB root at:
223
+
224
+ ```
225
+ <root>/.data/cli-config.json
226
+ ```
227
+
228
+ Future runs inherit these defaults unless overridden by new flags or env vars. Delete or edit the file to reset.
229
+
230
+ ---
231
+
232
+ ## Path rules & safety
233
+
234
+ - **Relative paths only.** Absolute paths and `..` traversal are rejected.
235
+ - **`.data/` is read‑only** for writes (reads allowed).
236
+ - **Soft delete**: files renamed with a sentinel; hidden from listing/search.
237
+ - Writes are serialized with per‑file locks to avoid corruption.
238
+
239
+ These rules are enforced in the validation and filesystem helpers.
240
+
241
+ ---
242
+
243
+ ## Testing
244
+
245
+ Install test deps and run:
246
+
247
+ ```bash
248
+ python -m pip install pytest
249
+ pytest -q
250
+ ```
251
+
252
+ Vector‑related tests are skipped if Chroma isn’t installed. To run them:
253
+
254
+ ```bash
255
+ python -m pip install 'mcp-kb[vector]'
256
+ pytest -q
257
+ ```
258
+
259
+ The suite exercises the real HTTP UI, vector endpoints, CLI config persistence, and FastMCP flows.
260
+
261
+ ---
262
+
263
+ ## Integrating with LLM clients
264
+
265
+ Provide the server command your client can execute. Two portable options:
266
+
267
+ - **Executable** (preferred if on PATH):
268
+
269
+ ```json
270
+ {
271
+ "command": "mcp-kb-server",
272
+ "args": ["--root", "/absolute/path/.knowledgebase", "--transport", "stdio"]
273
+ }
274
+ ```
275
+
276
+ - **Python module** (works even without entry points on PATH):
277
+
278
+ ```json
279
+ {
280
+ "command": "python",
281
+ "args": [
282
+ "-m",
283
+ "mcp_kb.cli.main",
284
+ "--root",
285
+ "/absolute/path/.knowledgebase",
286
+ "--transport",
287
+ "stdio"
288
+ ]
289
+ }
290
+ ```
291
+
292
+ Examples:
293
+
294
+ - **Claude Desktop** (`claude_desktop_config.json`):
295
+
296
+ ```json
297
+ {
298
+ "mcpServers": {
299
+ "local-kb": {
300
+ "command": "mcp-kb-server",
301
+ "args": [
302
+ "--root",
303
+ "/absolute/path/.knowledgebase",
304
+ "--transport",
305
+ "stdio"
306
+ ]
307
+ }
308
+ }
309
+ }
310
+ ```
311
+
312
+ - **VS Code (Claude MCP Extension)** (`settings.json`):
313
+
314
+ ```json
315
+ {
316
+ "claudeMcp.servers": {
317
+ "local-kb": {
318
+ "command": "mcp-kb-server",
319
+ "args": [
320
+ "--root",
321
+ "/absolute/path/.knowledgebase",
322
+ "--transport",
323
+ "stdio"
324
+ ],
325
+ "env": { "MCP_KB_ROOT": "/absolute/path/.knowledgebase" }
326
+ }
327
+ }
328
+ }
329
+ ```
330
+
331
+ ---
332
+
333
+ ## Troubleshooting
334
+
335
+ - **“Absolute paths are not permitted”** → Use a **relative** path in tools and UI.
336
+ - **“Writes are not allowed inside the protected folder '.data'”** → Choose a different directory (e.g., `docs/`).
337
+ - **Vector endpoints missing** → You didn’t install/enable the vector extras or a Chroma client.
338
+ - **UI port in use** → Set `--ui-port` to another number; it auto‑increments if busy.
mcp_kb-0.3.3/README.md ADDED
@@ -0,0 +1,319 @@
1
+ # MCP Knowledge Base Server
2
+
3
+ A local, text‑only knowledge base exposed as an MCP server with optional HTTP/SSE transports and a built‑in web UI. Supports creating, reading, updating, searching, and soft‑deleting UTF‑8 text files. Optionally mirrors content to Chroma for semantic search and 2D/3D vector visualization.
4
+
5
+ ## Highlights
6
+
7
+ - **MCP tools** for file lifecycle + search
8
+ - **HTTP/SSE transports** and a minimal **built‑in UI**
9
+ - **Deterministic path validation** and **soft deletes**
10
+ - **Optional Chroma mirroring** for semantic search and vector plotting
11
+ - **No lock‑in**: works with any Python toolchain (pip/pipx/Poetry/PDM/Rye/etc.)
12
+
13
+ ---
14
+
15
+ ## Table of contents
16
+
17
+ - [Quick start](#quick-start)
18
+ - [How it works](#how-it-works)
19
+ - [CLI usage](#cli-usage)
20
+ - [MCP tools](#mcp-tools)
21
+ - [Human UI](#human-ui)
22
+ - [UI HTTP API](#ui-http-api)
23
+ - [Optional: ChromaDB mirroring](#optional-chromadb-mirroring)
24
+ - [Reindexing CLI](#reindexing-cli)
25
+ - [Persistent CLI defaults](#persistent-cli-defaults)
26
+ - [Path rules & safety](#path-rules--safety)
27
+ - [Testing](#testing)
28
+ - [Integrating with LLM clients](#integrating-with-llm-clients)
29
+ - [Troubleshooting](#troubleshooting)
30
+
31
+ ---
32
+
33
+ ## Quick start
34
+
35
+ **Prereqs:** Python 3.11+ is required. :contentReference[oaicite:1]{index=1}
36
+
37
+ **Install (choose one):**
38
+
39
+ - From PyPI:
40
+
41
+ ```bash
42
+ python -m pip install mcp-kb
43
+ ```
44
+
45
+ **Run the server (HTTP transport + UI):**
46
+
47
+ ```bash
48
+ mcp-kb-server --root /path/to/knowledgebase --transport http
49
+ # Alternative if entry points aren't on PATH:
50
+ python -m mcp_kb.cli.main --root /path/to/knowledgebase --transport http
51
+ ```
52
+
53
+ On first launch, a documentation file is installed at `.data/KNOWLEDBASE_DOC.md`. The UI binds to port **8765** by default and increments until free, logging a URL like:
54
+
55
+ ```
56
+ UI available at http://127.0.0.1:8765
57
+ ```
58
+
59
+ > **Note:** The server defaults to `stdio` only. Add `--transport sse` and/or `--transport http` to enable network transports.
60
+
61
+ ---
62
+
63
+ ## How it works
64
+
65
+ - **KnowledgeBase**: safe, validated file operations (create/read/append/regex/soft‑delete).
66
+ - **MCP server**: exposes the operations as MCP tools over chosen transports.
67
+ - **Human UI**: small web UI for browsing, editing, and searching files.
68
+ - **Optional vector layer**: if Chroma is configured, semantic search and a 3D scatter of embeddings appear in the UI.
69
+
70
+ ---
71
+
72
+ ## CLI usage
73
+
74
+ The package exposes these entry points: `mcp-kb` / `mcp-kb-server` (run server) and `mcp-kb-reindex` (offline reindex).
75
+
76
+ Common flags (server):
77
+
78
+ - `--root <path>`: KB root directory (relative paths are enforced internally)
79
+ - `--transport {stdio|sse|http}` (repeatable; default: `stdio`)
80
+ - `--host <ip>` / `--port <int>`: apply to HTTP/SSE transports
81
+ - `--ui-port <int>`: starting port for UI (default 8765; auto‑increments if busy)
82
+ - `--no-ui`: disable the UI even if HTTP/SSE is active
83
+
84
+ Examples:
85
+
86
+ ```bash
87
+ # stdio only (default):
88
+ mcp-kb-server --root /path/to/kb
89
+
90
+ # HTTP + SSE + stdio:
91
+ mcp-kb-server --root /path/to/kb \
92
+ --transport stdio --transport sse --transport http \
93
+ --host 0.0.0.0 --port 9000
94
+ ```
95
+
96
+ ---
97
+
98
+ ## MCP tools
99
+
100
+ All tools operate on **relative** paths inside the KB root and respect soft‑deletes.
101
+
102
+ - `create_file(path, content) -> str`
103
+ - `read_file(path, start_line?, end_line?) -> {path, start_line, end_line, content}`
104
+ - `append_file(path, content) -> str`
105
+ - `regex_replace(path, pattern, replacement) -> {replacements}`
106
+ - `delete(path) -> str` _(soft delete; renames file with sentinel)_
107
+ - `search(query, limit=5) -> [FileSegment...]` _(semantic first if Chroma is on; otherwise literal scan)_
108
+ - `overview() -> str`
109
+ - `documentation() -> str`
110
+
111
+ `read_file` and `search` return **FileSegment** objects with `start_line`, `end_line`, and `content`. Line indices are **0‑based inclusive** in the JSON the server emits.
112
+
113
+ ---
114
+
115
+ ## Human UI
116
+
117
+ - Menu: **Browse** (always) and **Vectors** (when a vector store is available).
118
+ - Browse: left tree, right editor, Save/Cancel/Delete, and **New File**.
119
+ - Search: sidebar search filters the tree; clicking a result opens the file and highlights the matched lines. When vectors are available, the plot highlights results and the query point.
120
+
121
+ ---
122
+
123
+ ## UI HTTP API
124
+
125
+ Base path is the UI origin.
126
+
127
+ - `GET /api/tree` → file tree (nested `{name, path, type, children}`)
128
+ - `GET /api/file?path=<rel>` → `{path, start_line, end_line, content}`
129
+ - `PUT /api/file` (JSON `{path, content}`) → `204` on success
130
+ - `DELETE /api/file?path=<rel>` → `204` on success
131
+ - `GET /api/search?query=<text>&limit=<int>` →
132
+
133
+ ```json
134
+ {
135
+ "results": [
136
+ { "path": "notes/a.md", "start_line": 10, "end_line": 12, "content": "..." }
137
+ ],
138
+ "meta": {
139
+ "query_embeddings": [ ... ],
140
+ "query_embeddings_umap2d": [x, y],
141
+ "query_embeddings_umap3d": [x, y, z]
142
+ }
143
+ }
144
+ ```
145
+
146
+ _(Meta fields appear when Chroma is enabled.)_
147
+
148
+ **Vector endpoints** (visible when Chroma is configured):
149
+
150
+ - `GET /api/vector/status` → `{ "available": bool, "dimensions": int|null, "count": int|null }`
151
+ - `GET /api/vector/embeddings?limit=<int>&offset=<int>&path=<rel?>` → `[ { id, document_id, path, chunk, embedding, umap2d?, umap3d? } ]`
152
+ - `GET /api/vector/query_embedding?query=<text>` → `{ embedding: number[], used_model: string|null }`
153
+ - `POST /api/vector/reindex` → `{ status: "queued"|"running"|"unavailable"|"error" }`
154
+ - `POST /api/vector/refit` → `{ status: "queued"|"unavailable"|"error" }`
155
+
156
+ ---
157
+
158
+ ## Optional: ChromaDB mirroring
159
+
160
+ Install the vector extras (pick what you need):
161
+
162
+ ```bash
163
+ # core vector support (Chroma, UMAP integration, splitters)
164
+ python -m pip install 'mcp-kb[vector]'
165
+
166
+ # add Sentence Transformers embedding support
167
+ python -m pip install 'mcp-kb[sentence-transformer]'
168
+ ```
169
+
170
+ Enable via CLI flags (examples):
171
+
172
+ ```bash
173
+ mcp-kb-server \
174
+ --root /path/to/kb \
175
+ --transport http \
176
+ --chroma-client ephemeral \
177
+ --chroma-collection local-kb \
178
+ --chroma-embedding default
179
+ ```
180
+
181
+ Supported clients: `off`, `ephemeral`, `persistent`, `http`, `cloud`. All `--chroma-*` flags have `MCP_KB_CHROMA_*` env var equivalents (e.g., `MCP_KB_CHROMA_CLIENT=http`, `MCP_KB_CHROMA_HOST=...`). Chunking can be tuned with `--chroma-chunk-size` and `--chroma-chunk-overlap`.
182
+
183
+ ---
184
+
185
+ ## Reindexing CLI
186
+
187
+ Rebuild the Chroma index from disk without running the MCP transports:
188
+
189
+ ```bash
190
+ mcp-kb-reindex --root /path/to/kb \
191
+ --chroma-client persistent \
192
+ --chroma-data-dir /path/to/chroma \
193
+ --chroma-collection knowledge-base \
194
+ --chroma-embedding default
195
+ ```
196
+
197
+ This processes all active text files and updates the collection; some tests assert the reindex path mirrors content exactly.
198
+
199
+ ---
200
+
201
+ ## Persistent CLI defaults
202
+
203
+ Resolved CLI/environment settings are persisted per KB root at:
204
+
205
+ ```
206
+ <root>/.data/cli-config.json
207
+ ```
208
+
209
+ Future runs inherit these defaults unless overridden by new flags or env vars. Delete or edit the file to reset.
210
+
211
+ ---
212
+
213
+ ## Path rules & safety
214
+
215
+ - **Relative paths only.** Absolute paths and `..` traversal are rejected.
216
+ - **`.data/` is read‑only** for writes (reads allowed).
217
+ - **Soft delete**: files renamed with a sentinel; hidden from listing/search.
218
+ - Writes are serialized with per‑file locks to avoid corruption.
219
+
220
+ These rules are enforced in the validation and filesystem helpers.
221
+
222
+ ---
223
+
224
+ ## Testing
225
+
226
+ Install test deps and run:
227
+
228
+ ```bash
229
+ python -m pip install pytest
230
+ pytest -q
231
+ ```
232
+
233
+ Vector‑related tests are skipped if Chroma isn’t installed. To run them:
234
+
235
+ ```bash
236
+ python -m pip install 'mcp-kb[vector]'
237
+ pytest -q
238
+ ```
239
+
240
+ The suite exercises the real HTTP UI, vector endpoints, CLI config persistence, and FastMCP flows.
241
+
242
+ ---
243
+
244
+ ## Integrating with LLM clients
245
+
246
+ Provide the server command your client can execute. Two portable options:
247
+
248
+ - **Executable** (preferred if on PATH):
249
+
250
+ ```json
251
+ {
252
+ "command": "mcp-kb-server",
253
+ "args": ["--root", "/absolute/path/.knowledgebase", "--transport", "stdio"]
254
+ }
255
+ ```
256
+
257
+ - **Python module** (works even without entry points on PATH):
258
+
259
+ ```json
260
+ {
261
+ "command": "python",
262
+ "args": [
263
+ "-m",
264
+ "mcp_kb.cli.main",
265
+ "--root",
266
+ "/absolute/path/.knowledgebase",
267
+ "--transport",
268
+ "stdio"
269
+ ]
270
+ }
271
+ ```
272
+
273
+ Examples:
274
+
275
+ - **Claude Desktop** (`claude_desktop_config.json`):
276
+
277
+ ```json
278
+ {
279
+ "mcpServers": {
280
+ "local-kb": {
281
+ "command": "mcp-kb-server",
282
+ "args": [
283
+ "--root",
284
+ "/absolute/path/.knowledgebase",
285
+ "--transport",
286
+ "stdio"
287
+ ]
288
+ }
289
+ }
290
+ }
291
+ ```
292
+
293
+ - **VS Code (Claude MCP Extension)** (`settings.json`):
294
+
295
+ ```json
296
+ {
297
+ "claudeMcp.servers": {
298
+ "local-kb": {
299
+ "command": "mcp-kb-server",
300
+ "args": [
301
+ "--root",
302
+ "/absolute/path/.knowledgebase",
303
+ "--transport",
304
+ "stdio"
305
+ ],
306
+ "env": { "MCP_KB_ROOT": "/absolute/path/.knowledgebase" }
307
+ }
308
+ }
309
+ }
310
+ ```
311
+
312
+ ---
313
+
314
+ ## Troubleshooting
315
+
316
+ - **“Absolute paths are not permitted”** → Use a **relative** path in tools and UI.
317
+ - **“Writes are not allowed inside the protected folder '.data'”** → Choose a different directory (e.g., `docs/`).
318
+ - **Vector endpoints missing** → You didn’t install/enable the vector extras or a Chroma client.
319
+ - **UI port in use** → Set `--ui-port` to another number; it auto‑increments if busy.
@@ -0,0 +1 @@
1
+ """CLI subpackage exposing entry points for running the server."""