Skip to main content
Glama
andrewlwn77
by andrewlwn77

aggregate

Calculate summary statistics like count, sum, average, minimum, or maximum values from a NocoDB table column, with optional filtering for specific data subsets.

Instructions

Perform aggregation operations on a column

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_idYesThe ID of the base/project
table_nameYesThe name of the table
column_nameYesThe column to aggregate
functionYesAggregation function
whereNoOptional filter condition

Implementation Reference

  • Handler for the 'aggregate' MCP tool. Executes aggregation by delegating to NocoDBClient.aggregate and returns formatted result.
      handler: async (
        client: NocoDBClient,
        args: {
          base_id: string;
          table_name: string;
          column_name: string;
          function: "count" | "sum" | "avg" | "min" | "max";
          where?: string;
        },
      ) => {
        const value = await client.aggregate(args.base_id, args.table_name, {
          column_name: args.column_name,
          func: args.function,
          where: args.where,
        });
        return {
          value,
          aggregation: {
            column: args.column_name,
            function: args.function,
            where: args.where,
          },
        };
      },
    },
  • Input schema defining parameters for the 'aggregate' tool including base_id, table_name, column_name, function, and optional where.
    inputSchema: {
      type: "object",
      properties: {
        base_id: {
          type: "string",
          description: "The ID of the base/project",
        },
        table_name: {
          type: "string",
          description: "The name of the table",
        },
        column_name: {
          type: "string",
          description: "The column to aggregate",
        },
        function: {
          type: "string",
          description: "Aggregation function",
          enum: ["count", "sum", "avg", "min", "max"],
        },
        where: {
          type: "string",
          description: "Optional filter condition",
        },
      },
      required: ["base_id", "table_name", "column_name", "function"],
    },
  • Tool object definition for 'aggregate' within queryTools array, which is included in the main allTools for MCP server registration.
    {
      name: "aggregate",
      description: "Perform aggregation operations on a column",
      inputSchema: {
        type: "object",
        properties: {
          base_id: {
            type: "string",
            description: "The ID of the base/project",
          },
          table_name: {
            type: "string",
            description: "The name of the table",
          },
          column_name: {
            type: "string",
            description: "The column to aggregate",
          },
          function: {
            type: "string",
            description: "Aggregation function",
            enum: ["count", "sum", "avg", "min", "max"],
          },
          where: {
            type: "string",
            description: "Optional filter condition",
          },
        },
        required: ["base_id", "table_name", "column_name", "function"],
      },
      handler: async (
        client: NocoDBClient,
        args: {
          base_id: string;
          table_name: string;
          column_name: string;
          function: "count" | "sum" | "avg" | "min" | "max";
          where?: string;
        },
      ) => {
        const value = await client.aggregate(args.base_id, args.table_name, {
          column_name: args.column_name,
          func: args.function,
          where: args.where,
        });
        return {
          value,
          aggregation: {
            column: args.column_name,
            function: args.function,
            where: args.where,
          },
        };
      },
    },
  • Underlying NocoDBClient.aggregate method implementing client-side aggregation (count, sum, avg, min, max) by fetching records and computing locally.
    async aggregate(
      baseId: string,
      tableName: string,
      options: AggregateOptions,
    ): Promise<number> {
      // For now, implement client-side aggregation
      // as the aggregate endpoint might not be available in all versions
      const records = await this.listRecords(baseId, tableName, {
        where: options.where,
      });
    
      const values = records.list.map((r) => Number(r[options.column_name]) || 0);
    
      switch (options.func) {
        case "count":
          return records.list.length;
        case "sum":
          return values.reduce((a, b) => a + b, 0);
        case "avg":
          return values.length > 0
            ? values.reduce((a, b) => a + b, 0) / values.length
            : 0;
        case "min":
          return Math.min(...values);
        case "max":
          return Math.max(...values);
        default:
          throw new NocoDBError(`Unknown aggregate function: ${options.func}`);
      }
    }
  • Type definition for AggregateOptions used by the NocoDBClient.aggregate method.
    export interface AggregateOptions {
      column_name: string;
      func: "count" | "sum" | "avg" | "min" | "max";
      where?: string;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'aggregation operations' but doesn't specify whether this is read-only, what permissions are needed, how results are returned, or any rate limits. For a tool with 5 parameters and no annotations, this is insufficient.

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 a single, efficient sentence with zero waste. It's appropriately sized and front-loaded, clearly stating the core purpose without unnecessary elaboration.

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

Completeness2/5

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

Given 5 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns, error conditions, or behavioral traits. For a data manipulation tool in this context, more information is needed.

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%, so all parameters are documented in the schema. The description adds no additional parameter semantics beyond implying aggregation on a column, which aligns with the schema. 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.

Purpose4/5

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

The description clearly states the action ('perform aggregation operations') and the target ('on a column'), which is specific and distinguishes it from non-aggregation tools. However, it doesn't explicitly differentiate from the 'group_by' sibling tool, which might also involve aggregation operations.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'group_by' or 'query' for similar operations. It lacks context about prerequisites, when-not-to-use scenarios, or comparisons with sibling tools.

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

Install Server

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/andrewlwn77/nocodb-mcp'

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