Skip to main content
Glama

M-Pesa Transaction Status

mpesa_transaction_status
Read-onlyIdempotent

Query the status of any M-Pesa transaction by its receipt number. Verify payment success or failure to reconcile accounts and resolve disputes promptly.

Instructions

Query the status of any M-Pesa transaction by receipt number. Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL env vars.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
transaction_idYesM-Pesa receipt number e.g. QKL8XXXXXX

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual implementation of the mpesa_transaction_status tool. It takes a transaction_id (M-Pesa receipt number), builds a payload with the required Daraja API fields (Initiator, SecurityCredential, CommandID, TransactionID, PartyA, etc.), sends a POST request to /mpesa/transactionstatus/v1/query, and returns the async result info (conversation_id, response_code, etc.).
    @mcp.tool(annotations={
        'title': 'M-Pesa Transaction Status',
        'readOnlyHint': True,
        'destructiveHint': False,
        'idempotentHint': True,
        'openWorldHint': True,
    })
    def mpesa_transaction_status(
        transaction_id: Annotated[str, "M-Pesa receipt number e.g. QKL8XXXXXX"],
    ) -> dict:
        """
        Query the status of any M-Pesa transaction by receipt number.
        Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL env vars.
        """
        payload = {
            "Initiator":           os.environ["MPESA_INITIATOR_NAME"],
            "SecurityCredential":  os.environ["MPESA_SECURITY_CREDENTIAL"],
            "CommandID":           "TransactionStatusQuery",
            "TransactionID":       transaction_id,
            "PartyA":              os.environ["MPESA_SHORTCODE"],
            "IdentifierType":      "4",
            "ResultURL":           os.environ.get("MPESA_RESULT_URL", os.environ["MPESA_CALLBACK_URL"]),
            "QueueTimeOutURL":     os.environ.get("MPESA_TIMEOUT_URL", os.environ["MPESA_CALLBACK_URL"]),
            "Remarks":             "Status query via mpesa-mcp",
            "Occasion":            "",
        }
    
        token = _get_mpesa_token()
        resp  = requests.post(
            f"{_mpesa_base()}/mpesa/transactionstatus/v1/query",
            json=payload,
            headers={"Authorization": f"Bearer {token}"},
            timeout=10,
        )
        resp.raise_for_status()
        data = resp.json()
    
        return {
            "accepted":          data.get("ResponseCode") == "0",
            "conversation_id":   data.get("ConversationID"),
            "response_code":     data.get("ResponseCode"),
            "description":       data.get("ResponseDescription"),
            "note":              "Result delivered asynchronously to MPESA_RESULT_URL",
        }
  • The @mcp.tool decorator registers mpesa_transaction_status as a tool on the FastMCP server instance, with annotations including title 'M-Pesa Transaction Status', readOnlyHint=True, destructiveHint=False, idempotentHint=True.
    @mcp.tool(annotations={
  • The function signature defines the input schema: transaction_id is an Annotated[str, ...] parameter described as 'M-Pesa receipt number e.g. QKL8XXXXXX'. The return type is dict (no formal Pydantic model, relies on FastMCP's automatic schema generation from annotations).
    def mpesa_transaction_status(
        transaction_id: Annotated[str, "M-Pesa receipt number e.g. QKL8XXXXXX"],
    ) -> dict:
Behavior4/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true, which are consistent with description. Description adds the requirement of specific env vars, providing behavioral context beyond annotations. No contradiction.

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?

Two sentences with front-loaded main action and essential prerequisite info. No unnecessary words.

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 low complexity (1 parameter, read-only, output schema exists), description covers purpose and env vars. Could mention output format but not essential. Overall complete.

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

Parameters3/5

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

Input schema covers the only parameter with a clear description ('M-Pesa receipt number e.g. QKL8XXXXXX'), achieving 100% coverage. Description echoes 'by receipt number', adding no new semantics beyond schema.

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?

Description uses specific verb 'Query' and resource 'M-Pesa transaction status', clearly distinguishing from sibling tools like mpesa_stk_push (initiates) and mpesa_stk_query (queries STK push).

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?

Description mentions required environment variables (MPESA_INITIATOR_NAME, MPESA_SECURITY_CREDENTIAL) but does not explicitly state when to use this tool versus alternatives like mpesa_stk_query. Usage context is implied but not fully guided.

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/gabrielmahia/mpesa-mcp'

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