GitHub Pages documentation
A robust Solana-based payment system with MCP (Model Context Protocol) integration for processing payments and managing resource access.
.
โโโ config.py # Configuration and wallet management
โโโ payments.py # Flask payment API endpoints
โโโ server.py # MCP server with payment tools
โโโ utils.py # Utility functions for Solana operations
โโโ __init__.py # Package initialization
โโโ .env # Environment variables (create this)
โโโ README.md # This file
Create a .env file in the project root:
# Solana RPC endpoint
RPC_ENDPOINT=http://localhost:8899
# Payment wallet seed (comma-separated integers or hex with 0x prefix)
# Example: PAYMENT_WALLET_SEED=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32
# Or hex: PAYMENT_WALLET_SEED=0x1234567890abcdef...
# Flask configuration
FLASK_DEBUG=true
FLASK_PORT=5001
Resources and their prices are configured in server.py:
resource_prices = {
"resource_1": 0.1,
"resource_2": 0.5,
"premium_content": 1.0,
"basic_content": 0.05,
"pro_content": 2.0,
}
# Using uv (recommended)
python -m uv venv .venv
source .venv/Scripts/activate # On Windows
.venv/Scripts/python.exe -m uv pip install -e .
Set up environment variables:
Create a .env file with the required configuration.
Run the services:
Start the payment API server:
python payments.py
Start the MCP server (in another terminal):
python server.py
Use the MCP check_access tool to verify if a user has paid for a resource:
# Check if user has access to premium content
result = await check_access(
user_pubkey="UserPublicKeyHere",
resource_id="premium_content"
)
If access is denied, the user needs to make a payment:
# Process a completed payment transaction
result = await process_payment(
amount_sol=1.0,
payment_transaction="TransactionSignatureHere",
client_ip="127.0.0.1",
resource_id="premium_content",
user_pubkey="UserPublicKeyHere"
)
The Flask API provides endpoints for Solana Actions:
GET /process_payment_action - Get payment action metadataPOST /process_payment_action - Create payment transactionGET /health - Health checkGET /process_payment_action
Response:
{
"type": "action",
"icon": "https://raw.githubusercontent.com/solana-labs/token-list/main/assets/mainnet/So11111111111111111111111111111111111111112/logo.png",
"title": "Process Payment",
"description": "Make a SOL payment to access premium content.",
"label": "Pay with SOL",
"input": [
{
"name": "amount_sol",
"type": "number",
"label": "Amount of SOL to pay",
"min": 0.001,
"max": 1000
},
{
"name": "resource_id",
"type": "select",
"label": "Resource ID",
"options": [
{"label": "Resource 1", "value": "resource_1"},
{"label": "Resource 2", "value": "resource_2"},
{"label": "Premium Content", "value": "premium_content"}
]
}
]
}
POST /process_payment_action
Content-Type: application/json
{
"amount_sol": 1.0,
"resource_id": "premium_content",
"account": "UserPublicKeyHere"
}
# Get all payments for a user
history = await get_payment_history(
user_pubkey="UserPublicKeyHere"
)
# Get payments for specific resource
history = await get_payment_history(
user_pubkey="UserPublicKeyHere",
resource_id="premium_content"
)
PAYMENT_EXPIRY_HOURScurl http://localhost:5001/health
check_access - Check if user has paid for resourceprocess_payment - Process and validate SOL paymentget_resource_info - Get resource prices and informationget_payment_history - View user's payment historyfrom mcp_solana_internet import check_access, process_payment
# Check access
access_result = await check_access(
user_pubkey="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
resource_id="premium_content"
)
if not access_result["access"]:
print(f"Payment required: {access_result['payment_amount_sol']} SOL")
print(f"Payment URL: {access_result['payment_url']}")
"Invalid public key": Ensure the public key is a valid Solana address (32 bytes, base58 encoded)
"Transaction not found": The transaction may not be confirmed yet. Wait for confirmation.
"Insufficient payment": The payment amount is less than required for the resource.
"RPC Error": Check that the Solana RPC endpoint is accessible and functioning.
Check the console output for detailed error messages and transaction information.
resource_prices in server.pyVALID_RESOURCE_IDS in payments.pyExtend the validation functions in utils.py for custom business logic.
For production use, replace the in-memory payment storage with a proper database.
This project is licensed under the MIT-0 License - see the LICENSE file for details.
View the repository on GitHub.