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)
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states this is a search operation but doesn't disclose behavioral traits like whether it requires authentication, what happens if no product matches the ID, whether it's read-only or has side effects, rate limits, or error conditions. The description is minimal and lacks essential operational context.

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 well-structured and appropriately concise. It uses a clear title sentence, followed by organized sections for Args and Returns. Every sentence adds value: the purpose statement, parameter explanations, and return value description. There's no redundant or unnecessary information.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, no annotations, no output schema), the description is minimally adequate but has gaps. It covers the basic purpose and parameters but lacks behavioral context (authentication needs, error handling) and doesn't explain the return value format beyond 'dictionary containing matching products.' For a search tool with no annotations or output schema, more operational details would be helpful.

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

Parameters4/5

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

The description adds meaningful semantics beyond the schema. The input schema has 0% description coverage (no parameter descriptions), but the description explains both parameters: 'product_id: The product ID to search for' and 'location_id: Store location ID (uses preferred location if not provided)'. This clarifies the purpose of each parameter and the default behavior for location_id, compensating well for the schema's lack of documentation.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Search for products by their specific product ID.' This is a specific verb ('search') + resource ('products') with a clear method ('by product ID'). However, it doesn't explicitly differentiate from sibling tools like 'search_products' or 'get_product_details', which likely have different search methods or return different data granularity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'search_products' (likely keyword-based search) and 'get_product_details' (likely returns detailed info for a known product), there's no indication of when this ID-based search is preferred, what its limitations are, or when other tools might be more appropriate.

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