n8n
Call the M-Pesa tools from an n8n AI Agent through the MCP Client Tool node.
n8n's AI Agent can call the M-Pesa tools through the MCP Client Tool node. The server must be reachable over HTTPS, so self-host it first.
For plain workflows without an AI agent, install the community nodes
n8n-nodes-daraja-mpesainstead: STK Push, B2C, B2B, status and an M-Pesa Trigger for callbacks. In n8n, open Settings → Community Nodes → Install and entern8n-nodes-daraja-mpesa.
Import the example
- In n8n: Workflows → Import from file →
examples/n8n/mpesa-agent.json. - Open M-Pesa MCP:
- Endpoint:
https://<your-domain>/mcp - Server transport: HTTP Streamable
- Authentication: Bearer, with a new credential holding your
DARAJA_MCP_TOKEN
- Endpoint:
- Open Chat Model and pick your model credential.
- Open the chat and try: "Check my M-Pesa setup", then "Charge 07XXXXXXXX KES 1 for order 42" in the sandbox.
Node fields change between n8n versions. If the import complains, add the MCP Client Tool node by hand with the settings above.
Choose which tools the agent sees
- In the node, Tools to include → Selected limits the agent to what the workflow needs, e.g.
mpesa_stk_push_and_waitandmpesa_get_resultfor checkout. - On the server,
DARAJA_TOOLSETS=stkdoes the same for every client.
Approvals
n8n can't show MCP approval prompts. With the hosted defaults (DARAJA_APPROVAL_THRESHOLD=0), every payout is refused from n8n, with nothing sent. Collections such as STK Push work, because the customer approves with their PIN.
To allow payouts from n8n, set a threshold that covers what the workflow may pay without a human, plus DARAJA_ALLOWED_RECIPIENTS. Larger amounts stay refused. For a human step, add n8n's own approval (e.g. Send and Wait for Response) before the agent runs.