Skip to main content
Glama

get_preferred_location

Retrieve the currently set preferred store location details, including address and ID, for streamlined grocery shopping on the Kroger MCP Server.

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 asynchronous handler function for the 'get_preferred_location' MCP tool. It fetches the stored preferred location ID, retrieves detailed location information from the Kroger API, and returns a formatted dictionary response.
    @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 }
  • The call that registers all location tools, including 'get_preferred_location', with the FastMCP server instance.
    location_tools.register_tools(mcp)
  • Helper utility function that loads and returns the preferred location ID from the persistent preferences JSON file, used by the tool 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")
  • Internal helper function that loads the preferences JSON file containing the preferred location ID.
    def _load_preferences() -> dict: """Load preferences from file""" try: if os.path.exists(PREFERENCES_FILE): with open(PREFERENCES_FILE, 'r') as f: return json.load(f) except Exception as e: print(f"Warning: Could not load preferences: {e}") return {"preferred_location_id": None}

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