RAG MCP Server
A RAG knowledge base MCP server that adds vector search and reranking capabilities to opencode, supporting multimodal embeddings, multiple knowledge bases, and local storage.
README
RAG MCP Server
一个 RAG 知识库的 MCP server,给 opencode 加上向量检索和重排能力
本项目开发目的是为了在 opencode 中使用 rag 文档检索功能,但是使用的是标准的 mcp 格式,理论上在任何支持 mcp 的平台上都能用
设计架构
- 多模态支持:可以采用 VL 的向量和重排模型
- 多知识库:可以建多个知识库,分类存放不同类型的文档
- 本地存储:向量数据和源文件都保存在本地
- 图片 URL 支持:得益于
openai统一接口,base64 和 url 都支持且可以混用
┌──────────┐ ┌──────────────────────────────────────────────────┐
│ Opencode │ ──────> │ RAG MCP Server │
│ (Client) │ │ │
└──────────┘ │ ┌────────┐ ┌──────────┐ ┌───────────┐ │
│ │ Router │ ───> │ Embedder │ ──> │ Chroma DB │ │
│ └────────┘ └──────────┘ └───────────┘ │
│ │ │ │ │
│ │ └─────────────────┘ │
│ │ │ │
│ │ ┌──────────┐ │
│ └──────────────────> │ Search │ │
│ └──────────┘ │
│ │ │
│ ┌──────────┐ │
│ │ Rerank │ │
│ └──────────┘ │
└────────────────────────────────┼─────────────────┘
│
┌─────────────────────┐
│ Matched Docs │
│ + Context + Answer │
└─────────────────────┘
安装
git clone https://github.com/sglwsjxh/rag-mcp.git
cd rag-mcp
python -m venv venv
.\venv\Scripts\activate
pip install -e .
配置
复制 .env.example 到 .env
cp .env.example .env
填上 API key:
EMBEDDING_BASEURL=https://openrouter.ai/api/v1
EMBEDDING_MODEL=nvidia/llama-nemotron-embed-vl-1b-v2:free
EMBEDDING_API_KEY=sk-or-...
RERANK_BASEURL=https://ai.api.nvidia.com/v1
RERANK_MODEL=nvidia/llama-nemotron-rerank-vl-1b-v2
RERANK_API_KEY=nvapi-...
DATABASE_PATH=./database
推荐使用
OpenRouter和NVIDIA的免费模型,但是任何openai兼容的模型都可使用
注册到 opencode
在 ~/.config/opencode/opencode.json 里加这段:
{
"mcp": {
"rag": {
"enabled": true,
"type": "local",
"command": [
"C:/path/to/rag-mcp/venv/Scripts/python.exe",
"-m",
"rag_mcp"
]
}
}
}
重启 opencode,就能直接调这六个工具:
list_knowledge_bases- 列出所有知识库add_database- 新建知识库add_file- 往知识库里加文件search- 搜索知识库delete_file- 删除某个文件delete_database- 删除整个知识库
数据目录结构
database/
├── index.json # 知识库列表和元信息
├── python/ # 单文件夹知识库
│ ├── chroma_db/
│ └── assets/
├── cpp/
│ ├── chroma_db/
│ └── assets/
└── ...
许可证
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.