upsert_and_log
Finds or creates a custom food by name and logs it for a meal in one step, preventing duplicate entries and separate search, create, and log calls.
Instructions
Find-or-create a custom food then log it in one step
Searches the user's custom food library for food_name. If found, logs
it immediately. If not found, creates it with the provided nutrition
data and then logs it. This avoids duplicate food entries and removes
the need for separate search → create → log round-trips.
Matching is by food_name alone (case-insensitive) — brand_name never
affects find-or-create lookup, so it can't cause a duplicate by missing
an existing unbranded record. If an existing match is found, it is
logged as stored, using its first serving: calories, carbs, protein,
fat, brand_name, serving_unit and number_of_units are all ignored and
the stored food is not changed; only serving_qty applies. Those values
only take effect when creating a new food. To change an existing
food's nutrition, serving size or brand, use update_custom_food.
On an error after creation, custom_food_created is true and
write_committed describes the food log, not the library food. A failed
or exhausted lookup never triggers another create automatically.
Args:
meal_date: Date in YYYY-MM-DD format
meal_time: Time in HH:MM:SS format (account timezone); used to
determine the meal automatically
food_name: Name of the food to find or create
calories: Calories per serving (new food only)
carbs: Carbohydrates in grams per serving (new food only)
protein: Protein in grams per serving (new food only)
fat: Total fat in grams per serving (new food only)
brand_name: Brand or vendor name (new food only)
serving_unit: Unit for serving size (e.g. "G", "ML", "OZ"). Default "G"
(new food only)
number_of_units: Serving size in the specified unit. Default 100
(new food only)
serving_qty: Number of servings to log (default 1)
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"meal_date": "<meal_date>",
"meal_time": "<meal_time>",
"food_name": "<food_name>",
"calories": "<calories>"
},
"name": "upsert_and_log"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| fat | No | ||
| carbs | No | ||
| protein | No | ||
| calories | Yes | ||
| food_name | Yes | ||
| meal_date | Yes | ||
| meal_time | Yes | ||
| brand_name | No | ||
| serving_qty | No | ||
| serving_unit | No | G | |
| number_of_units | No |