Skip to main content
Glama

remove_from_cart

Update local cart tracking after removing items from your Kroger cart. This tool syncs local data when you've already removed products through the Kroger app or website.

Instructions

Remove an item from the local cart tracking only. IMPORTANT: This tool CANNOT remove items from the actual Kroger cart in the app/website. It only updates our local tracking to stay in sync. The user must remove the item from their actual cart through the Kroger app or website themselves. Use this tool only when: 1. The user has already removed an item from their Kroger cart through the app/website 2. You need to update the local tracking to reflect that change Args: product_id: The product ID to remove modality: Specific modality to remove (if None, removes all instances) Returns: Dictionary confirming the removal from local tracking

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
product_idYes
modalityNo

Implementation Reference

  • The main execution logic for the 'remove_from_cart' tool. Removes specified product from local JSON cart tracking file. Uses list comprehensions to filter out matching items. Updates timestamp if changes made. Includes input validation via type hints and comprehensive error handling. Note: Only affects local tracking, not actual Kroger cart.
    @mcp.tool() async def remove_from_cart( product_id: str, modality: str = None, ctx: Context = None ) -> Dict[str, Any]: """ Remove an item from the local cart tracking only. IMPORTANT: This tool CANNOT remove items from the actual Kroger cart in the app/website. It only updates our local tracking to stay in sync. The user must remove the item from their actual cart through the Kroger app or website themselves. Use this tool only when: 1. The user has already removed an item from their Kroger cart through the app/website 2. You need to update the local tracking to reflect that change Args: product_id: The product ID to remove modality: Specific modality to remove (if None, removes all instances) Returns: Dictionary confirming the removal from local tracking """ try: cart_data = _load_cart_data() current_cart = cart_data.get("current_cart", []) original_count = len(current_cart) if modality: # Remove specific modality cart_data["current_cart"] = [ item for item in current_cart if not (item.get("product_id") == product_id and item.get("modality") == modality) ] else: # Remove all instances cart_data["current_cart"] = [ item for item in current_cart if item.get("product_id") != product_id ] items_removed = original_count - len(cart_data["current_cart"]) if items_removed > 0: cart_data["last_updated"] = datetime.now().isoformat() _save_cart_data(cart_data) return { "success": True, "message": f"Removed {items_removed} items from local cart tracking", "items_removed": items_removed, "product_id": product_id, "modality": modality } except Exception as e: return { "success": False, "error": f"Failed to remove from cart: {str(e)}" }
  • Registers the cart_tools module (containing remove_from_cart) by calling cart_tools.register_tools(mcp) in the main server setup function.
    location_tools.register_tools(mcp) product_tools.register_tools(mcp) cart_tools.register_tools(mcp) info_tools.register_tools(mcp) profile_tools.register_tools(mcp) utility_tools.register_tools(mcp) auth_tools.register_tools(mcp)
  • Helper function to load cart data from kroger_cart.json file, used by remove_from_cart to retrieve current cart state.
    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}
  • Helper function to persist updated cart data to kroger_cart.json file after modifications in remove_from_cart.
    def _save_cart_data(cart_data: Dict[str, Any]) -> None: """Save cart data to file""" try: with open(CART_FILE, 'w') as f: json.dump(cart_data, f, indent=2) except Exception as e: print(f"Warning: Could not save cart data: {e}")

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/CupOfOwls/kroger-mcp'

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