modelscope·@CodaLabs-xyz/Template-x402-Mcp
暂无描述。
Production-ready MCP server template for consuming X402-protected APIs with gasless micropayments
This template provides everything you need to create an MCP (Model Context Protocol) server that can consume X402-enabled APIs, enabling AI agents like Claude to make micropayment-based API calls seamlessly.
For AI Developers: See CLAUDE.md for comprehensive X402 + MCP integration documentation, payment flows, and AI development guidance.
Claude Desktop / MCP Client
User Request: "Search for coffee shops near me"
MCP Protocol: CallTool("search_places", {query: "coffee"})
X402 MCP Server (This Template)
Tool Handler: Receives request
X402 Payment Client (x402-axios)
- EIP-712 signature generation
- Automatic 402 retry handling
- Payment authorization
X402-Protected API Server
1. First Request: Returns 402 Payment Required
- Includes payment requirements (price, network, address)
2. Payment Processing:
- Verify EIP-712 signature
- Submit to facilitator
- Execute USDC transfer (gasless)
3. Second Request: Payment authorized, returns data
Result Returned to Claude
- API response data
- Payment metadata
- Cost information
Key Points:
Template-x402-Mcp/
index.ts # Main MCP server implementation
package.json # Dependencies and scripts
tsconfig.json # TypeScript configuration
.env.example # Environment variables template
README.md # This file - setup and usage guide
CLAUDE.md # AI-friendly X402 + MCP documentation
# Navigate to template directory
cd Template-x402-Mcp
# Install dependencies
npm install
# Copy environment variables
cp .env.example .env
Edit .env file:
Option A: Demo Mode (No Payment)
# Leave PRIVATE_KEY empty or with placeholder
PRIVATE_KEY=<your-private-key-here>
# Set your X402 API endpoint
RESOURCE_SERVER_URL=https://places-api.x402hub.xyz
# Network (testnet for demo)
NETWORK=base-sepolia
Option B: Payment Mode (X402 Enabled)
# Add your wallet private key
PRIVATE_KEY=0x1234567890abcdef...
# Set your X402 API endpoint
RESOURCE_SERVER_URL=https://places-api.x402hub.xyz
# Network: base-sepolia (testnet) or base (mainnet)
NETWORK=base-sepolia
Edit index.ts to define your API-specific tools:
// In ListToolsRequestSchema handler
{
name: "your_custom_tool",
description: "Description of what your tool does",
inputSchema: {
type: "object",
properties: {
// Define your input parameters
param1: {
type: "string",
description: "Parameter description"
}
},
required: ["param1"]
}
}
Add tool handler:
case "your_custom_tool": {
const { param1 } = args as { param1: string };
// Make X402-protected API call
const response = await client.post("/api/your-endpoint", {
param1: param1
});
return {
content: [{
type: "text",
text: JSON.stringify(response.data, null, 2)
}]
};
}
# Build TypeScript
npm run build
# Test with MCP Inspector
npm run inspector
# Or test in development mode
npm run dev
Add to Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"x402-your-api": {
"command": "node",
"args": ["/absolute/path/to/Template-x402-Mcp/build/index.js"],
"env": {
"PRIVATE_KEY": "0x...",
"RESOURCE_SERVER_URL": "https://your-x402-api.example.com",
"NETWORK": "base-sepolia"
}
}
}
}
Restart Claude Desktop and your tools will be ava…
一座通过模型控制协议(Model Control Protocol)将Dune Analytics区块链数据连接到人工智能应用的桥梁,使大型语言模型(LLMs)能够通过自然语言交互访问链上数据。
暂无描述。
暂无描述。
暂无描述。
暂无描述。
贸易代理