Meilisearch MCP Server - 轻量级全文搜索引擎

Meilisearch MCP Server - 轻量级全文搜索引擎

官方实现 | Stars: 145 | Python | MIT

概述

Meilisearch MCP Server 是 Meilisearch 官方提供的 Model Context Protocol 实现,让 AI 助手能够通过自然语言管理搜索索引和执行全文搜索。它提供了轻量级、快速且易用的搜索引擎能力,特别适合需要即时搜索体验的应用场景。

该服务器提供了完整的 Meilisearch 功能访问,包括索引管理、文档操作、高级搜索、设置配置、API 密钥管理、任务监控等。通过 MCP 协议,开发者可以用自然语言完成复杂的搜索引擎配置和管理任务,无需编写代码。特别适合电商产品搜索、文档知识库、内容发现等场景。

核心特性

  • Meilisearch 官方实现,原生支持所有功能
  • 🚀 即时搜索体验,平均响应时间 < 50ms
  • 🛠️ 23 个专业工具,覆盖完整搜索引擎生命周期
  • 🔍 高级搜索能力,支持过滤、排序、分面搜索
  • 📊 容错搜索,智能处理拼写错误和近似匹配
  • 🌐 多语言支持,内置 30+ 语言的分词器
  • 🔌 灵活部署,支持本地和云端 Meilisearch 实例
  • 🔐 细粒度权限控制,API 密钥级别的访问管理

工具列表

连接管理 (2 个工具)

1. get-connection-settings

功能:查看当前 Meilisearch 连接配置

参数:无

示例

1
{}

返回

1
2
3
4
{
"url": "http://localhost:7700",
"hasApiKey": true
}

2. update-connection-settings

功能:动态更新 Meilisearch 连接 URL 和 API 密钥

参数

  • url (string, 可选) - 新的 Meilisearch 服务器 URL
  • apiKey (string, 可选) - 新的 API 密钥

示例

1
2
3
4
{
"url": "http://production-meili:7700",
"apiKey": "masterKey_xxxxx"
}

索引管理 (4 个工具)

3. create-index

功能:创建新的搜索索引

参数

  • indexName (string, 必需) - 索引名称(需符合命名规范)
  • primaryKey (string, 可选) - 文档的主键字段名

示例

1
2
3
4
{
"indexName": "products",
"primaryKey": "id"
}

最佳实践

  • 索引名只能包含字母、数字、连字符和下划线
  • 建议使用小写字母和连字符分隔单词
  • 主键字段应该是唯一且不可变的

4. list-indexes

功能:列出所有可用索引及其统计信息

参数:无

返回示例

1
2
3
4
5
6
7
8
9
10
11
{
"results": [
{
"uid": "products",
"primaryKey": "id",
"createdAt": "2025-10-14T00:00:00Z",
"updatedAt": "2025-10-14T00:00:00Z",
"numberOfDocuments": 1234
}
]
}

5. delete-index

功能:删除索引及其所有数据(不可恢复)

参数

  • indexName (string, 必需) - 要删除的索引名称

示例

1
2
3
{
"indexName": "old-products"
}

6. get-index-metrics

功能:获取索引的详细性能指标和统计信息

参数

  • indexName (string, 必需) - 索引名称

返回示例

1
2
3
4
5
6
7
8
9
{
"numberOfDocuments": 10000,
"isIndexing": false,
"fieldDistribution": {
"title": 10000,
"description": 9850,
"price": 10000
}
}

文档操作 (2 个工具)

7. get-documents

功能:从索引中分页检索文档

参数

  • indexName (string, 必需) - 目标索引名称
  • limit (number, 可选) - 返回文档数量(默认 20,最大 1000)
  • offset (number, 可选) - 分页偏移量(默认 0)

示例

1
2
3
4
5
{
"indexName": "products",
"limit": 50,
"offset": 100
}

8. add-documents

功能:向索引添加或更新文档(批量操作)

参数

  • indexName (string, 必需) - 目标索引名称
  • documents (array, 必需) - 文档数组,每个文档是 JSON 对象

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"indexName": "products",
"documents": [
{
"id": 1,
"title": "MacBook Pro",
"category": "electronics",
"price": 2399,
"description": "High-performance laptop"
},
{
"id": 2,
"title": "iPhone 15",
"category": "electronics",
"price": 999,
"description": "Latest smartphone"
}
]
}

注意事项

  • 如果文档主键已存在,会更新该文档
  • 批量添加是异步操作,返回任务 ID
  • 建议每批次 100-1000 个文档以获得最佳性能

搜索功能 (1 个工具)

功能:在索引中执行高级全文搜索

参数

  • indexName (string, 必需) - 要搜索的索引名称
  • query (string, 必需) - 搜索查询文本
  • filter (string, 可选) - 过滤表达式
  • sort (array, 可选) - 排序规则数组
  • limit (number, 可选) - 返回结果数量(默认 20)

示例

1
2
3
4
5
6
7
{
"indexName": "products",
"query": "laptop",
"filter": "price < 1500 AND category = electronics",
"sort": ["price:asc"],
"limit": 10
}

高级过滤语法

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 比较运算符
price > 100
price >= 100
price < 1000
price <= 1000
price = 500

# 逻辑运算符
category = electronics AND price < 1000
category = electronics OR category = computers

# 数组包含
tags IN [sale, featured]

# 组合条件
(category = electronics OR category = computers) AND price < 1000

设置管理 (2 个工具)

10. get-settings

功能:获取索引的完整配置设置

参数

  • indexName (string, 必需) - 索引名称

返回示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"rankingRules": [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness"
],
"searchableAttributes": ["*"],
"filterableAttributes": ["category", "price"],
"sortableAttributes": ["price"],
"displayedAttributes": ["*"],
"stopWords": [],
"synonyms": {}
}

11. update-settings

功能:更新索引的配置设置

参数

  • indexName (string, 必需) - 目标索引名称
  • settings (object, 必需) - 新的配置对象

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
"indexName": "products",
"settings": {
"searchableAttributes": [
"title",
"description",
"category"
],
"filterableAttributes": [
"category",
"price",
"tags"
],
"sortableAttributes": [
"price",
"createdAt"
],
"stopWords": ["the", "a", "an"],
"synonyms": {
"laptop": ["notebook", "computer"],
"phone": ["smartphone", "mobile"]
}
}
}

配置说明

  • searchableAttributes: 可搜索的字段,越靠前权重越高
  • filterableAttributes: 可用于过滤的字段
  • sortableAttributes: 可用于排序的字段
  • stopWords: 停用词列表,搜索时会被忽略
  • synonyms: 同义词映射,提升搜索相关性

API 密钥管理 (3 个工具)

12. get-keys

功能:列出所有 API 密钥及其权限

参数:无

返回示例

1
2
3
4
5
6
7
8
9
10
11
{
"results": [
{
"key": "abc123...",
"description": "Admin key",
"actions": ["*"],
"indexes": ["*"],
"expiresAt": null
}
]
}

13. create-key

功能:创建新的 API 密钥(细粒度权限控制)

参数

  • name (string, 必需) - 密钥名称/描述
  • actions (array, 必需) - 允许的操作列表
  • indexes (array, 必需) - 可访问的索引列表

示例

1
2
3
4
5
6
{
"name": "Read-only search key",
"actions": ["search"],
"indexes": ["products", "articles"],
"expiresAt": "2026-01-01T00:00:00Z"
}

可用操作

  • * - 所有操作
  • search - 搜索
  • documents.add - 添加文档
  • documents.delete - 删除文档
  • indexes.create - 创建索引
  • indexes.delete - 删除索引
  • settings.update - 更新设置

14. delete-key

功能:撤销并删除 API 密钥

参数

  • key (string, 必需) - 要删除的密钥字符串

示例

1
2
3
{
"key": "abc123def456..."
}

任务监控 (4 个工具)

15. get-task

功能:获取特定任务的详细信息

参数

  • taskId (string, 必需) - 任务 ID

返回示例

1
2
3
4
5
6
7
8
9
{
"uid": 123,
"indexUid": "products",
"status": "succeeded",
"type": "documentAdditionOrUpdate",
"duration": "PT0.123S",
"enqueuedAt": "2025-10-14T00:00:00Z",
"finishedAt": "2025-10-14T00:00:01Z"
}

16. get-tasks

功能:列出任务列表(支持过滤)

参数

  • limit (number, 可选) - 返回任务数量限制

示例

1
2
3
{
"limit": 50
}

17. cancel-tasks

功能:取消待处理的任务

参数

  • taskIds (array, 必需) - 要取消的任务 ID 列表

示例

1
2
3
{
"taskIds": [123, 124, 125]
}

18. delete-tasks

功能:删除已完成的任务记录

参数

  • taskIds (array, 必需) - 要删除的任务 ID 列表

示例

1
2
3
{
"taskIds": [100, 101, 102]
}

系统监控 (5 个工具)

19. health-check

功能:快速健康检查(返回 200 表示可用)

参数:无

20. get-health-status

功能:获取详细的健康状态评估

参数:无

21. get-version

功能:获取 Meilisearch 版本信息

参数:无

返回示例

1
2
3
4
5
{
"commitSha": "abc123",
"commitDate": "2025-10-01",
"pkgVersion": "v1.5.0"
}

22. get-stats

功能:获取数据库级别的统计信息

参数:无

返回示例

1
2
3
4
5
6
7
8
9
10
11
{
"databaseSize": 1048576,
"lastUpdate": "2025-10-14T00:00:00Z",
"indexes": {
"products": {
"numberOfDocuments": 10000,
"isIndexing": false,
"fieldDistribution": {}
}
}
}

23. get-system-info

功能:获取系统级别的详细信息

参数:无

配置方式

环境变量

1
2
3
4
5
# Meilisearch 服务器 URL
MEILI_HTTP_ADDR=http://localhost:7700

# Meilisearch 主密钥(可选,生产环境必需)
MEILI_MASTER_KEY=your-master-key-here

Claude Desktop 配置

claude_desktop_config.json 中添加:

1
2
3
4
5
6
7
8
9
10
11
12
{
"mcpServers": {
"meilisearch": {
"command": "uvx",
"args": ["meilisearch-mcp"],
"env": {
"MEILI_HTTP_ADDR": "http://localhost:7700",
"MEILI_MASTER_KEY": "your-master-key"
}
}
}
}

Docker 部署

1
2
3
4
5
6
7
8
9
10
11
12
13
# 启动 Meilisearch 服务器
docker run -d \
-p 7700:7700 \
-e MEILI_MASTER_KEY="masterKey" \
-v $(pwd)/meili_data:/meili_data \
getmeili/meilisearch:latest

# 启动 MCP 服务器
docker run -d \
-p 8000:8000 \
-e MEILI_HTTP_ADDR="http://localhost:7700" \
-e MEILI_MASTER_KEY="masterKey" \
getmeili/meilisearch-mcp:latest

本地运行

1
2
3
4
5
6
7
8
9
# 安装
pip install meilisearch-mcp

# 设置环境变量
export MEILI_HTTP_ADDR="http://localhost:7700"
export MEILI_MASTER_KEY="masterKey"

# 运行
uvx meilisearch-mcp

使用场景

1. 电商产品搜索

构建高性能的产品搜索引擎,支持即时搜索和复杂过滤。

示例流程

  1. 创建产品索引并配置搜索字段
  2. 批量导入商品数据
  3. 配置价格、分类等可过滤字段
  4. 实现即时搜索和分面导航

自然语言操作

1
2
3
4
"Create a 'products' index with 'sku' as primary key"
"Add 1000 products from the catalog"
"Configure price, category, and brand as filterable"
"Search for 'laptop' under $1500 in electronics category"

2. 文档知识库搜索

为企业文档和知识库提供智能搜索能力。

示例流程

  1. 创建文档索引
  2. 导入文档内容和元数据
  3. 配置多语言分词
  4. 实现语义相关性排序

自然语言操作

1
2
3
4
"Create a 'docs' index for technical documentation"
"Import 500 markdown documents with metadata"
"Enable Chinese word segmentation"
"Search for 'API authentication' and show top 10 results"

3. 内容发现平台

构建媒体、博客或新闻平台的内容搜索系统。

示例流程

  1. 索引文章标题、内容、标签
  2. 配置按发布日期排序
  3. 实现标签和分类过滤
  4. 支持近似搜索和拼写纠正

自然语言操作

1
2
3
4
"Create an 'articles' index with title, content, and tags"
"Add articles with publication dates"
"Search for 'machine lerning' (typo) and sort by date"
"Filter articles tagged with 'AI' from last month"

4. 实时搜索建议

为搜索框提供即时的自动补全和搜索建议。

示例流程

  1. 配置搜索词索引
  2. 设置低延迟搜索
  3. 返回热门搜索建议
  4. 跟踪搜索分析

自然语言操作

1
2
3
"Create a 'suggestions' index for search terms"
"Search for 'lap' and return top 5 suggestions"
"Track search analytics for 'laptop' queries"

5. 多租户 SaaS 搜索

为多租户应用提供隔离的搜索服务。

示例流程

  1. 为每个租户创建独立索引
  2. 配置租户级别的 API 密钥
  3. 实现数据隔离
  4. 监控各租户使用情况

自然语言操作

1
2
3
"Create index 'tenant-acme-products'"
"Create API key for tenant ACME with search-only access"
"Monitor search performance for all tenant indexes"

技术架构

搜索工作流程

1
2
3
4
5
6
7
8
9
用户查询 → Meilisearch MCP → Meilisearch Engine

分词 & 标准化

倒排索引查询

相关性排序

← 返回结果 ←

索引结构

1
2
3
4
5
6
7
8
9
10
11
Index
├── Documents (JSON 对象)
├── Settings
│ ├── Searchable Attributes (搜索字段)
│ ├── Filterable Attributes (过滤字段)
│ ├── Sortable Attributes (排序字段)
│ └── Ranking Rules (排序规则)
└── Statistics
├── Document Count
├── Index Size
└── Field Distribution

排序规则(默认)

  1. Words - 匹配单词数量
  2. Typo - 拼写错误容忍度
  3. Proximity - 单词邻近度
  4. Attribute - 字段权重
  5. Sort - 自定义排序
  6. Exactness - 精确匹配度

支持的数据类型

  • String - 文本内容
  • Number - 数值(整数和浮点数)
  • Boolean - 布尔值
  • Array - 数组
  • Object - 嵌套对象(扁平化处理)
  • Null - 空值

与其他搜索 MCP 服务器对比

特性 Meilisearch MCP Elasticsearch MCP Typesense MCP
即时搜索 ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
易用性 ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐
扩展性 ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐
内存占用
配置复杂度 简单 复杂 简单
容错搜索 ✅ 原生支持 ⚠️ 需配置 ✅ 原生支持
多语言 ✅ 30+ 语言 ✅ 分析器插件 ✅ 20+ 语言
适用场景 中小规模即时搜索 大规模复杂搜索 中规模快速搜索

最佳实践

1. 索引设计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 好的索引设计
{
"indexName": "products",
"primaryKey": "sku", # 使用业务主键
"settings": {
"searchableAttributes": [
"title", # 最重要的字段放在前面
"brand",
"description"
],
"filterableAttributes": [
"category", # 只索引需要过滤的字段
"price",
"inStock"
],
"sortableAttributes": [
"price",
"rating"
]
}
}

2. 搜索性能优化

1
2
3
4
5
6
7
8
9
10
11
12
// 限制返回字段,提升性能
{
"query": "laptop",
"attributesToRetrieve": ["title", "price", "thumbnail"],
"limit": 20
}

// 使用分面搜索,提升用户体验
{
"query": "laptop",
"facets": ["category", "brand", "priceRange"]
}

3. 批量操作

1
2
3
4
5
6
7
8
9
10
# 批量添加文档
documents = []
batch_size = 100

for item in large_dataset:
documents.append(item)
if len(documents) >= batch_size:
# 使用 add-documents 工具
add_documents(index="products", documents=documents)
documents = []

4. 多语言配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
"indexName": "multilang-docs",
"settings": {
"searchableAttributes": [
"title_en",
"title_zh",
"content_en",
"content_zh"
],
"stopWords": {
"en": ["the", "a", "an"],
"zh": ["的", "了", "在"]
}
}
}

5. 安全实践

1
2
3
4
5
6
7
8
9
10
# 生产环境配置
MEILI_MASTER_KEY="complex-master-key-xxxxx" # 使用强密钥

# 创建限制性 API 密钥
{
"name": "frontend-search",
"actions": ["search"], # 只允许搜索
"indexes": ["products"], # 只能访问特定索引
"expiresAt": "2026-01-01" # 设置过期时间
}

6. 监控和维护

1
2
3
4
5
6
7
8
9
# 定期检查索引健康
get-index-metrics(indexName: "products")

# 监控任务状态
get-tasks(limit: 100)

# 检查系统资源
get-stats()
get-system-info()

常见问题

Q: Meilisearch 与 Elasticsearch 的主要区别?

Meilisearch

  • 专注于即时搜索体验(< 50ms)
  • 开箱即用,配置简单
  • 内存占用低,适合中小规模
  • 容错搜索内置

Elasticsearch

  • 功能更全面,适合大规模
  • 配置复杂,学习曲线陡峭
  • 需要更多资源
  • 灵活性更高

Q: 如何部署生产级 Meilisearch?

1
2
3
4
5
6
7
8
9
10
11
12
13
# Docker Compose 示例
version: '3'
services:
meilisearch:
image: getmeili/meilisearch:latest
ports:
- "7700:7700"
environment:
- MEILI_MASTER_KEY=${MEILI_MASTER_KEY}
- MEILI_ENV=production
volumes:
- ./meili_data:/meili_data
restart: always

Q: 支持中文搜索吗?

完全支持!Meilisearch 内置中文分词器:

1
2
3
4
{
"searchableAttributes": ["title_zh", "content_zh"],
"stopWords": ["的", "了", "在", "是"]
}

Q: 如何实现搜索词高亮?

1
2
3
4
5
6
{
"query": "laptop",
"attributesToHighlight": ["title", "description"],
"highlightPreTag": "<mark>",
"highlightPostTag": "</mark>"
}

Q: 性能指标如何?

  • 索引速度: ~10,000 docs/秒(取决于文档大小)
  • 搜索延迟: < 50ms(单索引,< 1M 文档)
  • 并发处理: 支持数千 QPS
  • 内存占用: ~300MB 基础 + 文档大小

Q: 如何迁移现有数据?

1
2
3
4
5
6
7
8
9
10
11
# 从 JSON 文件导入
import json

with open('products.json') as f:
products = json.load(f)

# 使用 add-documents 工具批量导入
batch_size = 1000
for i in range(0, len(products), batch_size):
batch = products[i:i+batch_size]
# 调用 add-documents(index="products", documents=batch)

Q: 支持地理位置搜索吗?

目前不支持原生地理位置搜索,但可以通过以下方式实现:

  1. 将坐标存储为字段
  2. 使用过滤器进行范围查询
  3. 在应用层计算距离

评分详情

维度 评分 说明
功能性 4.7/5.0 完整的搜索引擎功能,即时搜索体验优秀
文档质量 4.8/5.0 官方文档详尽,示例丰富,中文支持好
社区活跃度 4.5/5.0 Meilisearch 官方维护,社区活跃
维护状态 4.6/5.0 持续更新,bug 修复及时
代码质量 4.5/5.0 代码规范,测试覆盖良好
综合评分 4.6/5.0 优秀的轻量级搜索引擎 MCP 实现

总结

Meilisearch MCP Server 是构建即时搜索体验的理想选择。它将专业级搜索引擎能力与简单易用的特性完美结合,特别适合需要快速搜索响应的应用场景。

推荐指数: ⭐⭐⭐⭐⭐ (5/5)

适合你的情况

  • ✅ 需要即时搜索体验(< 50ms)
  • ✅ 电商产品搜索
  • ✅ 文档和知识库搜索
  • ✅ 中小规模数据(< 10M 文档)
  • ✅ 容错搜索和拼写纠正
  • ✅ 多语言内容搜索

不适合的情况

  • ❌ 超大规模数据(> 100M 文档)
  • ❌ 复杂的聚合分析需求
  • ❌ 需要地理位置搜索
  • ❌ 需要 SQL 式复杂查询
  • ❌ 需要图数据库功能

相关资源


更新时间: 2025-10-14
数据来源: GitHub, 质量评分: 4.6/5.0

© 2026 Generative AI Discovery All Rights Reserved.
Theme by hiero