Skip to content

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

  1. Verify the signed context, expiry, URL run ID, and provider account.
  2. Validate eventName, positive integer count, optional toolName, and metadata.
  3. Look up an existing ledger row for (runId, idempotencyKey).
  4. Calculate the count allowed by maxTotalChargeUsd.
  5. Ask cron-api to ensure buyer wallet balance for the calculated total.
  6. Insert the local charge ledger and settlement outbox in one database transaction.
  7. The worker sends the idempotent buyer debit through the configured billing provider.
  8. 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.