Provider event accounting
A provider_event charge resolves pricing from mcp_market_pricing_events using the token’s MCP ID, requested eventName, and status = 'active'. Unknown or non-active events return HTTP 400.
Charge sequence
- Verify the signed context, expiry, URL run ID, and provider account.
- Validate
eventName, positive integercount, optionaltoolName, and metadata. - Look up an existing ledger row for
(runId, idempotencyKey). - Calculate the count allowed by
maxTotalChargeUsd. - Ask
cron-apito ensure buyer wallet balance for the calculated total. - Insert the local charge ledger and settlement outbox in one database transaction.
- The worker sends the idempotent buyer debit through the configured billing provider.
- Only after debit succeeds, it credits the provider’s net revenue.
Settlement failures are retried with exponential backoff and become
dead_letter after ten attempts. The local ledger remains authoritative.
Price and revenue fields
totalChargedUsd is chargedCount * unitPriceUsd. The backend snapshots the current MCP Market commission, calculates commissionUsd, and sets providerRevenueUsd = totalChargedUsd - commissionUsd.
Providers set only gross user prices. They cannot submit their own net revenue value.
Legacy strategy
For tool_call_fixed, the proxy checks wallet balance before the upstream call and writes the tool-call ledger only after a successful upstream response. Provider charge-context headers are not emitted for this strategy.