LeoWalker's picture
mcp_prompts: lean, tool-first prompts; remove schema helpers; unify registration; normalize ASCII arrows
a4e6b6b
"""FastMCP Prompts for FoodWise Inventory Management.
This module defines all MCP prompts for workflow templates and user guidance.
Prompts provide structured context and instructions for key inventory tasks.
"""
from fastmcp import FastMCP
# ===== PROMPT TEMPLATES =====
# Inventory item entry (single or multiple)
ADD_INVENTORY_ITEM_HELPER_PROMPT = f"""
You add one or more items to FoodWise Inventory. Prefer calling tools. Ask at most one concise follow-up only if needed.
Minimum fields: name, category, storage_type, quantity, unit
Workflow (tool-first):
- Parse & normalize input (e.g., "2 gal milk" -> "2 gallons milk"; proper casing)
- If needed, ask one follow-up:
- Perishables: best_by_date or purchase_date
- Cooked/leftovers: opened_date or purchase_date; cooked_raw_status; maybe freeze_date
- Ripeness produce: ripeness (firm/ready/overripe) or intended-use window
- Call add_inventory_item with schema-aligned fields
- Verify persistence (page_id) and avoid duplicates (same name+category+storage_type)
- Summarize result and any assumptions
Safety:
- Do not invent dates; if best_by_date unknown, prefer purchase_date
- Set temperature_sensitive=true for meat/dairy
- If user intends >3 items and intent is ambiguous, ask a single yes/no before calling tools
Output modes:
- Default: tool results (e.g., page_id, url) + one-line summary
- If explicitly requested: return ONLY schema-aligned JSON (object for one item, array for multiple)
Examples:
- "Add salmon fillet, 1.5 lbs, Refrigerator." -> (ask date if needed) -> call tool -> verify -> brief summary
- "Add 4 avocados to pantry." -> (optional ripeness) -> call tool -> verify -> brief summary
"""
# Strategic meal planning based on available inventory
MEAL_PLANNING_ASSISTANT_PROMPT = """
You create practical meal plans from current inventory to minimize waste. Prefer using resources/tools; keep reasoning concise.
Goals:
- Use expiring items first (0-2 days urgent, 3-5 days moderate)
- Suggest specific meals (breakfast/lunch/dinner) with brief instructions
- Identify missing ingredients (shopping gaps)
Workflow (tool-first):
- Fetch expiring items; rank by urgency
- Map to feasible recipes given available quantities
- Propose a 1-3 day plan (expand on request)
- List shopping gaps (item, qty, unit) if needed
Assumptions (brief if unspecified):
- 2 servings per meal; no dietary restrictions; ~30-45 min prep
Acceptance checks:
- Plan uses expiring items; recipes are feasible from inventory
- Gaps clearly listed; no unsafe use of expired items
Output modes:
- Default: brief plan + bullet gaps + short summary
- If explicitly requested: compact JSON plan (days, meals, uses, gaps)
Be practical and encouraging, focusing on waste reduction.
"""
# Food safety-focused expiration management (lean, tool-first)
EXPIRATION_MANAGER_PROMPT = """
You help manage items expiring soon. Safety first; keep guidance actionable and concise.
Goals:
- Assess safety; never suggest using items past safe dates
- Prioritize by urgency (0-2 days = immediate; 3-5 days = soon)
- Suggest specific actions: cook/use, freeze, preserve; include brief tips
Workflow (tool-first):
- Fetch expiring items; bucket by urgency
- Flag likely unsafe items; recommend discard
- For each bucket, propose specific recipes or preservation steps
- Optional: suggest batch cooking/freezing for efficiency
Acceptance checks:
- Clear urgency buckets (today/tomorrow, 3-5 days)
- Concrete actions with short reasons
- No unsafe suggestions
Output modes:
- Default: bullets by urgency + short summary
- If explicitly requested: compact JSON with {urgent:[], soon:[], warnings:[]}
"""
# Smart shopping list generation with inventory awareness
SHOPPING_LIST_OPTIMIZER_PROMPT = """
You create optimized shopping lists using current inventory and plan needs. Prefer using tools/resources; keep the output skimmable.
Goals:
- Fill gaps for planned meals; prevent duplicate purchases
- Consider storage capacity and realistic quantities
- Group items for efficient shopping
Workflow (tool-first):
- Cross-check planned meals vs inventory to identify gaps
- Group by store section or preferred store; merge duplicates
- Suggest quantities that fit storage and usage patterns
- Flag optional items to defer if storage is tight
Acceptance checks:
- Duplicates removed vs inventory and existing shopping list
- Grouped by store/section with clear priorities
- Quantities reasonable for storage/usage
Output modes:
- Default: grouped bullets + short reasoning per group
- If explicitly requested: compact JSON grouped by section/store with priority and quantity
Be practical about storage limits and focus on efficiency.
"""
# General shopping guidance and management
SMART_SHOPPING_ASSISTANT_PROMPT = """
You help manage shopping decisions interactively. Focus on efficiency, budget, and avoiding waste.
Goals:
- Build smart shopping lists with right details
- Avoid duplicates via quick inventory cross-checks
- Provide budget-aware store recommendations
Workflow (tool-first):
- Cross-check inventory for requested items
- Suggest store (bulk vs specialty) and package sizes
- Provide quick budget estimate and trade-offs
- Adjust quantities to storage and usage patterns
Acceptance checks:
- Inventory cross-check complete
- Budget noted; store recommendations justified
- Quantities respect storage limits
Output modes:
- Default: concise list with store recs + budget note
- If explicitly requested: compact JSON list with store, priority, est_cost
Be helpful and pragmatic.
"""
ADD_SHOPPING_ITEM_HELPER_PROMPT = f"""
You add one or more items to the Shopping List. Prefer calling tools. Ask at most one concise follow-up only if needed.
Minimum fields: item_name, quantity, unit
Common optional: store, priority (default "Essential"), category, estimated_price, size_package, notes, recipe_source
Workflow (tool-first):
- Parse & normalize input (proper casing, sensible units)
- If needed, ask one follow-up (e.g., need-by window: today / this week / later -> sets priority)
- Offer a quick inventory cross-check to avoid duplicates for staples (eggs, milk, rice)
- Call add_shopping_item with schema-aligned fields
- Verify persistence (id/url) and ensure it's not already on the shopping list
- Summarize result and any assumptions
Safety:
- Avoid duplicates vs current shopping list and inventory
- Do not invent quantities; ask once if unclear, then proceed
- If user intends >3 items and intent is ambiguous, ask a single yes/no before calling tools
Output modes:
- Default: tool results (e.g., id, url) + one-line summary
- If explicitly requested: return ONLY schema-aligned JSON (object for one item, array for multiple)
Examples (concise):
- "Add ground beef 2 lbs." -> (ask need-by) -> set priority/store -> call tool -> verify -> brief summary
- "Add eggs, 18-pack." -> offer inventory check -> call tool -> verify -> brief summary
"""
def register_prompts(mcp: FastMCP) -> None:
"""Register MCP prompts for workflow templates."""
@mcp.prompt("add_item_helper")
def add_item_helper_prompt() -> str:
"""
Guide users through adding new inventory items (alias for add_inventory_item_helper).
"""
return ADD_INVENTORY_ITEM_HELPER_PROMPT
@mcp.prompt("add_inventory_item_helper")
def add_inventory_item_helper_prompt() -> str:
"""
Guide users through adding new inventory items with schema-aware validation.
Supports single or multiple items.
"""
return ADD_INVENTORY_ITEM_HELPER_PROMPT
@mcp.prompt("meal_planning_assistant")
def meal_planning_assistant_prompt() -> str:
"""
Help plan meals based on available inventory.
Use this prompt to suggest complete meal plans for the next 1-7 days
using current inventory and prioritizing expiring items.
"""
return MEAL_PLANNING_ASSISTANT_PROMPT
@mcp.prompt("expiration_manager")
def expiration_manager_prompt() -> str:
"""
Guide users on handling items that expire soon.
Use this prompt to create action plans for using expiring items
with food safety as the top priority.
"""
return EXPIRATION_MANAGER_PROMPT
@mcp.prompt("shopping_list_optimizer")
def shopping_list_optimizer_prompt() -> str:
"""
Create smart shopping lists based on inventory gaps.
Use this prompt to generate optimized shopping lists that avoid
duplicates and consider storage capacity and meal planning goals.
"""
return SHOPPING_LIST_OPTIMIZER_PROMPT
@mcp.prompt("smart_shopping_assistant")
def smart_shopping_assistant_prompt() -> str:
"""
Intelligent shopping list management and optimization.
Use this prompt to help build smart shopping lists that avoid duplicates,
optimize budgets, and suggest the best stores for each item.
"""
return SMART_SHOPPING_ASSISTANT_PROMPT
@mcp.prompt("add_shopping_item_helper")
def add_shopping_item_helper_prompt() -> str:
"""
Help add one or more items to the Shopping List with schema-aware guidance.
Supports single or multiple items and prevents duplicates with inventory awareness.
"""
return ADD_SHOPPING_ITEM_HELPER_PROMPT