Skip to main content
Glama

Aggregate / Group By

db_aggregate
Read-onlyIdempotent

Group rows by columns and compute count, sum, avg, min, max aggregations for analytical questions such as total sales per category or average order value per month.

Instructions

Groups rows by one or more columns and computes aggregate functions (count, sum, avg, min, max) on each group. This is the tool for analytical queries like "total sales by category", "average order value by month", or "count of users per country". Results are sorted by the aggregate by default.

When to use:

  • "How many products in each category?" (by=category, _count="*")

  • "Total revenue by region" (by=region, _sum="amount")

  • "Average order value by status" (by=status, _avg="total")

  • "Min and max prices per category" (by=category, _min="price", _max="price")

Parameter guidance:

  • by: comma-separated column names to group by (required). Example: "category, region"

  • where: optional JSON filter applied before grouping

  • orderBy: JSON object for sorting results. Use "_count", "_sum", "_avg", "_min", "_max" as the key. Example: {"_count": "desc"}

  • sum/avg/min/max: comma-separated numeric columns to aggregate

  • take: max groups to return (default 50)

Behavioral notes:

  • All aggregations run in a read-only transaction with a configurable timeout.

  • Results are returned as an array of group objects with the computed aggregates.

  • Groups with zero rows are excluded from the results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
byYesComma-separated column names to group by
avgNoComma-separated numeric columns to average
maxNoComma-separated columns to find maximum
minNoComma-separated columns to find minimum
sumNoComma-separated numeric columns to sum
takeNoMax groups to return (default 50)
tableYesName of the table to query
whereNoOptional JSON filter applied before grouping
orderByNoJSON order object, e.g. '{"_count":"desc"}'
databaseNoName of the database to query (from pgautopilot.json). Omit to use the current default database.
Install Server

TDQS

A4.7/5.0
Behavior5/5

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

Annotations only signal read-only, idempotent, non-destructive. The description adds genuinely useful behavior: read-only transaction with configurable timeout, default sorting by the aggregate, zero-row groups being excluded, and return shape as an array of group objects. This goes well beyond annotation data.

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

Conciseness5/5

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

The description is organized into purpose, usage, parameter guidance, and behavioral notes; every sentence adds operational value. It is longer than one-liner tools but justified by 10 parameters and no output schema.

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 10-parameter tool with no output schema, the description covers selection, invocation patterns, parameter semantics, ordering, limits, filtering, and return behavior. Count semantics are slightly implicit since there is no count input parameter, but the orderBy guidance and examples treat count as a returned aggregate key, so the description remains complete enough for correct invocation.

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, but the description adds practical parameter meaning: comma-separated syntax for by, JSON shape with '_count'/'_sum' keys for orderBy, where being applied before grouping, and take's default. It does not enrich the table/database parameters, so not a 5.

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 description opens with a specific action—'Groups rows by ... and computes aggregate functions'—and names the exact resource pattern. It also says 'This is the tool for analytical queries' and gives concrete query examples, making it easy to distinguish from row-retrieval siblings like db_find_many or db_count.

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?

There is an explicit 'When to use' section with four query-pattern examples that map user intents to parameters. It does not name sibling tools or state when not to use it (e.g., for unaggregated rows use db_find_many), so it stops just short of full exclusion guidance.

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

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cyberreinxy/pgautopilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server