Skip to main content
Glama

add_or_update_meal_item

Add or update food items in meal logs with nutritional data for accurate fitness tracking.

Instructions

Add or update a food item within a meal.

The AI should first use OpenNutrition MCP to find food_id and get macros, then call this tool with the calculated values for the serving quantity.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYes
meal_nameYes
food_idYes
food_nameYes
serving_quantityYes
serving_unitYes
caloriesYes
protein_gYes
carbs_gYes
fats_gYes
fiber_gYes
brand_nameNo
gramsNo
notesNo
item_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The tool `add_or_update_meal_item` is implemented as a decorated function in `src/main.py`, which handles both the insertion of new meal items and updating of existing ones by interacting with the database.
    @app.tool()
    def add_or_update_meal_item(
        date: str,
        meal_name: str,
        food_id: str,
        food_name: str,
        serving_quantity: float,
        serving_unit: str,
        calories: float,
        protein_g: float,
        carbs_g: float,
        fats_g: float,
        fiber_g: float,
        brand_name: Optional[str] = None,
        grams: Optional[float] = None,
        notes: Optional[str] = None,
        item_id: Optional[int] = None,
    ) -> dict[str, int]:
        """Add or update a food item within a meal.
    
        The AI should first use OpenNutrition MCP to find food_id and get macros,
        then call this tool with the calculated values for the serving quantity.
        """
        date = _ensure_date(date)
        conn = get_connection()
        cursor = conn.cursor()
    
        # Ensure day and meal exist
        cursor.execute("INSERT OR IGNORE INTO nutrition_days (date) VALUES (?)", (date,))
        cursor.execute("SELECT id FROM nutrition_days WHERE date = ?", (date,))
        day_id = cursor.fetchone()[0]
    
        cursor.execute(
            "INSERT OR IGNORE INTO meals (day_id, name, order_index) VALUES (?, ?, 0)",
            (day_id, meal_name),
        )
        cursor.execute("SELECT id FROM meals WHERE day_id = ? AND name = ?", (day_id, meal_name))
        meal_id = cursor.fetchone()[0]
    
        if item_id:
            # Update existing item
            cursor.execute(
                """UPDATE meal_items SET
                   food_id=?, food_name=?, brand_name=?, serving_quantity=?, serving_unit=?,
                   grams=?, calories=?, protein_g=?, carbs_g=?, fats_g=?, fiber_g=?, notes=?
                   WHERE id=?""",
                (
                    food_id, food_name, brand_name, serving_quantity, serving_unit,
                    grams, calories, protein_g, carbs_g, fats_g, fiber_g, notes, item_id,
                ),
            )
        else:
            # Insert new item
            cursor.execute(
                """INSERT INTO meal_items (
                   meal_id, food_id, food_name, brand_name, serving_quantity, serving_unit,
                   grams, calories, protein_g, carbs_g, fats_g, fiber_g, notes
                ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)""",
                (
                    meal_id, food_id, food_name, brand_name, serving_quantity, serving_unit,
                    grams, calories, protein_g, carbs_g, fats_g, fiber_g, notes,
                ),
            )
            item_id = cursor.lastrowid
    
        conn.commit()
        conn.close()
        return {"item_id": item_id, "meal_id": meal_id, "day_id": day_id}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions that the tool 'adds or updates,' implying mutation, but doesn't disclose behavioral traits like permissions needed, whether updates are destructive or idempotent, error handling, or rate limits. The description adds minimal context beyond the basic action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence states the purpose, and the second provides usage guidelines. Every sentence earns its place with no wasted words, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (15 parameters, 11 required, no annotations) and the presence of an output schema (which reduces the need to explain return values), the description is partially complete. It covers purpose and usage but lacks details on parameters, behavioral traits, and error handling, leaving gaps for a mutation tool with many inputs.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It mentions 'calculated values for the serving quantity,' which hints at 'serving_quantity' and possibly 'calories,' 'protein_g,' etc., but doesn't explain the semantics of the 15 parameters (e.g., what 'date' format, what 'meal_name' options, the role of 'item_id'). The description adds limited meaning beyond the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Add or update a food item within a meal.' It specifies the verb ('add or update'), resource ('food item'), and context ('within a meal'). However, it doesn't explicitly differentiate from sibling tools like 'upsert_meal' or 'delete_meal_item', which would require a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit usage guidance: 'The AI should first use OpenNutrition MCP to find food_id and get macros, then call this tool with the calculated values for the serving quantity.' This specifies a prerequisite action (using another tool) and the timing of invocation, offering clear when-to-use instructions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JohnZolton/MCP-logger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server