Safaricom Daraja API MCP
A comprehensive Model Context Protocol (MCP) implementation for the Safaricom Daraja API, enabling seamless integration with M-Pesa payment services.
Developed by: Meshack Musyoka
🚀 Features
Core Payment Operations
- M-Pesa Express (STK Push) - Lipa Na M-Pesa Online payments
- C2B Payments - Customer to Business transactions
- B2C Payments - Business to Customer disbursements
- B2B Payments - Business to Business transfers
Utility Operations
- Account Balance - Query M-Pesa account balance
- Transaction Status - Check transaction status
- Transaction Reversal - Reverse erroneous transactions
- Dynamic QR Codes - Generate payment QR codes
Advanced Features
- Sandbox & Production environment support
- Comprehensive error handling with detailed responses
- Rate limiting and retry logic
- Secure credential management
- Full TypeScript support with type definitions
📦 Available Implementations
| Language | Status | Directory | Package Manager | Features |
|---|---|---|---|---|
| Node.js/TypeScript | ✅ Complete | nodejs/ | npm | Full MCP server with async/await |
| Python | ✅ Complete | python/ | PyPI (coming soon) | Pythonic implementation with type hints |
| PHP | ✅ Complete | php/ | Composer (coming soon) | Modern PHP 8+ with OOP structure |
🛠 MCP Tools
Authentication
daraja_generate_token- Generate OAuth access tokens for API calls
Payment Operations
daraja_stk_push- Initiate M-Pesa Express payment requestdaraja_stk_query- Query STK Push transaction statusdaraja_c2b_register- Register C2B confirmation and validation URLsdaraja_c2b_simulate- Simulate C2B payment (sandbox only)daraja_b2c_payment- Send money from business to customerdaraja_b2b_payment- Transfer funds between business accounts
Utility Operations
daraja_account_balance- Check M-Pesa account balancedaraja_transaction_status- Query the status of any transactiondaraja_reversal- Reverse a transactiondaraja_generate_qr- Generate dynamic QR codes for payments
🚀 Quick Start
Node.js/TypeScript
Install from npm (Recommended)
bash# Global installation npm install -g @meshark/safaricom-daraja-mcp # Set environment variables and run export DARAJA_CONSUMER_KEY=your_key export DARAJA_CONSUMER_SECRET=your_secret export DARAJA_BUSINESS_SHORT_CODE=your_shortcode export DARAJA_PASS_KEY=your_pass_key export DARAJA_ENVIRONMENT=sandbox mcp-daraja
Build from source
bashcd nodejs npm install npm run build npm start
🔌 Quick MCP Setup
After installing via npm, configure with your preferred AI tool:
Claude Desktop:
json{ "mcpServers": { "daraja": { "command": "mcp-daraja", "env": { "DARAJA_CONSUMER_KEY": "your_key", "DARAJA_CONSUMER_SECRET": "your_secret", "DARAJA_BUSINESS_SHORT_CODE": "your_shortcode", "DARAJA_PASS_KEY": "your_pass_key", "DARAJA_ENVIRONMENT": "sandbox" } } } }
Python
bashcd python pip install -r requirements.txt python -m mcp_daraja
PHP
bashcd php composer install php src/server.php
📖 Documentation
- 🔌 MCP Integration Guide - Complete setup for Claude Desktop, VS Code, Cursor & more
- API Reference - Detailed documentation of all MCP tools
- Integration Guide - Step-by-step integration instructions
- Configuration - Environment setup and configuration
- Examples - Code examples for each implementation
- Troubleshooting - Common issues and solutions
🔐 Configuration
All implementations require the following Daraja API credentials:
json{ "consumer_key": "your_consumer_key", "consumer_secret": "your_consumer_secret", "business_short_code": "your_shortcode", "pass_key": "your_pass_key", "environment": "sandbox" // or "production" }
🌐 Environment Support
Sandbox URLs
- Base URL:
https://sandbox.safaricom.co.ke - OAuth:
/oauth/v1/generate - STK Push:
/mpesa/stkpush/v1/processrequest
Production URLs
- Base URL:
https://api.safaricom.co.ke - OAuth:
/oauth/v1/generate - STK Push:
/mpesa/stkpush/v1/processrequest
🤝 Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
👨💻 Author
Meshack Musyoka
- Email: meshnzai1@gmail.com
- GitHub: @Meshhack
💝 Support This Project
If this MCP server has been helpful for your M-Pesa integration, consider supporting its development:
☕ Buy Me a Coffee
📱 M-Pesa (Kenya)
For local supporters in Kenya, you can send M-Pesa donations directly:
📞 +254 702 152 220 (Meshack Musyoka)
Your support helps maintain and improve this open-source project! 🙏
🙏 Acknowledgments
- Safaricom for the Daraja API
- Model Context Protocol by Anthropic
- The open-source community for inspiration and tools
📞 Support
For support and questions:
- Create an issue
- Check the documentation
- Review examples




