Ez402
spin up x402 endpoints on demand
Installation
npx ez402Ask AI about Ez402
Powered by Claude Β· Grounded in docs
I know everything about Ez402. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
ez402 - Easy x402 Endpoint Wrapper Service
A Next.js application that makes it easy to wrap existing HTTP API endpoints with the x402 micropayment protocol, enabling instant monetization using USDC on Base network. Now featuring auto-generated MCP servers and an AI chat interface powered by Claude.
Overview
This service allows API providers to wrap their existing endpoints with x402 protocol without modifying their original APIs. Clients pay per request using USDC on Base network, and payments are verified and settled via Coinbase's CDP Facilitator.
New in v2: Registered endpoints are automatically available as MCP (Model Context Protocol) tools that can be invoked by Claude in an interactive chat interface, with payments handled transparently.
Features
Core Features
- β Zero Code Changes: Wrap existing APIs without modifications
- β Instant Monetization: Set pricing and start earning immediately
- β Secure Payments: On-chain USDC payments on Base network
- β Encrypted Storage: API keys encrypted with AES-256-GCM
- β Automatic Settlement: Payments settled directly to provider wallets
- β x402 Protocol: Full HTTP 402 Payment Required implementation
AI & MCP Features (New)
- π€ Auto-Generated MCP Servers: Endpoints automatically become AI tools
- π¬ AI Chat Interface: Built-in Claude-powered chat with tool calling
- π¨ Interactive UI Components: Rich responses via MCP-UI
- π° Transparent Payments: x402 payments handled automatically for AI
- π On-Demand Deployment: Deploy MCP servers to Cloudflare Workers
Tech Stack
Core Stack
- Framework: Next.js 15 (App Router)
- Database: MongoDB with Mongoose
- Payments: Coinbase CDP Facilitator
- Blockchain: Base Mainnet (USDC)
- Authentication: AES-256-GCM encryption
- UI: shadcn/ui + Tailwind CSS
- Validation: Zod + React Hook Form
AI & MCP Stack
- AI Model: Claude 4 (Anthropic) via Vercel AI SDK
- MCP Server: @modelcontextprotocol/sdk
- Chat UI: assistant-ui (React)
- Interactive UI: mcp-ui
- Payment Handler: x402-axios
- Wallet: viem (Base network)
Prerequisites
- Node.js 18+ and pnpm
- MongoDB Atlas account
- Coinbase CDP API credentials
- Base network wallet address (for receiving payments)
- Anthropic API key (for AI chat)
- Base wallet with USDC (for MCP server to make payments)
Installation
- Install dependencies:
pnpm install
- Set up environment variables:
cp .env.example .env.local
- Configure environment variables in
.env.local:
# MongoDB connection string
MONGODB_URI=mongodb+srv://...
# CDP credentials (get from https://portal.cdp.coinbase.com)
CDP_API_KEY_ID=your-key-id
CDP_API_KEY_SECRET=your-secret
# Generate encryption key
ENCRYPTION_KEY=$(node -e "console.log(require('crypto').randomBytes(32).toString('hex'))")
# Base URL (update for production)
NEXT_PUBLIC_BASE_URL=http://localhost:3000
# AI Chat - Anthropic API (get from https://console.anthropic.com)
ANTHROPIC_API_KEY=sk-ant-api03-...
# MCP Server Wallet - Private key with USDC on Base
MCP_WALLET_PRIVATE_KEY=0x...
# Optional: Cloudflare Workers deployment
CLOUDFLARE_API_TOKEN=...
CLOUDFLARE_ACCOUNT_ID=...
See .env.example for complete configuration options.
- Run the development server:
pnpm dev
Project Structure
βββ app/
β βββ api/
β β βββ chat/ # AI chat API (NEW)
β β βββ mcp/ # MCP server management (NEW)
β β βββ register/ # Endpoint registration
β β βββ test-endpoint/ # Endpoint testing
β β βββ x402/[providerId] # x402 proxy
β βββ chat/ # AI chat interface page (NEW)
β βββ register/ # Registration UI
βββ components/ # React components
βββ lib/
β βββ db/
β β βββ models/
β β β βββ endpoint.ts # Endpoint configurations
β β β βββ mcp-config.ts # MCP server configs (NEW)
β β βββ connection.ts
β βββ mcp/ # MCP server implementation (NEW)
β β βββ server.ts # Dynamic MCP server
β β βββ tools.ts # MCP tool definitions
β β βββ ui-factory.ts # MCP-UI resources
β βββ services/ # Core services
β β βββ mcp-generator.ts # MCP tool generation (NEW)
β β βββ mcp-deployer.ts # Cloudflare deployment (NEW)
β β βββ facilitator.ts # CDP Facilitator
β β βββ payment-requirements.ts
β β βββ request-forwarder.ts
β β βββ encryption.ts
β β βββ endpoint-tester.ts
β βββ utils/ # Utility functions
β βββ constants.ts # Configuration
β βββ types.ts # TypeScript types
β βββ validation.ts # Zod schemas
βββ middleware.ts # CORS middleware
Development
pnpm dev # Start dev server
pnpm build # Build for production
pnpm start # Start production server
pnpm lint # Lint code
Usage
1. Register an Endpoint
Visit http://localhost:3000/register and fill out the registration form:
- Original API endpoint URL
- HTTP method (GET, POST, PUT, DELETE)
- Price per request in USD
- Wallet address for payments
- Authentication method and credentials
- Description and metadata
2. Get Your Wrapped Endpoint
After registration, you'll receive:
- A wrapped x402 endpoint:
http://localhost:3000/api/x402/{providerId} - The endpoint is automatically available as an MCP tool
3. Use in AI Chat
Visit http://localhost:3000/chat to:
- Chat with Claude AI
- Claude can invoke your registered endpoints as tools
- Payments are handled automatically with x402 protocol
- See transaction hashes and payment details in the chat
4. Test x402 Payment Flow
Use the test script to verify your endpoint works with x402:
# Update ENDPOINT variable in test-x402-payment.ts
tsx test-x402-payment.ts
How It Works
Traditional x402 Flow
Client β [402 Response] β Sign Payment β [200 Response + Data]
AI Chat Flow (New)
User β Claude Chat β Tool Call β MCP Server β x402 Endpoint β Payment β Data β Claude β User
The MCP server acts as a smart client that:
- Receives tool calls from Claude
- Makes x402 payment automatically with its wallet
- Returns data to Claude for natural language response
Deployment
Web App (Vercel)
Deploy to Vercel and set environment variables in the dashboard.
MCP Server (Cloudflare Workers)
MCP servers can be deployed to Cloudflare Workers for global edge distribution:
# Deploy from the dashboard at /mcp (coming soon)
# Or manually deploy to Cloudflare Workers
Documentation
- See
CLAUDE.mdfor AI-assisted development guidelines - See
TECHNICAL_SPEC.mdfor complete architecture and implementation details - See
test.mdfor testing documentation
License
MIT
