Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

aggregate_data

Perform data aggregations (count, sum, avg, min, max) on specified tables using a Hasura GraphQL filter. Supported by the Advanced Hasura GraphQL MCP Server for efficient data analysis.

Instructions

Performs a simple aggregation (count, sum, avg, min, max)...

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
aggregateFunctionYesThe aggregation function...
fieldNoRequired for 'sum', 'avg', 'min', 'max'...
filterNoOptional. A Hasura GraphQL 'where' filter object...
tableNameYesThe exact name of the table...

Implementation Reference

  • The handler function that implements the core logic of the 'aggregate_data' tool, constructing and executing a GraphQL aggregation query on a Hasura table.
    async ({ tableName, aggregateFunction, field, filter }) => {
      console.log(`[INFO] Executing tool 'aggregate_data': ${aggregateFunction} on ${tableName}...`);
      
      if (aggregateFunction !== 'count' && !field) {
        throw new Error(`The 'field' parameter is required for '${aggregateFunction}' aggregation.`);
      }
      if (aggregateFunction === 'count' && field) {
          console.warn(`[WARN] 'field' parameter is ignored for 'count' aggregation.`);
      }
    
      const aggregateTableName = `${tableName}_aggregate`;
      
      let aggregateSelection = '';
      if (aggregateFunction === 'count') {
          aggregateSelection = `{ count }`;
      } else if (field) { 
          aggregateSelection = `{ ${aggregateFunction} { ${field} } }`;
      } else {
          throw new Error(`'field' parameter is missing for '${aggregateFunction}' aggregation.`);
      }
    
      const boolExpTypeName = `${tableName}_bool_exp`;
      const filterVariableDefinition = filter ? `($filter: ${boolExpTypeName}!)` : ""; 
      const whereClause = filter ? `where: $filter` : "";
    
      const query = gql` 
        query AggregateData ${filterVariableDefinition} {
          ${aggregateTableName}(${whereClause}) {
            aggregate ${aggregateSelection}
          }
        }
      `;
    
      const variables = filter ? { filter } : {};
    
      try {
        const rawResult = await makeGqlRequest(query, variables);
        
        let finalResult = null;
        if (rawResult && rawResult[aggregateTableName] && rawResult[aggregateTableName].aggregate) {
            finalResult = rawResult[aggregateTableName].aggregate;
        } else {
            console.warn('[WARN] Unexpected result structure from aggregation query:', rawResult);
            finalResult = rawResult; 
        }
    
        return { content: [{ type: "text", text: JSON.stringify(finalResult, null, 2) }] };
      } catch (error: any) {
        if (error instanceof ClientError && error.response?.errors) {
            const gqlErrors = error.response.errors.map(e => e.message).join(', ');
            console.error(`[ERROR] Tool 'aggregate_data' failed: ${gqlErrors}`, error.response);
            throw new Error(`GraphQL aggregation failed: ${gqlErrors}. Check table/field names and filter syntax.`);
        }
        console.error(`[ERROR] Tool 'aggregate_data' failed: ${error.message}`);
        throw error;
      }
    }
  • Zod schema for input validation of the 'aggregate_data' tool parameters.
    {
      tableName: z.string().describe("The exact name of the table..."),
      aggregateFunction: z.enum(["count", "sum", "avg", "min", "max"]).describe("The aggregation function..."),
      field: z.string().optional().describe("Required for 'sum', 'avg', 'min', 'max'..."),
      filter: z.record(z.unknown()).optional().describe("Optional. A Hasura GraphQL 'where' filter object..."),
    },
  • src/index.ts:370-372 (registration)
    Registration of the 'aggregate_data' tool with the MCP server using server.tool().
    server.tool(
      "aggregate_data",
      "Performs a simple aggregation (count, sum, avg, min, max)...",
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 'simple aggregation' but doesn't clarify permissions needed, rate limits, whether it's read-only or has side effects, or what the output format looks like. For a data querying tool with zero annotation coverage, this leaves significant behavioral gaps.

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 extremely concise - a single sentence fragment that gets straight to the point. Every word earns its place by specifying the core functionality without any fluff or redundant information.

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?

For a data aggregation tool with 4 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what the tool returns, how results are formatted, error conditions, or provide enough context for an agent to understand the full scope of this operation beyond the basic function listing.

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 the schema already documents all four parameters thoroughly. The description adds minimal value by listing the aggregation functions but doesn't provide additional context about parameter interactions or usage patterns beyond what's in the schema descriptions.

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 tool performs aggregation operations (count, sum, avg, min, max) on data, which is a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'preview_table_data' or 'run_graphql_query' that might also access data, leaving some ambiguity about when to choose this specific aggregation tool.

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. It doesn't mention sibling tools like 'run_graphql_query' that might handle similar data operations, nor does it specify prerequisites or contexts where aggregation is preferred over other data retrieval methods.

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

Related 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/husamabusafa/hasura_mcp'

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