API支付代理服务

MCP (Model Context Protocol) 服务器,允许AI代理通过信用余额调用x402-enabled API,无需钱包、区块链或Web3知识。

  • by HTTPayer
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 HTTPayer/mcp

使用说明

@httpayer/mcp

HTTP层的MCP(模型上下文协议)服务器。让AI代理使用信用余额调用支持x402的API——无需钱包、区块链,也不需要Web3知识。


快速入门

使用AI代理(推荐)

将此粘贴到任何MCP兼容代理(Claude Code、Cursor、Windsurf、OpenCode…)中:

Set up https://httpayer.com/skill.md

代理检测您的环境并自动处理一切。

无代理(手动)

1.运行安装程序:

npx @httpayer/mcp setup

获取API密钥: app.httpayer.com 当提示时。

旗帜:

标志 描述
--key sk-live-... 非交互式提供密钥
--client <name> 目标客户: claude-code, claude-desktop, cursor, windsurf, opencode, zed, cline, warp, codex
--scope user|project Claude代码范围(默认值: user)
--yes / -y 跳过所有提示
--update-key 替换现有密钥

2.添加到您的客户:

克劳德代码:

claude mcp add httpayer --scope user -- npx -y @httpayer/mcp@latest

克劳德桌面 (~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上, %APPDATA%\Claude\claude_desktop_config.json 在Windows上):

{
  "mcpServers": {
    "httpayer": {
      "command": "npx",
      "args": ["-y", "@httpayer/mcp@latest"]
    }
  }
}

光标 (.cursor/mcp.json), 帆板运动 (.windsurf/mcp.json), 克莱恩 (.cline/mcp_settings.json):

{
  "mcpServers": {
    "httpayer": {
      "command": "npx",
      "args": ["-y", "@httpayer/mcp@latest"]
    }
  }
}

开源代码 (opencode.json 或 ~/.config/opencode/config.json):

{
  "mcp": {
    "httpayer": {
      "type": "local",
      "command": ["npx", "-y", "@httpayer/mcp@latest"],
      "enabled": true
    }
  }
}

Zed:

{
  "context_servers": {
    "httpayer": {
      "command": {
        "path": "npx",
        "args": ["-y", "@httpayer/mcp@latest"]
      }
    }
  }
}

3.重新启动客户端并验证:

问你的经纪人: “取回https://api.httpayer.com/demo/v1/base-weather"

天气响应意味着HTTPayer正在工作。


运作原理

User prompt
    │
    ▼
AI agent (Claude Code, Cursor, Windsurf...)
    │  uses MCP tools + prompts + resources
    ▼
@httpayer/mcp (local MCP server via npx)
    │  REST calls with x-api-key header
    ▼
api.httpayer.com
    │  proxy handles x402 payment to target
    ▼
Target x402-gated API

运行时流程

  1. 您的客户端通过以下方式启动MCP服务器 npx -y @httpayer/mcp@latest 启动时(stdio传输)。
  2. 服务器从中读取API密钥 ~/.httpayer/mcp-config.json.
  3. 代理在其上下文中接收工具列表、系统指令、提示和资源。
  4. 当代理人来电时 fetch,MCP服务器将请求转发给 POST https://api.httpayer.com/proxy.
  5. HTTPayer的代理检测到402,使用您的信用支付,重试,并返回最终响应。
  6. 结果(状态、正文、标题)返回给代理。

MCP功能

此服务器公开了三个MCP原语,因此代理可以自动获取上下文,而无需用户询问。

工具

六种工具(见下文完整参考)。

提示

名称 描述
httpayer-context 将完整的HTTPayer支付上下文注入代理。支持提示的客户端将在会话开始时自动加载此提示。

兼容的客户端(Claude Desktop、Cursor等)调用 prompts/list 在连接时,主动将这些注入代理的上下文中。

资源

URI 描述
httpayer://skill.md 完整的设置指南、触发模式、可用端点和工作流。客户可以根据需要将其作为基础上下文。

MCP工具参考

get_balance

检查信用余额和日常使用情况。

输入: 无

示例响应:

{
  "account_id": "account_123",
  "mainnet": {
    "credits_balance": 50000,
    "daily_limit": 100000,
    "daily_spend": 15500,
    "daily_remaining": 84500
  }
}

fetch

向任何启用x402的端点发出HTTP请求。付款是自动处理的。

输入:

字段 类型 必填 描述
url string yes 目标URL
method string 否 GET, POST, PUT, DELETE, PATCH --默认值 GET
body object no JSON请求体
params object no 查询字符串参数
headers object 否 其他请求标头
timeout number no 超时(秒),最大120

示例响应:

{
  "status": 200,
  "body": { "data": "..." },
  "headers": { "content-type": "application/json" }
}

在502上,响应包括 webhook_id 用于异步轮询。


simulate

干洗一次。返回不含支出抵免的成本估算。

输入: 同 fetch (除 timeout).

示例响应:

{
  "requiresPayment": true,
  "proxyFeeBreakdown": {
    "targetAmount": 0.01,
    "proxyFee": 0.0003,
    "totalCreditsCharged": 10.3
  }
}

get_topup_link

返回仪表板URL以添加积分。余额低时向用户显示。

输入: 无


check_limits

检查全局HTTPayer系统的每日限制和剩余容量。

输入: 无


get_webhook_status

轮询异步操作的状态。使用时 fetch 返回502 webhook_id.

输入: webhook_id (字符串,必填)

状态值: pending, success, success_refunded, payment_failed, upstream_error, internal_error, rate_limited


HTTPayer API参考

身份验证: x-api-key: sk-live-... 所有请求的标题。

方法 路径 工具
GET /v1/credits/balance get_balance
POST /proxy fetch
POST /proxy/sim simulate
GET /limits check_limits
GET /webhooks/{id} get_webhook_status

代理终结点

POST https://api.httpayer.com/proxy

{
  "api_url": "https://target.example.com/endpoint",
  "method": "GET",
  "json": { "key": "value" },
  "params": { "query": "param" },
  "headers": { "Custom-Header": "value" },
  "timeout": 30
}

仅 api_url 和 method 是必需的。

状态代码:

代码 含义
200 成功
402 学分不足
429 价格有限
500 代理错误
502 目标拒绝付款——包括 webhook_id

配置

API密钥存储在: ~/.httpayer/mcp-config.json

{ "apiKey": "sk-live-..." }

要更新,请执行以下操作: npx @httpayer/mcp setup --update-key


x402协议概述

x402是一种HTTP原生微支付协议,使用 402 Payment Required 状态代码。

没有HTTPayer:

  1. 客户端到达端点→ gets 402 +付款要求
  2. 客户在链上支付(需要钱包+USDC)
  3. 客户端使用付款证明重试

使用HTTPayer:

  1. 客户电话 POST /proxy { api_url, method, ... }
  2. HTTP层检测到 402,使用您的信用额度支付
  3. HTTP层重试并返回最终响应

所有区块链交互都发生在HTTPayer一侧。


信用体系

单位 值
1学分 0.001美元
1美元 1000个信用点
代理费 目标付款的3%

充值至 app.httpayer.com。低于100个积分,代理商会提示您充值。


错误处理

设置错误

情境 行为
密钥格式无效 打印错误,退出1
密钥被拒绝(401) 打印“API密钥被拒绝”,退出1
网络无法连接 打印原因,退出1

MCP工具错误

所有错误返回 isError: true --服务器保持活动状态,代理收到可读的消息。

情况 消息
无配置 "No HTTPayer API key configured. Run: npx @httpayer/mcp setup"
API非2xx "HTTPayer {status}: {body}"
未知工具 "Unknown tool: {name}"

©2026 HTTPayer股份有限公司。