文档搜索服务

一个基于Meilisearch的自托管上下文搜索服务,专为AI代理设计,支持从多种来源下载、索引文档和文件,并通过Model Context Protocol (MCP)服务器提供快速、灵活的搜索功能。

  • by adomi-io
  • Python
  • 本地部署
  • 5 星标
  • 更新于
在 GitHub 查看 adomi-io/mcp-global-search

使用说明

全局搜索:文档→ Meilisearch→ MCP

一个自托管的Meilisarch为AI代理提供上下文搜索。允许AI代理以简单的术语搜索您提供的文档、文件和示例。

一个端到端、容器友好的管道,它:

  • 将文档和文件从多个来源下载到本地 output/ 文件夹
  • 在Meilisearch中为这些文件建立索引,以实现快速、灵活的搜索
  • 公开一个最小的模型上下文协议(MCP)服务器,以便AI代理可以可靠地查询“用户加载”的文档,并获取精确的源文件以进行接地

亮点

  • 📥 统一下载器:Git和HTTP源代码合并到一棵树中(output/)
  • 🔎 Meilisearch索引与智能内容处理(frontmatter Markdown、YAML/JSON/CSV作为结构化数据)
  • 🧭 安全、明确的范围:索引来源于您的顶级文件夹;可选的允许列表限制搜索和文件获取
  • 🔌 基于HTTP或stdio的MCP服务器:列出索引、搜索和获取确切的文件以进行应答
  • 🐳 电池包括:一个 docker compose up -d --build 运行整个堆栈
  • 🛠️ 设计可扩展:在大多数情况下,调整加载程序规则、文件过滤器和环境,而无需重建图像

入门

[!警告] 该项目旨在通过Docker运行。如果您使用的是Windows或macOS,请安装Docker Desktop。

https://www.docker.com/products/docker-desktop/

创建 .env

至少,您必须设置Meilisearch主密钥,以便依赖服务可以进行身份验证。

echo "MEILISEARCH_MASTER_KEY=$(openssl rand -hex 32)" >> .env

您现在或以后可以添加的可选变量:

# Restrict which Meilisearch indexes the MCP server will expose (space/comma/newline separated)
MEILISEARCH_ALLOWED_INDEXES="docs guides examples"

# Run containers as your host user (helps with file ownership on ./output)
UID=1000
GID=1000

定义你的来源

编辑 data-sources.yml 描述要下载的内容。使用统一 config: 形状。一个最小的例子:

config:
  sources:
    - type: git
      repo: https://github.com/example/docs.git
      subpath: docs
      ref: main
      destination: docs

    - type: http
      url: https://example.com/guide.md
      filename: guide.md
      destination: examples

每个源过滤可以使用 include/exclude 在单个源条目上。例如,要从Git源代码中排除锁文件:

config:
  sources:
    - type: git
      repo: https://github.com/nitrojs/nitro.git
      subpath: docs
      destination: nitro
      exclude:
        - "pnpm-lock.yaml"

有关完整的模式和过滤规则,请参阅下载器README: src/downloader_web/README.md.

配置架构

config:
  sources: []
  loaders: []
  destinations: {}
  collections: {}

完整配置示例

config:
  destinations:
    docs:
      description: |
        Docs for the main project
    guides:
      description: |
        Guides and tutorials

  collections:
    project:
      description: |
        Core project documentation
      destinations:
        - docs
    learning:
      description: |
        Guides and tutorials
      destinations:
        - guides

  loaders:
    - path: guides
      type: frontmatter

  sources:
    - type: git
      repo: https://github.com/example/docs.git
      subpath: docs
      ref: main
      destination: docs
      include:
        - "**/*.md"

    - type: git
      repo: https://github.com/example/guides.git
      subpath: content
      destination: guides
      exclude:
        - "**/pnpm-lock.yaml"

    - type: http
      url: https://example.com/guide.md
      filename: getting-started.md
      destination: guides

启动堆栈

docker compose up -d --build

服务和默认端口:

  • 美丽搜索API:http://localhost:7700
  • 下载器Web API:http://localhost:8080(健康、刷新)
  • MCP服务器(HTTP):http://localhost:8000

第一次运行将下载源代码,写入 ./output,对它们进行索引,然后通过MCP服务器公开它们。

[!提示] 如果你编辑 data-sources.yml,您可以刷新下载而无需重新启动:

curl -X POST http://localhost:8080/refresh

服务概述

下载器-Web

从互联网(HTTP、Git等)获取文件到 ./output.

文件加载器

索引来自的文件 ./output 进入梅里斯拱门。

MCP 服务器

通过MCP将索引暴露给AI工具。

编写文件: docker-compose.yml 把一切联系在一起。

典型数据流

  • downloader_web填充 ./output 来自您配置的源
  • file_loader对Meilisearch执行初始完整索引,然后监视更改
  • mcpserver列出/搜索这些索引,并可以在以下位置获取确切的文件内容 ./output

更新中

  • 更改后刷新下载 data-sources.yml:
curl -X POST http://localhost:8080/refresh
  • 如果更改环境变量,请重新启动服务:
docker compose restart

故障排除

  • 梅里似乎不健康: docker compose logs -f meilisearch
  • 下载器未就绪(/health 503):检查 docker compose logs -f downloader_web
  • 未编入索引的文件:验证file_loader README中的文件扩展名/大小限制,以及文件是否位于 ./output
  • MCP搜索未显示索引:确认 MEILISEARCH_ALLOWED_INDEXES (如果已设置),该file_loader在Meilisearch中创建了索引
  • 从MCP获取文件被拒绝:路径遍历被阻止,如果设置了允许列表,则只允许第一段匹配(例如。, docs/...)