nutrition_db
Generates personalized 7-day meal plans based on user profile and goals, and provides daily calorie catch-up suggestions when intake falls short.
README
🥗 MCP Nutrition - AI Meal Planner
Generate a personalized 7-day meal plan from your profile and goal, get daily calorie catch-up when you fall short, and track your progress over time. It runs as a FastAPI web app and, because the same engine is exposed over the Model Context Protocol (MCP), also as AI tools, resources, and prompts any MCP client (Claude Desktop, etc.) can use.
The intelligence is a deliberate blend:
- 🤖 OpenAI proposes concrete, varied meals for each day.
- 🥦 API Ninjas looks up macros for each food when your key returns them. Heads-up: the free API Ninjas tier gates
calories/protein, so in practice many values fall back to the bundled ~29-food catalog or an Atwater estimate (see Data & limits). - 🌤️ OpenWeather nudges calories/hydration for the day's conditions.
- 🧮 Deterministic Python computes the targets, keeps the LLM out of the arithmetic, reconciles each day to the calorie goal, and runs the catch-up math - the parts that are guaranteed and unit-tested.
Runs offline too: with no API keys, it falls back to a bundled food catalog + cache, so
git clone && runworks immediately.
Quickstart
# 1. Install (uv recommended)
uv sync --extra dev
# 2. (optional) add API keys for live LLM meals + real macros
cp .env.example .env # then edit .env
# 3. Run the web app
uv run uvicorn app.main:app --reload
# open http://127.0.0.1:8000
Prefer pip? python -m venv .venv && . .venv/Scripts/activate && pip install -e ".[dev]".
Environment (all optional)
| Key | Enables | Without it |
|---|---|---|
OPENAI_API_KEY |
LLM-generated meals | meals come from the bundled catalog |
API_NINJAS_KEY |
real macro numbers | macros come from cache / catalog |
OPENWEATHER_API_KEY |
weather-based adjustment | adjustment is skipped |
Run it as an MCP server
The planner is also a stdio MCP server named nutrition_db:
uv run nutrition-mcp # or: python -m mcp_server
Register it in an MCP client (e.g. Claude Desktop claude_desktop_config.json):
{
"mcpServers": {
"nutrition_db": {
"command": "uv",
"args": ["run", "nutrition-mcp"],
"cwd": "/absolute/path/to/MCP Nutrition"
}
}
}
It exposes all three MCP primitives, not just tools:
- Tools:
get_food_nutrients,get_current_conditions,compute_targets,generate_weekly_meal_plan,log_daily_intake,adjust_daily_calories. - Resources (read-only context):
nutrition://catalog,nutrition://profile,nutrition://targets,nutrition://log/today,nutrition://history. - Prompts (guided flows):
plan_my_week,log_my_meal,what_should_i_eat_now.
How it works
flowchart LR
UI["Web UI (form)"] -->|HTTP| API["FastAPI · app/"]
MCP["MCP client<br/>(Claude Desktop)"] -->|tools · resources · prompts| SRV["nutrition_db · mcp_server/"]
API --> CORE
SRV --> CORE
subgraph CORE["core/ engine - single source of truth"]
direction LR
T["targets<br/>(BMR→TDEE→goal)"] --> P["planner"]
P --> R["reconcile ±10%"]
ADJ["catch-up adjuster"]
H["history"]
end
P -->|propose foods| OA["OpenAI"]
P -->|ground macros| AN["API Ninjas"]
T -->|weather adjust| OW["OpenWeather"]
core/ is the single source of truth; the web app and the MCP server are thin layers over it.
See docs/DECISIONS.md for the design tradeoffs and roadmap.
Plan generation (core/planner.py), per day: OpenAI proposes foods → API Ninjas returns real
macros (cached) → deterministic code scales portions to hit the calorie target (±10%). A rolling
"avoid recently-used items" list keeps the week varied. No OpenAI key? The bundled catalog builds
the day instead.
Calorie catch-up (core/adjuster.py): compares logged intake to target. If you're under, it
suggests catch-up foods for the meals you have left today, or rolls a capped portion of the
shortfall into tomorrow. (This is the opposite of naively lowering the goal when you under-eat.)
Targets (core/targets.py): Mifflin-St Jeor BMR → activity TDEE → goal adjustment
(-500 weight loss / +300 muscle gain) → macro split.
Project layout
core/ deterministic engine + service facade + API/LLM clients (the brains)
mcp_server/ nutrition_db MCP server (tools + resources + prompts over core/)
app/ FastAPI backend + minimal web UI (form, plan, catch-up, progress chart)
data/ food_catalog.json (fallback), nutrition_cache.json, state.json (runtime)
evals/ plan-quality eval harness + SCORECARD.md (python -m evals)
docs/ DECISIONS.md (design tradeoffs & roadmap)
tests/ pytest suite (targets, planner, adjuster, allergens, service, evals)
Testing & evals
uv run pytest -q # 34 tests
uv run ruff check .
uv run python -m evals # regenerate evals/SCORECARD.md
Tests run the real engine in offline mode (deterministic via the catalog) and use small fakes to exercise the LLM path without a network call.
Plan-quality evals (evals/, scorecard: evals/SCORECARD.md)
score generated plans across a golden set of profiles (goals × diets × allergies) on calorie
adherence, 100% allergen safety, protein adequacy, diet compliance, and variety. CI gates the
non-negotiables - measuring a non-deterministic LLM system, not just unit-testing pure functions.
Data & limits
Be clear-eyed about what this does and doesn't guarantee:
- Macro source. Authoritative macros come from API Ninjas only when your key returns them. On the free tier
calories/proteinare premium-gated, so values fall back to the curated ~29-food catalog (data/food_catalog.json) or an Atwater (4/4/9) estimate. The bundled catalog is what makes offline mode work. - "On target" means calories. Days are reconciled to the calorie target (±10%); protein/carb/fat are shown as guidance and a day is flagged when protein runs low, but macros aren't enforced.
- Allergens. Typed allergies are expanded to ingredient keywords (
core/allergens.py) and excluded from catalog, LLM-proposed, and catch-up foods - but it's best-effort keyword matching, not a medical guarantee. Verify ingredients yourself. - Not medical advice. Estimates only; not for pregnancy, medical conditions, or disordered eating. Single-user, local state; no accounts or sync.
Provenance
This started as an MCP nutrition benchmark server and grew into a standalone product. All code here is original work by harmehak0173; it has no dependency on the original benchmark framework.
License
MIT © 2026 harmehak0173 - see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。