count_topups_by_number
Count airtime top-up transactions for a specific phone number to track usage patterns and analyze recharge frequency.
Instructions
Counts the number of top-ups for a specific phone number.
Args:
phone_number (str): The phone number to count transactions for.
Returns:
str: The total count of top-ups for the given number or an error message.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| phone_number | Yes |
Implementation Reference
- main.py:263-289 (handler)The main handler function for the 'count_topups_by_number' tool. It formats the phone number, queries the SQLite database to count transactions for that number, and returns the count or an error message.@mcp.tool() async def count_topups_by_number(phone_number: str) -> str: """Counts the number of top-ups for a specific phone number. Args: phone_number (str): The phone number to count transactions for. Returns: str: The total count of top-ups for the given number or an error message. """ try: formatted_number = format_phone_number(phone_number) with sqlite3.connect(DB_PATH) as conn: cursor = conn.cursor() cursor.execute( """ SELECT COUNT(*) as count FROM transactions WHERE phone_number = ? """, (formatted_number,), ) count = cursor.fetchone()[0] return f"Number of successful top-ups to {formatted_number}: {count}" except Exception as e: return f"Error counting top-ups: {str(e)}"