一个用于通过Claude等LLM接口与Meilisearch交互的模型上下文协议(MCP)服务器。
# 克隆仓库
git clone <repository_url>
cd meilisearch-mcp
# 创建虚拟环境并安装
uv venv
source .venv/bin/activate # 在Windows上:.venv\Scripts\activate
uv pip install -e .
# 安装开发依赖(用于测试和开发)
uv pip install -r requirements-dev.txt

启动Meilisearch服务器:
# 使用Docker(推荐用于开发)
docker run -d -p 7700:7700 getmeili/meilisearch:v1.6
# 或者使用brew(macOS)
brew install meilisearch
meilisearch
# 或者从https://github.com/meilisearch/meilisearch/releases下载

安装开发工具:
# 安装uv用于Python包管理
pip install uv
# 安装Node.js用于MCP Inspector测试
# 访问https://nodejs.org/或使用你的包管理器

该项目包括全面的集成测试,验证MCP工具的功能:
# 运行所有测试
python -m pytest tests/ -v
# 运行特定测试文件
python -m pytest tests/test_mcp_client.py -v
# 运行测试并生成覆盖率报告
python -m pytest --cov=src tests/
# 在监视模式下运行测试(需要pytest-watch)
pytest-watch tests/

重要提示:测试需要在http://localhost:7700
上运行Meilisearch实例。测试将:
# 使用Black格式化代码
black src/ tests/
# 运行类型检查(如果配置了mypy)
mypy src/
# 代码检查(如果配置了flake8)
flake8 src/ tests/

MEILI_HTTP_ADDR=http://localhost:7700 # 默认Meilisearch URL
MEILI_MASTER_KEY=your_master_key # 可选:默认Meilisearch API密钥

服务器提供了在运行时查看和更新连接设置的工具:
get-connection-settings
:查看当前连接URL和API密钥状态update-connection-settings
:更新URL和/或API密钥以连接到不同的Meilisearch实例通过MCP的示例用法:
// 获取当前设置
{
"name": "get-connection-settings"
}
// 更新连接设置
{
"name": "update-connection-settings",
"arguments": {
"url": "http://new-host:7700",
"api_key": "new-api-key"
}
}

服务器提供了一个灵活的搜索工具,可以在一个或所有索引中搜索:
search
:通过Meilisearch索引进行搜索,可选参数通过MCP的示例用法:
// 在特定索引中搜索
{
"name": "search",
"arguments": {
"query": "搜索词",
"indexUid": "movies",
"limit": 10
}
}
// 在所有索引中搜索
{
"name": "search",
"arguments": {
"query": "搜索词",
"limit": 5,
"sort": ["releaseDate:desc"]
}
}

可用的搜索参数:
query
:搜索查询(必需)indexUid
:要搜索的特定索引(可选)limit
:每个索引的最大结果数(可选,默认:20)offset
:要跳过的结果数(可选,默认:0)filter
:过滤表达式(可选)sort
:排序规则(可选)python -m src.meilisearch_mcp
要与Claude Desktop一起使用,请将以下内容添加到你的claude_desktop_config.json
中:
{
"mcpServers": {
"meilisearch": {
"command": "uvx",
"args": ["-n", "meilisearch-mcp"]
}
}
}

npx @modelcontextprotocol/inspector python -m src.meilisearch_mcp
get-connection-settings
:查看当前Meilisearch连接URL和API密钥状态update-connection-settings
:更新URL和/或API密钥以连接到不同的实例create-index
:创建一个带有可选主键的新索引list-indexes
:列出所有可用索引delete-index
:删除现有索引及其所有文档get-index-metrics
:获取特定索引的详细指标get-documents
:从索引中检索文档,支持分页add-documents
:在索引中添加或更新文档search
:在单个或多个索引中进行灵活搜索,支持过滤和排序选项get-settings
:查看索引的当前设置update-settings
:更新索引设置(排名、分面等)get-keys
:列出所有API密钥create-key
:创建具有特定权限的新API密钥delete-key
:删除现有API密钥get-task
:获取特定任务的信息get-tasks
:列出任务,支持可选过滤器:
limit
:要返回的最大任务数from
:要跳过的任务数reverse
:任务的排序顺序batchUids
:按批次UID过滤uids
:按任务UID过滤canceledBy
:按取消来源过滤types
:按任务类型过滤statuses
:按任务状态过滤indexUids
:按索引UID过滤afterEnqueuedAt
/beforeEnqueuedAt
:按入队时间过滤afterStartedAt
/beforeStartedAt
:按开始时间过滤afterFinishedAt
/beforeFinishedAt
:按完成时间过滤cancel-tasks
:取消挂起或已入队的任务delete-tasks
:删除已完成的任务health-check
:基本健康检查get-health-status
:综合健康状态get-version
:获取Meilisearch版本信息get-stats
:获取数据库统计信息get-system-info
:获取系统级信息我们欢迎贡献!请遵循以下指南:
main
创建功能分支# 创建功能分支
git checkout -b feature/你的功能名称
# 进行更改,先编写测试
# 编辑文件...
# 运行测试以确保一切正常
python -m pytest tests/ -v
# 格式化代码
black src/ tests/
# 提交并推送
git add .
git commit -m "添加功能描述"
git push origin feature/你的功能名称

该项目使用自动版本控制和发布到PyPI。发布流程设计为简单且自动化。
自动发布:当pyproject.toml
中的版本号在main
分支上更改时,GitHub Action会自动:
版本检测:工作流会比较pyproject.toml
中的当前版本与之前的提交,以检测更改
PyPI发布:使用PyPA的官方发布操作,支持可信发布(无需手动API密钥)
要创建新版本,请按照以下步骤操作:
遵循语义版本控制(MAJOR.MINOR.PATCH):
# 1. 从最新的main创建分支
git checkout main
git pull origin main
git checkout -b release/v0.5.0
# 2. 更新pyproject.toml中的版本
# 将version = "0.4.0"行更新为你的新版本
# 3. 提交并推送
git add pyproject.toml
git commit -m "版本升级到0.5.0"
git push origin release/v0.5.0
# 4. 创建PR并获取审核/合并
gh pr create --title "发布v0.5.0" --body "版本升级发布"

一旦PR被批准并合并到main
,GitHub Action将自动:
pip install meilisearch-mcp
可用合并后,验证发布:
# 检查GitHub Action状态
gh run list --workflow=publish.yml
# 在PyPI上验证(可能需要几分钟)
pip index versions meilisearch-mcp
# 测试新版本的安装
pip install --upgrade meilisearch-mcp

自动发布由.github/workflows/publish.yml
处理,它:
main
分支时触发pyproject.toml
版本是否更改发布未触发:检查pyproject.toml
中的版本是否在提交之间实际更改
构建失败:检查GitHub Actions日志以查找Python包构建错误
PyPI发布失败:验证包名称并确保可信发布配置正确
版本冲突:确保新版本号在PyPI上未被使用过
pip install -e .
pip install meilisearch-mcp
pip install meilisearch-mcp==0.5.0
安装MIT