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
| Name | Required | Description | Default |
|---|---|---|---|
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": [] }
- src/kroger_mcp/server.py:75-75 (registration)The registration call that adds the info_tools (including list_departments) to the MCP server.info_tools.register_tools(mcp)