Build Paid MCP Servers: Charge Users Inside Claude
The Problem: Your AI Agent Needs Real Revenue
You've built an incredible MCP server—maybe it writes sales copy, generates designs, or automates customer support. Claude users love it. But there's a gap: your tool is free. And free doesn't scale.
The traditional payment flow is broken for AI agents:
- Stripe/PayPal require redirects outside Claude (user friction = 60% drop-off).
- In-app payments demand hosted infrastructure, PCI compliance, and fraud monitoring (months of work).
- Self-hosted wallets mean you're holding user money—a liability nightmare.
What if payment collection just worked inside Claude, required zero compliance overhead, and the cash hit the merchant's bank account in minutes?
That's AgentPay VN.
What Is AgentPay VN? (And Why It's Different)
AgentPay VN is an open-source Python SDK + MCP server (MIT license) that lets Claude agents collect payments via VietQR—Vietnam's national QR payment standard—without ever touching the money.
Here's the magic:
- You never hold funds. The QR code points directly to your merchant bank account.
- Settlement confirmation is automatic. A bank feed webhook tells your agent when payment landed.
- Inside Claude. No redirects. No friction. User scans QR → Claude gets notified → service unlocks.
- Dead simple. 3-line flow: create request → share checkout URL → await settlement.
Install in 10 seconds:
pip install agentpay-vn
That's it. No API keys. No merchant registration boilerplate (you handle that separately with your bank).
Real-World Use Case: An AI Course-Selling Bot
Imagine you've built an MCP server called course_builder—it generates lesson plans, video scripts, and quizzes using Claude.
Without AgentPay: - User asks Claude: "Build me a 10-week Python course." - Claude responds: "That'll be $29. Click here → [external link] → sign up → pay → come back → I'll generate it." - User abandons. 70% churn.
With AgentPay: - User: "Build me a 10-week Python course." - Claude MCP agent creates a payment request → generates a VietQR checkout URL → sends it inline. - User scans QR with phone camera (2 seconds). - Payment hits your bank in 90 seconds. - Claude confirms settlement → instantly generates the course (no waiting for manual webhook processing). - Revenue: $29. User happiness: 9/10.
This workflow works for: - Online educators selling course modules ($15–99). - Designers charging for brand identity packages ($50–500). - Consultants offering AI-powered business audits ($100–1000). - Content platforms unlocking premium AI features (pay-per-generation).
Step 1: Install & Authenticate
Your Python environment needs agentpay-vn:
pip install agentpay-vn
No API keys needed yet. But you do need a Vietnamese business bank account (most fintech-friendly banks like Techcombank, ACB, or VPBank support VietQR).
Once your bank assigns you a VietQR merchant ID and account number, you'll pass them to the SDK.
Step 2: Create & Send a Payment Request
Here's the core pattern:
from agentpay_vn import PaymentClient
import asyncio
# Initialize the client (in production, load these from env vars)
payment_client = PaymentClient(
merchant_id="YOUR_MERCHANT_ID",
merchant_account="YOUR_ACCOUNT_NUMBER",
merchant_name="Your Business Name",
merchant_bank_code="TECHCOMBANK" # or ACB, VIETCOMBANK, etc.
)
# Create a payment request
async def charge_for_course():
# Step 1: Create the payment request
payment_request = await payment_client.create_payment_request(
amount=29000, # VND (29 USD ≈ 700k VND; this example uses 29k)
description="10-Week Python Course",
user_id="claude_user_12345", # Unique identifier for this user
metadata={
"course_id": "py-101",
"lesson_count": 10,
"user_email": "student@example.com"
}
)
# Step 2: Extract the checkout URL (this is what you send to Claude output)
checkout_url = payment_request['checkout_url']
qr_image_base64 = payment_request['qr_image'] # VietQR QR code
request_id = payment_request['request_id'] # Track this payment
print(f"Payment request created: {request_id}")
print(f"Share this URL with user: {checkout_url}")
return request_id, checkout_url, qr_image_base64
# Run it
request_id, url, qr = asyncio.run(charge_for_course())
Line-by-line breakdown:
- Line 1–5: Import the SDK and create a
PaymentClientwith your merchant details. - Line 9–18:
create_payment_request()takes the amount (in VND), a description, a unique user ID, and optional metadata (course ID, email, etc.). Returns a dict withcheckout_url,qr_image, andrequest_id. - Line 21–24: Extract the three critical fields. The
checkout_urlis what you render inside Claude (user scans the QR or clicks the link).
Step 3: Await Settlement & Unlock Access
Once the user pays, your agent needs to confirm and unlock the product:
async def wait_for_payment_settlement(request_id, timeout_seconds=300):
"""
Poll for payment confirmation. In production, use webhooks instead.
"""
start_time = asyncio.get_event_loop().time()
while True:
elapsed = asyncio.get_event_loop().time() - start_time
if elapsed > timeout_seconds:
return False, "Payment timeout. Please try again."
# Check settlement status
settlement = await payment_client.check_settlement(
request_id=request_id
)
if settlement['status'] == 'confirmed':
return True, "Payment received! Course unlocking now..."
elif settlement['status'] == 'failed':
return False, "Payment failed. No charge applied."
# Still pending; wait 2 seconds before retry
await asyncio.sleep(2)
# Usage in your MCP handler:
async def handle_course_purchase():
request_id, checkout_url, qr = await charge_for_course()
# Return QR/URL to Claude (user pays)
print(f"Scan to pay: {checkout_url}")
# Wait for confirmation
success, message = await wait_for_payment_settlement(request_id)
if success:
# Generate & return the course
course_content = await generate_python_course()
return f"✅ {message}\n\n{course_content}"
else:
return f"❌ {message}"
What's happening:
- Line 5–7: Polling loop with timeout. (In production, use async webhooks from your bank for instant confirmation.)
- Line 10–12:
check_settlement()queries whether the payment hit your bank account. Status is one of:pending,confirmed, orfailed. - Line 14–16: If confirmed, unlock the product immediately.
- Line 22–30: Real-world usage: create payment → show URL → wait → unlock.
Note: AgentPay VN never holds the money. You're just checking your bank's settlement ledger via API.
Step 4: Register Your MCP Server with Claude
To make your payment flow available inside Claude, you register the MCP server. AgentPay provides a pre-built MCP wrapper:
Install the MCP server:
pip install agentpay-mcp
Configure in Claude's MCP settings (via JSON):
{
"mcpServers": {
"agentpay": {
"command": "python",
"args": ["-m", "agentpay_mcp"],
"env": {
"AGENTPAY_MERCHANT_ID": "YOUR_MERCHANT_ID",
"AGENTPAY_MERCHANT_ACCOUNT": "YOUR_ACCOUNT_NUMBER",
"AGENTPAY_MERCHANT_NAME": "Your Business Name",
"AGENTPAY_MERCHANT_BANK_CODE": "TECHCOMBANK"
}
}
}
}
Now, inside Claude, you can call:
Tool: agentpay_create_payment → Get QR URL
Tool: agentpay_check_settlement → Confirm payment
Claud will handle these automatically. Zero friction.
Advanced: Webhooks for Instant Settlement
Polling works, but webhooks are faster. When your bank confirms a payment, it POSTs to your webhook URL:
from fastapi import FastAPI, Request
app = FastAPI()
@app.post("/webhook/settlement")
async def on_settlement(body: Request):
payload = await body.json()
request_id = payload['request_id']
status = payload['status'] # 'confirmed' or 'failed'
amount = payload['amount']
if status == 'confirmed':
# Unlock the course immediately (no polling!)
await unlock_course_for_user(request_id)
return {"ok": True}
return {"ok": False}
Tell your bank to POST settlement events to https://yourserver.com/webhook/settlement. Now payments unlock in <1 second instead of 2–5.
Do's and Don'ts
| Do | Don't |
|---|---|
Store request_id in your database to track payments |
Try to hold or transfer user funds |
| Use webhooks for instant settlement confirmation | Assume QR code is valid forever (set expiry times) |
| Include metadata (course ID, email) for analytics | Hardcode merchant credentials in code (use env vars) |
| Test in sandbox mode first (if available) | Charge without explicit user consent |
| Log settlement events for reconciliation | Rely only on polling for production systems |
Pricing Examples for Different Use Cases
SaaS Course Platform: - Intro course: 29,000 VND (~$1.20) → 100 students/month = 2.9M VND (~$120) - Premium course: 299,000 VND (~$12.50) → 20 students/month = 5.98M VND (~$250) - MRR potential: ~$370
Design Service Bot: - Logo package: 499,000 VND (~$21) → 30 projects/month = 14.97M VND (~$630) - Brand guide: 1,490,000 VND (~$62) → 5 projects/month = 7.45M VND (~$310) - MRR potential: ~$940
Consulting Audit Tool: - Quick audit: 199,000 VND (~$8.30) → 50/month = 9.95M VND (~$415) - Deep audit: 999,000 VND (~$41.60) → 10/month = 9.99M VND (~$416) - MRR potential: ~$831
FAQ
Q: Does AgentPay hold my money? No. The QR code points directly to your bank account. You receive payment within 90 seconds of the user's confirmation.
Q: What countries can I use VietQR in? VietQR works for Vietnamese bank accounts and users with Vietnamese banking access. If your users are outside Vietnam, VietQR won't work for them (you'd need a separate Stripe integration).
Q: How do I handle failed payments?
Check the status field in check_settlement() or listen for webhook events. If status == 'failed', don't unlock access. The user can retry.
Q: Can I charge multiple times per user?
Yes. Each create_payment_request() is independent. Use unique user_id and request_id to track them separately.
Q: Is there a transaction fee? AgentPay itself is free (MIT open-source). Your bank will charge you a VietQR transaction fee—typically 0.5–2% depending on your merchant agreement.
Key Takeaways
- AgentPay VN = open-source SDK that lets AI agents inside Claude collect payments instantly, without holding funds.
- 3-line flow:
create_payment_request()→ send checkout URL →check_settlement()or webhooks. - No compliance burden. You're not storing payment data; the QR points to your bank.
- Revenue unlocked. Monetize your MCP servers in minutes, not months.
- Real-world validated. Used by Vietnamese fintech platforms and education startups.
Ready to Monetize Your AI Agents?
Get started now:
- Install:
pip install agentpay-vn - Read the full docs: https://agentpay.servicesai.vn/v1/docs
- Explore the code: https://github.com/phuocdu/agentpay-vn
- Deploy your first paid MCP server (30 minutes from install to first payment).
Your AI deserves to be profitable. Let's build it.