The Real Problem
Developers creating custom Model Context Protocol (MCP) tools and servers for Claude Desktop, Cursor, or AI sidecars need a way to charge for tool execution or server invocations (e.g. database lookups, code analysis, image generation).
Real-World Example: For example, an MCP server offering code security audits or context lookups could set a price of $0.10 per tool invocation using the L402 protocol.
How aipp Solves It
When an LLM invokes an MCP tool or server method, the server returns an L402 payment challenge. The agent client executes the payment via Lightning/USDC, attaches the proof to the tool call arguments, and the tool returns the payload.
Step-by-Step Payment Flow
STEP 01
MCP Tool Call
LLM client invokes tool via MCP protocol.
STEP 02
402 Payment Challenge
MCP server returns payment requirement details.
STEP 03
Payment Settlement
Client pays Lightning invoice or USDC.
STEP 04
Tool Result Returned
MCP tool executes and returns context to the LLM.
Scope & Boundaries
What aipp Does
- ✓ Enables pay-per-use monetization for MCP tool servers
- ✓ Verifies preimages and transaction proofs before tool execution
- ✓ Auto-forwards net earnings to merchant wallet
What aipp Does Not Do
- ✗ Does not host the MCP server process
- ✗ Does not modify Anthropic or Cursor protocol core
Implementation Pattern
Below is the minimal implementation pattern using standard aipp endpoints / SDK:
@app.call_tool()
async def run_security_audit(name: str, arguments: dict):
payment_hash = arguments.get("payment_hash")
if not is_settled(payment_hash):
return {"error": "L402 Payment Required", "invoice": create_invoice(amount_usd=0.10)}
return {"audit_results": "Zero critical vulnerabilities found."}
Settlement Architecture Note:
• Lightning Rail: In hosted Lightning flows, payments route through aipp's Lightning gateway before net proceeds are automatically forwarded to your configured wallet address.
• Base USDC Rail: USDC transfers settle directly on-chain to your designated EVM wallet address.
• No Merchant Spending Balance: aipp does not maintain a spendable merchant balance or require manual withdrawal steps.
Requirements & Limitations
- The client MCP host must support 402 challenge negotiation or tool retry
- aipp provides payment verification; developer hosts the MCP server
Frequently Asked Questions
Does this work with both individual MCP tools and full MCP servers?
Yes. You can monetise single tool methods or protect an entire MCP server endpoint with aipp L402 challenges.
Related Use Cases
Implement Paid MCP Tool & MCP Server with aipp
Read the developer documentation or generate your API key to gate requests behind Lightning and Base USDC payments.