M-Pesa MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add -e "MPESA_CONSUMER_KEY=${MPESA_CONSUMER_KEY}" -e "MPESA_CONSUMER_SECRET=${MPESA_CONSUMER_SECRET}" -e "MPESA_SHORTCODE=${MPESA_SHORTCODE}" -e "MPESA_PASSKEY=${MPESA_PASSKEY}" -e "MPESA_CALLBACK_URL=${MPESA_CALLBACK_URL}" -e "MPESA_SANDBOX=${MPESA_SANDBOX}" -e "AT_USERNAME=${AT_USERNAME}" -e "AT_API_KEY=${AT_API_KEY}" mpesa-mcp -- uvx mpesa-mcp
Required:MPESA_CONSUMER_KEYMPESA_CONSUMER_SECRETMPESA_SHORTCODEMPESA_PASSKEYMPESA_CALLBACK_URLMPESA_SANDBOXAT_USERNAMEAT_API_KEY
README.md

MCP server for East African fintech APIs — M-Pesa and Africa's Talking

mpesa-mcp

MCP server for East African fintech APIs — M-Pesa (Safaricom Daraja) and Africa's Talking

Give your AI agent the ability to trigger M-Pesa payments, check transaction status, send SMS, and top up airtime across 20+ African telecom networks.

Why this exists

M-Pesa processes more transactions per day than PayPal does in Africa. Africa's Talking reaches users in 20+ countries on basic phones via SMS and USSD. Neither has an MCP server.

This means every AI agent built today — Claude, GPT, Gemini, or any MCP-compatible runtime — cannot trigger an M-Pesa payment or send a Kiswahili SMS without custom integration work.

mpesa-mcp closes that gap in one pip install.

Tools

Tool Description
mpesa_stk_push Trigger STK Push payment prompt on customer's M-Pesa phone
mpesa_stk_query Check status of an STK Push request
mpesa_transaction_status Query any M-Pesa transaction by receipt number
sms_send Send SMS to 1–1,000 recipients across African networks
airtime_send Send airtime top-up to any subscriber (KES, NGN, GHS, UGX, etc.)

Coverage

  • M-Pesa: Kenya (Safaricom Daraja v3) — STK Push, C2B, transaction status
  • SMS/Airtime: Kenya, Nigeria, Ghana, Tanzania, Uganda, Rwanda, South Africa, and 15+ more via Africa's Talking

Install

pip install mpesa-mcp

Or run directly with uvx:

uvx mpesa-mcp

Configuration

Set these environment variables before starting the server:

# M-Pesa (Safaricom Daraja)
MPESA_CONSUMER_KEY=your_consumer_key
MPESA_CONSUMER_SECRET=your_consumer_secret
MPESA_SHORTCODE=174379               # sandbox test shortcode
MPESA_PASSKEY=your_passkey
MPESA_CALLBACK_URL=https://yourdomain.com/mpesa/callback
MPESA_SANDBOX=true                   # set false for production

# Africa's Talking
AT_USERNAME=sandbox                  # your AT username (sandbox for testing)
AT_API_KEY=your_at_api_key

Sandbox credentials

M-Pesa sandbox: https://developer.safaricom.co.ke — create a free app to get test credentials.

  • Test shortcode: 174379
  • Test passkey: bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919

Africa's Talking sandbox: https://account.africastalking.com — use username=sandbox, any API key.

Usage with Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "mpesa": {
      "command": "uvx",
      "args": ["mpesa-mcp"],
      "env": {
        "MPESA_CONSUMER_KEY": "your_key",
        "MPESA_CONSUMER_SECRET": "your_secret",
        "MPESA_SHORTCODE": "174379",
        "MPESA_PASSKEY": "your_passkey",
        "MPESA_CALLBACK_URL": "https://yourdomain.com/mpesa/callback",
        "MPESA_SANDBOX": "true",
        "AT_USERNAME": "sandbox",
        "AT_API_KEY": "your_at_key"
      }
    }
  }
}

Usage with Claude Code

claude mcp add mpesa -- uvx mpesa-mcp

Set env vars in your shell before running claude.

Example prompts

Once connected, you can ask your AI agent:

"Send KES 500 STK Push to +254712345678 for order #1234"

"Check if the payment QKL8ABC123 has been received"

"Send an SMS to these 50 farmers with today's maize price: [list]"

"Top up KES 50 airtime for our field agents: [list of numbers]"

Real-world scenarios

Field agent payment dispatch

"Send KES 300 STK Push to each of these 12 field agents for today's data collection: [list]"

The agent triggers 12 sequential STK pushes, tracks each checkout_request_id, and polls for confirmation — without any code from you.

Farmer alert + airtime

"SMS these 200 Garissa farmers that the river is rising. Then top up KES 20 airtime each so they can call in reports."

One prompt → 200 SMS messages and 200 airtime top-ups across Safaricom, Airtel, and Telkom.

Payment reconciliation

"Check whether receipt OKL8M3B2HF was a successful payment and how much it was for"

Useful for support agents using Claude to verify M-Pesa transactions in real time.

Development

git clone https://github.com/gabrielmahia/mpesa-mcp
cd mpesa-mcp
pip install -e ".[dev]"
pytest tests/ -v

Security

Do not commit API keys. Use environment variables or a secrets manager.
Report vulnerabilities to: contact@aikungfu.dev

License

MIT — © 2026 Gabriel Mahia

Tools (5)

mpesa_stk_pushTrigger STK Push payment prompt on customer's M-Pesa phone
mpesa_stk_queryCheck status of an STK Push request
mpesa_transaction_statusQuery any M-Pesa transaction by receipt number
sms_sendSend SMS to 1–1,000 recipients across African networks
airtime_sendSend airtime top-up to any subscriber

Environment Variables

MPESA_CONSUMER_KEYrequiredSafaricom Daraja consumer key
MPESA_CONSUMER_SECRETrequiredSafaricom Daraja consumer secret
MPESA_SHORTCODErequiredM-Pesa shortcode
MPESA_PASSKEYrequiredM-Pesa passkey
MPESA_CALLBACK_URLrequiredURL for M-Pesa callbacks
MPESA_SANDBOXrequiredSet to true for sandbox, false for production
AT_USERNAMErequiredAfrica's Talking username
AT_API_KEYrequiredAfrica's Talking API key

Configuration

claude_desktop_config.json
{"mcpServers": {"mpesa": {"command": "uvx", "args": ["mpesa-mcp"], "env": {"MPESA_CONSUMER_KEY": "your_key", "MPESA_CONSUMER_SECRET": "your_secret", "MPESA_SHORTCODE": "174379", "MPESA_PASSKEY": "your_passkey", "MPESA_CALLBACK_URL": "https://yourdomain.com/mpesa/callback", "MPESA_SANDBOX": "true", "AT_USERNAME": "sandbox", "AT_API_KEY": "your_at_key"}}}}

Try it

Send KES 500 STK Push to +254712345678 for order #1234
Check if the payment QKL8ABC123 has been received
Send an SMS to these 5 farmers with today's maize price: [list]
Top up KES 50 airtime for our field agents: [list of numbers]

Frequently Asked Questions

What are the key features of M-Pesa MCP?

Trigger M-Pesa STK Push payments. Query M-Pesa transaction status by receipt. Send bulk SMS to 20+ African countries. Automated airtime top-up for mobile subscribers.

What can I use M-Pesa MCP for?

Automated payment dispatch for field agents. Bulk SMS alerts and airtime distribution for rural communities. Real-time payment reconciliation for support agents.

How do I install M-Pesa MCP?

Install M-Pesa MCP by running: pip install mpesa-mcp

What MCP clients work with M-Pesa MCP?

M-Pesa MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep M-Pesa MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare