query_products
Search bakery product data by code, name, department, price range, or tags to find items in the catalog.
Instructions
Query product master data. Search by product code, name, department, price range, or tags.
Input 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. |
Input Schema (JSON Schema)
{
"properties": {
"department_id": {
"description": "Department ID. Optional.",
"type": "number"
},
"include_tags": {
"description": "Include tag information in results. Default: false.",
"type": "boolean"
},
"limit": {
"description": "Maximum number of results. Default: 100.",
"type": "number"
},
"max_price": {
"description": "Maximum price. Optional.",
"type": "number"
},
"min_price": {
"description": "Minimum price. Optional.",
"type": "number"
},
"plu_code": {
"description": "Product PLU code. Optional.",
"type": "string"
},
"product_name": {
"description": "Product name to search (partial match). Optional.",
"type": "string"
},
"tag": {
"description": "Search products by tag (uses extended product table). Optional.",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/bakery_data_mcp/server.py:288-332 (handler)Handler function for 'query_products' tool. Builds dynamic SQL query based on input parameters to fetch products from 'products' or 'products_extended' table, applies filters, and returns JSON 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 name, description, and input schema.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 defining parameters for the 'query_products' tool.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." } } }