kb-agent-mcp 0.1.1__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.
- kb_agent_mcp-0.1.1/PKG-INFO +340 -0
- kb_agent_mcp-0.1.1/README-MCP.md +300 -0
- kb_agent_mcp-0.1.1/README.md +673 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/__init__.py +8 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/base_agent.py +522 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/cli/__init__.py +1 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/cli/generate.py +449 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/cli/setup.py +266 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/cli/watch.py +346 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/config.py +227 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/context_budget.py +330 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/domain_agent.py +170 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/domain_rules.py +239 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/embeddings.py +150 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/file_parser.py +470 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/memory.py +143 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/orchestrator.py +411 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/server.py +246 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp/vector_store.py +387 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp.egg-info/PKG-INFO +340 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp.egg-info/SOURCES.txt +31 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp.egg-info/dependency_links.txt +1 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp.egg-info/entry_points.txt +5 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp.egg-info/requires.txt +26 -0
- kb_agent_mcp-0.1.1/kb_agent_mcp.egg-info/top_level.txt +1 -0
- kb_agent_mcp-0.1.1/pyproject.toml +73 -0
- kb_agent_mcp-0.1.1/setup.cfg +4 -0
- kb_agent_mcp-0.1.1/tests/test_base_agent.py +99 -0
- kb_agent_mcp-0.1.1/tests/test_config.py +62 -0
- kb_agent_mcp-0.1.1/tests/test_domain_rules.py +125 -0
- kb_agent_mcp-0.1.1/tests/test_file_parser.py +63 -0
- kb_agent_mcp-0.1.1/tests/test_memory.py +88 -0
- kb_agent_mcp-0.1.1/tests/test_orchestrator.py +166 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kb-agent-mcp
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A zero-config MCP server that turns any folder of documents into a queryable multi-agent knowledge base
|
|
5
|
+
Author: KnowledgeBase Agent Contributors
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Keywords: mcp,ai,knowledge-base,rag,agents,llm
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: fastmcp>=2.0.0
|
|
18
|
+
Requires-Dist: chromadb>=0.5.0
|
|
19
|
+
Requires-Dist: httpx>=0.27.0
|
|
20
|
+
Requires-Dist: numpy>=1.26.0
|
|
21
|
+
Requires-Dist: scikit-learn>=1.4.0
|
|
22
|
+
Requires-Dist: watchdog>=4.0.0
|
|
23
|
+
Requires-Dist: pypdf>=4.0.0
|
|
24
|
+
Requires-Dist: python-pptx>=1.0.0
|
|
25
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
26
|
+
Requires-Dist: python-docx>=1.1.0
|
|
27
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
28
|
+
Requires-Dist: rich>=13.0.0
|
|
29
|
+
Requires-Dist: sentence-transformers>=3.0.0
|
|
30
|
+
Provides-Extra: openai
|
|
31
|
+
Requires-Dist: openai>=1.0.0; extra == "openai"
|
|
32
|
+
Provides-Extra: anthropic
|
|
33
|
+
Requires-Dist: anthropic>=0.30.0; extra == "anthropic"
|
|
34
|
+
Provides-Extra: dev
|
|
35
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-mock>=3.14.0; extra == "dev"
|
|
38
|
+
Requires-Dist: build>=1.0.0; extra == "dev"
|
|
39
|
+
Requires-Dist: twine>=5.0.0; extra == "dev"
|
|
40
|
+
|
|
41
|
+
# kb-agent-mcp
|
|
42
|
+
|
|
43
|
+
A zero-config pip-installable MCP server that turns **any folder of documents** into a queryable, multi-agent knowledge base.
|
|
44
|
+
|
|
45
|
+
Connect it to Claude Desktop, Bob, Cursor, or any MCP-compatible AI tool — then ask questions in natural language.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- **Zero configuration** — point at a folder, run one command, start asking questions
|
|
52
|
+
- **Multi-domain routing** — automatically routes questions to the right knowledge domain
|
|
53
|
+
- **README-first RAG** — uses compact AUTO-INDEX blocks for fast answers; falls back to full-document search for complex/data questions
|
|
54
|
+
- **Passthrough mode** — works with *no local LLM*; your AI tool answers using retrieved context
|
|
55
|
+
- **Supports all major document types** — PDF, DOCX, XLSX (with streaming aggregation for large files), PPTX, MD, TXT, CSV, BoxNote
|
|
56
|
+
- **ChromaDB vector search** — persistent, hash-based change detection (only re-indexes changed files)
|
|
57
|
+
- **Multi-session memory** — per-session conversation history with configurable timeout
|
|
58
|
+
- **Hot-reload** — `kb-agent-watch` keeps indexes in sync as you add/modify files
|
|
59
|
+
- **LLM providers** — Ollama (local), OpenAI, Anthropic, any OpenAI-compatible endpoint
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
# Install
|
|
67
|
+
pip install kb-agent-mcp
|
|
68
|
+
|
|
69
|
+
# Run the setup wizard
|
|
70
|
+
cd /path/to/your/documents
|
|
71
|
+
kb-agent-setup
|
|
72
|
+
|
|
73
|
+
# Or manually: generate indexes and domain configs
|
|
74
|
+
kb-agent-generate
|
|
75
|
+
|
|
76
|
+
# Start the MCP server (stdio — for Claude Desktop / Bob)
|
|
77
|
+
kb-agent-serve
|
|
78
|
+
|
|
79
|
+
# Or HTTP/SSE
|
|
80
|
+
kb-agent-serve --transport http --port 8765
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install kb-agent-mcp
|
|
89
|
+
|
|
90
|
+
# With OpenAI embeddings
|
|
91
|
+
pip install "kb-agent-mcp[openai]"
|
|
92
|
+
|
|
93
|
+
# With Anthropic
|
|
94
|
+
pip install "kb-agent-mcp[anthropic]"
|
|
95
|
+
|
|
96
|
+
# For development
|
|
97
|
+
pip install "kb-agent-mcp[dev]"
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Requires Python 3.10+.
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## MCP Tools
|
|
105
|
+
|
|
106
|
+
Once the server is running, the following tools are available:
|
|
107
|
+
|
|
108
|
+
| Tool | Description |
|
|
109
|
+
|---|---|
|
|
110
|
+
| `ask(question, format?, session_id?)` | Query all relevant domains and return a markdown answer |
|
|
111
|
+
| `list_domains()` | List indexed knowledge domains with descriptions |
|
|
112
|
+
| `reindex()` | Re-scan KB_ROOT and rebuild all ChromaDB indexes |
|
|
113
|
+
| `clear_memory(session_id?)` | Clear conversation history for a session |
|
|
114
|
+
| `show_memory(session_id?)` | Show current session state and recent history |
|
|
115
|
+
|
|
116
|
+
### `ask` examples
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
ask("What is IBM ACE?")
|
|
120
|
+
ask("What is our Q3 revenue by product?", format="table")
|
|
121
|
+
ask("Explain the architecture of CP4I", format="bullets")
|
|
122
|
+
ask("How many deals closed last quarter?", session_id="my-session")
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Configuration
|
|
128
|
+
|
|
129
|
+
All configuration is via environment variables (or a `.env` file):
|
|
130
|
+
|
|
131
|
+
```env
|
|
132
|
+
# Required
|
|
133
|
+
KB_ROOT=/path/to/your/KnowledgeBase
|
|
134
|
+
|
|
135
|
+
# LLM provider (default: ollama)
|
|
136
|
+
KB_LLM_PROVIDER=ollama # ollama | openai | anthropic | custom | passthrough
|
|
137
|
+
KB_LLM_BASE_URL=http://localhost:11434
|
|
138
|
+
KB_MODEL=qwen3:14b
|
|
139
|
+
KB_API_KEY= # required for openai/anthropic/custom
|
|
140
|
+
|
|
141
|
+
# Embeddings
|
|
142
|
+
KB_EMBED_MODEL= # auto-detected from provider; or set explicitly
|
|
143
|
+
|
|
144
|
+
# Context budgets (chars, ~4 chars = 1 token)
|
|
145
|
+
KB_BUDGET_TOTAL=24000
|
|
146
|
+
KB_BUDGET_INDEX=8000
|
|
147
|
+
KB_BUDGET_FULL_README=24000
|
|
148
|
+
KB_BUDGET_RAG_FILE=4000
|
|
149
|
+
|
|
150
|
+
# Session memory
|
|
151
|
+
KB_SESSION_TIMEOUT_HOURS=2
|
|
152
|
+
KB_SESSION_MAX_TURNS=20
|
|
153
|
+
KB_SESSION_MAX_ANSWER_CHARS=400
|
|
154
|
+
|
|
155
|
+
# Ignore these top-level folders
|
|
156
|
+
KB_IGNORE_FOLDERS=archive,tmp
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Passthrough mode
|
|
160
|
+
|
|
161
|
+
When `KB_LLM_PROVIDER=passthrough` (or when Ollama is unreachable and `KB_PASSTHROUGH_FALLBACK` is not `false`), the server automatically detects that no local LLM is available and returns the retrieved document context as clean markdown:
|
|
162
|
+
|
|
163
|
+
```markdown
|
|
164
|
+
> **No local LLM detected.** Retrieved context is provided below —
|
|
165
|
+
> use it to answer the question.
|
|
166
|
+
|
|
167
|
+
### BizOps Agent
|
|
168
|
+
*Source: BizOps/Revenue.xlsx*
|
|
169
|
+
|
|
170
|
+
Q1 revenue: $1.2M
|
|
171
|
+
Q2 revenue: $1.5M
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
The calling AI tool (Claude, Bob, Cursor) receives this directly from the `ask` tool and can answer the question from the context — **no special parsing or configuration needed on the client side**.
|
|
175
|
+
|
|
176
|
+
To disable the automatic fallback (hard-fail instead):
|
|
177
|
+
```env
|
|
178
|
+
KB_PASSTHROUGH_FALLBACK=false
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
This is the recommended mode for most users — no local model required.
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Folder Structure
|
|
186
|
+
|
|
187
|
+
Each top-level folder under `KB_ROOT` becomes a **knowledge domain**:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
~/KnowledgeBase/
|
|
191
|
+
ACE Docs/ ← domain "ACE Docs"
|
|
192
|
+
Installation.pdf
|
|
193
|
+
API Reference.md
|
|
194
|
+
domain_config.yaml ← generated by kb-agent-generate
|
|
195
|
+
BizOps/ ← domain "BizOps"
|
|
196
|
+
Revenue.xlsx
|
|
197
|
+
Won Deals.xlsx
|
|
198
|
+
domain_config.yaml
|
|
199
|
+
.kb_index/ ← ChromaDB + session memory (auto-created)
|
|
200
|
+
chroma/
|
|
201
|
+
session_memory/
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Files in nested subfolders are indexed into their parent domain.
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## domain_config.yaml
|
|
209
|
+
|
|
210
|
+
Generated by `kb-agent-generate`, one per domain folder. Edit manually to tune the agent:
|
|
211
|
+
|
|
212
|
+
```yaml
|
|
213
|
+
folder_name: BizOps
|
|
214
|
+
agent_name: BizOps Agent
|
|
215
|
+
description: Business operations — CP4I and ACE revenue, won deals, renewals
|
|
216
|
+
keywords:
|
|
217
|
+
- revenue
|
|
218
|
+
- quota
|
|
219
|
+
- attainment
|
|
220
|
+
- ACE
|
|
221
|
+
- CP4I
|
|
222
|
+
top_n: 5
|
|
223
|
+
max_chars: 8000
|
|
224
|
+
system_prompt: |
|
|
225
|
+
You are the BizOps Agent, a specialist in IBM APC region business data.
|
|
226
|
+
CRITICAL: For revenue questions use only Revenue Report files (Rev Act @ PC column).
|
|
227
|
+
Be concise, accurate, and cite the source file.
|
|
228
|
+
retrieval_rules:
|
|
229
|
+
pin_files:
|
|
230
|
+
- "*Revenue*.xlsx" # always included for data questions
|
|
231
|
+
boost_keywords:
|
|
232
|
+
- revenue # ranked to top of results
|
|
233
|
+
question_classifier:
|
|
234
|
+
data_patterns:
|
|
235
|
+
- "\\brevenue\\b" # regex → bypass README-first, use raw file content
|
|
236
|
+
complex_patterns: []
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## CLI Commands
|
|
242
|
+
|
|
243
|
+
| Command | Description |
|
|
244
|
+
|---|---|
|
|
245
|
+
| `kb-agent-setup` | Interactive setup wizard |
|
|
246
|
+
| `kb-agent-generate` | Build ChromaDB indexes + generate domain_config.yaml |
|
|
247
|
+
| `kb-agent-serve` | Start the MCP server |
|
|
248
|
+
| `kb-agent-watch` | Watch for file changes and auto-update indexes |
|
|
249
|
+
|
|
250
|
+
### kb-agent-generate flags
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
kb-agent-generate # incremental — skip unchanged
|
|
254
|
+
kb-agent-generate --force # regenerate all domain_config.yaml files
|
|
255
|
+
kb-agent-generate --no-llm # index only, use minimal YAML defaults
|
|
256
|
+
kb-agent-generate --domain Foo # only process the "Foo" folder
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### kb-agent-serve flags
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
kb-agent-serve # stdio (Claude Desktop / Bob)
|
|
263
|
+
kb-agent-serve --transport http # HTTP/SSE on port 8765
|
|
264
|
+
kb-agent-serve --transport http --port 9000
|
|
265
|
+
kb-agent-serve --version
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Connecting to Claude Desktop
|
|
271
|
+
|
|
272
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
273
|
+
|
|
274
|
+
```json
|
|
275
|
+
{
|
|
276
|
+
"mcpServers": {
|
|
277
|
+
"knowledge-base": {
|
|
278
|
+
"command": "kb-agent-serve",
|
|
279
|
+
"env": {
|
|
280
|
+
"KB_ROOT": "/path/to/your/KnowledgeBase"
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
## Connecting to Bob
|
|
290
|
+
|
|
291
|
+
After running `kb-agent-generate`, a SKILL.md is auto-installed at:
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
~/.bob/skills/knowledgebase-agent/SKILL.md
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Bob will automatically load it. Configure the server in your Bob MCP settings with:
|
|
298
|
+
|
|
299
|
+
```json
|
|
300
|
+
{
|
|
301
|
+
"command": "kb-agent-serve",
|
|
302
|
+
"env": { "KB_ROOT": "/path/to/your/KnowledgeBase" }
|
|
303
|
+
}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## Backward Compatibility
|
|
309
|
+
|
|
310
|
+
This package (`kb-agent-mcp`) is built **alongside** the original `agents/` and `scripts/` system. Nothing in the existing codebase is modified. Both systems can run independently from the same `KB_ROOT`.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## Development
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
git clone <this-repo>
|
|
318
|
+
cd KnowledgeBase
|
|
319
|
+
pip install -e ".[dev]"
|
|
320
|
+
pytest tests/ -q
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
---
|
|
324
|
+
|
|
325
|
+
## Releasing
|
|
326
|
+
|
|
327
|
+
Merging to `main` triggers the CI/CD pipeline, which automatically:
|
|
328
|
+
|
|
329
|
+
1. Bumps the **patch** version in `pyproject.toml` (e.g. `0.1.0` → `0.1.1`)
|
|
330
|
+
2. Commits the bump back to `main` with `[skip ci]` to prevent re-triggering
|
|
331
|
+
3. Builds the wheel + source distribution
|
|
332
|
+
4. Publishes to PyPI as `kb-agent-mcp`
|
|
333
|
+
|
|
334
|
+
For a **minor** or **major** version bump (e.g. `0.2.0` or `1.0.0`), manually edit `version` in `pyproject.toml` in your PR before merging — CI will auto-bump the patch on top of it.
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## License
|
|
339
|
+
|
|
340
|
+
MIT
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# kb-agent-mcp
|
|
2
|
+
|
|
3
|
+
A zero-config pip-installable MCP server that turns **any folder of documents** into a queryable, multi-agent knowledge base.
|
|
4
|
+
|
|
5
|
+
Connect it to Claude Desktop, Bob, Cursor, or any MCP-compatible AI tool — then ask questions in natural language.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Zero configuration** — point at a folder, run one command, start asking questions
|
|
12
|
+
- **Multi-domain routing** — automatically routes questions to the right knowledge domain
|
|
13
|
+
- **README-first RAG** — uses compact AUTO-INDEX blocks for fast answers; falls back to full-document search for complex/data questions
|
|
14
|
+
- **Passthrough mode** — works with *no local LLM*; your AI tool answers using retrieved context
|
|
15
|
+
- **Supports all major document types** — PDF, DOCX, XLSX (with streaming aggregation for large files), PPTX, MD, TXT, CSV, BoxNote
|
|
16
|
+
- **ChromaDB vector search** — persistent, hash-based change detection (only re-indexes changed files)
|
|
17
|
+
- **Multi-session memory** — per-session conversation history with configurable timeout
|
|
18
|
+
- **Hot-reload** — `kb-agent-watch` keeps indexes in sync as you add/modify files
|
|
19
|
+
- **LLM providers** — Ollama (local), OpenAI, Anthropic, any OpenAI-compatible endpoint
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Quick Start
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# Install
|
|
27
|
+
pip install kb-agent-mcp
|
|
28
|
+
|
|
29
|
+
# Run the setup wizard
|
|
30
|
+
cd /path/to/your/documents
|
|
31
|
+
kb-agent-setup
|
|
32
|
+
|
|
33
|
+
# Or manually: generate indexes and domain configs
|
|
34
|
+
kb-agent-generate
|
|
35
|
+
|
|
36
|
+
# Start the MCP server (stdio — for Claude Desktop / Bob)
|
|
37
|
+
kb-agent-serve
|
|
38
|
+
|
|
39
|
+
# Or HTTP/SSE
|
|
40
|
+
kb-agent-serve --transport http --port 8765
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install kb-agent-mcp
|
|
49
|
+
|
|
50
|
+
# With OpenAI embeddings
|
|
51
|
+
pip install "kb-agent-mcp[openai]"
|
|
52
|
+
|
|
53
|
+
# With Anthropic
|
|
54
|
+
pip install "kb-agent-mcp[anthropic]"
|
|
55
|
+
|
|
56
|
+
# For development
|
|
57
|
+
pip install "kb-agent-mcp[dev]"
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Requires Python 3.10+.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## MCP Tools
|
|
65
|
+
|
|
66
|
+
Once the server is running, the following tools are available:
|
|
67
|
+
|
|
68
|
+
| Tool | Description |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `ask(question, format?, session_id?)` | Query all relevant domains and return a markdown answer |
|
|
71
|
+
| `list_domains()` | List indexed knowledge domains with descriptions |
|
|
72
|
+
| `reindex()` | Re-scan KB_ROOT and rebuild all ChromaDB indexes |
|
|
73
|
+
| `clear_memory(session_id?)` | Clear conversation history for a session |
|
|
74
|
+
| `show_memory(session_id?)` | Show current session state and recent history |
|
|
75
|
+
|
|
76
|
+
### `ask` examples
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
ask("What is IBM ACE?")
|
|
80
|
+
ask("What is our Q3 revenue by product?", format="table")
|
|
81
|
+
ask("Explain the architecture of CP4I", format="bullets")
|
|
82
|
+
ask("How many deals closed last quarter?", session_id="my-session")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
All configuration is via environment variables (or a `.env` file):
|
|
90
|
+
|
|
91
|
+
```env
|
|
92
|
+
# Required
|
|
93
|
+
KB_ROOT=/path/to/your/KnowledgeBase
|
|
94
|
+
|
|
95
|
+
# LLM provider (default: ollama)
|
|
96
|
+
KB_LLM_PROVIDER=ollama # ollama | openai | anthropic | custom | passthrough
|
|
97
|
+
KB_LLM_BASE_URL=http://localhost:11434
|
|
98
|
+
KB_MODEL=qwen3:14b
|
|
99
|
+
KB_API_KEY= # required for openai/anthropic/custom
|
|
100
|
+
|
|
101
|
+
# Embeddings
|
|
102
|
+
KB_EMBED_MODEL= # auto-detected from provider; or set explicitly
|
|
103
|
+
|
|
104
|
+
# Context budgets (chars, ~4 chars = 1 token)
|
|
105
|
+
KB_BUDGET_TOTAL=24000
|
|
106
|
+
KB_BUDGET_INDEX=8000
|
|
107
|
+
KB_BUDGET_FULL_README=24000
|
|
108
|
+
KB_BUDGET_RAG_FILE=4000
|
|
109
|
+
|
|
110
|
+
# Session memory
|
|
111
|
+
KB_SESSION_TIMEOUT_HOURS=2
|
|
112
|
+
KB_SESSION_MAX_TURNS=20
|
|
113
|
+
KB_SESSION_MAX_ANSWER_CHARS=400
|
|
114
|
+
|
|
115
|
+
# Ignore these top-level folders
|
|
116
|
+
KB_IGNORE_FOLDERS=archive,tmp
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Passthrough mode
|
|
120
|
+
|
|
121
|
+
When `KB_LLM_PROVIDER=passthrough` (or when Ollama is unreachable and `KB_PASSTHROUGH_FALLBACK` is not `false`), the server automatically detects that no local LLM is available and returns the retrieved document context as clean markdown:
|
|
122
|
+
|
|
123
|
+
```markdown
|
|
124
|
+
> **No local LLM detected.** Retrieved context is provided below —
|
|
125
|
+
> use it to answer the question.
|
|
126
|
+
|
|
127
|
+
### BizOps Agent
|
|
128
|
+
*Source: BizOps/Revenue.xlsx*
|
|
129
|
+
|
|
130
|
+
Q1 revenue: $1.2M
|
|
131
|
+
Q2 revenue: $1.5M
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The calling AI tool (Claude, Bob, Cursor) receives this directly from the `ask` tool and can answer the question from the context — **no special parsing or configuration needed on the client side**.
|
|
135
|
+
|
|
136
|
+
To disable the automatic fallback (hard-fail instead):
|
|
137
|
+
```env
|
|
138
|
+
KB_PASSTHROUGH_FALLBACK=false
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
This is the recommended mode for most users — no local model required.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Folder Structure
|
|
146
|
+
|
|
147
|
+
Each top-level folder under `KB_ROOT` becomes a **knowledge domain**:
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
~/KnowledgeBase/
|
|
151
|
+
ACE Docs/ ← domain "ACE Docs"
|
|
152
|
+
Installation.pdf
|
|
153
|
+
API Reference.md
|
|
154
|
+
domain_config.yaml ← generated by kb-agent-generate
|
|
155
|
+
BizOps/ ← domain "BizOps"
|
|
156
|
+
Revenue.xlsx
|
|
157
|
+
Won Deals.xlsx
|
|
158
|
+
domain_config.yaml
|
|
159
|
+
.kb_index/ ← ChromaDB + session memory (auto-created)
|
|
160
|
+
chroma/
|
|
161
|
+
session_memory/
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Files in nested subfolders are indexed into their parent domain.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## domain_config.yaml
|
|
169
|
+
|
|
170
|
+
Generated by `kb-agent-generate`, one per domain folder. Edit manually to tune the agent:
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
folder_name: BizOps
|
|
174
|
+
agent_name: BizOps Agent
|
|
175
|
+
description: Business operations — CP4I and ACE revenue, won deals, renewals
|
|
176
|
+
keywords:
|
|
177
|
+
- revenue
|
|
178
|
+
- quota
|
|
179
|
+
- attainment
|
|
180
|
+
- ACE
|
|
181
|
+
- CP4I
|
|
182
|
+
top_n: 5
|
|
183
|
+
max_chars: 8000
|
|
184
|
+
system_prompt: |
|
|
185
|
+
You are the BizOps Agent, a specialist in IBM APC region business data.
|
|
186
|
+
CRITICAL: For revenue questions use only Revenue Report files (Rev Act @ PC column).
|
|
187
|
+
Be concise, accurate, and cite the source file.
|
|
188
|
+
retrieval_rules:
|
|
189
|
+
pin_files:
|
|
190
|
+
- "*Revenue*.xlsx" # always included for data questions
|
|
191
|
+
boost_keywords:
|
|
192
|
+
- revenue # ranked to top of results
|
|
193
|
+
question_classifier:
|
|
194
|
+
data_patterns:
|
|
195
|
+
- "\\brevenue\\b" # regex → bypass README-first, use raw file content
|
|
196
|
+
complex_patterns: []
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## CLI Commands
|
|
202
|
+
|
|
203
|
+
| Command | Description |
|
|
204
|
+
|---|---|
|
|
205
|
+
| `kb-agent-setup` | Interactive setup wizard |
|
|
206
|
+
| `kb-agent-generate` | Build ChromaDB indexes + generate domain_config.yaml |
|
|
207
|
+
| `kb-agent-serve` | Start the MCP server |
|
|
208
|
+
| `kb-agent-watch` | Watch for file changes and auto-update indexes |
|
|
209
|
+
|
|
210
|
+
### kb-agent-generate flags
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
kb-agent-generate # incremental — skip unchanged
|
|
214
|
+
kb-agent-generate --force # regenerate all domain_config.yaml files
|
|
215
|
+
kb-agent-generate --no-llm # index only, use minimal YAML defaults
|
|
216
|
+
kb-agent-generate --domain Foo # only process the "Foo" folder
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### kb-agent-serve flags
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
kb-agent-serve # stdio (Claude Desktop / Bob)
|
|
223
|
+
kb-agent-serve --transport http # HTTP/SSE on port 8765
|
|
224
|
+
kb-agent-serve --transport http --port 9000
|
|
225
|
+
kb-agent-serve --version
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Connecting to Claude Desktop
|
|
231
|
+
|
|
232
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
{
|
|
236
|
+
"mcpServers": {
|
|
237
|
+
"knowledge-base": {
|
|
238
|
+
"command": "kb-agent-serve",
|
|
239
|
+
"env": {
|
|
240
|
+
"KB_ROOT": "/path/to/your/KnowledgeBase"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Connecting to Bob
|
|
250
|
+
|
|
251
|
+
After running `kb-agent-generate`, a SKILL.md is auto-installed at:
|
|
252
|
+
|
|
253
|
+
```
|
|
254
|
+
~/.bob/skills/knowledgebase-agent/SKILL.md
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Bob will automatically load it. Configure the server in your Bob MCP settings with:
|
|
258
|
+
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"command": "kb-agent-serve",
|
|
262
|
+
"env": { "KB_ROOT": "/path/to/your/KnowledgeBase" }
|
|
263
|
+
}
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Backward Compatibility
|
|
269
|
+
|
|
270
|
+
This package (`kb-agent-mcp`) is built **alongside** the original `agents/` and `scripts/` system. Nothing in the existing codebase is modified. Both systems can run independently from the same `KB_ROOT`.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Development
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
git clone <this-repo>
|
|
278
|
+
cd KnowledgeBase
|
|
279
|
+
pip install -e ".[dev]"
|
|
280
|
+
pytest tests/ -q
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## Releasing
|
|
286
|
+
|
|
287
|
+
Merging to `main` triggers the CI/CD pipeline, which automatically:
|
|
288
|
+
|
|
289
|
+
1. Bumps the **patch** version in `pyproject.toml` (e.g. `0.1.0` → `0.1.1`)
|
|
290
|
+
2. Commits the bump back to `main` with `[skip ci]` to prevent re-triggering
|
|
291
|
+
3. Builds the wheel + source distribution
|
|
292
|
+
4. Publishes to PyPI as `kb-agent-mcp`
|
|
293
|
+
|
|
294
|
+
For a **minor** or **major** version bump (e.g. `0.2.0` or `1.0.0`), manually edit `version` in `pyproject.toml` in your PR before merging — CI will auto-bump the patch on top of it.
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
## License
|
|
299
|
+
|
|
300
|
+
MIT
|