How to Connect M-Pesa STK Push and B2C Payouts to MCP (Claude, Cursor and VS Code)

Connect M-Pesa STK Push and B2C payouts to Claude, Cursor or VS Code with the PalPluss MCP server. Setup in 2 minutes, human approval on every payment.

By
PalPluss Engineering
Published
Reading time
9 min

The short answer

  • To connect M-Pesa to an AI tool, run the open-source PalPluss MCP server: npx -y @palpluss/mcp with your PalPluss API key. It works in Claude Code, Cursor, VS Code and any client that speaks the Model Context Protocol.
  • Your assistant can then send M-Pesa STK Push requests, wait for the payment result, check wallet balances and, once you switch the payouts toolset on, send B2C payouts to M-Pesa numbers.
  • Every action that moves money needs a human's yes, in your MCP client or in the PalPluss console. The AI model can't approve its own actions, and payouts are capped by per-payout and daily limits.
  • No Daraja setup is needed: PalPluss holds the Safaricom configuration. Prefer not to install anything? Connect to the hosted server at https://api.palpluss.com/mcp.

AI coding assistants are now good at building and operating software, but on their own they can't touch money. The Model Context Protocol (MCP) fixes that: it is an open standard that lets an AI tool call real services through a small server that exposes well-defined tools. Connect an MCP server for M-Pesa and your assistant can ask a customer to pay, check whether they did, and pay a supplier or agent, all from a chat.

This guide shows how to connect M-Pesa STK Push (collecting payments) and M-Pesa B2C (sending payouts) to Claude Code, Cursor and VS Code using the PalPluss MCP server, @palpluss/mcp. Setup takes about two minutes, and every payment is approved by a person before it happens.

What an M-Pesa MCP server lets your AI do

The PalPluss MCP server is a thin client of the public PalPluss API. It turns each capability into a tool your assistant can call, grouped into toolsets you switch on as you need them:

ToolsetWhat the AI can doOn by default
readList and look up transactions, check service and B2C wallet balances, wallet history, fee estimates, payment links, payment channelsAlways
walletsTop up the service wallet or B2C wallet by STK promptYes
collectSend an M-Pesa STK Push, wait up to 90 seconds for the result, create or disable payment linksYes
channelsAdd, edit or remove the Paybills and Tills (including bank Paybills) where payments landNo
payoutsSend B2C payouts to M-Pesa numbersNo
Toolsets in @palpluss/mcp. Channels and payouts stay off until you enable them.

Typical requests then look like "What's my B2C wallet balance?", "Show my failed STK payments from today", "Ask 0712 345 678 to pay KES 1,500 for order 1042" or "Pay KES 2,000 to the rider on 0722 000 111 for this week".

Before you start

  • Node.js 18 or newer, if you run the server on your machine (the hosted option needs nothing installed).
  • A PalPluss account. Create one free. Live B2C payouts and service wallet top-ups need your business KYC approved.
  • An API key from the console → API Keys. For AI tools, choose the AI tools (MCP) key type: PalPluss then enforces the permissions, payout limits and approvals you set on the key. A test key uses simulated money, which is the best way to try everything first.

Step 1: Add the PalPluss MCP server to your AI tool

Claude Code

bash
claude mcp add palpluss -e PALPLUSS_API_KEY=your_api_key -- npx -y @palpluss/mcp

Cursor

.cursor/mcp.json
{
  "mcpServers": {
    "palpluss": {
      "command": "npx",
      "args": ["-y", "@palpluss/mcp"],
      "env": { "PALPLUSS_API_KEY": "your_api_key" }
    }
  }
}

VS Code

VS Code can prompt for the key so it never sits in the file:

.vscode/mcp.json
{
  "inputs": [
    { "id": "palpluss-key", "type": "promptString", "description": "PalPluss API key", "password": true }
  ],
  "servers": {
    "palpluss": {
      "command": "npx",
      "args": ["-y", "@palpluss/mcp"],
      "env": { "PALPLUSS_API_KEY": "${input:palpluss-key}" }
    }
  }
}

Hosted server (nothing to install)

PalPluss also runs the server for you at https://api.palpluss.com/mcp. Clients that support MCP sign-in (OAuth) open the PalPluss console so you can connect your account and choose what the AI may do. Other clients can send an MCP key as Authorization: Bearer <key>. In Claude Code:

bash
claude mcp add --transport http palpluss https://api.palpluss.com/mcp

Restart or reload your tool, then ask "What's my PalPluss service wallet balance?" If you get a balance back, the connection works.

Step 2: Collect a payment with M-Pesa STK Push

STK Push is the PIN prompt that appears on the customer's phone. With the collect toolset (on by default), ask your assistant something like:

text
Ask 0712 345 678 to pay KES 1,500 for order 1042, then tell me when it's paid.
  1. The assistant calls palpluss_send_stk_push with the amount, phone number and your reference.
  2. Your MCP client shows you an approval request with the amount and the masked phone number. Nothing is sent until you accept.
  3. The customer gets the M-Pesa prompt and enters their PIN.
  4. The assistant calls palpluss_wait_for_payment, which waits up to 90 seconds for the final status, and reports back with the M-Pesa receipt or the reason it failed (for example Request Cancelled by user).

Payments land in your default payment channel. To collect into a specific Paybill, Till or bank Paybill, add it as a payment channel first (enable the channels toolset, or add it in the console).

Step 3: Send B2C payouts to M-Pesa

Payouts are off by default. Switch them on by adding the toolset when you start the server:

bash
claude mcp add palpluss \
  -e PALPLUSS_API_KEY=your_api_key \
  -e PALPLUSS_MCP_TOOLSETS=read,wallets,collect,payouts \
  -e PALPLUSS_MCP_MAX_PAYOUT=5000 \
  -e PALPLUSS_MCP_DAILY_PAYOUT_TOTAL=20000 \
  -- npx -y @palpluss/mcp

Payouts are paid from your B2C wallet, so top it up first (the assistant can do this with palpluss_topup_b2c_wallet, again with your approval). Then:

text
Pay KES 2,000 to 0722 000 111 for rider commission, week 48.
  1. The server checks your payout limits before asking you: the largest single payout, the daily total and count, and the optional allowlist of numbers.
  2. You approve the payout in your MCP client. With an MCP key set to hold payouts for console approval, it goes to the PalPluss console instead and the tool returns PENDING_APPROVAL; the assistant follows up with palpluss_wait_for_approval.
  3. The limits are checked again just before sending, then palpluss_send_payout sends the money to the M-Pesa number.
  4. If M-Pesa rejects the payout, PalPluss credits the amount back to your B2C wallet automatically.

How the PalPluss MCP server keeps money safe

Letting an AI near payments raises fair questions. These are the protections built in, on top of PalPluss's own API rate limits and per-phone limits:

  • A human's yes for every write. Top-ups, STK pushes, payouts and channel changes ask you first through MCP elicitation. If your client can't show approval requests, those tools refuse instead of going ahead. The model never sees or answers the approval, so it can't approve itself.
  • Payout limits per payout, per day (total and count), plus an optional allowlist of recipient numbers.
  • No double payments. Payouts and top-ups carry an idempotency key, so an AI retrying after a timeout can't pay twice.
  • Prompt-injection defence. Text written by customers or providers (references, descriptions, result messages) is returned marked untrusted:, and the AI is told never to act on it.
  • Privacy. Phone numbers are masked in everything returned to the AI, and the API key is never logged.
  • Audit log and kill switch. PALPLUSS_MCP_AUDIT_FILE writes one JSON line per tool call; PALPLUSS_MCP_READ_ONLY=true removes every tool that changes anything.

Configuration reference

VariableDefaultWhat it does
PALPLUSS_API_KEYrequiredYour PalPluss API key (an AI tools (MCP) key is recommended)
PALPLUSS_MCP_TOOLSETSread,wallets,collectAdd channels, payouts, or use all
PALPLUSS_MCP_READ_ONLYfalsetrue turns off every tool that changes anything
PALPLUSS_MCP_APPROVALelicitbackend relies on approvals set on an MCP key in the console
PALPLUSS_MCP_MAX_PAYOUT5000Largest single payout (KES)
PALPLUSS_MCP_DAILY_PAYOUT_TOTAL20000Payout total per Nairobi day (KES)
PALPLUSS_MCP_DAILY_PAYOUT_COUNT20Payouts per Nairobi day
PALPLUSS_MCP_PAYOUT_ALLOWLISTempty (any)Comma-separated numbers payouts may go to
PALPLUSS_MCP_MAX_STK150000Largest STK push (KES)
PALPLUSS_MCP_AUDIT_FILEnonePath for a JSON-lines audit log
Full list in the @palpluss/mcp README and at docs.palpluss.com/sdks/mcp.

Troubleshooting common errors

You seeWhat it meansFix
KYC_NOT_VERIFIEDB2C payouts and service wallet top-ups need approved business KYCFinish KYC in the console, or use a test key meanwhile
INSUFFICIENT_FUNDSThe B2C wallet doesn't cover the payoutTop up the B2C wallet
B2C_PAYOUT_COOLDOWNA payout already went to this number in the last minuteWait a minute; this stops double-clicks and runaway loops
RATE_LIMIT_EXCEEDEDToo many API requests per minute for this keySlow down and retry
Write tools refuse to runYour MCP client doesn't support approval requests (elicitation)Use a client that does, or an MCP key with PALPLUSS_MCP_APPROVAL=backend

Building an AI agent or your own app

The same server runs inside your own Node.js app. createPalplussMcpServer() connects to any MCP transport, and you can pass your own approver to show payment approvals in your own interface. For many merchants behind one endpoint there is an HTTP mode with per-merchant sessions. Details are in the MCP docs and the open-source PalPluss SDK repository.

If you would rather call the API directly from your code, see how to automate M-Pesa STK Push and how to integrate M-Pesa B2C payouts.

Frequently asked questions

What is an M-Pesa MCP server?

It is a Model Context Protocol server that exposes M-Pesa actions, such as sending an STK Push, checking a payment and sending a B2C payout, as tools an AI assistant can call. The PalPluss MCP server (@palpluss/mcp) does this through the PalPluss API, so you don't need your own Daraja setup.

Which AI tools work with the PalPluss MCP server?

Any MCP client, including Claude Code, Cursor and VS Code. Run it locally with npx -y @palpluss/mcp, or connect to the hosted server at https://api.palpluss.com/mcp. For payments, your client should support approval requests (MCP elicitation), or use an MCP key with console approvals.

Is it safe to let an AI send M-Pesa payments?

Every action that moves money needs a human's approval, in your MCP client or the PalPluss console, and the AI can't answer that approval itself. Payouts are also capped per payout and per day, can be limited to an allowlist of numbers, and carry idempotency keys so a retry never pays twice.

Do I need a Safaricom Daraja account?

No. PalPluss holds the Safaricom configuration for STK Push and B2C. You need a PalPluss account and API key, plus approved business KYC before sending live B2C payouts. You can still collect into your own Paybill, Till or bank Paybill.

Can I test without real money?

Yes. Create a test API key in the PalPluss console. With a test key, STK pushes and payouts are simulated, and no approval prompt is needed because no real money moves.

How much does the PalPluss MCP server cost?

The MCP server itself is free and open source under the MIT licence. Live STK Push and B2C payouts are charged the normal PalPluss transaction fees listed on the pricing page.

Does the AI see my customers' phone numbers?

Phone numbers are masked in everything the server returns to the AI and in its audit log, and your API key is never logged.

Build it on Palpluss. M‑Pesa collections and payouts in one API.

Create an account and get KES 15 in free tokens to send your first live M‑Pesa STK Push in minutes.