Add recipe creation functions - #43
Merged
Merged
Conversation
# Conflicts: # src/cronometer_api_mcp/client.py # tests/test_client.py
Contributor
Author
|
Thanks for reviewing and merging. Glad this was useful |
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.
What
create_recipe(name, ingredients=[(food_id, grams), ...])on the client,plus an
add_recipeMCP tool.How the payload shape was established
Recipes go through the existing
/api/v2/add_foodendpoint — what makes afood a recipe is the presence of an
ingredientsarray. I confirmed thatrather than assuming it.
Shape came from decoding the web app's GWT-RPC
addFood/editFoodcallsacross five captures (serving-based and weight-based, simple and advanced
serving sizes), then reading the results back through this client to see
how the mobile API represents the same food. I did not attempt to intercept
the mobile app.
Verified with one POST and a read-back diff (food 79474948):
grams all preserved, with server-assigned row IDs
defaultMeasureIdsent as 0 comes back assigned from the first measurein the array
the account's catalog
sending it is advisory
sourceandownersent as null come back set correctlyDesign notes
Weight-based rather than serving-based. Cronometer supports both: serving-
based recipes use
type: "Recipe"measures and store nutrients per batch,which is what makes the diary's
gramsfield a serving count — the quirkenrich_diary_servingsalready handles. Weight-based usestype: "Weight"measures with nutrients per-100g, matching
create_custom_food's existingconvention and avoiding that quirk entirely.
Ingredients are
(food_id, grams). The measure ID is display metadata —Cronometer renders the amount as grams / measure value — so it's resolved
automatically to the food's gram measure. A three-tuple overrides it where
that matters.
One batched
get_foodsresolves every ingredient. Unresolvable IDs raiserather than being silently dropped. Input is validated before any network
call, so a malformed tuple fails fast.
Tests
Five: payload shape (ingredients, weight-based measures, per-100g
aggregation), explicit serving size and comments, measure-ID override,
input validation, and missing-food handling. Plus
add_recipeadded to thetool-registry set — which caught the omission on its first run.