scale_recipe
Adjust recipe ingredient quantities to match desired serving sizes. Input a recipe name and target servings to calculate precise measurements.
Instructions
Scales a recipe for a different number of servings.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| recipe_name | Yes | ||
| servings | Yes |
Implementation Reference
- main.py:190-193 (registration)Registers the 'scale_recipe' tool with the MCP framework using the @mcp.tool decorator, specifying the name and description.@mcp.tool( name="scale_recipe", description="Scales a recipe for a different number of servings.", )
- main.py:194-212 (handler)The main handler function for the 'scale_recipe' tool. It finds a recipe by name from the Christmas recipes list, scales the ingredient quantities (assuming gram units) proportional to the new number of servings, updates the recipe object, and returns the scaled recipe as a dictionary. Returns an error if the recipe is not found.async def scale_recipe(recipe_name: str, servings: int) -> Dict: """Met à l'échelle une recette pour un nombre de personnes différent.""" for recipe in christmas_recipes(): if recipe.name.lower() == recipe_name.lower(): scaled_ingredients = {} for ingredient, quantity in recipe.ingredients.items(): try: # Simple scaling, may not work for all units amount, unit = quantity.split("g") scaled_amount = (int(amount) / recipe.servings) * servings scaled_ingredients[ingredient] = f"{scaled_amount:.0f}g" except ValueError: scaled_ingredients[ingredient] = quantity # Cannot scale scaled_recipe = recipe.model_copy() scaled_recipe.servings = servings scaled_recipe.ingredients = scaled_ingredients return scaled_recipe.model_dump() return {"error": "Recette non trouvée."}