MCP billing gateway sdk agent

Client SDK and docs for MCP Billing Gateway — add Stripe + x402 billing to any MCP server

by sapph1re·MIT license·★ 2 Stars on the repo·GitHub ↗

Files of MCP billing gateway sdk

sapph1re/main1 file
README.md
Show the full text264 lines

MCP Billing Gateway

Glama MCP Server MCP.Directory

Add Stripe subscriptions, per-call credits, and x402 crypto payments to any MCP server — without writing billing code.

MCP Billing Gateway is a hosted billing proxy that sits between AI agents and your MCP server. It handles payment verification, usage tracking, and tier enforcement automatically. You register your server, set a pricing plan, and point callers to the proxied URL. No billing code required.

Live service: https://mcp-billing-gateway-production.up.railway.app

Tutorial: Monetize any MCP server in 10 minutes — step-by-step demo with working code

Installation

pip install mcp-billing-gateway

Or with uvx:

uvx mcp-billing-gateway
Configuration for Claude Desktop

Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "mcp-billing-gateway": {
      "command": "uvx",
      "args": ["mcp-billing-gateway"]
    }
  }
}
Configuration for Cursor

Add to .cursor/mcp.json in your project:

{
  "mcpServers": {
    "mcp-billing-gateway": {
      "command": "uvx",
      "args": ["mcp-billing-gateway"]
    }
  }
}

Restart your editor after adding the configuration to activate the MCP server.

Tools

Tool Description
get_billing_info Returns service capabilities, supported payment methods, features, and integration docs

The local MCP server provides service discovery. The full billing functionality runs on the hosted gateway — register as an operator and proxy your MCP servers through it.

How it works

AI Agent → MCP Billing Gateway → Your MCP Server
            (billing enforced here)
  1. Register as an operator and get an API key
  2. Register your MCP server URL + pricing plan
  3. Point callers to your proxy slug: https://mcp-billing-gateway-production.up.railway.app/proxy/{your-slug}/mcp
  4. Callers pay via Stripe API key or x402 USDC — billing is handled transparently

Features

  • Per-call billing — charge callers per tool call (fiat or crypto)
  • Subscriptions — monthly/annual Stripe plans with call limits
  • Tiered pricing — free tier + paid tiers based on usage
  • x402 micropayments — accept USDC on Base from AI agents with no API keys
  • Operator dashboard — track revenue, usage, and callers in real time
  • MCP transport — full Streamable HTTP MCP transport at /mcp/ endpoint

Quick Start

1. Register as operator
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"}'

Response:

{
  "operator_id": "op_abc123",
  "api_key": "bg_live_xxxxxxxxxxxx",
  "message": "Operator registered successfully"
}
2. Register your MCP server
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. Create a pricing plan
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. Connect callers to your proxied server
{
  "mcpServers": {
    "my-server": {
      "url": "https://mcp-billing-gateway-production.up.railway.app/proxy/my-server/mcp",
      "headers": {
        "Authorization": "Bearer CALLER_API_KEY"
      }
    }
  }
}

Payment Methods

Method Best for How
Stripe subscription Human developers Monthly or annual plan via Stripe Checkout
Stripe per-call Human developers Credits consumed per tool call
x402 micropayments AI agents USDC on Base, no API keys needed

Examples

Check gateway capabilities
# 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"
# }
Register and monetize an existing MCP server
# 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

Operator Dashboard

Access your dashboard at:

https://mcp-billing-gateway-production.up.railway.app/dashboard

Track revenue, usage, active callers, and configure your servers in real time.

API Reference

Operator endpoints
Endpoint Method Description
/api/v1/operator/register POST Create operator account
/api/v1/operator/profile GET View profile and API keys
/api/v1/operator/stats GET Revenue and usage stats
Server management
Endpoint Method Description
/api/v1/servers POST Register an MCP server
/api/v1/servers GET List your servers
/api/v1/servers/{id}/plans POST Create pricing plan
Proxy
Endpoint Method Description
/proxy/{slug}/* ANY Proxied calls with billing enforcement
/mcp/ ANY Streamable HTTP MCP transport

Architecture

┌─────────────┐     ┌──────────────────────┐     ┌──────────────────┐
│  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

The gateway is a transparent proxy. Callers interact with your MCP server normally — the gateway intercepts requests, verifies payment, tracks usage, and forwards to your upstream server.

Self-hosted

The gateway is open for use at the hosted URL above. For self-hosted deployments, clone the server repository and deploy via Docker:

docker build -t mcp-billing-gateway .
docker run -p 3000:3000 mcp-billing-gateway

License

MIT

1<!-- mcp-name: io.github.sapph1re/mcp-billing-gateway -->
2# MCP Billing Gateway
3 
4[![Glama MCP Server](https://glama.ai/mcp/servers/sapph1re/mcp-billing-gateway-sdk/badge)](https://glama.ai/mcp/servers/sapph1re/mcp-billing-gateway-sdk)
5[![MCP.Directory](https://img.shields.io/badge/MCP.Directory-listed-blue)](https://mcp.directory/servers?q=mcp-billing-gateway)
6 
7Add **Stripe subscriptions**, **per-call credits**, and **x402 crypto payments** to any MCP server — without writing billing code.
8 
9MCP Billing Gateway is a hosted billing proxy that sits between AI agents and your MCP server. It handles payment verification, usage tracking, and tier enforcement automatically. You register your server, set a pricing plan, and point callers to the proxied URL. No billing code required.
10 
11Live service: **https://mcp-billing-gateway-production.up.railway.app**
12 
13**Tutorial:** [Monetize any MCP server in 10 minutes](https://github.com/sapph1re/mcp-billing-demo) — step-by-step demo with working code
14 
15## Installation
16 
17```bash
18pip install mcp-billing-gateway
19```
20 
21Or with [uvx](https://docs.astral.sh/uv/):
22 
23```bash
24uvx mcp-billing-gateway
25```
26 
27### Configuration for Claude Desktop
28 
29Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
30 
31```json
32{
33 "mcpServers": {
34 "mcp-billing-gateway": {
35 "command": "uvx",
36 "args": ["mcp-billing-gateway"]
37 }
38 }
39}
40```
41 
42### Configuration for Cursor
43 
44Add to `.cursor/mcp.json` in your project:
45 
46```json
47{
48 "mcpServers": {
49 "mcp-billing-gateway": {
50 "command": "uvx",
51 "args": ["mcp-billing-gateway"]
52 }
53 }
54}
55```
56 
57Restart your editor after adding the configuration to activate the MCP server.
58 
59## Tools
60 
61| Tool | Description |
62|------|-------------|
63| `get_billing_info` | Returns service capabilities, supported payment methods, features, and integration docs |
64 
65The local MCP server provides service discovery. The full billing functionality runs on the hosted gateway — register as an operator and proxy your MCP servers through it.
66 
67## How it works
68 
69```
70AI Agent → MCP Billing Gateway → Your MCP Server
71 (billing enforced here)
72```
73 
741. Register as an operator and get an API key
752. Register your MCP server URL + pricing plan
763. Point callers to your proxy slug: `https://mcp-billing-gateway-production.up.railway.app/proxy/{your-slug}/mcp`
774. Callers pay via Stripe API key or x402 USDC — billing is handled transparently
78 
79## Features
80 
81- **Per-call billing** — charge callers per tool call (fiat or crypto)
82- **Subscriptions** — monthly/annual Stripe plans with call limits
83- **Tiered pricing** — free tier + paid tiers based on usage
84- **x402 micropayments** — accept USDC on Base from AI agents with no API keys
85- **Operator dashboard** — track revenue, usage, and callers in real time
86- **MCP transport** — full Streamable HTTP MCP transport at `/mcp/` endpoint
87 
88## Quick Start
89 
90### 1. Register as operator
91 
92```bash
93curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/operator/register \
94 -H "Content-Type: application/json" \
95 -d '{"email": "[email protected]", "name": "Your Name"}'
96```
97 
98Response:
99 
100```json
101{
102 "operator_id": "op_abc123",
103 "api_key": "bg_live_xxxxxxxxxxxx",
104 "message": "Operator registered successfully"
105}
106```
107 
108### 2. Register your MCP server
109 
110```bash
111curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/servers \
112 -H "Authorization: Bearer bg_live_xxxxxxxxxxxx" \
113 -H "Content-Type: application/json" \
114 -d '{
115 "name": "My MCP Server",
116 "upstream_url": "https://your-mcp-server.com/mcp",
117 "proxy_slug": "my-server"
118 }'
119```
120 
121### 3. Create a pricing plan
122 
123```bash
124curl -X POST https://mcp-billing-gateway-production.up.railway.app/api/v1/servers/{server_id}/plans \
125 -H "Authorization: Bearer bg_live_xxxxxxxxxxxx" \
126 -H "Content-Type: application/json" \
127 -d '{
128 "name": "Pay as you go",
129 "billing_model": "per_call",
130 "price_per_call_usd_micro": 10000,
131 "free_calls_per_month": 100
132 }'
133```
134 
135### 4. Connect callers to your proxied server
136 
137```json
138{
139 "mcpServers": {
140 "my-server": {
141 "url": "https://mcp-billing-gateway-production.up.railway.app/proxy/my-server/mcp",
142 "headers": {
143 "Authorization": "Bearer CALLER_API_KEY"
144 }
145 }
146 }
147}
148```
149 
150## Payment Methods
151 
152| Method | Best for | How |
153|--------|----------|-----|
154| Stripe subscription | Human developers | Monthly or annual plan via Stripe Checkout |
155| Stripe per-call | Human developers | Credits consumed per tool call |
156| x402 micropayments | AI agents | USDC on Base, no API keys needed |
157 
158## Examples
159 
160### Check gateway capabilities
161 
162```python
163# Using the MCP client
164result = await session.call_tool("get_billing_info")
165print(result)
166# {
167# "service": "MCP Billing Gateway",
168# "version": "0.1.0",
169# "payment_methods": ["stripe_subscription", "stripe_metered", "x402_crypto"],
170# "features": ["Per-call usage tracking", "Tiered pricing", ...],
171# "live_service": "https://mcp-billing-gateway-production.up.railway.app"
172# }
173```
174 
175### Register and monetize an existing MCP server
176 
177```bash
178# 1. Register
179API_KEY=$(curl -s -X POST .../api/v1/operator/register \
180 -H "Content-Type: application/json" \
181 -d '{"email": "[email protected]", "name": "Dev"}' | jq -r .api_key)
182 
183# 2. Add your server
184SERVER_ID=$(curl -s -X POST .../api/v1/servers \
185 -H "Authorization: Bearer $API_KEY" \
186 -H "Content-Type: application/json" \
187 -d '{"name": "my-tool", "upstream_url": "https://my-tool.com/mcp", "proxy_slug": "my-tool"}' \
188 | jq -r .server_id)
189 
190# 3. Set pricing: $0.01 per call, 100 free calls/month
191curl -X POST .../api/v1/servers/$SERVER_ID/plans \
192 -H "Authorization: Bearer $API_KEY" \
193 -H "Content-Type: application/json" \
194 -d '{"name": "Starter", "billing_model": "per_call", "price_per_call_usd_micro": 10000, "free_calls_per_month": 100}'
195 
196# Callers now connect via: .../proxy/my-tool/mcp
197```
198 
199## Operator Dashboard
200 
201Access your dashboard at:
202 
203```
204https://mcp-billing-gateway-production.up.railway.app/dashboard
205```
206 
207Track revenue, usage, active callers, and configure your servers in real time.
208 
209## API Reference
210 
211### Operator endpoints
212 
213| Endpoint | Method | Description |
214|----------|--------|-------------|
215| `/api/v1/operator/register` | POST | Create operator account |
216| `/api/v1/operator/profile` | GET | View profile and API keys |
217| `/api/v1/operator/stats` | GET | Revenue and usage stats |
218 
219### Server management
220 
221| Endpoint | Method | Description |
222|----------|--------|-------------|
223| `/api/v1/servers` | POST | Register an MCP server |
224| `/api/v1/servers` | GET | List your servers |
225| `/api/v1/servers/{id}/plans` | POST | Create pricing plan |
226 
227### Proxy
228 
229| Endpoint | Method | Description |
230|----------|--------|-------------|
231| `/proxy/{slug}/*` | ANY | Proxied calls with billing enforcement |
232| `/mcp/` | ANY | Streamable HTTP MCP transport |
233 
234## Architecture
235 
236```
237┌─────────────┐ ┌──────────────────────┐ ┌──────────────────┐
238│ AI Agent / │────▶│ MCP Billing Gateway │────▶│ Your MCP Server │
239│ MCP Client │◀────│ (hosted on Railway) │◀────│ (upstream) │
240└─────────────┘ └──────────────────────┘ └──────────────────┘
241 │
242 ├── Payment verification (Stripe / x402)
243 ├── Usage tracking & rate limiting
244 ├── Tier enforcement
245 └── Operator dashboard
246```
247 
248The gateway is a transparent proxy. Callers interact with your MCP server normally — the gateway intercepts requests, verifies payment, tracks usage, and forwards to your upstream server.
249 
250## Self-hosted
251 
252The gateway is open for use at the hosted URL above. For self-hosted deployments, clone the server repository and deploy via Docker:
253 
254```bash
255docker build -t mcp-billing-gateway .
256docker run -p 3000:3000 mcp-billing-gateway
257```
258 
259## License
260 
261[MIT](LICENSE)
262 
263<!-- mcp-name: io.github.sapph1re/mcp-billing-gateway -->
264 

Discussion

Alternatives