Johnmiicheal/paystack-mcp-py
If you are the rightful owner of paystack-mcp-py and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Model Context Protocol (MCP) server for Paystack payment processing, enabling AI assistants to interact with Paystack's payment API through standardized tools.
initialize_transaction
Create a new payment transaction.
verify_transaction
Verify a transaction by reference.
list_transactions
List transactions with optional filters.
create_customer
Create a new customer.
list_customers
List customers.
create_plan
Create a subscription plan.
list_plans
List subscription plans.
list_banks
List supported banks.
resolve_account
Resolve and verify bank account details.
create_refund
Create a refund for a transaction.
Paystack MCP Server
A Model Context Protocol (MCP) server for Paystack payment processing. This server provides AI assistants with the ability to interact with Paystack's payment API through standardized tools.
Features
š Payment Operations
- Initialize transactions
- Verify payment status
- List transaction history
- Process refunds
š„ Customer Management
- Create and manage customers
- List customers
- Update customer information
š Subscription Plans
- Create subscription plans
- List and manage plans
š¦ Banking Integration
- List supported banks
- Verify bank account details
Installation
- Clone the repository:
git clone <your-repo-url>
cd paystack-mcp
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
cp example.env .env
# Edit .env with your Paystack credentials
Required environment variables:
PAYSTACK_SECRET_KEY
: Your Paystack secret key (required)PAYSTACK_PUBLIC_KEY
: Your Paystack public key (optional)PAYSTACK_ENVIRONMENT
: Set to 'test' or 'live' (default: 'test')
Usage
Running the Server
The MCP server can be run directly:
python -m paystack_mcp.server
Or using the installed script:
paystack-mcp
JavaScript Client Integration
This Python MCP server can be easily integrated with JavaScript clients. Here's an example:
// Using the MCP client in Node.js
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
// Create transport to the Python server
const transport = new StdioClientTransport({
command: "python",
args: ["-m", "paystack_mcp.server"]
});
// Create and connect client
const client = new Client(
{
name: "paystack-client",
version: "1.0.0",
},
{
capabilities: {},
}
);
await client.connect(transport);
// Use Paystack tools
const result = await client.callTool({
name: "initialize_transaction",
arguments: {
email: "customer@example.com",
amount: 50000, // 500 NGN in kobo
currency: "NGN"
}
});
console.log(result);
Available Tools
Transaction Management
initialize_transaction
Create a new payment transaction.
Parameters:
email
(string, required): Customer emailamount
(integer, required): Amount in kobo/centscurrency
(string, optional): Currency code (default: "NGN")reference
(string, optional): Unique transaction referencecallback_url
(string, optional): Callback URL after paymentmetadata
(object, optional): Additional transaction data
verify_transaction
Verify a transaction by reference.
Parameters:
reference
(string, required): Transaction reference to verify
list_transactions
List transactions with optional filters.
Parameters:
per_page
(integer, optional): Number of results per page (default: 50)page
(integer, optional): Page number (default: 1)customer
(string, optional): Filter by customer IDstatus
(string, optional): Filter by transaction statusfrom_date
(string, optional): Start date (YYYY-MM-DD)to_date
(string, optional): End date (YYYY-MM-DD)
Customer Management
create_customer
Create a new customer.
Parameters:
email
(string, required): Customer emailfirst_name
(string, optional): Customer first namelast_name
(string, optional): Customer last namephone
(string, optional): Customer phone numbermetadata
(object, optional): Additional customer data
list_customers
List customers.
Parameters:
per_page
(integer, optional): Number of results per page (default: 50)page
(integer, optional): Page number (default: 1)
Subscription Plans
create_plan
Create a subscription plan.
Parameters:
name
(string, required): Plan nameamount
(integer, required): Plan amount in kobo/centsinterval
(string, required): Billing interval (daily, weekly, monthly, quarterly, biannually, annually)description
(string, optional): Plan descriptioncurrency
(string, optional): Currency code (default: "NGN")
list_plans
List subscription plans.
Parameters:
per_page
(integer, optional): Number of results per page (default: 50)page
(integer, optional): Page number (default: 1)
Banking
list_banks
List supported banks.
Parameters:
country
(string, optional): Country to get banks for (default: "nigeria")
resolve_account
Resolve and verify bank account details.
Parameters:
account_number
(string, required): Account number to verifybank_code
(string, required): Bank code
Refunds
create_refund
Create a refund for a transaction.
Parameters:
transaction
(string, required): Transaction ID or referenceamount
(integer, optional): Amount to refund in kobo/cents (full amount if not specified)currency
(string, optional): Currency codecustomer_note
(string, optional): Note for customermerchant_note
(string, optional): Internal merchant note
Development
Testing
Run tests with pytest:
pytest tests/
Run tests with coverage:
pytest tests/ --cov=paystack_mcp
Code Quality
Format code:
black paystack_mcp/
Lint code:
ruff check paystack_mcp/
Type check:
mypy paystack_mcp/
Project Structure
paystack-mcp/
āāā paystack_mcp/ # Main package
ā āāā __init__.py # Package initialization
ā āāā server.py # Main MCP server
ā āāā client.py # Paystack API client
ā āāā models.py # Pydantic models
ā āāā config.py # Configuration
āāā tests/ # Test files
ā āāā __init__.py
ā āāā test_server.py
āāā pyproject.toml # Project configuration
āāā requirements.txt # Dependencies
āāā example.env # Environment variables example
āāā README.md # This file
Configuration
The server uses environment variables for configuration:
- PAYSTACK_SECRET_KEY: Your Paystack secret key (sk_test_... or sk_live_...)
- PAYSTACK_PUBLIC_KEY: Your Paystack public key (optional)
- PAYSTACK_ENVIRONMENT: Environment setting ('test' or 'live')
- PAYSTACK_BASE_URL: API base URL (usually not needed)
Error Handling
The server provides comprehensive error handling:
- PaystackAPIError: Raised for Paystack API errors
- Validation errors: For invalid input parameters
- Network errors: For connection issues
All errors are properly formatted and returned to the client with descriptive messages.
Security
- Never commit your
.env
file or actual API keys - Use test keys during development
- Only use live keys in production environments
- Validate all input parameters
- Follow Paystack's security best practices
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions about this MCP server:
- Open an issue on GitHub
- Check the Paystack API documentation
- Review the MCP specification
For Paystack API questions:
- Visit Paystack Documentation
- Contact Paystack Support