Skip to main content
Glama

Run Cost Pivot

run_cost_pivot
Read-only

Break spend down by ANY combination of dimensions — THE tool for "cost by product", "by usage type", "by tag", "by region", "by cost center", "by charge type", or "which provider is this spend on". This is the ONLY tool that can do those pivots: query_costs view="detailed" returns just the pivot vocabulary (pivotsAvailable: false), and to compare two windows by any of these dimensions, use compare_periods with that group_by — it runs the two pivots for you. Group with dimensions (1-3, outermost first): "service", "account", "region", "provider", "service_category", "subcategory" (usage type), "usage_family", "charge_type", "charge_subtype", "tagged", "cost_center", "resource", or "tag:" for any tag key. ⚠ TAG KEYS ARE CASE- AND HYPHEN-SENSITIVE — call get_available_tag_keys first and copy the key exactly; a wrong key silently returns one "untagged" row (the untagged bucket is lowercase). Scope with EXACTLY ONE of provider, integration_id or integration_ids. Window: granularity "monthly" (default) / "weekly" / "daily", plus either explicit start_date/end_date or months_back (default 3, counted in units of the granularity). THE BACKEND CLAMPS SILENTLY — daily to ~30 days, weekly to ~55 days, monthly to ~6 months — so the response always echoes requestedWindow AND returnedWindow, and adds a windowNote when they differ. Report figures against the window that was SERVED. ASYNC: this runs an Athena job. Quick pivots come back with rows; a slow one returns { jobId, status, pollAfterMs } and you call get_cost_pivot with that job_id. Jobs expire 24 hours after creation. ⚠ THE MAIN FAILURE MODE IS RESPONSE_TOO_LARGE (413) on a wide pivot — this backend returns every row in one response and does not page. The fix is FEWER DIMENSIONS or a SHORTER WINDOW, never a different limit (which is applied here, after sorting by _total desc, and cannot shrink the server-side payload). WHICH SPECIFIC RESOURCES: add "resource" as the LAST dimension to break any pivot down to individual resources — "which instances is this service's spend actually on", "which volumes are driving this account". It has FOUR rules, all checked before the job is submitted so you get a sentence instead of an error code: (1) it must be LAST in dimensions; (2) the pivot must be scoped with integration_id — never provider or integration_ids, because resource ids are only meaningful inside one connection; (3) at most 2 other dimensions before it; (4) a monthly window covers at most 3 months, not the usual 6. ⚠ READING RESOURCE ROWS (verified on prod, and NOT what you would assume): _resource_id and _region are OPTIONAL AND INDEPENDENT — a row may have both, either, or neither, within one response. Check before you use them; a missing _resource_id means the backend did not attribute one, NOT that the resource has no id. The displayed resource value is sometimes the full ARN and sometimes just a short name, so prefer _resource_id for console links and fall back to naming the resource without one. resource can also be the EMPTY STRING "" — that is spend with no resource attribution at all (support, commitment fees, tax), not a bug. And rows valued "Others" are the backend's collapse bucket: match that literal string, because such a row can still carry _resource_id and _region when only one small resource was folded into it. RELATED: get_resource_breakdown is the better tool for the SINGLE-SERVICE, SINGLE-DAY question ("what resources drove AmazonRDS on 2026-09-04") — it takes a service and a date directly and needs no job. Use a "resource" pivot when you want resources ACROSS a grouping or over several time columns. Rows use the dimension name verbatim as the key, so a tag pivot row has a literal "tag:user_app" key alongside each time column and _total. Read-only. Examples: { "dimensions": ["tag:user_app"], "provider": "aws", "granularity": "daily", "months_back": 14 } for daily spend by that tag; { "dimensions": ["provider", "service_category"], "provider": "aws", "granularity": "monthly", "months_back": 3 } for a monthly cross-provider category breakdown; { "dimensions": ["cost_center", "service"], "provider": "aws", "limit": 50 } for which services each cost center is spending on; { "dimensions": ["service", "resource"], "integration_id": "", "granularity": "monthly", "months_back": 1 } for the individual resources behind each service on one connection.

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": {
      "dimensions": "<dimensions>"
    },
    "name": "run_cost_pivot"
  }
}

Input Schema

NameRequiredDescriptionDefault
limitNoMax rows to return, applied AFTER sorting by `_total` desc (default 100, max 500).
end_dateNoWindow end. Defaults to today; billing data lags 2-3 days, so the last columns are often 0.
providerNoPivot across ALL of this provider's connections. Exactly one of provider / integration_id / integration_ids is required.
servicesNoFilter to these provider-native service names (get_available_services lists them).
cost_basisNoOptional accounting basis. ⚠ ALL FIVE toggles are required when you use it: a pivot job applies cost_settings verbatim and does NOT layer a partial basis over the organization's saved settings the way query_costs does. Omit it entirely to use the saved settings.
dimensionsYesHow to group the spend, outermost first. 1-3 of: "service", "account", "region", "provider", "service_category" (FOCUS category), "subcategory" (usage type), "usage_family", "charge_type", "charge_subtype", "tagged" (Tagged/Untagged split), "cost_center", "resource" — or "tag:<key>" for any tag key. ⚠ TAG KEYS ARE CASE- AND HYPHEN-SENSITIVE: call get_available_tag_keys first and copy the key exactly ("tag:user_app", not "tag:User_App"). Each extra dimension multiplies rows, so start with one or two. ⚠ "resource" HAS ITS OWN RULES: it must be LAST, needs `integration_id` scope (never `provider`/`integration_ids`), allows at most 2 other dimensions, and caps a monthly window at 3 months.
start_dateNoWindow start. Omit to use `months_back` (which is translated into a start date for you).
granularityNoColumn width. "monthly" (default) = one column per calendar month, max ~6 months. "weekly" = Monday-anchored weeks, max ~8. "daily" = one per day, max 30. The backend CLAMPS a longer window silently — the response tells you what it actually served.monthly
months_backNoRelative window size, in units of `granularity` (months / weeks / days). Default 3, and capped at 3 when a `resource` dimension is present. Converted to an explicit start date before submitting, so the window you ask for is the window that is requested.
cost_centersNoFilter to these cost-center ids. "UNALLOCATED" selects unattributed spend.
wait_secondsNoHow long to wait for the job before handing back a handle (default 20, max 22). Most pivots finish in a few seconds; wide ones do not.
account_namesNoFilter to these sub-account NAMES (get_available_linked_accounts lists them).
integration_idNoPivot one connection. REQUIRED for a "resource" dimension, and for daily granularity with 3 dimensions.
integration_idsNoPivot an explicit set of connections (they must share one provider).
response_formatNoconcise = dimensions, `_total` and the last two time columns per row (default). detailed = every column.concise

Output Schema

NameRequiredDescriptionDefault
codeNoBackend error code, e.g. RESPONSE_TOO_LARGE.
noteNoWhat to do next.
rowsNoPivot rows, largest `_total` first. One key per dimension (named verbatim), one per time column, plus `_total`. On a `resource` pivot each row MAY also carry `_resource_id` and `_region` — both are optional and independent (a row can have both, either or neither), so check before using them; a missing `_resource_id` means the backend attributed none, not that the resource has none. The displayed `resource` value is sometimes the full ARN and sometimes a short name; it is the empty string "" for spend with no resource attribution (support, commitment fees, tax), and the literal "Others" for the backend collapse bucket — which can itself carry `_resource_id`/`_region`, so detect it by that string.
toolNoWhich tool truncated (only on a truncated result).
errorNoTrue on a backend error envelope.
jobIdNoThe pivot job. Pass to get_cost_pivot to pick it up later; expires 24h after creation.
statusNoqueued | running | succeeded | failed | cancelled | expired.
columnsNoTime-column labels (YYYY-MM monthly, YYYY-MM-DD weekly/daily). THE authority on the window served.
detailsNoBackend error details, when any.
messageNoHow to narrow the request (only on a truncated result).
nextStepNoHow to recover from the error in `code`.
rowsNoteNoPresent when rows were capped client-side.
expiresAtNoWhen the job is discarded (24h after creation).
totalRowsNoHow many rows matched before `limit` was applied.
truncatedNoPresent and true when the result exceeded the output-size budget and was WITHHELD. When you see this, no data fields are present — narrow the request as `message` says and call again.
dimensionsNoThe group-by actually applied, in order. Row keys use these names VERBATIM (a tag dimension is a literal "tag:<key>" key).
isLastPageNoAlways true — see `nextCursor`.
nextCursorNoAlways null: this backend returns every row in one response (paging is disabled).
windowNoteNoPresent only when the served window differs from the requested one — the backend clamps silently. Quote it.
emptyReasonNoWhy the pivot returned no rows.
grandTotalsNoOrg-wide totals per time column plus `_total`, independent of `limit`.
granularityNomonthly | weekly | daily.
pollAfterMsNoHow long to wait before calling get_cost_pivot (only on a not-yet-finished job).
approx_charsNoApproximate size of the withheld result (only on a truncated result).
returnedRowsNoHow many rows are in `rows`.
collapsedNoteNoPresent when the backend folded small rows into an `Others` bucket.
returnedWindowNoThe window actually served, derived from `columns`.
requestedWindowNoThe window asked for, `{start, end}`.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.9/5.0
Behavior5/5

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

Annotations only declare readOnlyHint and openWorldHint; the description adds a large amount of behavior an agent could not otherwise know — async Athena job with { jobId, status, pollAfterMs }, 24-hour job expiry, silent backend clamping with requestedWindow/returnedWindow echo, and the 413 RESPONSE_TOO_LARGE failure mode with the correct remedy. It further discloses non-obvious row semantics for resource pivots (optional/independent _resource_id and _region, empty-string resource, the "Others" collapse bucket).

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

Conciseness4/5

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

Front-loaded with the core purpose and organized into clear blocks (dimensions, scope, window, async, resource rules, related tools, examples). It is unusually long and repeats the tag-key warning in both the body and the dimensions guidance, and the heavy CAPS/⚠ emphasis adds noise, though nearly every sentence carries real information.

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

Completeness5/5

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

For a 15-parameter tool with nested objects, three enums, and an output schema, the description covers everything an agent needs: scoping exclusivity, window mechanics and clamping, async handling, failure modes, and a set of worked examples. Return-shape explanation is appropriately delegated to the output schema.

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

Parameters5/5

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

Schema coverage is 100%, but the description still adds meaning beyond it: the resource-dimension rules (must be last, requires integration_id, max 2 other dimensions, 3-month monthly cap), the warning that limit is applied after sorting and cannot shrink the payload, and the reiteration that tag keys are case- and hyphen-sensitive with the 'untagged' lowercase bucket. These are selection-critical semantics not fully conveyed by the schema text 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?

States a specific verb and resource ("break spend down by ANY combination of dimensions") and explicitly carves out its territory against siblings, saying it is the ONLY tool that does these pivots while naming query_costs, compare_periods, and get_resource_breakdown as alternatives. An agent can select it over its siblings without opening a schema.

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

Usage Guidelines5/5

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

Gives explicit when-to-use rules with named alternatives and the conditions that select them: compare_periods for two-window comparisons, get_resource_breakdown for single-service/single-day resource questions, get_cost_pivot for polling a job. It also prescribes a prerequisite (call get_available_tag_keys first) and states the resource-pivot conditions precisely.

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.

Resources