list_departments
Retrieve a detailed list of all available departments in Kroger stores using this tool. Provides department information to streamline grocery shopping and product searches.
Instructions
Get a list of all available departments in Kroger stores.
Returns:
Dictionary containing department information
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main execution logic for the list_departments tool. Fetches departments via Kroger client, formats them, and returns structured data with error handling.@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": [] }
- src/kroger_mcp/server.py:72-78 (registration)Server initialization where info_tools.register_tools(mcp) is called. This invokes the registration of the list_departments tool via its @mcp.tool() decorator.location_tools.register_tools(mcp) product_tools.register_tools(mcp) cart_tools.register_tools(mcp) info_tools.register_tools(mcp) profile_tools.register_tools(mcp) utility_tools.register_tools(mcp) auth_tools.register_tools(mcp)