Skip to main content
Glama

search_products_by_id

Retrieve product details by entering a specific product ID. Supports store-specific searches using a location ID. Returns a dictionary of matching products for quick access.

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
location_idNo
product_idYes

Implementation Reference

  • The core handler function implementing the search_products_by_id tool logic. It uses the Kroger client to search products by ID, formats the results, handles location preferences, and includes error handling.
    @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 registration call for all product tools, including search_products_by_id, in the main server setup.
    product_tools.register_tools(mcp)
  • The register_tools function in product_tools module that defines and registers all product tools using @mcp.tool() decorators, including search_products_by_id.
    def register_tools(mcp): """Register product-related tools with the FastMCP server"""

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