get_last_topups
Retrieve the latest N airtime top-up transactions to monitor and analyze recent activity in Africa's Talking API-supported countries. Input the desired limit for results.
Instructions
Get the last N top-up transactions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No |
Implementation Reference
- main.py:174-214 (handler)The handler function for the 'get_last_topups' tool. It is decorated with @mcp.tool() for registration, queries the SQLite database for the last N transactions, formats the output as a string listing phone number, amount, currency, and time, handling date parsing and errors.@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)}"