query_transactions
Retrieve and filter bakery POS transaction records by date, product, payment method, or amount to analyze sales data.
Instructions
Query POS transaction data. Supports filtering by date range, product code/name, payment method, and amount range. Returns transaction details.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| start_date | No | Start date (YYYY-MM-DD format). Optional. | |
| end_date | No | End date (YYYY-MM-DD format). Optional. | |
| product_code | No | Product code to filter by. Optional. | |
| product_name | No | Product name to search (partial match). Optional. | |
| payment_method | No | Payment method (e.g., '現金', 'クレジット'). Optional. | |
| min_amount | No | Minimum transaction amount. Optional. | |
| max_amount | No | Maximum transaction amount. Optional. | |
| limit | No | Maximum number of results to return. Default: 100. |
Implementation Reference
- src/bakery_data_mcp/server.py:244-287 (handler)The core handler logic within the call_tool function that processes input arguments, dynamically builds an SQL query to filter transactions table based on provided parameters, executes the query using the database cursor, fetches results, and returns them as JSON-formatted text content.if name == "query_transactions": # Build query with filters query = "SELECT * FROM transactions WHERE 1=1" params = [] if "start_date" in arguments: query += " AND datetime >= ?" params.append(arguments["start_date"]) if "end_date" in arguments: query += " AND datetime <= ?" params.append(arguments["end_date"] + " 23:59:59") if "product_code" in arguments: query += " AND product_code = ?" params.append(arguments["product_code"]) if "product_name" in arguments: query += " AND product_name LIKE ?" params.append(f"%{arguments['product_name']}%") if "payment_method" in arguments: query += " AND payment_method = ?" params.append(arguments["payment_method"]) if "min_amount" in arguments: query += " AND amount >= ?" params.append(arguments["min_amount"]) if "max_amount" in arguments: query += " AND amount <= ?" params.append(arguments["max_amount"]) query += " ORDER BY datetime DESC 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:48-84 (schema)Input schema for the query_transactions tool, defining optional parameters for filtering by date range, product details, payment method, amount range, and result limit.inputSchema={ "type": "object", "properties": { "start_date": { "type": "string", "description": "Start date (YYYY-MM-DD format). Optional." }, "end_date": { "type": "string", "description": "End date (YYYY-MM-DD format). Optional." }, "product_code": { "type": "string", "description": "Product code to filter by. Optional." }, "product_name": { "type": "string", "description": "Product name to search (partial match). Optional." }, "payment_method": { "type": "string", "description": "Payment method (e.g., '現金', 'クレジット'). Optional." }, "min_amount": { "type": "number", "description": "Minimum transaction amount. Optional." }, "max_amount": { "type": "number", "description": "Maximum transaction amount. Optional." }, "limit": { "type": "number", "description": "Maximum number of results to return. Default: 100." } } }
- src/bakery_data_mcp/server.py:45-85 (registration)Registration of the query_transactions tool in the list_tools() function via the MCP Tool object, including name, description, and input schema.Tool( name="query_transactions", description="Query POS transaction data. Supports filtering by date range, product code/name, payment method, and amount range. Returns transaction details.", inputSchema={ "type": "object", "properties": { "start_date": { "type": "string", "description": "Start date (YYYY-MM-DD format). Optional." }, "end_date": { "type": "string", "description": "End date (YYYY-MM-DD format). Optional." }, "product_code": { "type": "string", "description": "Product code to filter by. Optional." }, "product_name": { "type": "string", "description": "Product name to search (partial match). Optional." }, "payment_method": { "type": "string", "description": "Payment method (e.g., '現金', 'クレジット'). Optional." }, "min_amount": { "type": "number", "description": "Minimum transaction amount. Optional." }, "max_amount": { "type": "number", "description": "Maximum transaction amount. Optional." }, "limit": { "type": "number", "description": "Maximum number of results to return. Default: 100." } } } ),