Skip to main content
Glama
CupOfOwls

Kroger MCP Server

get_preferred_location

Retrieve the currently selected Kroger store location for grocery shopping, enabling personalized product searches and cart management.

Instructions

    Get the currently set preferred store location.
    
    Returns:
        Dictionary containing the preferred location information
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'get_preferred_location' tool. It retrieves the preferred location ID using a helper, fetches details via the Kroger API client, and returns formatted location information or an error.
    @mcp.tool()
    async def get_preferred_location(ctx: Context = None) -> Dict[str, Any]:
        """
        Get the currently set preferred store location.
        
        Returns:
            Dictionary containing the preferred location information
        """
        preferred_location_id = get_preferred_location_id()
        
        if not preferred_location_id:
            return {
                "success": False,
                "message": "No preferred location set. Use set_preferred_location to set one."
            }
        
        if ctx:
            await ctx.info(f"Getting preferred location details for {preferred_location_id}")
        
        # Get location details
        client = get_client_credentials_client()
        
        try:
            location_details = client.location.get_location(preferred_location_id)
            loc_data = location_details.get("data", {})
            
            return {
                "success": True,
                "preferred_location_id": preferred_location_id,
                "location_details": {
                    "name": loc_data.get("name"),
                    "chain": loc_data.get("chain"),
                    "phone": loc_data.get("phone"),
                    "address": loc_data.get("address", {})
                }
            }
            
        except Exception as e:
            if ctx:
                await ctx.error(f"Error getting preferred location details: {str(e)}")
            return {
                "success": False,
                "error": str(e),
                "preferred_location_id": preferred_location_id
            }
  • Registration of the location_tools module, which includes the get_preferred_location tool via its register_tools function.
    location_tools.register_tools(mcp)
  • Helper function that loads and returns the stored preferred location ID from the preferences JSON file, used by the get_preferred_location handler.
    def get_preferred_location_id() -> Optional[str]:
        """Get the current preferred location ID from preferences file"""
        preferences = _load_preferences()
        return preferences.get("preferred_location_id")
  • Companion helper function to store the preferred location ID to the preferences file, referenced in related tools.
    def set_preferred_location_id(location_id: str) -> None:
        """Set the preferred location ID in preferences file"""
        preferences = _load_preferences()
        preferences["preferred_location_id"] = location_id
        _save_preferences(preferences)

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