Skip to main content
Glama

count-daily-emails

Count emails received daily within a specified date range to track email volume patterns and manage inbox activity.

Instructions

Count emails received for each day in a date range

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
start_dateYesStart date in YYYY-MM-DD format
end_dateYesEnd date in YYYY-MM-DD format

Implementation Reference

  • Registration of the 'count-daily-emails' tool, including its name, description, and JSON schema for input validation (start_date and end_date required).
    types.Tool(
        name="count-daily-emails",
        description="Count emails received for each day in a date range",
        inputSchema={
            "type": "object",
            "properties": {
                "start_date": {
                    "type": "string",
                    "description": "Start date in YYYY-MM-DD format",
                },
                "end_date": {
                    "type": "string",
                    "description": "End date in YYYY-MM-DD format",
                },
            },
            "required": ["start_date", "end_date"],
        },
    ),
  • Main handler for the 'count-daily-emails' tool. Parses start and end dates, loops through each day, performs IMAP search for emails received 'ON' that date using the count_emails_async helper, handles timeouts, and formats results as a markdown table of daily counts.
    elif name == "count-daily-emails":
        start_date = datetime.strptime(arguments["start_date"], "%Y-%m-%d")
        end_date = datetime.strptime(arguments["end_date"], "%Y-%m-%d")
        
        result_text = "Daily email counts:\n\n"
        result_text += "Date | Count\n"
        result_text += "-" * 30 + "\n"
        
        current_date = start_date
        while current_date <= end_date:
            date_str = current_date.strftime("%d-%b-%Y")
            search_criteria = f'(ON "{date_str}")'
            
            try:
                async with asyncio.timeout(SEARCH_TIMEOUT):
                    count = await count_emails_async(mail, search_criteria)
                    result_text += f"{current_date.strftime('%Y-%m-%d')} | {count}\n"
            except asyncio.TimeoutError:
                result_text += f"{current_date.strftime('%Y-%m-%d')} | Timeout\n"
            
            current_date += timedelta(days=1)
        
        return [types.TextContent(
            type="text",
            text=result_text
        )]
  • Helper function used by the count-daily-emails handler to asynchronously count the number of emails matching an IMAP search criteria (e.g., emails received on a specific date). Runs IMAP search in executor to avoid blocking.
    async def count_emails_async(mail: imaplib.IMAP4_SSL, search_criteria: str) -> int:
        """Asynchronously count emails matching the search criteria."""
        loop = asyncio.get_event_loop()
        try:
            _, messages = await loop.run_in_executor(None, lambda: mail.search(None, search_criteria))
            return len(messages[0].split()) if messages[0] else 0
        except Exception as e:
            raise Exception(f"Error counting emails: {str(e)}")

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

B3.2/5.0
Behavior2/5

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

With no annotations, description carries full burden. It does not disclose scope (e.g., all folders, spam), side effects, rate limits, or output format. Minimal behavioral context beyond the basic operation.

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

Conciseness5/5

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

Single sentence, zero waste, front-loaded with verb and resource.

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?

Missing output format (array of date-count objects), scope (which mailbox), and assumptions about missing days. No output schema to compensate.

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 coverage is 100%, so baseline is 3. Description adds no extra meaning beyond schema; it implies date range but doesn't clarify inclusive/exclusive bounds or format validation.

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

Purpose5/5

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

The description 'Count emails received for each day in a date range' uses a specific verb ('count') and resource ('emails') and clearly distinguishes from sibling tools like 'search-emails' or 'send-email'.

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?

No guidance on when to use this tool versus alternatives. It does not mention when not to use it or compare to other tools like 'search-emails' for broader queries.

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