Skip to main content

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

Project description

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.

Tests PyPI License: MIT Glama

mpesa-mcp MCP server

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.

Tool annotations

All tools declare MCP tool annotations so clients can gate calls appropriately:

Tool readOnly destructive idempotent
mpesa_stk_push
mpesa_stk_query
mpesa_transaction_status
sms_send
airtime_send

Claude Desktop and other MCP clients will request confirmation before triggering payment, SMS, or airtime operations.

Server discovery

Capabilities are advertised via .well-known/mcp.json — the emerging MCP Server Cards standard. Registries and browsers can index this server's tools without connecting to it.

# Check capabilities
curl https://raw.githubusercontent.com/gabrielmahia/mpesa-mcp/main/.well-known/mcp.json

Testing and accuracy

The MCP ecosystem benchmark (CData, 2026) found most MCP servers accurate 60–75% of the time on complex queries — particularly silent failures on write operations and partial parameter application.

mpesa-mcp is tested against all three Kenyan phone number formats, boundary amount values, and missing optional fields:

pytest tests/ -v  # run full suite
pytest tests/test_phone_formats.py  # format normalization
pytest tests/test_boundary_amounts.py  # min/max amount edge cases

Write operations (STK push, SMS, airtime) have explicit validation before any API call is made.

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

CC BY-NC-ND 4.0 — © 2026 Gabriel Mahia

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpesa_mcp-0.1.4.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mpesa_mcp-0.1.4-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file mpesa_mcp-0.1.4.tar.gz.

File metadata

  • Download URL: mpesa_mcp-0.1.4.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mpesa_mcp-0.1.4.tar.gz
Algorithm Hash digest
SHA256 12ed238e85701a2214eec23f0891a9eb8635498b4e00719138a251ca329c1a70
MD5 698f93a4222111dfdca0542669ac21b3
BLAKE2b-256 33a8c25547a071deb1a307f396372182170e8d7144775d5e0beece0166d4719e

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpesa_mcp-0.1.4.tar.gz:

Publisher: publish.yml on gabrielmahia/mpesa-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mpesa_mcp-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: mpesa_mcp-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mpesa_mcp-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 528025c72acdb6d9bd25f2a49c960c0a9e414d58d8ab4f84a9106abdafd8bf75
MD5 c63d73c6182810fa0820fddb13ea283e
BLAKE2b-256 48aa54800239dc376633a267f37e90e10d792162bfa85c1999588a3dbaafa106

See more details on using hashes here.

Provenance

The following attestation bundles were made for mpesa_mcp-0.1.4-py3-none-any.whl:

Publisher: publish.yml on gabrielmahia/mpesa-mcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page