Daraja M-Pesa Integration
STDIOMCP server integrating AI applications with Safaricom's Daraja API for M-Pesa services.
MCP server integrating AI applications with Safaricom's Daraja API for M-Pesa services.
A Model Context Protocol (MCP) server designed to integrate AI applications with Safaricom's Daraja API, enabling seamless interaction with M-Pesa services.
⚠️ Warning: Not Production Ready
This project is currently in development and is not recommended for production use. It's designed for:
- Learning and experimentation
- Development and testing environments
- Proof of concept implementations
For production use, please ensure:
- Thorough security testing
- Proper error handling
- Complete implementation of all planned features
- Compliance with Safaricom's production requirements
MCP (Model Context Protocol) servers provide capabilities for LLMs to interact with external systems. MCP servers can provide three main types of capabilities:
Daraja MCP specifically leverages this architecture to connect AI systems with Safaricom's Daraja M-Pesa API.
Daraja MCP is a bridge between AI, fintech, and M-Pesa, making AI-driven financial automation accessible and efficient. By standardizing the connection between LLMs (Large Language Models) and financial transactions, Daraja MCP allows AI-driven applications to process payments, retrieve transaction data, and automate financial workflows effortlessly.
Install uv Package Manager
For Mac/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
For Windows (PowerShell):
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
Clone the Repository
git clone https://github.com/jameskanyiri/DarajaMCP.git cd DarajaMCP
Create and Activate a Virtual Environment
uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate
✅ Expected Output: Your terminal prompt should change, indicating the virtual environment is activated.
Install Dependencies
uv sync
Copy the example environment file:
cp .env.example .env
Update the .env
file with your actual credentials and configuration values.
Note: For development, use the sandbox environment. Switch to the production URL when ready.
Install Claude Desktop
Configure Claude Desktop
Open your Claude Desktop configuration file:
# On MacOS/Linux code ~/Library/Application\ Support/Claude/claude_desktop_config.json # On Windows code %APPDATA%\Claude\claude_desktop_config.json
Create the file if it doesn't exist
Add Server Configuration Choose one of the following configurations:
{ "mcpServers": { "daraja": { "command": "uv", "args": [ "--directory", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP", "run", "main.py" ] } } }
{ "mcpServers": { "DarajaMCP": { "command": "/ABSOLUTE/PATH/TO/PARENT/.local/bin/uv", "args": [ "--directory", "/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP", "run", "main.py" ] } } }
Note:
- Replace
/ABSOLUTE/PATH/TO/PARENT
with your actual path- To find the full path to
uv
, run:
# On MacOS/Linux which uv # On Windows where uv
Verify Configuration
Initiate an M-Pesa STK push request to prompt the customer to authorize a payment on their mobile device.
Inputs:
amount
(int): The amount to be paidphone_number
(int): The phone number of the customerReturns: JSON formatted M-PESA API response
Generate a QR code for a payment request that customers can scan to make payments.
Inputs:
merchant_name
(str): Name of the company/M-Pesa Merchant Nametransaction_reference_no
(str): Transaction reference numberamount
(int): The total amount for the sale/transactiontransaction_type
(Literal["BG", "WA", "PB", "SM", "SB"]): Transaction typecredit_party_identifier
(str): Credit Party Identifier (Mobile Number, Business Number, Agent Till, Paybill, or Merchant Buy Goods)Returns: JSON formatted M-PESA API response containing the QR code data
Generate a prompt for initiating an M-Pesa STK push payment request.
Inputs:
phone_number
(str): The phone number of the customeramount
(int): The amount to be paidpurpose
(str): The purpose of the paymentReturns: Formatted prompt string for STK push request
Generate a prompt for creating an M-Pesa QR code payment request.
Inputs:
merchant_name
(str): Name of the merchant/businessamount
(int): Amount to be paidtransaction_type
(str): Type of transaction (BG for Buy Goods, WA for Wallet, PB for Paybill, SM for Send Money, SB for Send to Business)identifier
(str): The recipient identifier (till number, paybill, phone number)reference
(str, optional): Transaction reference number. If not provided, a default will be used.Returns: Formatted prompt string for QR code generation
Create a connector from data source to unstructured server for processing.
Inputs:
connector_name
(str): The name of the source connector to createReturns: Source connector details including name and ID
Create a connector from unstructured server to destination for data storage.
Inputs:
connector_name
(str): The name of the destination connector to createReturns: Destination connector details including name and ID
Create a workflow to process data from source connector to destination connector.
Inputs:
workflow_name
(str): The name of the workflow to createsource_id
(str): The ID of the source connectordestination_id
(str): The ID of the destination connectorReturns: Workflow details including name, ID, status, type, sources, destinations, and schedule
Execute a workflow.
Inputs:
workflow_id
(str): The ID of the workflow to runReturns: Workflow execution status
Get detailed information about a workflow.
Inputs:
workflow_id
(str): The ID of the workflow to get detailsReturns: Workflow details including name, ID, and status
Fetch documents analyzed during workflow execution.
Inputs: None
Returns: List of analyzed documents
Generate a prompt to create and run a workflow for document processing.
Inputs:
user_input
(str): The user's processing requirementsReturns: Formatted prompt for workflow creation and execution
Example:
# Example usage prompt = await create_and_run_workflow_prompt( user_input="Process all PDF invoices from the invoices folder and store them in the processed folder" ) # Returns: "The user wants to achieve Process all PDF invoices from the invoices folder and store them in the processed folder. Assist them by creating a source connector and a destination connector, then setting up the workflow and executing it."
Currently, no resources are available.
For any inquiries, please open an issue on the GitHub repository.