mpesa-mcp
mpesa-mcp
用于东非金融科技 API 的 MCP 服务器 — M-Pesa (Safaricom Daraja) 和 Africa's Talking
让你的 AI 智能体具备触发 M-Pesa 支付、检查交易状态、发送短信以及为 20 多个非洲电信网络充值话费的能力。
为什么存在这个项目
M-Pesa 在非洲每天处理的交易量超过了 PayPal。Africa's Talking 通过短信和 USSD 在 20 多个国家/地区触达使用基础手机的用户。目前两者都没有 MCP 服务器。
这意味着当今构建的每一个 AI 智能体(无论是 Claude、GPT、Gemini 还是任何兼容 MCP 的运行时)如果不进行自定义集成工作,都无法触发 M-Pesa 支付或发送斯瓦希里语短信。
mpesa-mcp 通过一次 pip install 填补了这一空白。
Related MCP server: M-Pesa MCP Server
工具
工具 | 描述 |
| 在客户的 M-Pesa 手机上触发 STK 推送支付提示 |
| 检查 STK 推送请求的状态 |
| 通过收据编号查询任何 M-Pesa 交易 |
| 向非洲各网络的 1 到 1,000 名收件人发送短信 |
| 向任何订阅者发送话费充值(KES、NGN、GHS、UGX 等) |
覆盖范围
M-Pesa: 肯尼亚 (Safaricom Daraja v3) — STK 推送、C2B、交易状态
短信/话费: 肯尼亚、尼日利亚、加纳、坦桑尼亚、乌干达、卢旺达、南非以及通过 Africa's Talking 覆盖的 15 多个国家/地区
Glama (托管 MCP)
mpesa-mcp 可作为托管 MCP 服务器在 Glama 上使用:
安装
pip install mpesa-mcp或者直接使用 uvx 运行:
uvx mpesa-mcp配置
在启动服务器之前设置这些环境变量:
# 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沙盒凭据
M-Pesa 沙盒: https://developer.safaricom.co.ke — 创建一个免费应用以获取测试凭据。
测试短代码:
174379测试密钥:
bfb279f9aa9bdbcf158e97dd71a467cd2e0c893059b10f78e6b72ada1ed2c919
Africa's Talking 沙盒: https://account.africastalking.com — 使用 username=sandbox,以及任意 API 密钥。
与 Claude Desktop 一起使用
添加到 ~/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"
}
}
}
}与 Claude Code 一起使用
claude mcp add mpesa -- uvx mpesa-mcp在运行 claude 之前在你的 shell 中设置环境变量。
示例提示词
连接后,你可以询问你的 AI 智能体:
"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]"
现实场景
外勤人员支付调度
"Send KES 300 STK Push to each of these 12 field agents for today's data collection: [list]"
智能体触发 12 次连续的 STK 推送,跟踪每个 checkout_request_id,并轮询确认结果 — 无需你编写任何代码。
农民提醒 + 话费充值
"SMS these 200 Garissa farmers that the river is rising. Then top up KES 20 airtime each so they can call in reports."
一个提示词 → 在 Safaricom、Airtel 和 Telkom 网络上发送 200 条短信并进行 200 次话费充值。
支付对账
"Check whether receipt OKL8M3B2HF was a successful payment and how much it was for"
对于使用 Claude 实时验证 M-Pesa 交易的支持人员非常有用。
工具注解
所有工具都声明了 MCP 工具注解,以便客户端可以适当地控制调用:
工具 | 只读 | 破坏性 | 幂等 |
| ❌ | ✅ | ❌ |
| ✅ | ❌ | ✅ |
| ✅ | ❌ | ✅ |
| ❌ | ✅ | ❌ |
| ❌ | ✅ | ❌ |
Claude Desktop 和其他 MCP 客户端会在触发支付、短信或话费操作前请求确认。
服务器发现
功能通过 .well-known/mcp.json 进行通告 — 这是新兴的 MCP 服务器卡片标准。注册表和浏览器可以在不连接的情况下索引此服务器的工具。
# Check capabilities
curl https://raw.githubusercontent.com/gabrielmahia/mpesa-mcp/main/.well-known/mcp.json测试与准确性
MCP 生态系统基准测试 (CData, 2026) 发现,大多数 MCP 服务器在复杂查询上的准确率为 60–75% — 特别是在写入操作的静默失败和部分参数应用方面。
mpesa-mcp 针对所有三种肯尼亚电话号码格式、边界金额值和缺失的可选字段进行了测试:
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写入操作(STK 推送、短信、话费)在进行任何 API 调用之前都有明确的验证。
生态系统背景 — Mojaloop + MCP
Mojaloop(由盖茨基金会资助)处理支付互操作性 — 连接东非及其他地区的银行、移动钱包和商户。
mpesa-mcp 处理* AI 智能体工具层* — 使 AI 编码助手能够以编程方式触发和查询 M-Pesa 支付。
它们是互补的:
Mojaloop:金融提供商之间的互操作性轨道
mpesa-mcp:将 AI 智能体连接到这些轨道的 MCP 接口层
有关此模式的更多信息,请参阅 Mojaloop 文档贡献。
MCP 与 A2A — 两种不同的协议
mpesa-mcp 实现了 MCP (模型上下文协议) — AI 智能体如何与工具对话。
还有一个互补协议 A2A (智能体到智能体),它处理智能体如何相互对话。它们解决不同的问题并协同工作:
MCP: 你的 AI 智能体 → mpesa-mcp → Daraja API / Africa's Talking
A2A: 编排智能体 ↔ 支付子智能体 ↔ 通知子智能体
对于大多数集成,你只需要 MCP。当你构建多智能体系统,其中支付工作流需要与其他专业智能体协调时,A2A 才会变得相关。
开发
git clone https://github.com/gabrielmahia/mpesa-mcp
cd mpesa-mcp
pip install -e ".[dev]"
pytest tests/ -v安全
不要提交 API 密钥。请使用环境变量或密钥管理器。 报告漏洞请联系:contact@aikungfu.dev
许可证
MIT — © 2026 Gabriel Mahia
保持更新
获取新版本和东非 API 开发的通知: 订阅更新 →
或者在 GitHub 上关注此仓库以获取发布通知。
同系列包
包 | 安装 | 描述 |
| 肯尼亚干旱情报 MCP 服务器 | |
| 东非公民 AI SDK |
相关包
均为 MIT 协议 · 均为东非公民 AI 技术栈的一部分
包 | 安装 | 描述 |
| 肯尼亚干旱情报 MCP 服务器 | |
| 肯尼亚健康数据 MCP — NHIF、设施、孕产、权利 | |
| 东非公民 AI SDK |
完整作品集:gabrielmahia.github.io
Available Tools
5 toolsairtime_sendSend AirtimeADestructive
Send airtime top-up to any MTN/Safaricom/Airtel/Vodafone subscriber. Common use: NGO field incentives, survey rewards, agent payouts. No real airtime sent in sandbox mode.
Inputs: phone (required), amount (required), currency_code. Returns: object
mpesa_stk_pushM-Pesa STK PushADestructive
Trigger an M-Pesa STK Push — sends a payment prompt to the customer's phone. The customer enters their M-Pesa PIN to complete payment. Returns a CheckoutRequestID to track the transaction with mpesa_stk_query. Async: use mpesa_stk_query after 10-30 seconds to check completion.
Inputs: phone (required), amount (required), account_ref (required), description. Returns: object
mpesa_stk_queryM-Pesa STK QueryARead-onlyIdempotent
Check the status of an STK Push request. Poll this 10-30 seconds after calling mpesa_stk_push. ResultCode 0 = success, 1032 = cancelled by user, 1037 = timed out.
Inputs: checkout_request_id (required). Returns: object
mpesa_transaction_statusM-Pesa Transaction StatusARead-onlyIdempotent
Query the status of any M-Pesa transaction by receipt number. Requires MPESA_INITIATOR_NAME and MPESA_SECURITY_CREDENTIAL env vars.
Inputs: transaction_id (required). Returns: object
sms_sendSend SMSADestructive
Send SMS to one or many recipients via Africa's Talking. Supports up to 1,000 recipients per call. Works across Kenya, Nigeria, Ghana, Tanzania, Uganda, and 15+ African markets. Returns per-recipient status and cost.
Inputs: message (required), recipients (required), sender_id. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool targets a distinct function: airtime sending, STK push initiation, STK push status query, transaction status by receipt, and SMS sending. There is no overlap or ambiguity.
Most tools follow a verb_noun or noun_verb pattern (e.g., airtime_send, sms_send, mpesa_stk_push), but mpesa_transaction_status lacks a verb, breaking the pattern slightly.
With 5 tools, the server is well-scoped for its purpose, covering core M-Pesa and SMS operations without being too few or too many.
The set covers STK push initiation/query and basic transaction status, but lacks airtime status, B2C/C2B transfers, or account balance queries, leaving notable gaps for a full M-Pesa integration.
Maintenance
Related MCP Connectors
South African MCP server for airtime, data, SMS, VAS, electricity, balance, and network lookup.
MCP Server for agents to onboard, pay, and provision services autonomously with InFlow
MCP server for Modern Treasury — payment orders, transactions, counterparties and ledgers.
MCP server for SuperPhone — contacts, conversations, tags and consent-based text messages.
Related MCP Servers
FlicenseNot gradedqualityDmaintenanceOpen-source MCP server that streamlines payment integration for AI agents and financial apps in Africa, providing unified tools for providers like M-Pesa.1-- FlicenseNot gradedqualityBmaintenanceAn experimental MCP server that lets AI agents interact with guarded payment workflows through typed tools, enabling safe agent-assisted payments with M-Pesa and mock Airtel Money.3-
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that integrates Safaricom's M-PESA Daraja API with Claude, enabling natural language payment processing and real-time transaction notifications.3-
- AlicenseNot gradedqualityDmaintenanceMCP server for the Lipila payment gateway, enabling AI agents to initiate mobile money and card collections, disburse funds, check transaction statuses, and verify webhook callbacks.1ISC