Skip to main content
Glama
CupOfOwls

Kroger MCP Server

list_chains

Retrieve information about all Kroger-owned grocery store chains to identify available shopping locations and services.

Instructions

    Get a list of all Kroger-owned chains.
    
    Returns:
        Dictionary containing chain information
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'list_chains' tool. It retrieves the list of Kroger chains using the client API, formats the data, provides context feedback, handles errors, and returns a structured dictionary.
    async def list_chains(ctx: Context = None) -> Dict[str, Any]:
        """
        Get a list of all Kroger-owned chains.
        
        Returns:
            Dictionary containing chain information
        """
        if ctx:
            await ctx.info("Getting list of Kroger chains")
        
        client = get_client_credentials_client()
        
        try:
            chains = client.location.list_chains()
            
            if not chains or "data" not in chains or not chains["data"]:
                return {
                    "success": False,
                    "message": "No chains found",
                    "data": []
                }
            
            # Format chain data
            formatted_chains = [
                {
                    "name": chain.get("name"),
                    "division_numbers": chain.get("divisionNumbers", [])
                }
                for chain in chains["data"]
            ]
            
            if ctx:
                await ctx.info(f"Found {len(formatted_chains)} chains")
            
            return {
                "success": True,
                "count": len(formatted_chains),
                "data": formatted_chains
            }
            
        except Exception as e:
            if ctx:
                await ctx.error(f"Error listing chains: {str(e)}")
            return {
                "success": False,
                "error": str(e),
                "data": []
            }
  • Registration block in the server creation where info_tools.register_tools(mcp) is called at line 75, registering the list_chains tool along with others.
    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 used by list_chains to obtain a KrogerAPI client with client credentials for accessing public location data.
    def get_client_credentials_client() -> KrogerAPI:
        """Get or create a client credentials authenticated client for public data"""
        global _client_credentials_client
        
        if _client_credentials_client is not None and _client_credentials_client.test_current_token():
            return _client_credentials_client
        
        _client_credentials_client = None
        
        try:
            load_and_validate_env(["KROGER_CLIENT_ID", "KROGER_CLIENT_SECRET"])
            _client_credentials_client = KrogerAPI()
            
            # Try to load existing token first
            token_file = ".kroger_token_client_product.compact.json"
            token_info = load_token(token_file)
            
            if token_info:
                # Test if the token is still valid
                _client_credentials_client.client.token_info = token_info
                if _client_credentials_client.test_current_token():
                    # Token is valid, use it
                    return _client_credentials_client
            
            # Token is invalid or not found, get a new one
            token_info = _client_credentials_client.authorization.get_token_with_client_credentials("product.compact")
            return _client_credentials_client
        except Exception as e:
            raise Exception(f"Failed to get client credentials: {str(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