Skip to main content
Glama
t2hnd

Bakery Data MCP Server

by t2hnd

sales_summary

Generate sales summary statistics by aggregating bakery transaction data across date ranges, products, departments, or payment methods to analyze performance.

Instructions

Get sales summary statistics. Aggregate sales data by date range, product, department, or payment method.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNoStart date (YYYY-MM-DD format). Optional.
end_dateNoEnd date (YYYY-MM-DD format). Optional.
group_byNoHow to group the results. Optional.
department_idNoFilter by department ID. Optional.
limitNoMaximum number of results. Default: 100.

Implementation Reference

  • Handler for the 'sales_summary' tool. Constructs dynamic SQL queries based on the 'group_by' parameter (product, department, payment_method, date, month, or default overall summary), applies date and department filters, executes the query on the transactions table (with joins as needed), and returns aggregated sales statistics as JSON.
    elif name == "sales_summary":
        group_by = arguments.get("group_by")
    
        # Base query
        if group_by == "product":
            query = """
                SELECT product_code, product_name,
                       COUNT(*) as transaction_count,
                       SUM(quantity) as total_quantity,
                       SUM(amount) as total_revenue
                FROM transactions
                WHERE 1=1
            """
            group_clause = " GROUP BY product_code, product_name ORDER BY total_revenue DESC"
    
        elif group_by == "department":
            query = """
                SELECT d.department_id, d.department_name,
                       COUNT(*) as transaction_count,
                       SUM(t.quantity) as total_quantity,
                       SUM(t.amount) as total_revenue
                FROM transactions t
                JOIN products p ON t.product_code = p.plu_code
                JOIN departments d ON p.department_id = d.department_id
                WHERE 1=1
            """
            group_clause = " GROUP BY d.department_id, d.department_name ORDER BY total_revenue DESC"
    
        elif group_by == "payment_method":
            query = """
                SELECT payment_method,
                       COUNT(*) as transaction_count,
                       SUM(quantity) as total_quantity,
                       SUM(amount) as total_revenue
                FROM transactions
                WHERE 1=1
            """
            group_clause = " GROUP BY payment_method ORDER BY total_revenue DESC"
    
        elif group_by == "date":
            query = """
                SELECT DATE(datetime) as date,
                       COUNT(*) as transaction_count,
                       SUM(quantity) as total_quantity,
                       SUM(amount) as total_revenue
                FROM transactions
                WHERE 1=1
            """
            group_clause = " GROUP BY DATE(datetime) ORDER BY date"
    
        elif group_by == "month":
            query = """
                SELECT strftime('%Y-%m', datetime) as month,
                       COUNT(*) as transaction_count,
                       SUM(quantity) as total_quantity,
                       SUM(amount) as total_revenue
                FROM transactions
                WHERE 1=1
            """
            group_clause = " GROUP BY strftime('%Y-%m', datetime) ORDER BY month"
    
        else:
            # Overall summary
            query = """
                SELECT COUNT(*) as transaction_count,
                       COUNT(DISTINCT transaction_number) as unique_transactions,
                       SUM(quantity) as total_quantity,
                       SUM(amount) as total_revenue,
                       AVG(amount) as avg_transaction_amount,
                       MIN(datetime) as first_transaction,
                       MAX(datetime) as last_transaction
                FROM transactions
                WHERE 1=1
            """
            group_clause = ""
    
        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 "department_id" in arguments and group_by != "department":
            if "JOIN products" not in query:
                query = query.replace("FROM transactions",
                                     "FROM transactions t JOIN products p ON t.product_code = p.plu_code")
                query = query.replace("WHERE 1=1", "WHERE 1=1")
            query += " AND p.department_id = ?"
            params.append(arguments["department_id"])
    
        query += group_clause
    
        if group_by:
            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)
        )]
  • Input schema definition for the 'sales_summary' tool, defining parameters for date range, grouping options, department filter, 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."
            },
            "group_by": {
                "type": "string",
                "enum": ["product", "department", "payment_method", "date", "month"],
                "description": "How to group the results. Optional."
            },
            "department_id": {
                "type": "number",
                "description": "Filter by department ID. Optional."
            },
            "limit": {
                "type": "number",
                "description": "Maximum number of results. Default: 100."
            }
        }
    }
  • Registration of the 'sales_summary' tool in the list_tools() function, including name, description, and input schema.
    Tool(
        name="sales_summary",
        description="Get sales summary statistics. Aggregate sales data by date range, product, department, or payment method.",
        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."
                },
                "group_by": {
                    "type": "string",
                    "enum": ["product", "department", "payment_method", "date", "month"],
                    "description": "How to group the results. Optional."
                },
                "department_id": {
                    "type": "number",
                    "description": "Filter by department ID. Optional."
                },
                "limit": {
                    "type": "number",
                    "description": "Maximum number of results. Default: 100."
                }
            }
        }
    ),
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a 'Get' operation implying read-only behavior, but doesn't mention important aspects like authentication requirements, rate limits, pagination behavior (beyond the limit parameter), error conditions, or what format the summary statistics are returned in. The description is minimal and leaves critical behavioral traits unspecified.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with two sentences that efficiently convey the core functionality. The first sentence states the primary purpose, and the second elaborates on aggregation capabilities. There's no unnecessary verbiage, though it could be slightly more structured by separating different aspects of functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 5-parameter aggregation tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what 'summary statistics' actually means (totals, averages, counts?), doesn't mention how results are structured when grouped, and provides no information about response format or error handling. The description leaves too many contextual gaps for effective tool selection and invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds marginal value by mentioning the aggregation dimensions (date range, product, department, payment method) which correspond to some parameters, but doesn't provide additional semantic context beyond what's in the schema descriptions. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Get sales summary statistics' with specific aggregation dimensions (date range, product, department, payment method). It uses a clear verb ('Get') and resource ('sales summary statistics'), but doesn't explicitly distinguish it from sibling tools like 'query_transactions' or 'top_products' which might overlap in sales data analysis.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions aggregation capabilities but doesn't specify scenarios where this summary tool is preferred over raw data queries like 'query_transactions' or specialized tools like 'top_products'. No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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