内容
<!-- mcp-name: io.github.sapph1re/mcp-billing-gateway -->
# MCP 计费网关
[](https://glama.ai/mcp/servers/sapph1re/mcp-billing-gateway-sdk)
[](https://mcp.directory/servers?q=mcp-billing-gateway)
将 **Stripe 订阅**、**每次调用积分** 和 **x402 加密货币支付** 添加到任何 MCP 服务器 - 无需编写计费代码。
MCP 计费网关是一个托管的计费代理,位于 AI 代理和您的 MCP 服务器之间。它自动处理支付验证、用法跟踪和分级强制执行。您注册服务器、设置定价计划,并将调用者指向代理 URL。无需计费代码。
实时服务:**https://mcp-billing-gateway-production.up.railway.app**
## 安装
```bash
pip install mcp-billing-gateway
```
或使用 [uvx](https://docs.astral.sh/uv/):
```bash
uvx mcp-billing-gateway
```
### 配置 Claude Desktop
添加到 `~/Library/Application Support/Claude/claude_desktop_config.json`(macOS)或 `%APPDATA%\Claude\claude_desktop_config.json`(Windows):
```json
{
"mcpServers": {
"mcp-billing-gateway": {
"command": "uvx",
"args": ["mcp-billing-gateway"]
}
}
}
```
### 配置 Cursor
添加到 `.cursor/mcp.json`:
```json
{
"mcpServers": {
"mcp-billing-gateway": {
"command": "uvx",
"args": ["mcp-billing-gateway"]
}
}
}
```
添加配置后重启编辑器以激活 MCP 服务器。
## 工具
| 工具 | 描述 |
|------|-------------|
| `get_billing_info` | 返回服务功能、支持的支付方式、功能和集成文档 |
本地 MCP 服务器提供服务发现。完整的计费功能在托管网关上运行 - 注册为操作员并通过它代理您的 MCP 服务器。
## 工作原理
```
AI 代理 → MCP 计费网关 → 您的 MCP 服务器
(此处强制计费)
```
1. 注册为操作员并获取 API 密钥
2. 注册您的 MCP 服务器 URL + 定价计划
3. 将调用者指向您的代理 slug:`https://mcp-billing-gateway-production.up.railway.app/proxy/{your-slug}/mcp`
4. 调用者通过 Stripe API 密钥或 x402 USDC 支付 - 计费透明处理
## 功能
- **每次调用计费** - 按工具调用次数向调用者收费(法定货币或加密货币)
- **订阅** - 每月/年度 Stripe 计划,带有调用限制
- **分级定价** - 免费层 + 基于使用情况的付费层
- **x402 微支付** - 接受 AI 代理在 Base 上无需 API 密钥的 USDC
- **操作员仪表盘** - 实时跟踪收入、使用情况和调用者
- **MCP 传输** - 在 `/mcp/` 端点处提供完整的 Streamable HTTP MCP 传输
## 快速开始
### 1. 注册为操作员
```bash
curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/operator/register \
-H "Content-Type: application/json" \
-d '{"email": "you@example.com", "name": "Your Name"}'
```
响应:
```json
{
"operator_id": "op_abc123",
"api_key": "bg_live_xxxxxxxxxxxx",
"message": "Operator registered successfully"
}
```
### 2. 注册您的 MCP 服务器
```bash
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. 创建定价计划
```bash
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. 将调用者连接到您的代理服务器
```json
{
"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 代理 | Base 上的 USDC,无需 API 密钥 |
## 示例
### 检查网关功能
```python
# 使用 MCP 客户端
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 服务器
```bash
# 1. 注册
API_KEY=$(curl -s -X POST .../api/v1/operator/register \
-H "Content-Type: application/json" \
-d '{"email": "dev@example.com", "name": "Dev"}' | jq -r .api_key)
# 2. 添加您的服务器
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. 设置定价:$0.01/次调用,100 次免费调用/月
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}'
# 调用者现在通过:.../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 代理 / │────▶│ MCP 计费网关 │────▶│ 您的 MCP 服务器 │
│ MCP 客户端 │◀────│ (托管在 Railway 上)│◀────│ (上游) │
└─────────────┘ └──────────────────────┘ └──────────────────┘
│
├── 支付验证(Stripe / x402)
├── 用法跟踪和速率限制
├── 分级强制执行
└── 操作员仪表盘
```
网关是一个透明的代理。调用者与您的 MCP 服务器正常交互 - 网关拦截请求,验证支付,跟踪用法,并转发到您的上游服务器。
## 自托管
网关在上述托管 URL 上开放使用。对于自托管部署,请克隆服务器仓库并通过 Docker 部署:
```bash
docker build -t mcp-billing-gateway .
docker run -p 3000:3000 mcp-billing-gateway
```
## 许可证
[MIT](LICENSE)
<!-- mcp-name: io.github.sapph1re/mcp-billing-gateway -->