Skip to main content
Alpha Notice: These docs cover the v1‑alpha release. Content is incomplete and subject to change. Expect breaking changes. For production, pin versions and review the Install guide before shipping.
This quickstart shows you how to use the PayLink SDK directly to initiate payments without any agentic framework.
1

Initialize the SDK

Create a PayLink client that points to your MCP server. Here we use a local M‑Pesa server at http://localhost:5002/mcp.
from paylink import PayLink

# Initialize PayLink client (points to local M-Pesa MCP server)
paylink_client = PayLink(base_url="http://localhost:5002/mcp")
2

List available tools

Tools are server‑exposed actions. list_tools() returns names and metadata so you can call them by name. In this quickstart, only stk_push is available.
tools = await paylink_client.list_tools()
print([tool.name for tool in tools.tools])
3

Initiate a payment (STK Push)

STK Push prompts the customer to approve payment on their phone. Send the fields below, parse the JSON response, and check status.
import json

# Prepare request
request = {
    "amount": "10",
    "phone_number": "254712345678",
    "account_reference": "ORDER123",
    "transaction_desc": "TestPayment",
}

# Invoke tool and pretty‑print result
response = await paylink_client.call_tool("stk_push", request)
result = json.loads(response.content[0].text)
print(json.dumps(result, indent=2))

# Minimal success check
assert result.get("status") == "success", result
Quick recap:
  • SDK initialized to your MCP server
  • Tools listed and how to call them
  • STK Push payment initiated and response parsed