Skip to main content
Glama

Dataset Aggregate & Pivot

aggregate_rows

SQL GROUP BY and a spreadsheet pivot table for a list of JSON rows, in one call. Returns one output row per group with the aggregated columns, plus a summary: groups found, groups dropped by topN, values skipped because they were blank or not numeric (never guessed), and warnings such as a misspelled field name. Use it to turn scraped or API records into totals: orders and revenue per region, average price per brand, listings per city per month, top 10 products by revenue. Messy data is expected: "South" and "south " group together, and "$1,234.50" sums as 1234.5. Leave groupByFields empty to summarise all rows into one row. At most 500 rows per call.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rowsYesThe records to aggregate, up to 500. Each row is a JSON object; keys may differ between rows.
topNNoAfter sorting, keep only the first N groups. The totals row still covers every input row.
sortByNoAn output column to sort by: a group field, an aggregation alias such as "total_amount", or a pivot column. Omitted sorts by the group fields.
pivotFieldNoTurns this field's distinct values into columns, pivot-table style: group by "region" and pivot on "product" for one row per region with a column per product. Must not also be a group-by field. At most 50 distinct values.
aggregationsNoWhat to compute per group, for example [{"function":"count","alias":"orders"}, {"field":"amount","function":"sum","alias":"total_amount"}]. Every function except count needs a field. alias is the output column name (defaults to function_field, or "count"). Omitted gives a plain row count per group. Up to 20.
groupByFieldsNoOne output row per distinct combination of these field values, like SQL GROUP BY, for example ["region"] or ["city", "category"]. Dot paths like "address.city" work. Empty or omitted aggregates every row into a single row.
groupMatchingNonormalized (default) ignores letter case and extra whitespace when grouping, so "South" and "south " are one group. exact requires identical values.
pivotFunctionNoHow pivot cell values are combined. Defaults to sum when pivotValueField is set; ignored (row count) without one.
sortDirectionNoasc (default) or desc. Use desc with topN for "top N by" questions.
lenientNumbersNoOn by default: "$1,234.50", "49 USD", "12%" and "(300)" count as numbers for sum, avg, min, max and median. Set false to accept only real numbers and plain numeric strings.
dateBucketFieldNoA date or timestamp field to group by time period, for example "orderedAt". Adds a group column named like "orderedAt_month". Unreadable dates land in an "(invalid date)" group.
pivotValueFieldNoThe field whose values fill the pivot cells, for example "amount". Omitted fills each cell with a row count.
includeTotalsRowNoAppends a grand-total row labelled "(total)" and adds a _rowType column ("group" or "total").
dateBucketGranularityNoBucket size for dateBucketField: day (2026-08-19), week (2026-W34), month (2026-08, default), quarter (2026-Q3) or year.

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.1/5.0
Behavior4/5

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

No annotations are provided, so the description carries full behavioral burden, and it does well: it discloses the output shape (one row per group plus a summary), dropped groups via topN, blank/non-numeric values being skipped rather than guessed, warnings for misspelled fields, normalization behavior ('South' vs 'south '), and lenient number parsing ('$1,234.50' -> 1234.5). The 500-row cap is stated. It doesn't describe permissions, rate limits, or idempotency, but for a pure in-memory aggregation those are largely irrelevant.

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-loads the core analogy, then adds incremental behavioral details in a tight four-sentence block. Every sentence adds information (output shape, use cases, data-messiness handling, row cap). Slightly dense for a description that must be skimmed, but no filler.

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 a 14-parameter, no-output-schema tool with no annotations, the description covers the essentials an agent needs: purpose, output shape, edge-case behavior, and limits. It stops short of fully documenting every interaction between 14 parameters, but the schema covers those and an agent can call correctly from this description plus the schema.

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

Parameters3/5

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

Schema description coverage is 100% and all 14 parameters are documented in the schema with enums, examples, and defaults. The description adds a few cross-cutting facts not in the schema (500-row cap, normalization example, empty groupByFields behavior), but does not document individual parameter semantics beyond what the schema already provides. Baseline 3 is appropriate when the schema does the heavy lifting.

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?

Opens with a concrete analogy ('SQL GROUP BY and a spreadsheet pivot table for a list of JSON rows, in one call') that nails the verb, resource, and output shape. It distinguishes itself from its single sibling, list_capabilities, by being obviously a data-transformation tool. An agent can select this without opening the schema.

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?

Gives concrete task examples (orders and revenue per region, average price per brand, top 10 products by revenue) that make usage context clear. It also states the key alternative behavior (leave groupByFields empty for a single summary row). However, there is no explicit when-not-to-use or named alternative tool, and the single sibling is unrelated, so the guidance is clear but not exhaustive.

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.