Back to MCP directory
publicPublicdnsLocal runtime

mcp-rag

基于MCP协议的低延迟RAG服务,支持本地知识检索和智能摘要,提供双模式检索和模块化架构

article

README

🚀 MCP - RAG:低延迟 RAG 服务

MCP - RAG 是基于 MCP(Model Context Protocol)协议构建的低延迟 RAG(Retrieval - Augmented Generation)服务架构,能够高效地实现知识检索与生成,为应用提供强大的知识支持。

🚀 快速开始

环境要求

  • Python >= 3.13
  • uv 包管理器

安装依赖

uv sync

启动服务

uv run mcp-rag serve

⚠️ 重要提示

首次启动会报错(懒得改),配置好配置文件就没问题了。

web 配置页面

uv run mcp-rag web
  • 访问配置页面http://localhost:8000/config-page
  • 访问资料管理页面http://localhost:8000/documents-page
  • 使用 HTTP APIhttp://localhost:8000/docs (Swagger UI)

配置管理

MCP - RAG 现在使用 JSON 文件进行持久化配置管理。data\config.json 文件存储配置信息,支持通过 Web 界面进行修改和保存。

默认配置示例:

{
  "host": "0.0.0.0",
  "port": 8000,
  "http_port": 8000,
  "debug": false,
  "vector_db_type": "chroma",
  "chroma_persist_directory": "./data/chroma",
  "qdrant_url": "http://localhost:6333",
  "embedding_provider": "doubao",
  "embedding_model": "doubao-embedding-text-240715",
  "embedding_device": "cpu",
  "embedding_cache_dir": null,
  "embedding_api_key": "KEY-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "embedding_base_url": "https://ark.cn-beijing.volces.com/api/v3",
  "llm_provider": "doubao",
  "llm_model": "doubao-seed-1-6-flash-250828",
  "llm_base_url": "https://ark.cn-beijing.volces.com/api/v3",
  "llm_api_key": "KEY-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "enable_llm_summary": false,
  "enable_thinking": false,
  "max_retrieval_results": 5,
  "similarity_threshold": 0.7,
  "enable_reranker": false,
  "enable_cache": false
}

MCP 服务器配置

小智 go 服务端能通过 MCP 协议与 MCP - RAG 进行交互。以下是一个示例配置:

{
    "mcpServers": {
        "rag": {
            "command": "uv",
            "args": [
                "run",
                "mcp-rag",
                "serve"
            ],
            "env": {
                "PYTHONUNBUFFERED": "1",
                "MODEL_TYPE": "OPENAI",

                "OPENAI_API_KEY": "aa2ae42b-c82b-41ec-bf4e-51c8ab0e4d78",
                "OPENAI_API_BASE": "https://ark.cn-beijing.volces.com/api/v3",
                "OPENAI_MODEL": "doubao-1-5-pro-32k-250115",
                "OPENAI_TEMPERATURE": "0",

                "EMBEDDING_PROVIDER": "OPENAI",
                "OPENAI_EMBEDDING_MODEL": "doubao-embedding-text-240715",

                "COLLECTION_NAME": "default_collection"
            }
        }
    }
}

使用 MCP 工具

{
  "name": "rag_ask",
  "arguments": {
    "query": "查询内容",
    "mode": "raw",
    "limit": 5
  }
}

✨ 主要特性

  • 极低延迟:可实现 <100ms 的本地知识检索。
  • 双模式支持:具备 Raw 模式(直接检索)和 Summary 模式(检索 + 摘要)。
  • LLM 总结功能:支持 Doubao、Ollama 等 LLM 提供商进行智能摘要。
  • 模块化架构:MCP Server 作为统一知识接口层。
  • 异步优化:采用异步调用与模型预热机制。
  • 可扩展设计:预留 reranker 与缓存模块接口。

🔧 技术细节

| 属性 | 详情 | |------|------| | 后端框架 | FastAPI | | 向量数据库 | ChromaDB(本地部署) | | 嵌入模型 | m3e - small / e5 - small (Sentence Transformers),Doubao 嵌入 API | | LLM 模型 | Doubao API,Ollama(本地部署) | | 协议 | MCP(Model Context Protocol) | | 包管理 | uv(现代化 Python 包管理器) |

📄 许可证

本项目采用 MIT License。

🤝 贡献

欢迎提交 Issue 和 Pull Request!

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client