Skip to main content
Glama
nasoma

Africa's Talking Airtime MCP

sum_last_n_topups

Calculate the total amount of recent successful airtime top-ups by summing the last 'n' transactions in the same currency.

Instructions

Calculates the sum of the last 'n' successful top-ups.

This tool retrieves the last 'n' transactions from the database and
calculates their total sum. It ensures that all transactions are in the
same currency before summing.

Args:
    n (int, optional): The number of recent top-ups to sum. Defaults to 3.

Returns:
    str: The total sum of the last 'n' top-ups or an error message if
         the currencies are mixed or no transactions are found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nNo

Implementation Reference

  • main.py:217-260 (handler)
    The core handler function for the 'sum_last_n_topups' MCP tool. It is registered via the @mcp.tool() decorator. The function queries the SQLite database for the last n transactions, ensures uniform currency, sums the amounts, and returns a formatted result string. Includes validation for n > 0 and comprehensive error handling. The docstring provides schema details for input (n: int=3) and output (str).
    @mcp.tool()
    async def sum_last_n_topups(n: int = 3) -> str:
        """Calculates the sum of the last 'n' successful top-ups.
    
        This tool retrieves the last 'n' transactions from the database and
        calculates their total sum. It ensures that all transactions are in the
        same currency before summing.
    
        Args:
            n (int, optional): The number of recent top-ups to sum. Defaults to 3.
    
        Returns:
            str: The total sum of the last 'n' top-ups or an error message if
                 the currencies are mixed or no transactions are found.
        """
        if n <= 0:
            return "Please provide the number of top-ups whose total you need."
    
        try:
            with sqlite3.connect(DB_PATH) as conn:
                cursor = conn.cursor()
                cursor.execute(
                    """
                    SELECT amount, currency_code
                    FROM transactions
                    ORDER BY transaction_time DESC
                    LIMIT ?
                    """,
                    (n,),
                )
                rows = cursor.fetchall()
    
            if not rows:
                return "No successful top-ups found."
    
            currencies = set(row[1] for row in rows)
            if len(currencies) > 1:
                return "Cannot sum amounts with different currencies."
    
            total = sum(amount for (amount, _) in rows)
            currency = rows[0][1]
            return f"Sum of last {n} successful top-ups:\n- {currency} {total:.2f}"
        except Exception as e:
            return f"Error calculating sum: {str(e)}"
Behavior4/5

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

With no annotations provided, the description carries the full burden and discloses key behavioral traits: it only sums successful top-ups, retrieves from a database, ensures currency consistency, and handles error cases (mixed currencies or no transactions). It doesn't cover aspects like performance, rate limits, or authentication needs, but provides substantial operational context beyond basic functionality.

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?

The description is appropriately sized and front-loaded: the first sentence states the core purpose, followed by operational details, then clearly formatted Args and Returns sections. Every sentence adds value—none are redundant or vague—and the structure enhances readability without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (database query with calculations and error handling), no annotations, and no output schema, the description is largely complete: it covers purpose, parameters, behavior, and return values. It could benefit from mentioning prerequisites (e.g., authentication) or performance characteristics, but adequately addresses core functionality and error cases for an agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful semantics beyond the input schema: it explains that 'n' represents 'the number of recent top-ups to sum' with a default of 3, and clarifies it's optional. With 0% schema description coverage (schema only has type and title), the description fully compensates by providing clear parameter meaning and usage context.

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 clearly states the tool's purpose with specific verbs ('calculates', 'retrieves', 'ensures') and resources ('last n successful top-ups', 'transactions from the database'). It distinguishes from siblings like 'check_balance' (current balance), 'count_topups_by_number' (counts by number), 'get_last_topups' (lists without summing), and 'load_airtime' (different operation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for summing recent top-ups, but doesn't explicitly state when to use this tool versus alternatives like 'get_last_topups' (for listing) or 'count_topups_by_number' (for counting by number). It mentions currency consistency as a requirement, which provides some contextual guidance, but lacks explicit when/when-not scenarios or named alternatives.

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

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