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

简介

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

要求

要遵循本指南,您需要

使用 Meilisearch MCP 服务器设置 Claude 桌面版

1. 安装 Claude 桌面版

下载并安装Claude 桌面版

2. 安装 Meilisearch MCP 服务器

您可以使用 uvpip 安装 Meilisearch MCP 服务器
# Using uv (recommended)
uv pip install meilisearch-mcp

# Using 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 桌面版设置了 Meilisearch MCP 服务器,您就可以通过要求 Claude 更新连接设置来连接到您的 Meilisearch 实例。 打开 Claude 桌面版并开始新对话。 接下来,通过要求 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 的日志

在您的文本编辑器或日志查看器中打开日志文件
  • 在 macOS 上:~/Library/Logs/Claude/mcp*.log
  • 在 Windows 上:%APPDATA%\Claude\logs\mcp*.log

4. 独立测试 MCP 服务器

打开您的终端并使用 npx 查询 MCP Inspector
npx @modelcontextprotocol/inspector uvx -n meilisearch-mcp

结论

Meilisearch MCP 与 Claude 的集成可以将多个 API 调用和配置任务转换为会话请求。这可以帮助您更多地专注于构建应用程序,而不是实施细节。 有关高级配置和功能的更多信息,请参阅Meilisearch 文档Meilisearch MCP 服务器存储库
© . This site is unofficial and not affiliated with Meilisearch.