Skip to main content
Glama
CupOfOwls

Kroger MCP Server

check_chain_exists

Verify if a specific grocery chain exists in the Kroger system by providing the chain name, returning a confirmation status for store availability checks.

Instructions

    Check if a chain exists in the Kroger system.
    
    Args:
        chain_name: Name of the chain to check
    
    Returns:
        Dictionary indicating whether the chain exists
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_nameYes

Implementation Reference

  • The handler function for the 'check_chain_exists' tool. It takes a chain_name parameter, uses get_client_credentials_client to get the API client, calls client.location.chain_exists(), and returns a success dict with existence status.
    @mcp.tool()
    async def check_chain_exists(
        chain_name: str,
        ctx: Context = None
    ) -> Dict[str, Any]:
        """
        Check if a chain exists in the Kroger system.
        
        Args:
            chain_name: Name of the chain to check
        
        Returns:
            Dictionary indicating whether the chain exists
        """
        if ctx:
            await ctx.info(f"Checking if chain '{chain_name}' exists")
        
        client = get_client_credentials_client()
        
        try:
            exists = client.location.chain_exists(chain_name)
            
            return {
                "success": True,
                "chain_name": chain_name,
                "exists": exists,
                "message": f"Chain '{chain_name}' {'exists' if exists else 'does not exist'}"
            }
            
        except Exception as e:
            if ctx:
                await ctx.error(f"Error checking chain existence: {str(e)}")
            return {
                "success": False,
                "error": str(e)
            }
  • The line where the info_tools module's register_tools function is called on the MCP server instance, registering the check_chain_exists tool along with other info tools.
    info_tools.register_tools(mcp)
  • Helper function get_client_credentials_client() that provides the KrogerAPI client instance used in the handler for accessing public endpoints like chain_exists.
    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