Skip to main content
Glama
CupOfOwls

Kroger MCP Server

list_departments

Retrieve all available departments in Kroger stores to browse products by category for grocery shopping.

Instructions

    Get a list of all available departments in Kroger stores.
    
    Returns:
        Dictionary containing department information
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function for the 'list_departments' tool. It fetches departments from the Kroger client, formats them, and returns a structured response with success status, count, and data.
    @mcp.tool()
    async def list_departments(ctx: Context = None) -> Dict[str, Any]:
        """
        Get a list of all available departments in Kroger stores.
        
        Returns:
            Dictionary containing department information
        """
        if ctx:
            await ctx.info("Getting list of departments")
        
        client = get_client_credentials_client()
        
        try:
            departments = client.location.list_departments()
            
            if not departments or "data" not in departments or not departments["data"]:
                return {
                    "success": False,
                    "message": "No departments found",
                    "data": []
                }
            
            # Format department data
            formatted_departments = [
                {
                    "department_id": dept.get("departmentId"),
                    "name": dept.get("name")
                }
                for dept in departments["data"]
            ]
            
            if ctx:
                await ctx.info(f"Found {len(formatted_departments)} departments")
            
            return {
                "success": True,
                "count": len(formatted_departments),
                "data": formatted_departments
            }
            
        except Exception as e:
            if ctx:
                await ctx.error(f"Error listing departments: {str(e)}")
            return {
                "success": False,
                "error": str(e),
                "data": []
            }
  • The registration call that adds the info_tools (including list_departments) to the MCP server.
    info_tools.register_tools(mcp)

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