Skip to content

Commit 8a4ac8c

Browse files
shantanu patilclaude
authored andcommitted
feat: add MCP server Docker support and AI agent integration docs
Add Docker integration for the MCP server so it runs alongside FastAPI and Next.js inside the container on port 8008 (streamable-http transport). Changes: - Dockerfile: expose port 8008, launch MCP server in start.sh - docker-compose.yml: add 8008:8008 port mapping - api/mcp/server.py: bind to 0.0.0.0 in HTTP mode (configurable via MCP_HOST/MCP_PORT env vars) for Docker container accessibility - api/pyproject.toml: add mcp[cli] as Poetry dependency - api/poetry.lock: regenerated with mcp[cli] and transitive deps - MCP_SETUP.md: replace "Optional, Future" Docker section with working setup docs including Claude Code and Claude Desktop config examples - README.md: add MCP server section with tool descriptions, Docker and local connection instructions, and port reference table AI agents (Claude Desktop, Claude Code, Cursor, Windsurf) can now query wiki documentation via 5 MCP tools: list_projects, get_wiki_overview, get_wiki_page, search_wiki, and ask_codebase. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b515e84 commit 8a4ac8c

7 files changed

Lines changed: 523 additions & 18 deletions

File tree

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ COPY --from=node_builder /app/.next/standalone ./
7777
COPY --from=node_builder /app/.next/static ./.next/static
7878

7979
# Expose the port the app runs on
80-
EXPOSE ${PORT:-8001} 3000
80+
EXPOSE ${PORT:-8001} 3000 8008
8181

8282
# Create a script to run both backend and frontend
8383
RUN echo '#!/bin/bash\n\
@@ -95,6 +95,8 @@ fi\n\
9595
\n\
9696
# Start the API server in the background with the configured port\n\
9797
python -m api.main --port ${PORT:-8001} &\n\
98+
# Start the MCP server on port 8008 (streamable-http transport)\n\
99+
python /app/api/mcp/server.py --http &\n\
98100
PORT=3000 HOSTNAME=0.0.0.0 node server.js &\n\
99101
wait -n\n\
100102
exit $?' > /app/start.sh && chmod +x /app/start.sh

MCP_SETUP.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -558,25 +558,35 @@ Expected: Claude calls `ask_codebase`, gets relevant wiki context, then reasons
558558

559559
---
560560

561-
## Docker Integration (Optional, Future)
561+
## Docker Integration
562562

563-
If you want the MCP server to run inside the Docker container alongside the existing services, add to `start.sh`:
563+
The MCP server runs automatically inside the Docker container alongside FastAPI and Next.js.
564564

565-
```bash
566-
# Start MCP server on port 8008 (HTTP mode for remote access)
567-
python api/mcp/server.py --http &
568-
```
565+
**What's configured:**
566+
- `mcp[cli]` is included in `api/pyproject.toml` as a Poetry dependency
567+
- `Dockerfile` exposes port 8008 and launches `python /app/api/mcp/server.py --http &` in `start.sh`
568+
- `docker-compose.yml` maps port 8008 to the host
569+
- The server binds to `0.0.0.0:8008` inside the container (configurable via `MCP_HOST` and `MCP_PORT` env vars)
570+
571+
**Usage after `docker compose up`:**
569572

570-
And expose port 8008 in `docker-compose.yml`:
573+
Remote MCP clients connect to `http://localhost:8008/mcp` (streamable-http transport).
571574

572-
```yaml
573-
ports:
574-
- "8008:8008" # MCP server
575-
- "8001:8001" # FastAPI
576-
- "3000:3000" # Next.js
575+
For Claude Code connecting to a Docker-hosted instance:
576+
```bash
577+
claude mcp add bettercodewiki --transport streamable-http http://localhost:8008/mcp
577578
```
578579

579-
Remote clients would then connect to `http://localhost:8008/mcp`.
580+
For Claude Desktop, use the URL-based config:
581+
```json
582+
{
583+
"mcpServers": {
584+
"bettercodewiki": {
585+
"url": "http://localhost:8008/mcp"
586+
}
587+
}
588+
}
589+
```
580590

581591
---
582592

README.md

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- **Export Options**: Export to Markdown, JSON, Notion, Confluence, and HTML formats
2727
- **Global Search**: Command palette (Cmd+K) for quick navigation
2828
- **Reading Mode**: Distraction-free reading with Alt+R toggle
29+
- **MCP Server**: Expose wiki data to AI agents (Claude Desktop, Claude Code, Cursor, Windsurf) via Model Context Protocol
2930

3031
## Quick Start
3132

@@ -162,6 +163,8 @@ BetterCodeWiki/
162163
│ ├── api.py # FastAPI implementation
163164
│ ├── rag.py # Retrieval Augmented Generation
164165
│ ├── data_pipeline.py # Data processing utilities
166+
│ ├── mcp/ # MCP server (standalone)
167+
│ │ └── server.py # 5 tools for AI agent access to wikis
165168
│ ├── pyproject.toml # Python dependencies (Poetry)
166169
│ └── poetry.lock # Locked Python dependency versions
167170
@@ -208,7 +211,7 @@ BetterCodeWiki/
208211
# Pull and run
209212
docker pull ghcr.io/asyncfuncai/deepwiki-open:latest
210213

211-
docker run -p 8001:8001 -p 3000:3000 \
214+
docker run -p 8001:8001 -p 3000:3000 -p 8008:8008 \
212215
-e GOOGLE_API_KEY=your_key \
213216
-e OPENAI_API_KEY=your_key \
214217
-v ~/.adalflow:/root/.adalflow \
@@ -221,6 +224,81 @@ Or use Docker Compose:
221224
docker-compose up
222225
```
223226

227+
### Ports
228+
229+
| Port | Service |
230+
|------|---------|
231+
| 3000 | Next.js frontend |
232+
| 8001 | FastAPI backend |
233+
| 8008 | MCP server (streamable-http) |
234+
235+
## MCP Server — AI Agent Integration
236+
237+
BetterCodeWiki includes a built-in [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server that lets AI coding agents query your wiki documentation in real-time.
238+
239+
### What It Does
240+
241+
Any MCP-compatible client (Claude Desktop, Claude Code, Cursor, Windsurf) can:
242+
- Discover which repos have generated wikis
243+
- Look up architecture overviews and specific wiki pages
244+
- Search documentation for relevant context
245+
- Ask questions about a codebase using wiki content
246+
247+
### 5 MCP Tools
248+
249+
| Tool | Description |
250+
|------|-------------|
251+
| `list_projects` | Discover all cached wiki repos |
252+
| `get_wiki_overview` | Get project architecture in one call |
253+
| `get_wiki_page` | Fetch a specific page by title (fuzzy match) or ID |
254+
| `search_wiki` | Full-text search across all wiki pages |
255+
| `ask_codebase` | Get relevant wiki context for a question |
256+
257+
### Connect via Docker (HTTP)
258+
259+
When running with Docker, the MCP server is available at `http://localhost:8008/mcp`.
260+
261+
**Claude Code:**
262+
```bash
263+
claude mcp add bettercodewiki --transport streamable-http http://localhost:8008/mcp
264+
```
265+
266+
**Claude Desktop** (`~/Library/Application Support/Claude/claude_desktop_config.json`):
267+
```json
268+
{
269+
"mcpServers": {
270+
"bettercodewiki": {
271+
"url": "http://localhost:8008/mcp"
272+
}
273+
}
274+
}
275+
```
276+
277+
### Connect Locally (stdio — no Docker needed)
278+
279+
```bash
280+
# Set up the venv once
281+
python3 -m venv api/mcp/.venv
282+
api/mcp/.venv/bin/pip install "mcp[cli]"
283+
284+
# Register with Claude Code
285+
claude mcp add bettercodewiki -- api/mcp/.venv/bin/python api/mcp/server.py
286+
```
287+
288+
**Claude Desktop** (stdio mode):
289+
```json
290+
{
291+
"mcpServers": {
292+
"bettercodewiki": {
293+
"command": "/absolute/path/to/BetterCodeWiki/api/mcp/.venv/bin/python",
294+
"args": ["/absolute/path/to/BetterCodeWiki/api/mcp/server.py"]
295+
}
296+
}
297+
}
298+
```
299+
300+
For full setup details, see [MCP_SETUP.md](MCP_SETUP.md).
301+
224302
## Ask & DeepResearch
225303

226304
- **Ask**: Chat with your repository using RAG for context-aware, streaming responses

api/mcp/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ def wiki_page_resource(owner: str, repo: str, page_id: str) -> str:
411411

412412
if __name__ == "__main__":
413413
if "--http" in sys.argv:
414-
print("Starting BetterCodeWiki MCP server on http://127.0.0.1:8008/mcp", file=sys.stderr)
415-
mcp.run(transport="streamable-http", host="127.0.0.1", port=8008)
414+
host = os.environ.get("MCP_HOST", "0.0.0.0")
415+
port = int(os.environ.get("MCP_PORT", "8008"))
416+
print(f"Starting BetterCodeWiki MCP server on http://{host}:{port}/mcp", file=sys.stderr)
417+
mcp.run(transport="streamable-http", host=host, port=port)
416418
else:
417419
mcp.run(transport="stdio")

0 commit comments

Comments
 (0)