Skip to main content
Glama

upsert_meal

Create or update a meal entry within a nutrition day for fitness tracking, enabling food logging and nutrition management in the MCP Logger server.

Instructions

Create or update a meal within a nutrition day.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dateYes
nameYes
order_indexNo

Implementation Reference

  • Implementation of the upsert_meal tool which creates or updates a meal entry within a specific nutrition day.
    def upsert_meal(date: str, name: str, order_index: int = 0) -> dict[str, int]:
        """Create or update a meal within a nutrition day."""
        date = _ensure_date(date)
        conn = get_connection()
        cursor = conn.cursor()
    
        # Ensure day exists
        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]
    
        # Upsert meal
        cursor.execute(
            """INSERT INTO meals (day_id, name, order_index) VALUES (?, ?, ?)
               ON CONFLICT(day_id, name) DO UPDATE SET order_index = ?""",
            (day_id, name, order_index, order_index),
        )
        meal_id = cursor.lastrowid or cursor.execute(
            "SELECT id FROM meals WHERE day_id = ? AND name = ?", (day_id, name)
        ).fetchone()[0]
    
        conn.commit()
        conn.close()
        return {"meal_id": meal_id}

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