Skip to main content

mcp-billing

Billing and monetization SDK for MCP servers. Add usage-based pricing in minutes.

16,000+ MCP servers exist. Zero have turnkey billing. This fixes that.

Install

pip install mcp-billing

Quick Start — 5 Lines to Monetize

from mcp.server.fastmcp import FastMCP
from mcp_billing import BillingGuard
from mcp_billing.middleware import billing_middleware

mcp = FastMCP("my-server")
guard = BillingGuard()  # SQLite-backed, zero config

@mcp.tool()
@billing_middleware(guard)
def analyze(query: str, api_key: str = "") -> str:
    return f"Analysis of: {query}"

That's it. Every call is now gated by API key, tracked with usage counts, and enforced with rate limits.

What You Get

  • API key gating — register keys, assign tiers, deny unknown callers
  • Rate limiting — per-minute and per-month caps per tier
  • Usage metering — every call logged to SQLite with cost tracking
  • Tier-based pricing — free/pro/enterprise out of the box, fully customizable
  • Stripe sync — optional, push usage events to Stripe Billing Meters
  • CLI tools — mcp-billing init and mcp-billing status

Register API Keys

guard = BillingGuard()

# Free tier: 10 req/min, 1000/month
guard.register_key("key-free-abc123", tier_name="free")

# Pro tier: 60 req/min, 50k/month, $0.001/call
guard.register_key("key-pro-xyz789", tier_name="pro")

# Enterprise: unlimited
guard.register_key("key-ent-456def", tier_name="enterprise")

Custom Pricing Tiers

from mcp_billing import PricingTier, BillingGuard

tiers = [
    PricingTier(name="starter", rate_limit=5, monthly_cap=500, cost_per_call=0.0),
    PricingTier(name="growth", rate_limit=100, monthly_cap=100_000, cost_per_call=0.002),
    PricingTier(
        name="scale",
        tools=["analyze", "generate"],  # restrict tool access by tier
        rate_limit=0,
        monthly_cap=0,
        cost_per_call=0.001,
    ),
]

guard = BillingGuard(tiers=tiers)

Or load from a JSON file:

mcp-billing init  # creates billing.json with default tiers
from mcp_billing.pricing import load_pricing

tiers = load_pricing("billing.json")
guard = BillingGuard(tiers=tiers)

Check Usage

mcp-billing status
Billing database: billing.db
API keys with usage: 3
--------------------------------------------------

  Key: key-free...c123
  Period: 2026-03
  Total calls: 847
  Total cost: $0.0000
  By tool:
    analyze: 847

Or programmatically:

from mcp_billing import UsageMeter

meter = UsageMeter("billing.db")
report = meter.get_usage("key-pro-xyz789", period="month")
print(f"Calls: {report.total_calls}, Cost: ${report.total_cost:.4f}")

Stripe Integration

guard = BillingGuard(stripe_api_key="sk_live_...")

# Register key with Stripe customer ID
guard.register_key("key-pro-xyz789", tier_name="pro", stripe_customer_id="cus_abc123")

# Usage events auto-sync to Stripe Billing Meters on each call

Or batch sync unsynced events:

from mcp_billing import UsageMeter

meter = UsageMeter("billing.db")
synced = meter.sync_unsynced("sk_live_...")
print(f"Synced {synced} events to Stripe")

How It Works

Client → MCP Tool Call
           ↓
    BillingGuard.check_access()
           ↓
    ┌──────────────────┐
    │ Key exists?       │ → 401
    │ Key active?       │ → 402
    │ Tool in tier?     │ → 402
    │ Under rate limit? │ → 429
    │ Under monthly cap?│ → 402
    └──────────────────┘
           ↓ PASS
    Execute tool
           ↓
    Record usage → SQLite
                 → Stripe (optional)

Architecture

Component Purpose
BillingGuard Access control + usage recording
UsageMeter Usage aggregation + Stripe sync
PricingTier Tier definitions (limits, costs, tool access)
billing_middleware Decorator to wrap any MCP tool
CLI init config + status dashboard

All data stored in a single billing.db SQLite file. No external services required. Stripe is optional.

Part of the LuciferForge Ecosystem

Package Purpose
kya-agent Agent identity standard + cryptographic signing
mcp-security-audit Security auditor for MCP servers
ai-injection-guard Prompt injection detection
ai-cost-guard LLM budget enforcement
ai-decision-tracer Agent decision audit trails
mcp-billing Billing SDK for MCP servers

License

MIT

Metadata

Release files for mcp-billing 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-billing 0.1.0
File Size Uploaded Provenance
mcp_billing-0.1.0.tar.gz 10.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-billing 0.1.0
File Interpreter ABI Platform
mcp_billing-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.3 kB

Release files / mcp_billing-0.1.0.tar.gz

Download URL mcp_billing-0.1.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d8cfb9e9089c94547d8a42da86b5e99b7c92dfe869423c0ec7bd7d5336a319cf
BLAKE2b-256 checksum
How to use checksums
72faf215dc7b4a648846416689b153d0482850a0c021ab541ee4fc3a04f46787
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Release files / mcp_billing-0.1.0-py3-none-any.whl

Download URL mcp_billing-0.1.0-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fea078fc72d5625a6cafd83f3330a9f92c66af9684c4f15823e6964ff1c33ca
BLAKE2b-256 checksum
How to use checksums
763b5f29cad088733acb0b0b468b50654d1985b791b2584b45b0235686446f06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.2

Security for mcp-billing 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page