Skip to main content
Glama
ayeyouok

a207-nutrition-calc-mcp

by ayeyouok
README.md
# a207-nutrition-calc-mcp

儿童慢性肾脏病(CKD)营养与食物计算 MCP 包,供 CKDNutri 项目的医生、营养师、家长三类智能体共用(M5 营养/食物计算器)。

依据:PRNT 2020(儿童 CKD 能量与蛋白 SDI)、Schofield 方程、腹膜透析葡萄糖吸收折算。

> 注意:本包**不提供**目标计算(原 `calc_nutrition_target` 已去重,目标计算统一由 M3 `calc_prnt_targets` 作为唯一权威引擎)。本包定位为纯食物层(查养分/份量换算/替换/磷蛋白比/腹透葡萄糖/药食交互)。

## 单位口径

- 能量:kcal;蛋白/钾/磷/钠:g 或 mg(食物成分表以 mg/100g 计);血电解质:mmol/L
- 体重:kg;身高:cm;年龄:岁(内部按月龄插值)

## 七个工具

| 工具 | 说明 |
|------|------|
| `lookup_food_nutrients` | 食物营养素查询,支持份量(碗/个/掌心/克)与烹饪降钾降磷处理,返回高钾/高磷/高钠警示 |
| `substitute_food` | 食物替换:低钾 / 低磷 / 低钠 / 低蛋白 / 等能量,优先同类食物候选 |
| `convert_to_household_measure` | 克 ↔ 家庭量具双向换算,附家长可感知锚点(鸡蛋/掌心瘦肉/牛奶/瓷勺油/碗饭) |
| `sum_diet_intake` | 多日饮食汇总,对比目标给出能量/蛋白达成率与钾磷钠来源排序及建议 |
| `calc_pnpr` | 磷蛋白比(mg P/g 蛋白)计算,辅助低磷食物优选 |
| `calc_pd_glucose_absorption` | 腹膜透析葡萄糖吸收量(按留腹时长 × 转运特性),折算 kcal |
| `check_drug_nutrient_interaction` | 药物-营养素交互提示(磷结合剂、活性维 D、利尿剂、激素、铁剂等) |

## 目录结构

```
a207-nutrition-calc-mcp/
├── pyproject.toml
├── README.md
├── src/a207_nutrition_calc_mcp/
│   ├── __init__.py
│   ├── core.py          # 7 工具门面(纯逻辑,无 MCP/pydantic 依赖)
│   ├── server.py        # FastMCP >=2 服务定义(8 个 @mcp.tool)
│   ├── models.py        # pydantic v2 入参模型(extra=forbid)
│   ├── constants.py     # 参考表与阈值
│   ├── targets.py       # 腹透葡萄糖吸收折算(目标计算已收归 M3)
│   ├── fooddb.py        # 食物数据访问与分级
│   ├── measures.py      # 家庭量具解析
│   ├── foods.py         # 查询/替换/换算/磷蛋白比
│   ├── diary.py         # 饮食汇总
│   ├── pharma.py        # 药物-营养素交互
│   └── data/food_data.csv
└── tests/test_tools.py
```

## 设计约束

- 不依赖、不 import 任何其它 `a207-*` 包(纯计算,无写权限)
- 结果可解释:返回 guideline 引用与规则依据
- 仅正向/边界/超时分支齐全,错误以 `{"ok": false, "error": ...}` 形式返回

## 运行与测试

```bash
# 编译(server.py/models.py 依赖 fastmcp/pydantic,仅做语法校验)
python -m py_compile src/a207_nutrition_calc_mcp/*.py

# 纯标准库自测(core 逻辑不依赖 fastmcp/pydantic,可独立运行)
python tests/test_tools.py
```

返回非零退出码表示存在失败用例。

## 启动 MCP 服务

```bash
pip install -e .
python -m a207_nutrition_calc_mcp.server
# 或
fastmcp dev src/a207_nutrition_calc_mcp/server.py
# 或(已注册 console script 后)
uvx --from . a207-nutrition-calc-mcp
```

TDQS

A3.8/5.0

Scored across 8 tools

Disambiguation5/5

Each tool serves a distinct purpose: target calculation, food lookup, substitution, measure conversion, intake summation, phosphorus ratio, dialysis glucose absorption, and drug interaction checking. There is no overlap or ambiguity between tool functions.

Naming Consistency5/5

All tool names follow a consistent snake_case verb_noun pattern (e.g., calc_nutrition_target, lookup_food_nutrients, substitute_food). The verbs are descriptive and uniform, making the toolset predictable and easy to navigate.

Tool Count5/5

With 8 tools, the server is well-scoped for its domain of pediatric CKD nutrition. Each tool adds meaningful functionality without redundancy, covering the essential calculators and data lookups needed for clinical and dietary management.

Completeness5/5

The toolset covers the full workflow: setting nutrition targets, looking up and substituting foods, converting measurements, summing intake against targets, and addressing special considerations like PD glucose absorption and drug interactions. No obvious gaps exist for the stated purpose.

Maintenance

ActivityMaintained
ResponsivenessSyncing