Skip to main content
Glama
nasoma

Africa's Talking Airtime MCP

get_last_topups

Retrieve recent airtime top-up transactions from Africa's Talking database to monitor payment history and track recharge patterns across supported countries.

Instructions

Retrieves the last N top-up transactions from the database.

Args:
    limit (int, optional): The number of recent transactions to fetch.
                           Defaults to 3.

Returns:
    str: A formatted string listing the last N transactions or a message
         if no transactions are found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo

Implementation Reference

  • main.py:174-215 (handler)
    The main handler function for the 'get_last_topups' tool. It is decorated with @mcp.tool(), which registers it with the MCP server. The function queries the SQLite database for the last 'limit' (default 3) top-up transactions, formats them nicely, and returns as a string. Handles errors gracefully.
    @mcp.tool()
    async def get_last_topups(limit: int = 3) -> str:
        """Retrieves the last N top-up transactions from the database.
    
        Args:
            limit (int, optional): The number of recent transactions to fetch.
                                   Defaults to 3.
    
        Returns:
            str: A formatted string listing the last N transactions or a message
                 if no transactions are found.
        """
        try:
            with sqlite3.connect(DB_PATH) as conn:
                cursor = conn.cursor()
                cursor.execute(
                    """
                    SELECT phone_number, amount, currency_code, transaction_time
                    FROM transactions
                    ORDER BY transaction_time DESC
                    LIMIT ?
                    """,
                    (limit,),
                )
                rows = cursor.fetchall()
    
            if not rows:
                return "No top-up transactions found."
    
            result = f"Last {limit} top-up transactions:\n"
            for row in rows:
                try:
                    transaction_time = datetime.strptime(
                        row[3], "%Y-%m-%d %H:%M:%S.%f"
                    ).strftime("%Y-%m-%d %H:%M:%S")
                except ValueError:
                    transaction_time = row[3]
                result += f"- {transaction_time}: {row[2]} {row[1]:.2f} to {row[0]}\n"
            return result
        except Exception as e:
            return f"Error fetching top-ups: {str(e)}"

Tool Definition Quality

Score is being calculated. Check back soon.

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

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