Payment-protected MCP tools using Server-Sent Events (SSE).
This example demonstrates:
- Server: SSE-based MCP server with free and paid tools
- Client: Connects to server and handles payment automatically via
McpClient
The server and client run in separate terminals, communicating via SSE.
- Python 3.12+
- Tempo testnet account with pathUSD balance
- Private key for signing transactions
cd examples/mcp-server
pip install -e .Server:
export DESTINATION_ADDRESS="0x..." # Payment recipient address (required)
export TEMPO_RPC_URL="https://rpc.testnet.tempo.xyz/" # Default: Tempo testnet
export MCP_PORT="8000" # Default: 8000Client:
export TEMPO_PRIVATE_KEY="0x..." # Private key for signing (required)
export MCP_SERVER_URL="http://127.0.0.1:8000/sse" # DefaultTerminal 1 - Start the server:
export DESTINATION_ADDRESS="0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00"
python server_decorator.pyTerminal 2 - Run the client:
export TEMPO_PRIVATE_KEY="0x..."
python client.pyServer:
Starting MCP server on http://127.0.0.1:8000/sse
Destination: 0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00
Client:
Connecting to MCP server at http://127.0.0.1:8000/sse
============================================================
Client address: 0x...
Available tools:
- echo: Echo a message back (free tool)
- premium_echo: Echo a message with style (paid tool - 100 units)
1. Calling free tool (echo)...
Result: Echo: Hello, world!
2. Calling paid tool (premium_echo)...
Result: ✨ Premium Echo ✨: Hello, premium! (paid by 0x..., tx: 0x...)
Receipt: success, ref=0x...
Two server implementations are provided:
| File | Description |
|---|---|
server_decorator.py |
Clean pattern using verify_or_challenge() |
server_manual.py |
Same pattern, shows manual request building |
Both implement the same tools:
echo: Free tool that echoes messagespremium_echo: Paid tool (100 pathUSD units) with styled output
Client Server
| |
|------ call premium_echo ----->|
| |
|<----- -32042 + challenge -----|
| |
| [pay on Tempo blockchain] |
| |
|-- call + credential (meta) -->|
| |
|<-------- result + receipt ----|
The server requires this payment for premium_echo:
{
"amount": "100",
"currency": "0x20c0000000000000000000000000000000000000",
"recipient": "<DESTINATION_ADDRESS>",
"expires": "<5 minutes from now>",
"methodDetails": {"chainId": 42431, "feePayer": true}
}Add to your Claude Desktop config:
{
"mcpServers": {
"paid-echo": {
"url": "http://127.0.0.1:8000/sse"
}
}
}Note: Claude Desktop doesn't yet support the payment flow automatically. You'll need to use the client script or a payment-aware MCP client.