MCP Knowledge Viz
Enables storage and semantic search of facts, and interactive 3D visualization of embeddings via MCP tools.
README
MCP Knowledge Viz
A knowledge-base chatbot with semantic search and interactive embedding visualisation, built as a hybrid of REST microservices (browser UI) and a proper MCP stdio server (Claude Desktop / Cursor integration).
Store facts in natural language, ask questions, and explore the embedding space in 2D (matplotlib) or interactive 3D (Plotly) — all backed by ChromaDB and SentenceTransformers.
Architecture Overview
The system has two independent access paths that share the same business logic:
| Layer | Transport | Use case |
|---|---|---|
REST servers (run_all.sh) |
HTTP | Browser chatbot UI |
MCP stdio server (mcp_tools.py) |
stdin/stdout JSON-RPC | Claude Desktop, Cursor, any MCP client |
Both layers delegate to kb_core.py — the single module that owns the ChromaDB client and the SentenceTransformer embedder. Neither layer duplicates data-access logic.
Key Design Principles
- Single source of truth for data access — only
kb_core.pytalks to ChromaDB. REST endpoints and MCP tools are thin wrappers. - No HTTP for MCP —
mcp_tools.pycallskb_coredirectly; the REST servers do not need to be running for an MCP client to use the tools. - SOLID / Pydantic structure — the Visualization package uses typed Pydantic models at every boundary (
EmbeddingPayload,VisualizationRequest,ReducedEmbeddings).
Diagrams
Module Structure
QnA Request Flow (REST)
Visualization Flow (2D + 3D)
MCP Tools Flow (stdio)
Regenerating diagrams
plantuml -tsvg docs/architecture/uml/*.puml -o ../images
plantuml -tpng docs/architecture/uml/*.puml -o ../images
REST API Reference
Knowledge Base Server — port 8000
Central data service. Also serves the chatbot browser UI.
| Method | Endpoint | Description |
|---|---|---|
GET |
/chatbot |
Browser UI (two-column layout) |
POST |
/add_fact |
Embed and store a fact in ChromaDB facts collection |
POST |
/add_query |
Embed and store a query in ChromaDB queries collection |
POST |
/search |
Semantic search — returns top-k facts + distances. Body: {"query": "...", "n_results": 5} |
GET |
/get_all_embeddings |
Return all facts + queries with raw embeddings (used by Viz server) |
QnA Server — port 8001
Thin HTTP wrapper. Calls the KB server; no direct DB access.
| Method | Endpoint | Description |
|---|---|---|
POST |
/ask |
Stores query via /add_query, fetches matches via /search, returns ranked results |
Visualization Server — port 8002
Generates embedding plots via PCA dimensionality reduction.
| Method | Endpoint | Query params | Returns |
|---|---|---|---|
GET |
/visualize_embeddings |
dimensions (2|3), show_radius, radius_neighbors, figure_width, figure_height, dpi |
image/png (matplotlib) |
GET |
/visualize_embeddings_3d |
show_radius, radius_neighbors, figure_width, figure_height, dpi |
image/png (matplotlib 3D) |
GET |
/visualize_embeddings_interactive |
show_radius, radius_neighbors |
application/json (Plotly figure) |
MCP Tools Reference
mcp_tools.py is a FastMCP stdio server. Configure it in your MCP client and the three tools below appear automatically — no REST servers needed.
| Tool | Arguments | Description |
|---|---|---|
add_fact |
text: str |
Embed and persist a fact in ChromaDB |
ask |
query: str, n_results: int = 5 |
Semantic search; also records the query for visualisation |
visualize_embeddings |
show_radius: bool = true, radius_neighbors: int = 3 |
Returns a Plotly 3D figure as a JSON string |
Connecting to Claude Desktop / Cursor
Copy mcp.json.example to mcp.json, fill in your absolute paths, then copy the mcpServers block into your client's config file:
- Claude Desktop:
~/Library/Application Support/Claude/claude_desktop_config.json - Cursor:
~/.cursor/mcp.json
// mcp.json.example — fill in your local paths
{
"mcpServers": {
"knowledge-viz": {
"command": "/path/to/your/project/.venv/bin/python",
"args": ["-m", "mcp_servers.mcp_tools"],
"cwd": "/path/to/your/project"
}
}
}
mcp.jsonis gitignored because it contains absolute local paths. Always editmcp.json.examplefor committed changes.
Getting Started
Prerequisites
- Python 3.11+
- PlantUML (optional, only to regenerate diagrams)
Setup
git clone <repository-url>
cd mcp-knowledge-viz
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
Run the REST + browser UI stack
chmod +x run_all.sh
./run_all.sh
Starts three servers:
| Server | Port | Role |
|---|---|---|
| Knowledge Base | 8000 | Data + chatbot UI |
| QnA | 8001 | Question answering |
| Visualization | 8002 | Embedding plots |
Open http://127.0.0.1:8000/chatbot in your browser.
Visualisation tuning parameters
| Parameter | Default | Range | Effect |
|---|---|---|---|
dimensions |
2 |
2 or 3 |
PCA target dimensions |
show_radius |
true |
bool | Draw search-radius circle / sphere around latest query |
radius_neighbors |
5 |
1–50 | Neighbour count used to compute the radius |
figure_width |
16 |
float | Matplotlib figure width (inches) |
figure_height |
10 |
float | Matplotlib figure height (inches) |
dpi |
160 |
int | Matplotlib output resolution |
n_results |
5 |
1–50 | Facts returned per search |
Project Structure
mcp-knowledge-viz/
├── app/
│ ├── static/
│ │ ├── chatbot.css # Two-column layout, vis viewport
│ │ └── chatbot.js # Fetch facts/QnA, Plotly 3D, spinner
│ └── templates/
│ └── chatbot.html # Bootstrap 5 two-column UI
├── docs/
│ └── architecture/
│ ├── images/ # Generated SVG + PNG diagrams
│ └── uml/ # PlantUML sources
├── mcp_servers/
│ ├── kb_core.py # ★ Shared ChromaDB + embedder logic
│ ├── knowledge_base_server.py # REST :8000 — delegates to kb_core
│ ├── qna_server.py # REST :8001 — HTTP wrapper
│ ├── visualization_server.py # REST :8002 — delegates to visualization/
│ ├── mcp_tools.py # ★ MCP stdio server (add_fact, ask, visualize)
│ └── visualization/
│ ├── models.py # Pydantic models
│ ├── kb_client.py # HTTP client → KB server
│ ├── reducer.py # PCA 2D/3D
│ ├── renderer.py # matplotlib (2D/3D static PNG)
│ ├── plotly_renderer.py # Plotly interactive 3D JSON
│ └── service.py # Orchestrator
├── chroma_db/ # Persistent vector store (gitignored)
├── mcp.json # Local MCP config (gitignored)
├── mcp.json.example # Template — commit this, not mcp.json
├── run_all.sh # Start all three REST servers
└── requirements.txt
Tech Stack
| Concern | Library |
|---|---|
| REST framework | FastAPI + uvicorn |
| Vector store | ChromaDB (persistent) |
| Embeddings | SentenceTransformers all-MiniLM-L6-v2 |
| Dimensionality reduction | scikit-learn PCA |
| 2D/3D static plots | matplotlib |
| Interactive 3D plots | Plotly (JS CDN + Python) |
| MCP server | mcp[cli] FastMCP |
| HTTP client | httpx |
| Frontend | Bootstrap 5, vanilla JS |
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。