模型上下文协议 - 通过 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 与 Claude 的 MCP 集成可以将多个 API 调用和配置任务转换为对话式请求。这可以帮助您更专注于构建应用程序,减少对实现细节的关注。

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