Skip to main content
Glama
t2hnd
by t2hnd

query_transactions

Retrieve and filter bakery POS transaction data by date range, product details, payment method, or amount to analyze sales patterns and transaction history.

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
NameRequiredDescriptionDefault
start_dateNoStart date (YYYY-MM-DD format). Optional.
end_dateNoEnd date (YYYY-MM-DD format). Optional.
product_codeNoProduct code to filter by. Optional.
product_nameNoProduct name to search (partial match). Optional.
payment_methodNoPayment method (e.g., '現金', 'クレジット'). Optional.
min_amountNoMinimum transaction amount. Optional.
max_amountNoMaximum transaction amount. Optional.
limitNoMaximum number of results to return. Default: 100.

Implementation Reference

  • Implements the core logic for the query_transactions tool: dynamically builds and executes an SQL query on the 'transactions' table using input filters for dates, products, payments, and amounts, then returns JSON results.
    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) )]
  • Registers the query_transactions tool in the MCP server's list_tools() function, defining its name, description, and input schema for parameters like dates, products, payments, and limits.
    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." } } } ),
  • Defines the input schema for the query_transactions tool, specifying types and descriptions for filter parameters.
    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." } } }
  • Helper function to convert SQLite query rows into dictionaries, used for JSON serialization of results.
    def dict_factory(cursor, row): """Convert database rows to dictionaries.""" fields = [column[0] for column in cursor.description] return {key: value for key, value in zip(fields, row)}

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/t2hnd/bakery_data_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server