Skip to main content
Glama

Derive revenue and credit events

derive_cel
Read-onlyIdempotent

SQL that derives CEL Revenue_Events from your billing data, or Credit_Events from your usage records, by the rules in the standard (cel.md, 'Deriving Revenue Events from a Subscription Ledger', 'Deriving Revenue Events from an Invoice Ledger' and 'Deriving Credit Events'). Most billing systems hold subscriptions or invoices, not events. source: subscription (default) turns the subscription dataset your mapping covers (subscription_id, customer_id, snapshot_date, mrr, subscription_status, segment, as snapshots at any cadence or a version history) into one revenue_event row per movement: a step is a change in a subscription's active MRR, the ledger's first date is the opening balance, prior_mrr and new_mrr are the customer's MRR chained so prior_mrr + mrr_change = new_mrr holds on every row and the event type (new, expansion, contraction, churn, reactivation) is read from the customer's MRR around the step, with the ATL lifecycle tag, change_nature permanent and an empty expansion_classification (the ledger cannot know it). source: invoice reads the invoice dataset instead (invoice_id, subscription_id, customer_id, snapshot_date, service_period_start, service_period_end, recurring_amount): each invoice is one service period whose MRR is the recurring amount over the months it covers. The same rules apply. Usage above a commitment is Consumption Revenue and no Revenue_Event, so neither source reads the usage records. target: credit_event writes it as credit_event rows instead, from the usage_record dataset (subscription_id, customer_id, period_end, committed_amount, usage_amount): one consumption event with basis overage per usage period over its commitment, dated the period's end, for the overage the period bills, with empty balances (usage within a ratable commitment is no event; a prepaid balance and its expiries come from the billing system's credit ledger). Takes the same mapping as generate_query (a GASP adapter or an Ossie mapping with its semantic_model) and the ledger's currency; the dialect is the one asked for, else the adapter's warehouse, else postgres. Unmapped fields stay as {{field@dataset}} placeholders and are listed. Run the result to build the revenue_event table and map it; the MRR movement metrics compile over it.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "adapter": "<adapter>",
      "currency": "<currency>"
    },
    "name": "derive_cel"
  }
}

Input Schema

NameRequiredDescriptionDefault
outputNo'report' (default): the SQL with the mapping it used, the unmapped fields and what the source can and cannot say; 'sql': the query alone.
sourceNoThe ledger to read: 'subscription' (default), the subscription dataset as snapshots or a version history; 'invoice', the invoice dataset read as one row per service period (recurring_amount over the months between service_period_start and service_period_end). Use invoice when the billing system keeps no subscription history.
targetNoWhat to derive: 'revenue_event' (default), the revenue events from the ledger; 'credit_event', one consumption event with basis overage per usage_record period over its commitment, for a company with usage records and no credit ledger (source and first_snapshot are ignored).
adapterYesYour mapping as text: a GASP adapter (JSON; schema: https://gaspwiki.com/schemas/gasp-adapter-v1.json) or an Ossie mapping document (YAML or JSON). It must cover the subscription dataset (the invoice dataset with source: invoice; the usage_record dataset with target: credit_event). Check it with validate_mapping first.
dialectNoSQL dialect: postgres (also Redshift), snowflake, bigquery or databricks. Omit to use the adapter's warehouse when it names one of them, else postgres.
currencyYesISO 4217 code of the ledger's currency (USD, EUR, GBP ...), written on every derived event.
first_snapshotNoWhat the rows on the ledger's first date are. 'opening' (default): opening balances that seed each customer's MRR and produce no event, for a ledger that starts after the oldest subscription. 'steps': steps from 0, for a ledger that starts with the business.
semantic_modelNoWith an Ossie mapping: your semantic model document (YAML or JSON), so table names and field expressions resolve. Ignored for a GASP adapter.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare a read-only, idempotent, non-destructive generation call, and the description goes well beyond that: unmapped fields remain as {{field@dataset}} placeholders and are listed, expansion_classification is deliberately empty because 'the ledger cannot know it', and the dialect fallback chain (requested → adapter warehouse → postgres) is spelled out. It stops short of describing the shape/size of the emitted SQL or report, but the semantic caveats are unusually rich.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The first sentence is well front-loaded, but the remainder is a single ~350-word run-on paragraph mixing source rules, target rules, dialect fallback and output notes with no sentence breaks or ordering. Almost all content is relevant, yet the monolithic packaging makes it hard to scan and forces the agent to parse deeply nested parentheticals.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For an 8-parameter, no-output-schema derivation tool, it covers the required inputs (adapter/semantic_model, currency), the enum-driven choices, placeholder handling and the follow-up action of running the SQL and mapping the result. What is missing is minor — primarily the practical size/format of the returned SQL and any constraints on the supported ledger shapes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3; the description earns above that by explaining what each dataset must contain for source: subscription, invoice and target: credit_event, and how first_snapshot's opening-vs-steps choice maps to real ledger situations. That field-level data-model context is not present in the schema descriptions alone.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The opening sentence gives a specific verb and artifact — SQL that derives CEL Revenue_Events or Credit_Events from billing data — and names the standard's rules it follows. It further distinguishes the two derivations (subscription/invoice ledgers vs usage records) so an agent can tell exactly what the tool produces and from which data shape.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It states the data conditions that select each mode: invoice when the billing system keeps no subscription history, credit_event 'for a company with usage records and no credit ledger', and explicitly notes usage above a commitment is Consumption Revenue and therefore no event. It also ties itself to generate_query's mapping and points at validate_mapping, but never names a sibling to use instead when you do not want derived events, so no true exclusions are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.