Skip to main content
Glama
CupOfOwls

Kroger MCP Server

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}")
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing critical behavioral constraints: it only affects local tracking, cannot modify the actual Kroger cart, and requires user action for real removal. It also describes the return value format. It doesn't cover potential errors or side effects, keeping it from a perfect score.

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 efficiently structured with clear sections: purpose statement, important limitation, usage guidelines, parameters, and return value. Every sentence earns its place, and critical information is front-loaded with the 'IMPORTANT' warning.

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

Completeness4/5

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

For a mutation tool with no annotations and no output schema, the description provides strong context about behavior, parameters, and returns. It could slightly improve by mentioning error cases or confirming no side effects beyond local tracking, but it's largely complete for its complexity.

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

Parameters5/5

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

With 0% schema description coverage, the description fully compensates by explaining both parameters: product_id identifies what to remove, and modality specifies which instance (with clarification that 'None' removes all). This adds essential meaning beyond the bare schema.

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

Purpose5/5

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

The description clearly states the specific action ('Remove an item from the local cart tracking only') and distinguishes it from siblings by explicitly contrasting with actual cart removal in the Kroger app/website. It avoids tautology by explaining the limited scope beyond just the tool name.

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 when-to-use criteria (two numbered conditions) and when-not-to-use warnings (cannot remove from actual cart). It distinguishes from siblings by clarifying this is for local tracking sync only, not actual cart operations.

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

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