Skip to main content
Glama
CupOfOwls

Kroger MCP Server

search_products_by_id

Find specific Kroger grocery products using their unique product ID, optionally filtered by store location for accurate availability.

Instructions

    Search for products by their specific product ID.
    
    Args:
        product_id: The product ID to search for
        location_id: Store location ID (uses preferred location if not provided)
    
    Returns:
        Dictionary containing matching products
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
product_idYes
location_idNo

Implementation Reference

  • The handler function for the 'search_products_by_id' tool. It uses the Kroger client to search products by ID, formats the results, and handles errors. Registered via the @mcp.tool() decorator.
    @mcp.tool()
    async def search_products_by_id(
        product_id: str,
        location_id: Optional[str] = None,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Search for products by their specific product ID.
        
        Args:
            product_id: The product ID to search for
            location_id: Store location ID (uses preferred location if not provided)
        
        Returns:
            Dictionary containing matching products
        """
        # Use preferred location if none provided
        if not location_id:
            location_id = get_preferred_location_id()
            if not location_id:
                return {
                    "success": False,
                    "error": "No location_id provided and no preferred location set. Use set_preferred_location first."
                }
        
        if ctx:
            await ctx.info(f"Searching for products with ID '{product_id}' at location {location_id}")
        
        client = get_client_credentials_client()
        
        try:
            products = client.product.search_products(
                product_id=product_id,
                location_id=location_id
            )
            
            if not products or "data" not in products or not products["data"]:
                return {
                    "success": False,
                    "message": f"No products found with ID '{product_id}'",
                    "data": []
                }
            
            # Format product data (similar to search_products but simpler)
            formatted_products = []
            for product in products["data"]:
                formatted_product = {
                    "product_id": product.get("productId"),
                    "upc": product.get("upc"),
                    "description": product.get("description"),
                    "brand": product.get("brand"),
                    "categories": product.get("categories", [])
                }
                
                # Add basic pricing if available
                if "items" in product and product["items"] and "price" in product["items"][0]:
                    price = product["items"][0]["price"]
                    formatted_product["pricing"] = {
                        "regular_price": price.get("regular"),
                        "sale_price": price.get("promo"),
                        "formatted_regular": format_currency(price.get("regular")),
                        "formatted_sale": format_currency(price.get("promo"))
                    }
                
                formatted_products.append(formatted_product)
            
            if ctx:
                await ctx.info(f"Found {len(formatted_products)} products with ID '{product_id}'")
            
            return {
                "success": True,
                "search_params": {
                    "product_id": product_id,
                    "location_id": location_id
                },
                "count": len(formatted_products),
                "data": formatted_products
            }
            
        except Exception as e:
            if ctx:
                await ctx.error(f"Error searching products by ID: {str(e)}")
            return {
                "success": False,
                "error": str(e),
                "data": []
            }
  • The call to product_tools.register_tools(mcp) which registers all product tools including search_products_by_id via their decorators.
    product_tools.register_tools(mcp)

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