query_products
Search bakery product data by code, name, department, price range, or tags to find specific items in the catalog.
Instructions
Query product master data. Search by product code, name, department, price range, or tags.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| plu_code | No | Product PLU code. Optional. | |
| product_name | No | Product name to search (partial match). Optional. | |
| department_id | No | Department ID. Optional. | |
| min_price | No | Minimum price. Optional. | |
| max_price | No | Maximum price. Optional. | |
| tag | No | Search products by tag (uses extended product table). Optional. | |
| include_tags | No | Include tag information in results. Default: false. | |
| limit | No | Maximum number of results. Default: 100. |
Implementation Reference
- src/bakery_data_mcp/server.py:288-332 (handler)Handler logic for the 'query_products' tool within the call_tool function. Builds a dynamic SQL query to fetch products from 'products' or 'products_extended' table based on filters like plu_code, product_name, department_id, price range, and tags. Executes the query and returns JSON-formatted results.elif name == "query_products": # Determine which table to use include_tags = arguments.get("include_tags", False) has_tag_filter = "tag" in arguments table = "products_extended" if (include_tags or has_tag_filter) else "products" query = f"SELECT * FROM {table} WHERE 1=1" params = [] if "plu_code" in arguments: query += " AND plu_code = ?" params.append(arguments["plu_code"]) if "product_name" in arguments: query += " AND product_name LIKE ?" params.append(f"%{arguments['product_name']}%") if "department_id" in arguments: query += " AND department_id = ?" params.append(arguments["department_id"]) if "min_price" in arguments: query += " AND price >= ?" params.append(arguments["min_price"]) if "max_price" in arguments: query += " AND price <= ?" params.append(arguments["max_price"]) if has_tag_filter: query += " AND tags LIKE ?" params.append(f"%{arguments['tag']}%") query += " LIMIT ?" params.append(arguments.get("limit", 100)) cursor.execute(query, params) results = cursor.fetchall() return [TextContent( type="text", text=json.dumps(results, ensure_ascii=False, indent=2) )]
- src/bakery_data_mcp/server.py:86-126 (registration)Registration of the 'query_products' tool in the list_tools() function, including the tool name, description, and input schema definition.Tool( name="query_products", description="Query product master data. Search by product code, name, department, price range, or tags.", inputSchema={ "type": "object", "properties": { "plu_code": { "type": "string", "description": "Product PLU code. Optional." }, "product_name": { "type": "string", "description": "Product name to search (partial match). Optional." }, "department_id": { "type": "number", "description": "Department ID. Optional." }, "min_price": { "type": "number", "description": "Minimum price. Optional." }, "max_price": { "type": "number", "description": "Maximum price. Optional." }, "tag": { "type": "string", "description": "Search products by tag (uses extended product table). Optional." }, "include_tags": { "type": "boolean", "description": "Include tag information in results. Default: false." }, "limit": { "type": "number", "description": "Maximum number of results. Default: 100." } } } ),
- src/bakery_data_mcp/server.py:89-125 (schema)Input schema definition for the 'query_products' tool, specifying properties for filtering products.inputSchema={ "type": "object", "properties": { "plu_code": { "type": "string", "description": "Product PLU code. Optional." }, "product_name": { "type": "string", "description": "Product name to search (partial match). Optional." }, "department_id": { "type": "number", "description": "Department ID. Optional." }, "min_price": { "type": "number", "description": "Minimum price. Optional." }, "max_price": { "type": "number", "description": "Maximum price. Optional." }, "tag": { "type": "string", "description": "Search products by tag (uses extended product table). Optional." }, "include_tags": { "type": "boolean", "description": "Include tag information in results. Default: false." }, "limit": { "type": "number", "description": "Maximum number of results. Default: 100." } } }