Back to MCP directory
publicPublicdnsLocal runtime

mcp-rag-server

mcp-rag-server是一个基于Model Context Protocol (MCP)的服务,支持检索增强生成(RAG),能够索引文档并为大型语言模型提供相关上下文。

article

README

🚀 mcp-rag-server

一个基于模型上下文协议(MCP)的服务器,支持检索增强生成(RAG)。它能够索引文档,并通过MCP协议为大型语言模型提供相关信息,有效提升模型处理复杂任务的能力。

🚀 快速开始

  1. 安装依赖

    npm install
    
  2. 启动服务器

    npm start
    
  3. 使用示例命令进行交互

    node example.js
    

✨ 主要特性

  • 文档索引:读取文件,根据 CHUNK_SIZE 分割文本,并进行排队以供嵌入处理。
  • 嵌入处理:按顺序将每个分块发送到嵌入 API,结果存储在 SQLite 数据库中。
  • 查询功能:对查询内容进行嵌入处理,从向量存储库中检索最相关的文本分块,并将其返回给客户端。

📦 安装指南

npm install mcp-rag-server

💻 使用示例

基础用法

通用 MCP 客户端配置

{
  "mcpServers": {
    "rag": {
      "command": "npx",
      "args": ["-y", "mcp-rag-server"],
      "env": {
        "BASE_LLM_API": "http://localhost:11434/v1",
        "EMBEDDING_MODEL": "nomic-embed-text",
        "VECTOR_STORE_PATH": "./vector_store",
        "CHUNK_SIZE": "500"
      }
    }
  }
}

示例交互

# 索引文档
>> tool:embedding_documents {"path":"./docs"}

# 检查状态
>> resource:embedding-status

<< rag://embedding/status
当前完成数:123
失败数:45
总数量:678

高级用法

MCP 工具

# 索引文档
>> tool:embedding_documents {"path":"./docs"}

# 查询文档内容
>> tool:query_document {"query":"查询内容", "numberOfChunks":3}

# 获取所有文档 URI
>> resource:rag://documents

# 获取单个文档内容
>> resource:rag://document/path/to/document.txt

MCP 资源

  • rag://documents:列出所有文档的 URI。
  • rag://document/{path}:获取指定路径的文档内容。
  • rag://query-document/{numberOfChunks}/{query}:按数量获取与查询相关的文档内容。
  • rag://embedding/status:查看当前索引状态(已完成、失败、总数)。

📚 详细文档

配置选项

| 属性 | 详情 | |------|------| | BASE_LLM_API | 嵌入 API 的基础 URL,示例值:"http://localhost:11434/v1" | | EMBEDDING_MODEL | 嵌入模型名称,示例值:"nomic-embed-text" | | VECTOR_STORE_PATH | 向量存储路径,示例值:"./vector_store" | | CHUNK_SIZE | 每个分块的字符数限制,示例值:"500" |

开发

npm install
npm run build      # 编译 TypeScript 代码
npm start          # 启动服务器
npm run watch      # 监控文件变化

贡献

欢迎贡献!请在 GitHub 上打开问题或拉取请求。

📄 许可证

MIT 2025 Quan Le

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