Token导航 LogoToken导航TokenDH.com
MCP Billing logo
运维云端stdio官方级别未说明来源级核验

MCP Billing

MCP Server

为MCP服务器提供基于使用量的计费和货币化功能的SDK。

工具数

0

提示词数

0

GitHub Stars

1

资源数

0
PythonAPI集成云端部署

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

作者 / 组织

LuciferForge

提供方

LuciferForge

最后核验

2026/5/17 20:21

快速接入

先看主来源和安装命令,再打开仓库或文档;下面只保留这个条目的关键接入事实。

命令预览

pip install mcp-billing

详细介绍

mcp计费

MCP服务器的计费和货币化SDK。在几分钟内添加基于使用量的定价。

现有16000多台MCP服务器。零有交钥匙计费。这解决了这个问题。

安装

pip install mcp-billing

快速入门——5行货币化

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}"

就是这样。现在每个调用都由API键进行门控,使用使用计数进行跟踪,并使用速率限制进行强制执行。

所得

  • API键选通 --注册密钥、分配层、拒绝未知调用者
  • 速率限制 --每层每分钟和每月上限
  • 使用计量 --记录到SQLite的每个调用都有成本跟踪
  • 分层定价 --免费/专业/企业开箱即用,完全可定制
  • 条纹同步 --可选,将使用事件推送到Stripe计费表
  • CLI工具mcp-billing initmcp-billing status

注册API密钥

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")

自定义定价级别

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)

或者从JSON文件加载:

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)

检查使用情况

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

或者以编程方式:

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}")

条纹集成

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

或批量同步未同步的事件:

from mcp_billing import UsageMeter

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

运作原理

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)

建筑

组件目的
BillingGuard访问控制+使用记录
UsageMeter使用量聚合+条带同步
PricingTier层级定义(限制、成本、工具访问)
billing_middleware装饰者包装任何MCP工具
CLIinit config+ status 仪表板

所有数据存储在单个 billing.db SQLite文件。不需要外部服务。条纹是可选的。

LuciferForge生态系统的一部分

包装用途
kya代理人代理身份标准+加密签名
mcp安全审计MCP服务器的安全审计员
人工智能注射防护装置快速注射检测
人工智能成本保护LLM预算执行
人工智能决策跟踪器代理决策审计跟踪
mcp计费MCP服务器计费SDK

许可证

麻省理工学院

目录标签

目录标签

PythonAPI集成云端部署计费系统本地部署货币化工具API管理速率限制Stripe集成

接入字段

传输方式(transport,传输协议)

stdio

鉴权方式(authType,认证方式)

none

工具数量(toolCount,工具数)

0

资源数量(resourceCount,资源数)

0

提示词数量(promptCount,提示词数)

0

权限和风险

stdionone部署方式未说明

接入前请确认传输方式、认证方式和部署位置,并根据实际工具能力限制访问范围。

安装前确认

不要直接授予不必要的文件、网络或账号权限;先核对安装命令和配置内容。

来源信息

继续浏览同类 MCP