关于 MCP Billing Gateway
MCP Billing Gateway 是托管式计费代理,供希望为 MCP 服务收费的运营者使用。它在调用方与上游服务之间验证付款、跟踪用量并执行定价方案。
主要功能
- 01按工具调用计费
- 02Stripe 订阅与分层定价
- 03支持 x402 USDC 微支付
- 04运营者收入与用量仪表板
- 05代理转发并执行付款规则
适用场景
- 01为现有 MCP 服务设置按次付费
- 02为开发者提供月度或年度订阅
- 03允许 AI Agent 使用 Base 上的 USDC 付款
MCP 相关
本地 MCP 服务提供能力查询工具 `get_billing_info`;托管网关则通过 Streamable HTTP 代理 MCP 服务,并对调用执行计费。
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
https://mcp-billing-gateway-production.up.railway.app/mcp/claude mcp add --transport http sapph1re-mcp-billing-gateway https://mcp-billing-gateway-production.up.railway.app/mcp/{"mcpServers":{"sapph1re-mcp-billing-gateway":{"type":"http","url":"https://mcp-billing-gateway-production.up.railway.app/mcp/"}}}在 Cursor 中打开{"servers":{"sapph1re-mcp-billing-gateway":{"type":"http","url":"https://mcp-billing-gateway-production.up.railway.app/mcp/"}}}在 VS Code 中打开{"mcpServers":{"sapph1re-mcp-billing-gateway":{"type":"http","url":"https://mcp-billing-gateway-production.up.railway.app/mcp/"}}}{"mcpServers":{"sapph1re-mcp-billing-gateway":{"serverUrl":"https://mcp-billing-gateway-production.up.railway.app/mcp/"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
12| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| name | string | 是 | 运营方或公司名称 |
| string | 是 | 运营方电子邮件地址 |
详细介绍
MCP 计费网关
为任何 MCP 服务添加 Stripe 订阅、按调用计费和 x402 加密货币支付,无需编写计费代码。
MCP Billing Gateway 是一个托管式计费代理,位于 AI Agent 与你的 MCP 服务之间。它会自动处理支付验证、用量跟踪和套餐限制。你只需注册服务、设置定价方案,并将调用方指向代理 URL。无需编写计费代码。
在线服务:https://mcp-billing-gateway-production.up.railway.app
教程:10 分钟让任何 MCP 服务实现营收 — 逐步演示,附带可运行代码
安装
pip install mcp-billing-gateway
也可以使用 uvx:
uvx mcp-billing-gateway
Claude Desktop 配置
添加到 ~/Library/Application Support/Claude/claude_desktop_config.json(macOS)或 %APPDATA%\Claude\claude_desktop_config.json(Windows):
{
"mcpServers": {
"mcp-billing-gateway": {
"command": "uvx",
"args": ["mcp-billing-gateway"]
}
}
}
Cursor 配置
添加到项目中的 .cursor/mcp.json:
{
"mcpServers": {
"mcp-billing-gateway": {
"command": "uvx",
"args": ["mcp-billing-gateway"]
}
}
}
添加配置后,重启编辑器以激活 MCP 服务。
工具
| 工具 | 说明 |
|---|---|
get_billing_info | 返回服务功能、支持的支付方式、特性和集成文档 |
本地 MCP 服务提供服务发现功能。完整的计费功能由托管网关提供——注册为运营方,并通过该网关代理你的 MCP 服务。
工作原理
AI Agent → MCP Billing Gateway → Your MCP Server
(billing enforced here)
- 注册为运营方并获取 API 密钥
- 注册你的 MCP 服务 URL 和定价方案
- 将调用方指向你的代理标识:
https://mcp-billing-gateway-production.up.railway.app/proxy/{your-slug}/mcp - 调用方通过 Stripe API 密钥或 x402 USDC 付款——计费过程透明处理
功能
- 按调用计费 — 按工具调用向调用方收费(法币或加密货币)
- 订阅 — 带调用次数限制的 Stripe 月度/年度方案
- 分级定价 — 免费套餐 + 按用量计费的付费套餐
- x402 小额支付 — 接受来自 AI Agent 的 Base 网络 USDC,无需 API 密钥
- 运营方仪表板 — 实时跟踪收入、用量和调用方
- MCP 传输 — 在
/mcp/端点提供完整的 Streamable HTTP MCP 传输
快速开始
1. 注册为运营方
curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/operator/register \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "name": "Your Name"}'
响应:
{
"operator_id": "op_abc123",
"api_key": "bg_live_xxxxxxxxxxxx",
"message": "Operator registered successfully"
}
2. 注册你的 MCP 服务
curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/servers \
-H "Authorization: Bearer bg_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"name": "My MCP Server",
"upstream_url": "https://your-mcp-server.com/mcp",
"proxy_slug": "my-server"
}'
3. 创建定价方案
curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/servers/{server_id}/plans \
-H "Authorization: Bearer bg_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"name": "Pay as you go",
"billing_model": "per_call",
"price_per_call_usd_micro": 10000,
"free_calls_per_month": 100
}'
4. 将调用方连接到你的代理服务
{
"mcpServers": {
"my-server": {
"url": "https://mcp-billing-gateway-production.up.railway.app/proxy/my-server/mcp",
"headers": {
"Authorization": "Bearer CALLER_API_KEY"
}
}
}
}
支付方式
| 方式 | 适用对象 | 说明 |
|---|---|---|
| Stripe 订阅 | 人类开发者 | 通过 Stripe Checkout 购买月度或年度方案 |
| Stripe 按调用计费 | 人类开发者 | 每次工具调用消耗额度 |
| x402 小额支付 | AI Agent | 使用 Base 网络 USDC,无需 API 密钥 |
示例
查看网关功能
# Using the MCP client
result = await session.call_tool("get_billing_info")
print(result)
# {
# "service": "MCP Billing Gateway",
# "version": "0.1.0",
# "payment_methods": ["stripe_subscription", "stripe_metered", "x402_crypto"],
# "features": ["Per-call usage tracking", "Tiered pricing", ...],
# "live_service": "https://mcp-billing-gateway-production.up.railway.app"
# }
注册现有 MCP 服务并实现营收
# 1. Register
API_KEY=$(curl -s -X POST .../api/v1/operator/register \
-H "Content-Type: application/json" \
-d '{"email": "[email protected]", "name": "Dev"}' | jq -r .api_key)
# 2. Add your server
SERVER_ID=$(curl -s -X POST .../api/v1/servers \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "my-tool", "upstream_url": "https://my-tool.com/mcp", "proxy_slug": "my-tool"}' \
| jq -r .server_id)
# 3. Set pricing: $0.01 per call, 100 free calls/month
curl -X POST .../api/v1/servers/$SERVER_ID/plans \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "Starter", "billing_model": "per_call", "price_per_call_usd_micro": 10000, "free_calls_per_month": 100}'
# Callers now connect via: .../proxy/my-tool/mcp
运营方仪表板
通过以下地址访问仪表板:
https://mcp-billing-gateway-production.up.railway.app/dashboard
实时跟踪收入、用量和活跃调用方,并配置你的服务。
API 参考
运营方端点
| 端点 | 方法 | 说明 |
|---|---|---|
/api/v1/operator/register | POST | 创建运营方账户 |
/api/v1/operator/profile | GET | 查看个人资料和 API 密钥 |
/api/v1/operator/stats | GET | 查看收入和用量统计 |
服务管理
| 端点 | 方法 | 说明 |
|---|---|---|
/api/v1/servers | POST | 注册 MCP 服务 |
/api/v1/servers | GET | 列出你的服务 |
/api/v1/servers/{id}/plans | POST | 创建定价方案 |
代理
| 端点 | 方法 | 描述 |
|---|---|---|
/proxy/{slug}/* | ANY | 强制执行计费的代理调用 |
/mcp/ | ANY | 可流式传输的 HTTP MCP 传输 |
架构
┌─────────────┐ ┌──────────────────────┐ ┌──────────────────┐
│ AI Agent / │────▶│ MCP Billing Gateway │────▶│ Your MCP Server │
│ MCP Client │◀────│ (hosted on Railway) │◀────│ (upstream) │
└─────────────┘ └──────────────────────┘ └──────────────────┘
│
├── Payment verification (Stripe / x402)
├── Usage tracking & rate limiting
├── Tier enforcement
└── Operator dashboard
该网关是一个透明代理。调用方可以像往常一样与您的 MCP 服务交互——网关会拦截请求、验证付款、跟踪用量,并将请求转发到您的上游服务。
可自托管
该网关可通过上方托管 URL 使用。若要自行托管,请克隆服务仓库并通过 Docker 部署:
docker build -t mcp-billing-gateway .
docker run -p 3000:3000 mcp-billing-gateway
许可证
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。