模型上下文协议 - 使用 Claude desktop 与 Meilisearch 对话

    简介

    本指南将引导你通过与 Claude AI 进行自然语言交互,经由模型上下文协议 (MCP) 设置和使用 Meilisearch。

    要求

    要遵循本指南,你需要:

    使用 Meilisearch MCP 服务器设置 Claude Desktop

    1. 安装 Claude Desktop

    下载并安装 Claude Desktop

    2. 安装 Meilisearch MCP 服务器

    你可以使用 uvpip 安装 Meilisearch MCP 服务器

    # Using uv (recommended)
    uv pip install meilisearch-mcp
    
    # Using pip
    pip install meilisearch-mcp
    

    3. 配置 Claude Desktop

    打开 Claude Desktop,点击顶部栏中的 Claude 菜单,然后选择 “Settings”(设置)。在 “Settings” 窗口中,点击左侧边栏中的 “Developer”(开发者),然后点击 “Edit Config”(编辑配置)。这将打开你的 claude_desktop_config.json 文件。

    将 Meilisearch MCP 服务器添加到你的配置中

    {
      "mcpServers": {
        "meilisearch": {
          "command": "uvx",
          "args": ["-n", "meilisearch-mcp"]
        }
      }
    

    保存文件并重启 Claude。

    连接到你的 Meilisearch 实例

    使用 Meilisearch MCP 服务器设置好 Claude Desktop 后,你可以通过要求 Claude 更新连接设置来连接到你的 Meilisearch 实例。

    打开 Claude Desktop 并开始新的对话。

    接下来,通过要求 Claude 更新连接设置来连接到你的 Meilisearch 实例,将 MEILISEARCH_URL 替换为你的项目 URL,并将 API_KEY 替换为你的项目的 API 密钥

    Please connect to my Meilisearch instance at MEILISEARCH_URL using the API key API_KEY
    

    Claude 将使用 MCP 服务器的 update-connection-settings 工具来建立与你的 Meilisearch 实例的连接。

    最后,通过询问以下内容验证连接

    Can you check the connection to my Meilisearch instance and tell me what version it's running?
    

    Claude 将使用 get-versionhealth-check 工具来验证连接,并提供有关你的实例的信息。

    创建电子商务索引

    现在你已经配置了 MCP 以与 Meilisearch 一起工作,你可以使用它来管理你的索引。

    首先,验证你的项目中有什么索引

    What indexes do I have in my Meilisearch instance?
    

    接下来,要求 Claude 创建一个针对电子商务优化的索引

    Create a new index called "products" for our e-commerce site with the primary key "product_id"
    

    最后,检查索引是否已成功创建并且完全为空

    How many documents are in my "products" index and what's its size?
    

    将文档添加到你的新索引

    要求 Claude 将几个测试文档添加到你的 “products” 索引

    Add these products to my "products" index:
    [
      {"product_id": 1, "name": "Ergonomic Chair", "description": "Comfortable office chair", "price": 299.99, "category": "Furniture"},
      {"product_id": 2, "name": "Standing Desk", "description": "Adjustable height desk", "price": 499.99, "category": "Furniture"}
    ]
    

    由于你仅将 “products” 用于测试,你还可以要求 Claude 自动使用占位符数据填充它

    Add 10 documents in the index "products" with a name, category, price, and description of your choice
    

    要验证数据插入是否按预期工作,请检索索引中的前几个文档

    Show me the first 5 products in my "products" index
    

    配置你的索引

    在执行首次搜索之前,设置一些索引设置以确保相关结果。

    要求 Claude 优先考虑完全匹配的单词而不是多个部分匹配的单词

    Update the ranking rules for the "products" index to prioritize word matches and handle typos, but make exact matches more important than proximity
    

    将可搜索属性限制为高度相关的字段,并且仅返回你将在搜索界面中显示的属性也是一个好习惯

    Configure my "products" index to make the "name" and "description" fields searchable, but only "name", "price", and "category" should be displayed in results
    

    使用 MCP 执行搜索

    使用以下提示执行你的首次搜索

    Search the "products" index for "desk" and return the top 3 results
    

    你还可以请求你的搜索使用其他 Meilisearch 功能,例如过滤器和排序

    Search the "products" index for "chair" where the price is less than 200 and the category is "Furniture". Sort results by price in ascending order.
    
    关于 LLM 限制的重要说明

    像 Claude 这样的大型语言模型倾向于对大多数请求说 “是”,即使它们实际上无法执行这些请求。

    Claude 只能执行通过 Meilisearch API 公开并在 MCP 服务器中实现的操作。如果你不确定特定操作是否可能,请参考 Meilisearch 文档MCP 服务器 README

    故障排除

    如果你在使用 Meilisearch MCP 集成时遇到问题,请尝试以下步骤:

    1. 要求 Claude 验证你的连接设置

    What are the current Meilisearch connection settings?
    

    2. 要求 Claude 检查你的 Meilisearch 实例健康状况

    Run a health check on my Meilisearch instance
    

    3. 查看 Claude 的日志

    在你的文本编辑器或日志查看器中打开日志文件

    4. 独立测试 MCP 服务器

    打开你的终端并使用 npx 查询 MCP Inspector

    npx @modelcontextprotocol/inspector uvx -n meilisearch-mcp
    

    结论

    Meilisearch MCP 与 Claude 的集成可以将多个 API 调用和配置任务转换为对话请求。这可以帮助你更专注于构建应用程序,而减少对实施细节的关注。

    有关高级配置和功能的更多信息,请参阅Meilisearch 文档Meilisearch MCP 服务器存储库