# gabrielmahia/mpesa-mcp [Health: Active]

**Category:** 💰 Finance & Fintech  
**Repository:** https://github.com/gabrielmahia/mpesa-mcp  
**GitHub Stars:** 7  
**Views:** 1  
**Installs:** 0  
**Upvotes:** 0  
**Directory Page:** https://allmcps.com/mcp/gabrielmahia-mpesa-mcp

## Description
First MCP server for M-PESA (Safaricom Daraja API) — STK push, B2C payments, balance queries, transaction status, SIM swap detection, Bill Manager, and 16 more tools for Kenya's 35M+ mobile money users. pip install mpesa-mcp.

## Tools
Capabilities this server exposes over MCP:

- **mpesa_stk_push** — Trigger M-Pesa STK Push — sends payment prompt to customer's phone.
Customer enters M-PESA PIN to complete payment.
Returns CheckoutRequestID; poll mpesa_stk_query after 10-30 seconds.
- **mpesa_stk_query** — Check STK Push status. Poll 10-30s after mpesa_stk_push.
ResultCode 0 = success, 1032 = cancelled, 1037 = timed out.

IMPORTANT: Daraja's STK Push has a ~60s window and the callback is NOT
guaranteed to fire if the user dismisses the prompt. Poll this tool 2-3
times across that window before treating silence as failure — a single
empty response does not mean the payment failed.
- **mpesa_b2c** — Business To Customer disbursement — send money from shortcode to phone.
Use for payroll, NGO field incentives, agent float, survey rewards.
Result delivered async to MPESA_RESULT_URL.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL env vars.
- **mpesa_business_paybill** — Pay directly from business shortcode to another paybill number.
Use for supplier payments, utility bills, inter-business transfers.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
- **mpesa_business_buygoods** — Pay from business shortcode to a till/buy-goods number.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
- **mpesa_business_pochi** — Pay from business shortcode to a Pochi la Biashara micro-SME wallet.
Used for micro-enterprise supplier payments and informal sector settlements.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
- **mpesa_transaction_status** — Query status of any M-Pesa transaction by receipt number.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
Result delivered async to MPESA_RESULT_URL.
- **mpesa_account_balance** — Query current balance of the business M-Pesa account (shortcode/till).
Result delivered async to MPESA_RESULT_URL.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
- **mpesa_query_org_info** — Validate a shortcode — returns the registered name and tariff type.
Use before sending B2B payments to confirm the destination shortcode is correct.
Prevents accidental payments to wrong paybill numbers.
- **mpesa_pull_transactions** — Pull all C2B transactions for reconciliation within a date range.
Returns customer payments to your shortcode for audit and reconciliation.
Max range: 48 hours per call. Max 10,000 records per call.
- **mpesa_reversal** — Reverse an erroneous M-Pesa transaction.
Use when a payment was sent to the wrong number or wrong amount.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
Result delivered async to MPESA_RESULT_URL.
- **mpesa_dynamic_qr** — Generate a Dynamic M-PESA QR code for a specific payment amount.
Customer scans QR with their M-PESA app — amount pre-fills automatically.
Returns base64-encoded QR image. Use for receipts, invoices, POS displays.
- **mpesa_tax_remittance** — Remit tax directly from M-PESA business account to Kenya Revenue Authority.
Provide the KRA Payment Registration Number (PRN) as account_reference.
KRA shortcode: 572572. Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
- **mpesa_b2b_express_checkout** — Initiate USSD Push to till — enables merchant-to-merchant payments.
Recipient merchant receives a USSD prompt to confirm payment from their till.
Use for wholesale supplier payments between Lipa Na M-PESA merchants.
Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL.
- **mpesa_ratiba_create** — Create an M-PESA Ratiba standing order — automated recurring payments.
Customer authorizes once; payments happen automatically on schedule.
Perfect for subscription billing, rent collection, loan repayments, SACCO contributions.
Returns a standing order ID to manage/cancel later.
- **mpesa_bill_manager_optin** — Enrol your business in M-PESA Bill Manager.
Must be called once before creating invoices.
After opt-in, customers can pay your invoices directly via M-PESA.
- **mpesa_bill_manager_invoice** — Create a Bill Manager invoice — customer receives SMS with payment link.
They can pay directly via M-PESA by clicking the link or using the paybill.
Returns invoice ID. Use mpesa_bill_manager_cancel to void outstanding invoices.
- **mpesa_bill_manager_cancel** — Cancel an outstanding Bill Manager invoice.
Customer will no longer be able to pay the cancelled invoice.
Use when an order is cancelled or a duplicate invoice was created.
- **mpesa_sim_swap_query** — Check if a phone number's SIM card was recently swapped.
Critical fraud prevention signal — SIM swaps often precede account takeovers.
Use before high-value B2C disbursements to verify recipient identity is stable.
Returns swap status and last swap date.
- **mpesa_imsi_query** — Verify a Safaricom number — returns registration date, SIM age, last swap, and hashed IMSI.
Enhanced KYC/AML signal for financial services compliance.
Older SIMs with no recent swaps have lower fraud risk.
Returns data suitable for risk scoring without exposing raw IMSI.
- **sms_send** — Send SMS to 1-1000 recipients via Africa's Talking.
Works across Kenya, Nigeria, Ghana, Tanzania, Uganda, Rwanda and 15+ more.
Returns per-recipient status and cost breakdown.
- **airtime_send** — Send airtime top-up to MTN/Safaricom/Airtel/Vodafone subscribers.
Use for NGO field incentives, survey rewards, agent payouts.

Currency is validated against the recipient's country code. Sending a KES
amount to a Tanzanian number is rejected with the correct currency named,
rather than topping up the wrong denomination silently.

No real airtime sent in sandbox mode (AT_USERNAME=sandbox).
- **get_model_hint** — Returns the recommended AI model for using mpesa-mcp tools.
Call this first when selecting a model to pair with mpesa-mcp.

## Claude Desktop Quick Installation
Install path detected from listing signals. Uses `uvx` (confidence: high):

```json
"mcpServers": {
  "mpesa-mcp": {
    "command": "uvx",
    "args": ["mpesa-mcp"],
    "env": {
      "MPESA_CONSUMER_KEY": "",
      "MPESA_CONSUMER_SECRET": "",
      "MPESA_SHORTCODE": "",
      "MPESA_PASSKEY": "",
      "MPESA_CALLBACK_URL": "",
      "MPESA_SANDBOX": "",
      "AT_USERNAME": "",
      "AT_API_KEY": ""
    }
  }
}
```

**Requires environment variables:** `MPESA_CONSUMER_KEY`, `MPESA_CONSUMER_SECRET`, `MPESA_SHORTCODE`, `MPESA_PASSKEY`, `MPESA_CALLBACK_URL`, `MPESA_SANDBOX`, `AT_USERNAME`, `AT_API_KEY` — the values above are empty placeholders; fill in real credentials before running (see the repository for what each one is for).

## Documentation

## What gabrielmahia/mpesa-mcp does

gabrielmahia/mpesa-mcp gives an MCP client access to Kenya's Safaricom Daraja API and Africa's Talking services. Its M-PESA coverage includes STK Push collections, B2C disbursements, business payments to paybills, tills, and Pochi la Biashara wallets, transaction and balance queries, reversals, dynamic QR codes, tax remittance, recurring Ratiba payments, and Bill Manager invoices.

The server also supports operational and risk workflows. Agents can validate destination shortcodes, pull C2B transactions for reconciliation, check SIM-swap history, and retrieve Safaricom number data such as registration date, SIM age, last swap, and hashed IMSI. Africa's Talking tools send SMS to recipients across multiple African countries and deliver airtime to supported mobile networks.

## How it works

The server runs as a local MCP process, commonly launched with `uvx mpesa-mcp`, and exposes the provider operations as tools. M-PESA access uses Safaricom Daraja credentials; SMS and airtime use Africa's Talking credentials. Daraja OAuth tokens are cached and refreshed automatically, while API errors are returned as structured results.

STK Push is asynchronous. After calling `mpesa_stk_push`, retain the returned checkout request ID and query `mpesa_stk_query` after 10–30 seconds. The STK interaction has an approximately 60-second window, and a dismissed prompt may not produce a callback, so several status checks are appropriate before concluding that it failed. Other asynchronous operations deliver results through `MPESA_RESULT_URL`.

## Setup and configuration

Install the package with:

```bash
pip install mpesa-mcp
```

Alternatively, run it directly with `uvx mpesa-mcp`. Configure the M-PESA consumer key and secret, shortcode, passkey, callback URL, and sandbox flag. SMS and airtime require an Africa's Talking username and API key. The sandbox uses Safaricom's test shortcode and Africa's Talking's `sandbox` username; production use requires live provider credentials and an appropriate callback endpoint.

Claude Desktop can start the server through its MCP configuration, while Claude Code can add it with `claude mcp add mpesa -- uvx mpesa-mcp`. Environment variables may be set in the client configuration or the shell.

## Tools and capabilities

- Start and query STK Push payments.
- Send B2C disbursements and business-to-business payments.
- Query transactions, balances, shortcode details, and C2B records.
- Reverse transactions and generate payment QR codes.
- Create, manage, and cancel Ratiba and Bill Manager payments.
- Remit KRA tax using a payment registration number.
- Check SIM swaps and Safaricom identity data for risk workflows.
- Send SMS and airtime across supported African networks.

## Limitations and notes

Live money-moving, SMS, and airtime tools require confirmation and are subject to configured payment, session, recipient, and SMS-recipient limits. `mpesa_b2c`, business payment, status, balance, and reversal operations require initiator and security-credential configuration. Airtime is not actually sent when Africa's Talking runs with `AT_USERNAME=sandbox`, and currency is checked against the recipient's country.

The server validates Kenyan phone numbers, uses HTTPS for Daraja calls, and logs tool activity with phone numbers represented by truncated SHA-256 hashes. Sandbox testing should be completed before production use, and a person should approve live financial or messaging actions.

_Full upstream README: https://allmcps.com/mcp/gabrielmahia-mpesa-mcp/readme_

