使用说明
Mealie MCP服务器
MCP服务器,用于与Mealie配方管理器实例交互。提供自然语言配方搜索、配方管理和导入功能。
特性
- 自然语言搜索 -按配料、食谱名称、来源(纽约时报、波拿巴)、时间限制进行搜索
- 智能缓存 -具有TTL的LRU缓存,可最大限度地减少API调用
- 连接池 -具有重试逻辑的持久HTTP连接
- 食谱管理 -创建、更新、从URL导入、应用标签、删除
- 灵活的配方更新 -修改任何配方字段(名称、成分、说明、时间、注释)
- HTTP/SSE传输 -作为持久服务运行,不需要SSH
需求
- Python 3.10+
- 具有API访问权限的Mealie实例
- Mealie的API代币(设置>API代币)
安装
本地开发
cp .env.example .env
# Edit .env with your Mealie URL and API key
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
# Run directly (stdio mode)
./run.sh
# Or with HTTP/SSE transport
mcp-proxy --port=8096 python3 server.py
部署到服务器
./deploy.sh
这将:
- 将文件复制到
/opt/mcp-servers/mealie/在服务VM上 - 创建Python venv并安装依赖项
- 安装并启动systemd服务
- 服务器监听端口8096
配置
环境变量(in .env):
| 变量 | 描述 |
|---|---|
MEALIE_URL |
Mealie实例URL(例如。, http://192.168.2.100:9000) |
MEALIE_API_KEY |
Mealie设置中的API令牌 |
MEALIE_USERNAME |
(可选)组段塞查找的用户名 |
MEALIE_PASSWORD |
(可选)组段符查找密码 |
Claude桌面配置
HTTP/SSE模式(建议用于远程服务器)
添加 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"mealie": {
"command": "npx",
"args": ["-y", "mcp-remote", "http://192.168.2.100:8096/sse", "--allow-http"]
}
}
}
注: 这 --allow-http 非HTTPS URL需要标记。
直接标准模式(本地开发)
{
"mcpServers": {
"mealie": {
"command": "/Users/bgrane/Claude/mcp-servers/mealie-mcp/run.sh"
}
}
}
端点
| 网络 | URL |
|---|---|
| 本地 | http://192.168.2.100:8096/sse |
| 尾秤 | http://100.78.245.24:8096/sse |
可用工具(共27个)
食谱管理
| 工具 | 说明 |
|---|---|
search_recipes |
自然语言食谱搜索 |
get_recipe |
通过slug获取完整的食谱细节 |
list_recipes |
按页码列出食谱 |
get_random_recipe |
获取随机食谱建议 |
create_recipe |
手动创建新配方 |
create_recipe_from_url |
从URL导入配方 |
update_recipe |
更新配方字段(名称、成分、说明、时间等) |
apply_tags |
将标签应用于食谱 |
delete_recipe |
删除配方 |
膳食计划
| 工具 | 说明 |
|---|---|
get_todays_meals |
今天有什么计划 |
get_meal_plan |
查看即将到来的用餐计划 |
plan_meal |
将食谱添加到膳食计划中 |
plan_random_meal |
在用餐计划中添加随机食谱 |
购物单
| 工具 | 说明 |
|---|---|
get_shopping_lists |
列出所有购物清单 |
get_shopping_list |
从购物清单中获取商品 |
add_to_shopping_list |
将商品添加到购物清单 |
add_recipe_to_shopping_list |
将食谱配料添加到列表中 |
组织
| 工具 | 说明 |
|---|---|
list_tags |
列出可用标签 |
get_recipes_by_tag |
获取带有特定标签的食谱 |
get_categories |
列出食谱类别 |
get_recipes_by_category |
在某个类别中获取食谱 |
get_cookbooks |
列出食谱集合 |
get_cookbook_recipes |
在烹饪书中获取食谱 |
get_favorites |
获取喜爱的食谱 |
公用事业
| 工具 | 说明 |
|---|---|
health_check |
检查服务器和API连接 |
get_statistics |
Mealie实例统计 |
clear_cache |
清除所有缓存数据 |
MCP提示
服务器包括提示,教克劳德如何在上下文中使用这些工具:
| 提示 | 目的 |
|---|---|
mealie_assistant |
一般指南:将自然需求映射到适当的工具 |
weekly_meal_planning |
规划一周三餐的分步工作流程 |
whats_for_dinner |
“我应该做什么?”问题的快速响应流程 |
连接后,Claude Desktop会自动使用这些提示。
用法示例
搜索
"chicken recipes" - Find recipes with chicken
"quick under 30 min" - Fast recipes
"garlic" - Search by ingredient
"nytimes" - Search by source
"pasta dinner" - Multiple terms
膳食计划
"What's for dinner tonight?" - get_todays_meals
"Plan my meals for the week" - get_meal_plan
"Add a random dinner for Friday" - plan_random_meal
"Add chicken piccata to Tuesday" - plan_meal
购物
"Show me my shopping list" - get_shopping_list
"Add chicken stir fry to my list" - add_recipe_to_shopping_list
"Add milk to shopping list" - add_to_shopping_list
更新食谱
这 update_recipe 该工具允许修改现有配方的任何字段。仅更改您指定的字段;其他人则保持不变。
参数:
| 参数 | 类型 | 说明 |
|---|---|---|
slug |
string | 配方段塞(必填) |
name |
string | 新配方名称 |
description |
string | 新描述 |
ingredients |
list[str] | 新成分列表(替换所有现有成分) |
instructions |
list[str] | 新指令步骤(替换所有现有步骤) |
prep_time |
string | 准备时间(例如“15分钟”) |
cook_time |
string | 烹饪时间(例如“30分钟”) |
total_time |
string | 总时间 |
servings |
string | 产量(例如,“4份”) |
notes |
list[str] | 配方注释(替换所有现有的) |
示例:
# Fix a typo in the recipe name
update_recipe(slug="chiken-piccata", name="Chicken Piccata")
# Update cooking time
update_recipe(slug="beef-stew", cook_time="2 hours", total_time="2 hours 30 minutes")
# Replace ingredients (useful for scaling or substitutions)
update_recipe(
slug="pancakes",
ingredients=[
"2 cups flour",
"2 eggs",
"1.5 cups milk",
"2 tbsp melted butter",
"1 tbsp sugar",
"1 tsp baking powder"
],
servings="8 pancakes"
)
# Add cooking notes
update_recipe(
slug="grilled-salmon",
notes=[
"Works great with cedar planks",
"Let rest 5 minutes before serving"
]
)
# Complete recipe overhaul
update_recipe(
slug="basic-pasta",
name="Garlic Butter Pasta",
description="Simple weeknight pasta with garlic butter sauce",
ingredients=["1 lb spaghetti", "4 cloves garlic", "1/2 cup butter", "Parmesan"],
instructions=[
"Cook pasta according to package directions",
"Mince garlic and sauté in butter until fragrant",
"Toss pasta with garlic butter",
"Top with freshly grated Parmesan"
],
prep_time="5 minutes",
cook_time="15 minutes",
servings="4 servings"
)
它是如何工作的:
- 从Mealie获取当前食谱
- 将您的更改合并到配方对象中
- 通过PUT请求发回更新的配方
- 使缓存无效,以便后续读取获得新数据
服务管理
# View status
ssh services "systemctl status mealie-mcp"
# View logs
ssh services "journalctl -u mealie-mcp -f"
# Restart
ssh services "systemctl restart mealie-mcp"
# Stop
ssh services "systemctl stop mealie-mcp"
建筑
Claude Desktop
│
├── (Option A: HTTP/SSE - recommended)
│ └── mcp-remote ─────► mcp-proxy (port 8096)
│ │
│ └── server.py (stdio)
│
└── (Option B: Direct stdio - local only)
└── run.sh ─────► server.py
│
▼
Mealie API
(http://192.168.2.100:9000)
安全说明
当前实现通过命令行参数传递API键,这使其在进程列表中可见(ps aux).对于家庭实验室环境,这是可以接受的,但对于更敏感的部署,请考虑:
- 使用systemd
LoadCredential指令 - 在运行时从文件中读取凭据
- 使用秘密管理器
故障排除
约24小时后连接超时(旧SSH方法)
- 这就是为什么我们现在使用HTTP/SSE传输
- 如果系统服务崩溃,它会自动重新启动
配料搜索“未找到食谱”
- 第一次搜索在构建缓存时可能很慢
- 尝试
clear_cache然后再次搜索
日志中的身份验证错误
- 组段符查找使用用户名/密码
- 如果未配置,则默认为“home”(通常可以)
- 仅影响配方URL构建,不影响API访问
发展
# Run tests
cd ~/Claude/mcp-servers/mealie-mcp
source venv/bin/activate
source .env && export MEALIE_URL MEALIE_API_KEY
python3 -c "from server import health_check; print(health_check())"