模型上下文协议 - 通过 Claude 桌面版与 Meilisearch 对话

简介

本指南将引导您通过模型上下文协议(MCP)使用 Claude AI 的自然语言交互方式来设置和使用 Meilisearch。

系统要求

要遵循本指南,您需要:

配置 Claude 桌面版与 Meilisearch MCP 服务器

1. 安装 Claude 桌面版

下载并安装 Claude 桌面版

2. 安装 Meilisearch MCP 服务器

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

# 使用 uv (推荐)
uv pip install meilisearch-mcp

# 使用 pip
pip install meilisearch-mcp

3. 配置 Claude 桌面版

打开 Claude 桌面版,点击顶部菜单栏中的 Claude 菜单,选择”设置”。在设置窗口中,点击左侧边栏的”开发者”,然后点击”编辑配置”。这将打开您的 claude_desktop_config.json 文件。

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

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

保存文件并重启 Claude。

连接到您的 Meilisearch 实例

当 Claude Desktop 完成 Meilisearch MCP 服务器设置后,您可以通过让 Claude 更新连接设置来连接到您的 Meilisearch 实例。

打开 Claude Desktop 并开始一个新对话。

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

请连接到我的 Meilisearch 实例,地址为 MEILISEARCH_URL,使用 API 密钥 API_KEY

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

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

能否检查与我的 Meilisearch 实例的连接并告诉我它运行的版本?

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

创建电商索引

现在您已配置好 MCP 与 Meilisearch 协同工作,可以使用它来管理您的索引。

首先,验证项目中已有的索引:

我的 Meilisearch 实例中有哪些索引?

接下来,让 Claude 创建一个针对电商优化的索引:

为我们的电商网站创建一个名为 "products" 的新索引,主键设为 "product_id"

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

我的 "products" 索引中有多少文档?它的尺寸是多少?

向新索引添加文档

让 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验证您的连接设置

当前Meilisearch连接设置是什么?

2. 让Claude检查您的Meilisearch实例健康状况

对我的Meilisearch实例运行健康检查

3. 查看Claude的日志

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

  • macOS系统:~/Library/Logs/Claude/mcp*.log
  • Windows系统:%APPDATA%\Claude\logs\mcp*.log

4. 独立测试MCP服务器

打开终端并使用npx查询MCP检查器:

npx @modelcontextprotocol/inspector uvx -n meilisearch-mcp

总结

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

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