使用说明
Mealie MCP服务器
A. 模型上下文协议(MCP) 使AI助手能够与之交互的服务器 米莉 用于食谱管理、膳食计划和购物清单。
特性
工具(共31个)
食谱
mealie_recipes_search-按名称、标签或类别搜索食谱mealie_recipes_get-获取完整的食谱细节,包括配料和说明mealie_recipes_list-按页码列出所有食谱mealie_recipes_create-创建新配方mealie_recipes_create_from_url-通过抓取URL导入食谱mealie_recipes_update-更新现有配方mealie_recipes_update_structured_ingredients-使用解析器中的结构化成分更新配方mealie_recipes_delete-删除配方
膳食计划
mealie_mealplans_list-列出一个日期范围的用餐计划mealie_mealplans_today-获取今天的餐点mealie_mealplans_get-获取具体的膳食计划条目mealie_mealplans_get_date-为特定日期准备餐点mealie_mealplans_create-创建膳食计划条目mealie_mealplans_update-更新膳食计划条目mealie_mealplans_delete-删除膳食计划条目mealie_mealplans_random-获取随机用餐建议
购物单
mealie_shopping_lists_list-列出所有购物清单mealie_shopping_lists_get-获取包含商品的购物清单mealie_shopping_lists_create-创建新的购物清单mealie_shopping_lists_delete-删除购物清单mealie_shopping_items_add-将项目添加到列表mealie_shopping_items_add_bulk-一次添加多个项目mealie_shopping_items_check-标记项目已选中/未选中mealie_shopping_items_delete-从列表中删除项目mealie_shopping_add_recipe-将食谱配料添加到列表中mealie_shopping_generate_from_mealplan-根据用餐计划生成购物清单mealie_shopping_clear_checked-清除所有选中的项目
成分解析
mealie_parser_ingredient-将单一成分字符串解析为结构化格式mealie_parser_ingredients_batch-一次解析多个成分字符串
资源
recipes://list-浏览所有食谱recipes://{slug}-查看特定食谱mealplans://current-本周的用餐计划mealplans://today-今天的饭菜mealplans://{date}-特定日期的餐食shopping://lists-所有购物清单shopping://{list_id}-具体购物清单
先决条件
- Docker(或Podman)
- 正在运行的Mealie实例
- Mealie API代币
快速开始
1.获取Docker镜像
选项A:从GitHub容器注册表中提取(推荐)
docker pull ghcr.io/mdlopresti/mealie-mcp:latest
选项B:从源代码构建
git clone https://github.com/mdlopresti/mealie-mcp.git
cd mealie-mcp
docker build -t mealie-mcp:latest .
2.获取您的API代币
- 登录您的Mealie实例
- 首选 用户设置 (点击侧边栏中的姓名)
- 导航到 API令牌
- 创建新令牌(例如“MCP服务器”)
- 立即复制令牌(不会再次显示)
3.配置克劳德代码
添加 .mcp.json 在项目根目录中:
{
"mcpServers": {
"mealie": {
"command": "docker",
"args": [
"run", "-i", "--rm",
"-e", "MEALIE_URL=https://your-mealie-instance.com",
"-e", "MEALIE_API_TOKEN=your-api-token-here",
"ghcr.io/mdlopresti/mealie-mcp:latest"
]
}
}
}
然后添加 mealie 给你的 ~/.claude/settings.json:
{
"allowedMcpServers": [
{ "serverName": "mealie" }
]
}
4.测试连接
重新启动Claude Code并尝试:
Can you search for recipes in Mealie?
使用示例
清除可选字段
要清除可选字段(删除其值),请传递特殊的哨兵值 "__CLEAR__":
# Remove recipe association from a meal plan entry
mealie_mealplans_update(
mealplan_id="abc-123",
recipe_id="__CLEAR__"
)
# Clear the title from an entry
mealie_mealplans_update(
mealplan_id="abc-123",
title="__CLEAR__"
)
# Clear the text/notes from an entry
mealie_mealplans_update(
mealplan_id="abc-123",
text="__CLEAR__"
)
# Clear multiple fields at once
mealie_mealplans_update(
mealplan_id="abc-123",
recipe_id="__CLEAR__",
title="__CLEAR__",
text="__CLEAR__"
)
要保持字段不变,只需在调用中省略它:
# Update only the date, preserving all other fields
mealie_mealplans_update(
mealplan_id="abc-123",
meal_date="2025-12-25"
)
发展
本地开发(无Docker)
# Create virtual environment
python -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export MEALIE_URL=https://your-mealie-instance.com
export MEALIE_API_TOKEN=your-api-token
# Run server
python -m src.server
运行测试
单元/集成测试 (模拟API,始终运行):
# Run all tests except E2E
pytest -m "not e2e"
# Run all tests with coverage
pytest --cov=src --cov-report=term-missing
端到端测试 (可选):
E2E测试针对真实的Mealie实例进行验证。支持两种模式:
Docker E2E测试 (推荐-隔离环境):
# Install test dependencies
pip install -r requirements-dev.txt
# Run Docker E2E tests
pytest tests/e2e/test_docker_e2e.py -v
# These tests:
# - Start a containerized Mealie instance automatically
# - Run tests in isolated environment
# - Clean up containers and data after tests
# - Require Docker/Podman to be running
实时实例E2E测试 (对现有服务器进行测试):
# Set required environment variables
export MEALIE_E2E_URL="https://your-mealie-instance.com"
export MEALIE_E2E_TOKEN="your-test-api-token"
# Run E2E tests against live instance
pytest -m e2e
# These tests are skipped if environment variables are not set
看 tests/e2e/README.md 获取详细的E2E测试文档。
注意:实时实例E2E测试创建和删除测试资源。使用测试/开发实例,而不是生产实例!
项目结构
mealie-mcp/
├── Dockerfile # Container definition
├── requirements.txt # Python dependencies
├── build.sh # Build helper script
└── src/
├── server.py # MCP server entry point
├── client.py # Mealie API client
├── tools/ # MCP tool implementations
│ ├── recipes.py
│ ├── mealplans.py
│ ├── shopping.py
│ └── parser.py
└── resources/ # MCP resource implementations
├── recipes.py
├── mealplans.py
└── shopping.py
安全
- 永远不要提交API令牌 -使用环境变量
- API代币可以完全访问您的Mealie帐户
- 考虑为MCP服务器创建一个专用的Mealie用户
需求
- Python 3.12+
- Mealie v1.0+(使用v3.6.1测试)
许可证
麻省理工学院
贡献
欢迎投稿!请打开问题或PR。