Documentation Index
Fetch the complete documentation index at: https://docs.snack.money/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This example demonstrates how to use the Model Context Protocol (MCP) with x402 payments to enable AI agents to make paid API calls to Snack Money.Features
- JSON-RPC 2.0 protocol implementation
- x402 payment integration
- Support for Base (EVM) and Solana networks
- Tool discovery and invocation
- Automatic payment handling
Installation
Clone the example repository:Configuration
Create a.env file with your credentials:
Usage
List Available Tools
Discover all available MCP tools:Send Payment via Base Network
- Call the MCP endpoint to send payment
- Receive payment requirements (error -32402)
- Sign the payment with x402 EVM client
- Retry with signed payment
- Display transaction receipt
Send Payment via Solana Network
Code Example
Here’s a simplified example of making an MCP call with payment:Protocol Flow
The MCP payment flow follows this sequence:- Initial Call - Client calls MCP tool without payment
- Payment Required - Server returns error -32402 with:
taskId- Unique identifier for this taskpaymentRequired- x402 payment requirements
- Sign Payment - Client signs payment using x402 client
- Retry with Payment - Client retries with:
- Original parameters
_meta.taskId- Task identifier_meta.x402Payment- Signed payment proof
- Success - Server returns result with receipt
Error Handling
Common error codes:| Code | Description | Action |
|---|---|---|
| -32402 | Payment required | Sign and retry with payment |
| -32600 | Invalid request | Check request format |
| -32601 | Method not found | Verify method name |
| -32602 | Invalid params | Check parameter format |
| -32603 | Internal error | Retry or contact support |
Supported Networks
- Base (Chain ID: 8453) - USDC on Base mainnet
- Base Sepolia (Chain ID: 84532) - USDC on Base testnet
- Solana - USDC on Solana mainnet
- Solana Devnet - USDC on Solana devnet
Integration with AI Agents
This MCP implementation is compatible with:- Coinbase CDP Payments MCP
- Claude Desktop MCP tools
- Custom AI agents using MCP protocol
Full Example
View the complete working example: GitHub: snack-money-examples/mcpRelated Examples
- A2A Example - Agent-to-Agent protocol
- Axios Example - HTTP interceptor for x402
- CDP SDK Example - Coinbase Developer Platform integration