Skip to main content
Glama
nasoma

Africa's Talking Airtime MCP

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
NameRequiredDescriptionDefault
phone_numberYes

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)}"

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/nasoma/africastalking-airtime-mcp'

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