加密货币支付服务器

AI42 MCP Server是一个为Claude Desktop设计的自动处理X402加密货币支付的服务器,支持支付跟踪、余额检查和消费限制等功能。

  • by Kishore-MK
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Kishore-MK/ai42-mcp

使用说明

AI42 MCP服务器

X402克劳德桌面支付MCP服务器

快速开始 • 特性 • 安装 • 用法


概述

AI42 MCP服务器使Claude Desktop能够自动处理X402支付的web请求。从任何URL获取数据,并在需要时无缝处理加密货币支付(402状态)。包括付款跟踪、余额检查和支出限额。

特性

  • 自动付款处理:对402个响应进行透明的X402支付处理
  • GET和POST支持:对API交互的完全HTTP方法支持
  • 支付管理:跟踪历史记录、检查余额、设置支出限额
  • Solana集成:基于Solana devnet/mainnet构建
  • 类型安全:完全支持TypeScript
  • 零配置:与Claude Desktop一起开箱即用

可用工具

工具 说明
fetch-with-payment 通过自动支付从URL获取数据
get-balance 查看钱包SOL余额
get-payment-history 查看会话期间的所有付款
set-payment-limit 设置每个请求的最大支出限额

安装

先决条件

  • Node.js 18+
  • Solana钱包私钥(base58格式)
  • 克劳德桌面

快速安装

无需手动安装!只需配置Claude Desktop:

增添 claude_desktop_config.json:

窗户:

{
  "mcpServers": {
    "x402-payment": {
      "command": "npx",
      "args": ["-y", "@ai42/mcp"],
      "env": {
        "SOLANA_PRIVATE_KEY": "your_base58_private_key_here"
      }
    }
  }
}

macOS:

{
  "mcpServers": {
    "x402-payment": {
      "command": "npx",
      "args": ["-y", "@ai42/mcp"],
      "env": {
        "SOLANA_PRIVATE_KEY": "your_base58_private_key_here"
      }
    }
  }
}

Linux:

{
  "mcpServers": {
    "x402-payment": {
      "command": "npx",
      "args": ["-y", "@ai42/mcp"],
      "env": {
        "SOLANA_PRIVATE_KEY": "your_base58_private_key_here"
      }
    }
  }
}

配置文件位置

平台 路径
窗户 %APPDATA%\Claude\claude_desktop_config.json
macOS ~/Library/Application Support/Claude/claude_desktop_config.json
Linux ~/.config/Claude/claude_desktop_config.json

添加配置后: 重新启动克劳德桌面!


快速开始

获取您的私钥

生成Solana密钥对:

solana-keygen new --outfile ~/.config/solana/id.json
solana-keygen pubkey ~/.config/solana/id.json

导出私钥(base58格式):

cat ~/.config/solana/id.json
# Copy the array, then convert to base58

⚠️ 永远不要将私钥提交给版本控制!

首次请求

配置完毕并重新启动Claude Desktop后,只需询问:

You: Check my wallet balance

Claude: [Uses get-balance tool] Your balance is 2.5 SOL on devnet

用法

对话示例

从URL获取数据

You: Get data from https://api.example.com/endpoint

Claude: [Uses fetch-with-payment] Here's the data from the API...

付款后提取

You: Fetch https://paid-service.com/premium-data

Claude: [Uses fetch-with-payment] Payment of 0.05 SOL made successfully. 
Here's the premium data...

发布请求

You: POST this data to https://api.example.com: {"message": "hello"}

Claude: [Uses fetch-with-payment] Successfully posted. Response: {...}

查询余额

You: What's my SOL balance?

Claude: [Uses get-balance] Your current balance:
- Balance: 2.5 SOL
- Network: devnet
- Address: 7xK...abc

设置付款限额

You: Set payment limit to 0.1 SOL

Claude: [Uses set-payment-limit] Payment limit set to 0.1 SOL. 
Any request exceeding this amount will be rejected.

查看付款历史记录

You: Show my payment history

Claude: [Uses get-payment-history] 
Total payments: 3
Total spent: 0.15 SOL

Recent payments:
1. 0.05 SOL to xyz...abc at 2025-11-12T10:30:00Z
2. 0.08 SOL to def...123 at 2025-11-12T11:45:00Z
3. 0.02 SOL to ghi...789 at 2025-11-12T12:15:00Z

工具参考

1. fetch-with-payment

通过自动支付处理从任何URL获取数据。

参数:

  • url (字符串,必填):要获取的URL
  • method (字符串,可选):HTTP方法-“GET”或“POST”(默认值:“GET”)
  • body (string,可选):POST请求的JSON字符串

退货:

{
  success: boolean;
  data: any;
  payment_made: boolean;
  payment_amount: number; // in SOL
}

例子:

Get data from https://api.weather.com/current

2. get-balance

查看您钱包中的当前SOL余额。

参数: 无

退货:

{
  balance: number;      // SOL amount
  unit: "SOL";
  network: string;      // "devnet" or "mainnet"
  address: string;      // Public key
}

例子:

Check my wallet balance

3. get-payment-history

查看当前会话期间的所有付款。

参数:

  • limit (数字,可选):要返回的最大记录数(默认值:全部)

退货:

{
  total_payments: number;
  total_spent: number;     // Total SOL spent
  records: Array<{
    url: string;
    amount: number;        // in SOL
    recipient: string;
    timestamp: string;
    signature: string;
  }>;
}

例子:

Show last 5 payments

4. set-payment-limit

设置每个请求的最大支出限制。设置为0可删除限制。

参数:

  • limit (数字,必填):最大SOL金额(0表示删除)

退货:

{
  message: string;
  current_limit: number | null;
}

例子:

Don't let me spend more than 0.05 SOL per request

运作原理

X402支付流程

  1. 请求:Claude向URL发出请求
  2. 402响应:如果端点要求付款,则返回HTTP 402
  3. 自动支付:MCP服务器使用您的Solana钱包自动处理付款
  4. 重试:使用付款证明重试请求
  5. 成功:数据返回给Claude

付款跟踪

  • 会话期间,所有付款都会记录在内存中
  • 跟踪金额、收件人、时间戳和交易签名
  • 随时查看历史记录 get-payment-history

支出限额

  • 设置每次请求的最大金额以防止超支
  • 超过限制的请求将自动被拒绝
  • 通过设置为0来删除限制

高级用法

MCP检验员测试

用于开发和调试:

# Install globally or use npx
npx @modelcontextprotocol/inspector npx @ai42/mcp

这将打开一个web UI,您可以在其中:

  • 查看所有已注册的工具
  • 使用自定义输入的测试工具调用
  • 查看请求/响应JSON
  • 调试付款流程

环境变量

如果在本地运行(不通过Claude配置中的npx):

# .env file
SOLANA_PRIVATE_KEY=your_base58_private_key_here

网络配置

目前支持:

  • 索拉纳发展网 (默认):用于使用测试SOL进行测试
  • 索拉纳主网:用于生产(源代码更新)

安全最佳实践

私钥安全

✅ 做:

  • 将私钥存储在环境变量中
  • 使用单独的钱包进行测试(devnet)和生产(主网)
  • 设定合理的付款限额
  • 定期检查付款历史

❌ 不要:

  • 将私钥提交给git
  • 在聊天或屏幕截图中共享私钥
  • 使用没有支付限制的生产钱包
  • 忽略付款历史记录

付款限额

基于使用情况的建议限制:

用例 建议限制
测试 0.01 SOL
光使用量 0.1 SOL
常规使用 0.5 SOL
大量使用 1.0 SOL

故障排除

“密钥大小错误”错误

您的私钥格式不正确。确保它是base58格式:

# Convert from JSON array to base58
node -e "console.log(require('bs58').encode(Buffer.from([your,array,here])))"

“找不到模块”错误

清除npx缓存并重新安装:

npx clear-npx-cache
# Restart Claude Desktop

“付款失败”错误

检查:

  1. 钱包有足够的余额(get-balance)
  2. 与Solana RPC的网络连接
  3. 私钥有效
  4. 未超过付款限额

工具未出现在Claude中

  1. 验证配置文件位置和语法
  2. 完全重新启动克劳德桌面
  3. 检查Claude Desktop日志是否有错误
  4. 使用MCP检查员进行测试

发展

地方发展

# Clone repository
git clone https://github.com/Kishore-MK/ai42-mcp
cd ai42-mcp

# Install dependencies
npm install

# Create .env file
echo "SOLANA_PRIVATE_KEY=your_key" > .env

# Build
npm run build

# Test locally
node dist/index.js

项目结构

ai42-mcp/
├── src/
│   ├── index.ts          # Main MCP server
|   ├── payment.ts        # Payment client wrapper
│   └── types.ts          # Types file
├── dist/                 # Compiled JavaScript
├── package.json
├── tsconfig.json
└── README.md

贡献

欢迎投稿!请随时提交拉取请求。

  1. 分叉存储库
  2. 创建功能分支(git checkout -b feature/amazing-feature)
  3. 提交您的更改(git commit -m 'Feat: Add amazing feature')
  4. 推到分支(git push origin feature/amazing-feature)
  5. 打开拉取请求

链接


许可证

MIT许可证-请参阅 许可证 详细信息文件


致谢

内置:


由以下材料制成❤️ 通过keyaru

NPM • GitHub • 问题