Core features
MCP Revenue
Per-call billing instrumentation for MCP servers. Define a pricing config, top up agent credit wallets, and let the middleware handle the rest — budget checks before calls, credit deduction on success, and a full ledger per agent.
How it works
The Revenue middleware sits between Confirmation and Audit in the pipeline:
- Budget check — before forwarding the call, checks the agent's wallet balance against the tool price. If the balance is insufficient and
enforceBudgetis true, returns a402 insufficient_creditserror. - Call executes — the tool handler runs normally.
- Deduct on success — credits are deducted only if the call succeeds. Errors are not charged.
Setup
import { createMCPProxy, FileAdapter } from "@businys/ops"
const proxy = createMCPProxy({
revenue: {
pricing: {
// Default price for any tool not listed in overrides
default: { perCall: 1 },
// Per-tool overrides (exact tool name)
overrides: {
create_invoice: { perCall: 5 },
send_email: { perCall: 3 },
generate_report: { perCall: 10 },
},
},
// Block calls when balance is 0 (default: true)
// Set to false for record-only mode (no enforcement)
enforceBudget: true,
},
})Managing wallets
Wallets are keyed by agentId. Top up wallets before sending traffic:
// Top up an agent's wallet
await proxy.storage.topUpCredits("agent-abc", 1000, "Initial grant")
await proxy.storage.topUpCredits("agent-abc", 500, "Monthly refill")
// Check balance
const wallet = await proxy.storage.getWallet("agent-abc")
console.log(wallet?.balance) // 1500
// View ledger
const ledger = await proxy.storage.getLedger("agent-abc", { limit: 20 })
// ledger[0] = { type: "topup", amount: 500, balanceAfter: 1500, ... }Insufficient credits response
When an agent's balance is too low, the middleware returns a structured error instead of forwarding the call:
{
"error": "insufficient_credits",
"message": "Insufficient credits for create_invoice. Balance: 3, required: 5.",
"balance": 3,
"required": 5
}The HTTP status is 402 Payment Required. The call is not forwarded to the tool handler and is not charged.
Record-only mode
Set enforceBudget: false to meter usage without blocking calls. Useful for analytics before enabling enforcement, or for internal agents that should never be blocked:
revenue: {
pricing: { default: { perCall: 1 } },
enforceBudget: false, // record usage, never block
}Wallets can go negative in record-only mode. Use this to audit usage patterns before deciding on pricing.
Ledger entry types
| Type | Description |
|---|---|
charge | Credit deducted after a successful tool call |
topup | Credits added (grant, refill, or Stripe webhook) |
refund | Credits returned (e.g. after a disputed call) |
PricingConfig
| Field | Type | Description |
|---|---|---|
default | { perCall: number } | Applied to any tool not in overrides |
overrides? | Record<string, { perCall: number }> | Per-tool price overrides (exact tool name match) |
Stripe integration
The hosted dashboard at businys.dev shows per-agent wallet balances, ledger history, and revenue analytics. Connect Stripe to automate top-ups from your billing system:
- Set up a Stripe webhook for
checkout.session.completed - In the webhook handler, call
storage.topUpCredits(agentId, amount) - The agent's balance updates immediately and appears in the dashboard