view_current_cart
Retrieve locally tracked cart contents and summaries added via the MCP server. Provides an overview of items without accessing the actual user cart through the Kroger API.
Instructions
View the current cart contents tracked locally.
Note: This tool can only see items that were added via this MCP server.
The Kroger API does not provide permission to query the actual user cart contents.
Returns:
Dictionary containing current cart items and summary
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for 'view_current_cart' tool. It loads local cart data, calculates summary statistics (total items, quantity, pickup/delivery counts), and returns the current cart contents with summary. Defined inside register_tools and decorated with @mcp.tool() for automatic registration.@mcp.tool() async def view_current_cart(ctx: Context = None) -> Dict[str, Any]: """ View the current cart contents tracked locally. Note: This tool can only see items that were added via this MCP server. The Kroger API does not provide permission to query the actual user cart contents. Returns: Dictionary containing current cart items and summary """ try: cart_data = _load_cart_data() current_cart = cart_data.get("current_cart", []) # Calculate summary total_quantity = sum(item.get("quantity", 0) for item in current_cart) pickup_items = [item for item in current_cart if item.get("modality") == "PICKUP"] delivery_items = [item for item in current_cart if item.get("modality") == "DELIVERY"] return { "success": True, "current_cart": current_cart, "summary": { "total_items": len(current_cart), "total_quantity": total_quantity, "pickup_items": len(pickup_items), "delivery_items": len(delivery_items), "last_updated": cart_data.get("last_updated") } } except Exception as e: return { "success": False, "error": f"Failed to view cart: {str(e)}" }
- src/kroger_mcp/server.py:74-74 (registration)Registration of the cart_tools module in the main server creation function. This call executes register_tools which defines and registers the view_current_cart tool using @mcp.tool().cart_tools.register_tools(mcp)
- Helper function used by view_current_cart to load the local cart data from 'kroger_cart.json' file, returning default empty cart if not found or error.def _load_cart_data() -> Dict[str, Any]: """Load cart data from file""" try: if os.path.exists(CART_FILE): with open(CART_FILE, 'r') as f: return json.load(f) except Exception: pass return {"current_cart": [], "last_updated": None, "preferred_location_id": None}