|
1 | | -# BetterCodeWiki MCP Server — Plan & Setup Guide |
| 1 | +# BetterCodeWiki MCP Server — Setup Guide |
2 | 2 |
|
3 | | -> How to expose BetterCodeWiki as an MCP server so Claude Desktop, Claude Code, Cursor, and Windsurf can query your codebase wikis in real-time. |
| 3 | +> Expose BetterCodeWiki as an MCP server so Claude Desktop, Claude Code, Cursor, and Windsurf can query your codebase wikis in real-time. |
| 4 | +> |
| 5 | +> **Status: Built and working.** Server is at `api/mcp/server.py`. |
4 | 6 |
|
5 | 7 | --- |
6 | 8 |
|
@@ -68,19 +70,20 @@ After analyzing what's actually useful for AI agents vs. what's noise, here are |
68 | 70 |
|
69 | 71 | --- |
70 | 72 |
|
71 | | -## Implementation Plan |
| 73 | +## Implementation |
72 | 74 |
|
73 | 75 | ### File Structure |
74 | 76 |
|
75 | 77 | ``` |
76 | 78 | api/mcp/ |
77 | | -├── server.py # MCP server entry point (standalone script) |
78 | | -└── requirements.txt # Just: mcp[cli]>=1.25 |
| 79 | +├── server.py # MCP server (standalone script, ~250 lines) |
| 80 | +├── .venv/ # Python 3.13 venv with mcp[cli] installed |
| 81 | +└── .gitignore # Excludes .venv/ and __pycache__/ |
79 | 82 | ``` |
80 | 83 |
|
81 | | -That's it. One file + one dependency. |
| 84 | +One file. One dependency (`mcp[cli]`). Zero imports from existing code. |
82 | 85 |
|
83 | | -### server.py — What It Will Look Like |
| 86 | +### server.py — Source |
84 | 87 |
|
85 | 88 | ```python |
86 | 89 | """ |
@@ -383,35 +386,33 @@ if __name__ == "__main__": |
383 | 386 | mcp.run(transport="stdio") |
384 | 387 | ``` |
385 | 388 |
|
386 | | -### What This Code Does |
| 389 | +See [`api/mcp/server.py`](api/mcp/server.py) for the full implementation. |
| 390 | + |
| 391 | +### How It Works |
387 | 392 |
|
388 | 393 | 1. **Reads `~/.adalflow/wikicache/` directly** — same JSON files the main app creates |
389 | 394 | 2. **No imports from existing code** — zero coupling, zero risk |
390 | 395 | 3. **All cached wiki tools are instant** — just file I/O and string search |
391 | | -4. **`ask_codebase` returns context, not LLM output** — the calling agent's own model reasons about the wiki content (this is how MCP tools should work) |
| 396 | +4. **`ask_codebase` returns context, not LLM output** — the calling agent's own model reasons about the wiki content (this is the correct MCP pattern) |
| 397 | +5. **Large page content is truncated** in `ask_codebase` (8KB max per page) to keep responses manageable; use `get_wiki_page` for full content |
392 | 398 |
|
393 | 399 | --- |
394 | 400 |
|
395 | 401 | ## Setup Guide |
396 | 402 |
|
397 | 403 | ### Prerequisites |
398 | 404 |
|
399 | | -1. BetterCodeWiki must be running and have generated at least one wiki (so cache files exist in `~/.adalflow/wikicache/`) |
| 405 | +1. BetterCodeWiki must have generated at least one wiki (so cache files exist in `~/.adalflow/wikicache/`) |
400 | 406 | 2. Python 3.10+ installed locally |
401 | 407 |
|
402 | 408 | ### Step 1: Install the MCP SDK |
403 | 409 |
|
404 | | -```bash |
405 | | -pip install "mcp[cli]" |
406 | | -``` |
407 | | - |
408 | | -Or if using a virtual environment: |
| 410 | +The venv is already set up at `api/mcp/.venv/`. To recreate it: |
409 | 411 |
|
410 | 412 | ```bash |
411 | 413 | cd /path/to/BetterCodeWiki |
412 | | -python -m venv .mcp-venv |
413 | | -source .mcp-venv/bin/activate |
414 | | -pip install "mcp[cli]" |
| 414 | +python3.13 -m venv api/mcp/.venv |
| 415 | +api/mcp/.venv/bin/pip install "mcp[cli]" |
415 | 416 | ``` |
416 | 417 |
|
417 | 418 | ### Step 2: Test the Server Locally |
|
0 commit comments