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
| Name | Required | Description | Default |
|---|---|---|---|
| chain_name | Yes |
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) }
- src/kroger_mcp/server.py:75-75 (registration)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)
- src/kroger_mcp/tools/shared.py:25-53 (helper)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)}")