Skip to main content

What is MCP?

The Model Context Protocol (MCP) is an open protocol that standardizes how AI systems interact with external tools and data sources. Snack Money implements MCP with x402 payment support, enabling AI agents to make paid API calls seamlessly.

How It Works

MCP uses JSON-RPC 2.0 for communication. When an AI agent calls a Snack Money tool through MCP:
  1. Tool Discovery - Agent queries available tools via tools/list
  2. Tool Invocation - Agent calls a tool with tools/call
  3. Payment Required - Server returns error code -32402 with payment requirements
  4. Payment Signing - Agent signs the payment using x402 protocol
  5. Retry with Payment - Agent retries with payment proof
  6. Success - Server processes the payment and returns results

MCP Payment Flow

Client                           Snack Money API
  |                                    |
  |-------- tools/call -------->      |
  |        (no payment)               |
  |                                    |
  |<------ Error -32402 --------      |
  |     (payment required)            |
  |                                    |
  |-- Sign with x402 client -->       |
  |                                    |
  |-------- tools/call -------->      |
  |     (with payment proof)          |
  |                                    |
  |<-------- Success ----------       |
  |      (with receipt)               |

Available Tools

Snack Money provides the following MCP tools, each requiring x402 payment:
ToolDescriptionParameters
pay_farcasterSend USDC to a Farcaster userreceiver, amount, description
pay_twitterSend USDC to a Twitter/X userreceiver, amount, description
pay_emailSend USDC to an email addressreceiver, amount, description
pay_webSend USDC to a web domain ownerreceiver, amount, description
pay_githubSend USDC to a GitHub userreceiver, amount, description
batch_paySend USDC to multiple recipientspayments[]

Quick Start

1. Install Dependencies

npm install @x402/core @x402/evm @x402/svm

2. Initialize MCP Session

const response = await fetch('https://api.snack.money/mcp', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'initialize',
    params: {
      protocolVersion: '0.1.0',
      clientInfo: { name: 'my-agent', version: '1.0.0' }
    },
    id: 1
  })
});

3. List Available Tools

const response = await fetch('https://api.snack.money/mcp', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'tools/list',
    id: 2
  })
});

const { result } = await response.json();
console.log('Available tools:', result.tools);

4. Call a Tool with Payment

import { X402 } from '@x402/core';
import { createEvmClient } from '@x402/evm';

// Initialize x402 client
const x402Client = createEvmClient({
  privateKey: process.env.EVM_PRIVATE_KEY,
  chainId: 8453 // Base mainnet
});

// First call - will require payment
const firstCall = await fetch('https://api.snack.money/mcp', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'tools/call',
    params: {
      name: 'pay_twitter',
      arguments: {
        receiver: 'alice',
        amount: 0.01,
        description: 'Thanks for the help!'
      }
    },
    id: 3
  })
});

const response = await firstCall.json();

// Check if payment is required
if (response.error?.code === -32402) {
  const { taskId, paymentRequired } = response.error.data;

  // Sign payment
  const signedPayment = await x402Client.createPaymentPayload(
    paymentRequired
  );

  // Retry with payment
  const paidCall = await fetch('https://api.snack.money/mcp', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'tools/call',
      params: {
        name: 'pay_twitter',
        arguments: {
          receiver: 'alice',
          amount: 0.01,
          description: 'Thanks for the help!'
        },
        _meta: {
          taskId,
          x402Payment: signedPayment
        }
      },
      id: 4
    })
  });

  const result = await paidCall.json();
  console.log('Payment successful:', result.result);
}

Full Example

Check out the complete MCP example in our GitHub repository for:
  • Base (EVM) network implementation
  • Solana network implementation
  • Tool listing and discovery
  • Batch payment support
  • Error handling

Integration with AI Agents

Coinbase CDP Payments MCP

Snack Money’s MCP implementation is compatible with Coinbase CDP Payments MCP, allowing you to:
  • Use Snack Money as a payment provider in CDP-powered AI agents
  • Send payments to social media users through CDP’s MCP interface
  • Integrate with Coinbase’s wallet infrastructure
  • Leverage CDP’s security and compliance features
For detailed integration instructions, see the CDP Payments MCP documentation.

Other AI Development Tools

Popular AI development tools that support MCP include:
  • Claude Desktop - Native MCP support for tool calling
  • Continue.dev - VS Code extension with MCP support
  • Cline - Command-line interface for MCP tools
  • Custom Agents - Build your own using the MCP SDK

Security Considerations

  • All payments require cryptographic signatures via x402
  • Task IDs prevent replay attacks
  • Payments are verified on-chain before processing
  • Rate limiting applies to prevent abuse