LLM钱包MCP服务器
通用MCP(模型上下文协议)服务器,为任何AI代理提供钱包功能和x402微支付功能。该服务器使AI代理能够创建钱包、管理支出限制,并自动处理付费API的小额支付。
此MCP服务器的功能
此服务器提供 18个MCP工具 允许AI代理:
- 创建和管理加密钱包 (带私钥加密的高清钱包)
- 支票余额 跨网络(Polygon、Polygon Amoy)
- 进行自动小额支付 到x402受保护的API
- 执行支出限制 (每笔交易和每日上限)
- 跟踪付款历史记录 以及事务日志
- 注册任何付费API 作为MCP工具,易于重复使用
- 支持多个网络 (测试网和主网)
步骤1:添加到MCP配置
对于光标(~/.cursor/mcp.json)
{
"mcpServers": {
"LLM Wallet": {
"command": "npx",
"args": ["llm-wallet-mcp"],
"env": {
"NETWORK": "polygon-amoy"
}
}
}
}适用于克劳德桌面(claude_desktop_config.json)
{
"mcpServers": {
"LLM Wallet": {
"command": "npx",
"args": ["llm-wallet-mcp"],
"env": {
"NETWORK": "polygon-amoy"
}
}
}
}步骤2:验证安装
在您的MCP客户端中,您现在应该看到 18工具 可用:
- 4款钱包管理工具
- 2个支出限制工具
- 2个x402买方工具
- 5 x402卖家工具
- 4个动态API工具
⚠️ 发展公告:该方案仍在开发中。请更喜欢在测试网(多边形amoy)上使用,或者如果在主网上使用,请只使用少量。请勿在生产环境中使用。
完整的买方流程示例
以下是如何从头到尾使用LLM Wallet MCP服务器的完整示例:
步骤1:创建或导入钱包
选项A:创建新钱包
# In Cursor chat:
create a new wallet with label "my-agent-wallet"选项B:导入现有钱包
# In Cursor chat:
import wallet with private key 0x1234... and label "my-wallet"预期响应:
{
"success": true,
"address": "0x742d35Cc6635C0532925a3b8D2A0a7e3E4b1b4e4",
"label": "my-agent-wallet",
"network": "polygon-amoy"
}第二步:检查钱包余额
# In Cursor chat:
check the balance for my-agent-wallet第3步:设置支出限额(可选但推荐)
# In Cursor chat:
@LLM Wallet set spending limits: max $0.10 per transaction and $5.00 daily limit预期响应:
{
"success": true,
"limits": {
"perTransaction": "0.10",
"dailyLimit": "5.00",
"dailySpent": "0.00"
}
}步骤4:注册付费API作为MCP工具
# In Cursor chat:
Register the weather API at http://localhost:4021/weather as a paid MCP tool called "weather_api"预期响应:
{
"success": true,
"toolName": "weather_api",
"endpoint": "http://localhost:4021/weather",
"requiresPayment": true,
"maxAmount": "0.001"
}步骤5:进行付费API调用(完整x402流量)
# In Cursor chat:
Call the weather_api tool with location "London"幕后发生了什么:
- ✅ MCP服务器调用
http://localhost:4021/weather?location=London - ✅ 服务器响应如下
402 Payment Required以及付款要求 - ✅ MCP服务器自动创建已签名的支付授权
- ✅ MCP服务器重试请求
X-Payment头球 - ✅ 卖方与协调人核实付款
- ✅ 卖家返回天气数据
- ✅ 付款记录在钱包历史记录中
预期响应:
{
"location": "London",
"temperature": 15,
"condition": "Cloudy",
"humidity": 78,
"payment": {
"amount": "0.001",
"status": "completed",
"transactionId": "0xabc123..."
}
}步骤6:检查付款历史记录
# In Cursor chat:
@LLM Wallet show payment history for my-agent-wallet预期响应:
{
"payments": [
{
"timestamp": "2025-01-14T15:30:45Z",
"recipient": "0xCA3953e536bDA86D1F152eEfA8aC7b0C82b6eC00",
"amount": "0.001",
"status": "completed",
"resource": "http://localhost:4021/weather",
"transactionId": "0xabc123..."
}
],
"dailySpent": "0.001",
"remainingDailyLimit": "4.999"
}步骤7:检查更新的支出限额
# In Cursor chat:
@LLM Wallet check current spending limits and daily usage预期响应:
{
"limits": {
"perTransaction": "0.10",
"dailyLimit": "5.00",
"dailySpent": "0.001",
"remainingDaily": "4.999"
},
"usage": {
"today": "0.001",
"thisWeek": "0.001",
"totalTransactions": 1
}
}完整的工具参考
钱包管理(4个工具)
wallet_create-使用加密存储创建新的HD钱包wallet_import-从私钥导入现有钱包wallet_balance-检查USDC和本地代币余额wallet_history-查看付款和交易历史记录
支出限额(2个工具)
wallet_set_limit-设置每笔交易和每日支出上限wallet_get_limits-获取当前限制和每日使用统计数据
x402买方工具(2个工具)
x402_check_payment-预先检查钱包是否可以支付(在支付之前)x402_pay-使用x402 fetch向x402受保护的资源付款
x402卖方工具(5个工具)
seller_verify_payment-核实买方收到的付款seller_settle_payment-在链上结算已验证的付款seller_decode_payment-无需呼叫协调人即可解码支付标头seller_create_requirements-生成受保护资源的付款要求seller_generate_402_response-生成402付款要求响应
动态API工具(4个工具)
api_register-将任何付费API端点注册为MCP工具api_list-列出所有注册的API工具api_call-使用参数执行已注册的API工具api_unregister-删除已注册的API工具
支持的网络
测试网(建议开发)
- 多边形淘 -链ID:80002
主网(生产使用)
- 多边形 -链ID:137
用例和示例
1.具有预算控制的AI代理
# Set strict limits for AI agent
@LLM Wallet set spending limits: max $0.05 per transaction and $1.00 daily
# Agent can now safely call paid APIs without overspending
@LLM Wallet call weather_api with location "New York"2.开发团队共享钱包
# Create team wallet
@LLM Wallet create wallet with label "team-dev-wallet"
# Set team spending limits
@LLM Wallet set spending limits: max $0.10 per transaction and $10.00 daily
# Register multiple APIs for team use
@LLM Wallet register OpenAI API as "openai_tool"
@LLM Wallet register Anthropic API as "anthropic_tool"3.具有监控功能的生产代理
# Check daily usage
@LLM Wallet check current spending limits and daily usage
# View payment history for audit
@LLM Wallet show payment history for production-wallet
# Monitor spending patterns
@LLM Wallet check balance for production-wallet4.多网络部署
# Deploy on testnet first
NETWORK=polygon-amoy @LLM Wallet create wallet with label "test-wallet"
# Then deploy on mainnet
NETWORK=polygon @LLM Wallet create wallet with label "prod-wallet"故障排除
常见问题
MCP客户端中“无可用工具”
- 完全重新启动MCP客户端(光标:Cmd+Q,然后重新打开)
- 验证
~/.cursor/mcp.json是有效的JSON - 检查路径
dist/index.js是正确和绝对的 - ✅ 确保MCP服务器成功构建:
npm run build
“找不到钱包”错误
- ✅ 先创建一个钱包:
@LLM Wallet create wallet with label "my-wallet" - ✅ 或导入现有:
@LLM Wallet import wallet with private key 0x...
“付款超过限额”错误
- ✅ 检查电流限制:
@LLM Wallet check current spending limits - ✅ 增加限制:
@LLM Wallet set spending limits: max $1.00 per transaction
“余额不足”错误
- ✅ 检查余额:
@LLM Wallet check balance for my-wallet - ✅ 从水龙头获取测试USDC(用于测试网)
- ✅ 确保您使用正确的网络
“验证失败”错误
- ✅ 验证环境变量中的主持人URL是否正确
- ✅ 检查与主持人的网络连接
- ✅ 确保钱包有足够的USDC余额
调试模式
启用调试日志记录:
LOG_LEVEL=debug node dist/index.js健康检查
测试MCP服务器是否响应:
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | node dist/index.js🔒 安全最佳实践
钱包安全
- ✅ 使用强加密密钥 (32+个字符,随机生成)
- ✅ 安全地存储加密密钥 (环境变量,不在代码中)
- ✅ 使用测试网进行开发 (Polygon Amoy、Base Sepolia)
- ✅ 设定适当的支出限额 (每笔交易和每日上限)
- ✅ 监控付款历史记录 定期
生产部署
- ✅ 使用HTTPS 用于所有通信
- ✅ 实施速率限制 防止滥用
- ✅ 定期备份 钱包数据
- ✅ 监控日志 可疑活动
- ✅ 仅使用主网 准备生产时
环境安全
# Generate secure encryption key
openssl rand -hex 32
# Use environment variables (never hardcode)
export WALLET_ENCRYPTION_KEY="your-secure-key"
export NETWORK="polygon-amoy" # Use testnet for development关键组件
钱包服务:使用AES-256-GCM加密创建和管理HD钱包 存储服务:保存钱包、限额和支付历史记录 X402服务:处理x402协议交互(仅买方) 工具操作员:带输入验证的MCP工具实现
📚 额外资源
文档
- x402协议:
- 模型上下文协议: 官方文件
- 我知道: 以太坊TypeScript库
相关项目
- x402:用于x402协议的Types/JavaScript SDK
- x402获取:自动402响应处理
- x402快递:用于x402的Express.js中间件
📄 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
