Mpesa Daraja MCP Server
Overview
Mpesa Daraja MCP Server is a Python-based server that implements the Mpesa Daraja API functionality using FastMCP, providing a simple interface to interact with Safaricom's Mpesa Daraja API.
To use the server, clone the repository, set up a virtual environment, install dependencies, configure your Mpesa Daraja credentials in a .env file, and start the server to listen for requests.
- OAuth token generation for Mpesa Daraja API - Secure credential management using environment variables - Comprehensive error handling and logging - FastMCP-based server implementation
- Generating access tokens for authenticating API requests.
- Integrating payment solutions in applications using Mpesa.
- Handling secure transactions through the Mpesa API.
Add to your AI client
Use these steps to connect Mpesa Daraja MCP Server in Cursor, Claude, VS Code, and other MCP-compatible apps. The same JSON appears in the Use with menu above for one-click copy.
Cursor
Add this to your .cursor/mcp.json file in your project root, then restart Cursor.
.cursor/mcp.json
{
"mcpServers": {
"mpesa-mcp-server-jameskanyiri": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mpesa-mcp-server-jameskanyiri"
]
}
}
}Claude Desktop
Add this server entry to the mcpServers object in your Claude Desktop config, then restart the app.
~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
{
"mcpServers": {
"mpesa-mcp-server-jameskanyiri": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mpesa-mcp-server-jameskanyiri"
]
}
}
}Claude Code
Add this to your project's .mcp.json file. Claude Code will detect it automatically.
.mcp.json (project root)
{
"mcpServers": {
"mpesa-mcp-server-jameskanyiri": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mpesa-mcp-server-jameskanyiri"
]
}
}
}VS Code (Copilot)
Add this to your .vscode/mcp.json file. Requires the GitHub Copilot extension with MCP support enabled.
.vscode/mcp.json
{
"servers": {
"mpesa-mcp-server-jameskanyiri": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mpesa-mcp-server-jameskanyiri"
]
}
}
}Windsurf
Add this to your Windsurf MCP config file, then restart Windsurf.
~/.codeium/windsurf/mcp_config.json
{
"mcpServers": {
"mpesa-mcp-server-jameskanyiri": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mpesa-mcp-server-jameskanyiri"
]
}
}
}Cline
Open Cline settings, navigate to MCP Servers, and add this server configuration.
Cline MCP Settings (via UI)
{
"mcpServers": {
"mpesa-mcp-server-jameskanyiri": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-mpesa-mcp-server-jameskanyiri"
]
}
}
}FAQ
What are the prerequisites for using this server?
You need Python 3.7 or higher and Mpesa Daraja API credentials (Consumer Key and Secret).
How do I start the server?
Run the command `python server.py` after setting up your environment.
Is there error handling in the server?
Yes, the server includes comprehensive error handling for various issues.7:["$","div",null,{"className":"container mx-auto flex flex-col gap-4","children":["$L26","$L27",["$","$L28",null,{"currentProject":{"id":3799,"uuid":"aedbb85c-554d-4be2-b0e8-96f9e3f2fbea","name":"mpesa_mcp_server","title":"Mpesa Daraja MCP Server","description":"","avatar_url":"https://avatars.githubusercontent.com/u/58394528?v=4","created_at":"2025-03-21T18:38:07.109Z","updated_at":"2025-03-21T18:49:14.595Z","status":"created","author_name":"jameskanyiri","author_avatar_url":"https://avatars.githubusercontent.com/u/58394528?v=4","tags":"[]","category":"developer-tools","is_featured":false,"sort":1,"url":"https://github.com/jameskanyiri/mpesa_mcp_server","target":"_self","content":"$29","summary":"$2a","img_url":null,"type":null,"metadata":"{\"star\":\"0\",\"license\":\"\",\"language\":\"Python\",\"is_official\":false,\"latest_commit_time\":\"2025-03-22 00:01:18\"}","user_uuid":null,"tools":null,"sse_url":null,"sse_provider":null,"sse_params":null,"is_official":false,"server_command":null,"server_params":null,"server_config":null,"allow_call":false,"is_innovation":false,"is_dxt":false,"dxt_manifest":null,"dxt_file_url":null,"is_audit":false},"randomProjects":[],"currentServerKey":"$undefined"}]]}]