Skip to main content
Glama
t2hnd

Bakery Data MCP Server

by t2hnd

top_products

Retrieve top-selling bakery products by quantity or revenue. Filter results by date range and department to analyze sales performance.

Instructions

Get top selling products by quantity or revenue. Supports filtering by date range and department.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateNoStart date (YYYY-MM-DD format). Optional.
end_dateNoEnd date (YYYY-MM-DD format). Optional.
department_idNoFilter by department ID. Optional.
metricNoRank by quantity sold or total revenue. Default: revenue.
limitNoNumber of top products to return. Default: 10.

Implementation Reference

  • Handler for the 'top_products' tool. Constructs and executes a SQL query to retrieve top-selling products based on specified metric (quantity or revenue), date range, department filter, and limit. Joins with products table if department filter is applied. Returns JSON-formatted results.
    elif name == "top_products":
        metric = arguments.get("metric", "revenue")
    
        if metric == "quantity":
            order_by = "total_quantity DESC"
        else:
            order_by = "total_revenue DESC"
    
        query = f"""
            SELECT product_code, product_name,
                   COUNT(*) as transaction_count,
                   SUM(quantity) as total_quantity,
                   SUM(amount) as total_revenue,
                   AVG(unit_price) as avg_price
            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 "department_id" in arguments:
            query = """
                SELECT t.product_code, t.product_name,
                       COUNT(*) as transaction_count,
                       SUM(t.quantity) as total_quantity,
                       SUM(t.amount) as total_revenue,
                       AVG(t.unit_price) as avg_price
                FROM transactions t
                JOIN products p ON t.product_code = p.plu_code
                WHERE p.department_id = ?
            """
            params.insert(0, arguments["department_id"])
    
            if "start_date" in arguments:
                query += " AND t.datetime >= ?"
            if "end_date" in arguments:
                query += " AND t.datetime <= ?"
    
        query += f" GROUP BY product_code, product_name ORDER BY {order_by} LIMIT ?"
        params.append(arguments.get("limit", 10))
    
        cursor.execute(query, params)
        results = cursor.fetchall()
    
        return [TextContent(
            type="text",
            text=json.dumps(results, ensure_ascii=False, indent=2)
        )]
  • Registration of the 'top_products' tool in the list_tools() function, including name, description, and input schema definition for MCP tool discovery.
    Tool(
        name="top_products",
        description="Get top selling products by quantity or revenue. Supports filtering by date range and department.",
        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."
                },
                "department_id": {
                    "type": "number",
                    "description": "Filter by department ID. Optional."
                },
                "metric": {
                    "type": "string",
                    "enum": ["quantity", "revenue"],
                    "description": "Rank by quantity sold or total revenue. Default: revenue."
                },
                "limit": {
                    "type": "number",
                    "description": "Number of top products to return. Default: 10."
                }
            }
        }
    ),
  • Input schema for the 'top_products' tool, defining parameters for date range, department, ranking metric, 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."
            },
            "department_id": {
                "type": "number",
                "description": "Filter by department ID. Optional."
            },
            "metric": {
                "type": "string",
                "enum": ["quantity", "revenue"],
                "description": "Rank by quantity sold or total revenue. Default: revenue."
            },
            "limit": {
                "type": "number",
                "description": "Number of top products to return. Default: 10."
            }
        }
    }
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 mentions what the tool does but doesn't address important behavioral aspects: whether this is a read-only operation, potential rate limits, authentication requirements, error handling, or what format the results will be returned in. The description is functional but lacks operational context.

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 clear sentences. The first sentence states the core purpose, the second adds key capabilities. No wasted words, though it could be slightly more front-loaded with the most critical information.

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 tool with 5 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the output looks like (list format, fields returned), doesn't mention default behavior when parameters are omitted, and provides no context about performance characteristics or limitations. The description leaves too many operational questions unanswered.

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 minimal value beyond the schema - it mentions filtering by date range and department, which the schema already covers. It doesn't provide additional context about parameter interactions or edge cases beyond what's in the schema descriptions.

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: 'Get top selling products by quantity or revenue' with specific verb+resource. It distinguishes itself from siblings like query_products or sales_summary by focusing on ranking products. However, it doesn't explicitly differentiate from all siblings (e.g., sales_summary might also provide ranking data).

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 like query_products, sales_summary, or execute_sql. It mentions filtering capabilities but doesn't specify scenarios where this tool is preferred over other data retrieval tools in the server.

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