Repository navigation
Refuse quantity-led serving names in add/update_custom_food - #3
Merged
Merged
Conversation
update_custom_food quietly split a leading number off serving_name
("2 cookies" became "cookies" x 2), while add_recipe/update_recipe refuse
the same input. Guessing the server's name parser proved fragile (mixed
numbers, "8 fl oz", unicode fractions), so both tools now fail fast through
one shared _serving_name helper: the number goes in serving_quantity.
Drops _QUANTITY_LED_NAME and its splitting branch. Resizing a custom food
still resets the quantity to serving_quantity (or 1), as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ColinToft
force-pushed
the
colin/unify-serving-names
branch
from
October 12, 2026 23:10
5bc2ca7 to
f46d115
Compare
create_custom_food defaulted to "1 serving" and relied on the server to split the number off a new measure's name. It now takes serving_quantity (default 1, sent as the measure's amount), defaults the name to "serving", and runs both through the same checks as the edit tools before any request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A serving_grams of 0 or less used to fall back to a scale of 1, storing the per-serving numbers as per-100g. It is now checked with _check_positive before any request, like update_custom_food (NaN and inf are refused too). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Split _settle_recipe_serving into a shared _settle_serving (read the serving back, re-send once if the server re-parsed its name, raise if it still doesn't match) plus the recipe-only nutrient-derivation check. create_custom_food now uses it, so "serving (1/2 batch)" no longer comes back as 0.5 x "batch)", and it returns the real measure_id (the add_custom_food tool no longer re-fetches the food for it). - update_custom_food raises instead of falling back to 100 g or a scale of 1 when the default serving's weight isn't a positive finite number, and refuses serving or nutrient edits on a food with no serving measure. - Share _is_positive_number between _check_positive and diary enrichment. - serving_grams docstrings: total weight of all serving_quantity units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- create_custom_food and create_recipe index defaultMeasureId directly. - _default_measure returns None only for a food with no measures, and raises when defaultMeasureId matches none, instead of quietly using the first measure. - Tests for create's failure paths after the food exists: a failing read-back, a failing re-send, and a read-back missing the default measure or its id all raise with the food's id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
update_custom_foodsplit a leading number offserving_name("2 cookies" became "cookies" × 2); the recipe tools refuse it. Nowadd_custom_foodandupdate_custom_foodfail fast too, via one shared_serving_name: the number goes inserving_quantity._QUANTITY_LED_NAME.add_custom_foodgainsserving_quantity(default 1); default name "serving".create_custom_foodnow settles its serving likecreate_recipe(shared_settle_serving): a name the server re-parses, e.g. "serving (1/2 batch)", is re-sent once. It returns the realmeasure_id.serving_quantity(or 1), as upstream update_custom_food: set the default serving's quantity rwestergren/cronometer-api-mcp#66 does.amount.Behaviour change: names like "0 calorie syrup" or "1/2 cup" are now refused, matching the recipe tools.
serving_gramsof 0 or less, NaN or inf is refused.update_custom_foodraises when the stored serving weight is unusable, the food has no serving, or its default measure id matches none, instead of falling back.🤖 Generated with Claude Code