The Daraja MCP server connects AI applications with Safaricom's Daraja API, allowing AI-driven systems to interact with M-Pesa services. This server follows the Model Context Protocol (MCP) architecture, providing tools for AI models to process payments, retrieve transaction data, and automate financial workflows through M-Pesa.
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
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.
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:
Anthropic's Recommended Format
{
"mcpServers": {
"daraja": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP",
"run",
"main.py"
]
}
}
}
Working Configuration (Tested)
{
"mcpServers": {
"DarajaMCP": {
"command": "/ABSOLUTE/PATH/TO/PARENT/.local/bin/uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP",
"run",
"main.py"
]
}
}
}
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.
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.
Inputs:
merchant_name
(str): Name of the company/M-Pesa Merchant Nametransaction_reference_no
(str): Transaction reference numberamount
(int): The total amount for the transactiontransaction_type
(Literal["BG", "WA", "PB", "SM", "SB"]): Transaction typecredit_party_identifier
(str): Credit Party Identifier (Mobile Number, Business Number, etc.)Returns: JSON formatted M-PESA API response with QR code data
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 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 transactionidentifier
(str): The recipient identifierreference
(str, optional): Transaction reference numberReturns: Formatted prompt string for QR code generation
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
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "daraja" '{"command":"uv","args":["--directory","/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP","run","main.py"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"daraja": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP",
"run",
"main.py"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"daraja": {
"command": "uv",
"args": [
"--directory",
"/ABSOLUTE/PATH/TO/PARENT/FOLDER/DarajaMCP",
"run",
"main.py"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect