Skip to main content
Glama

aggregate-logs

Analyze log data by performing aggregations to calculate metrics, group by fields, and create statistical summaries for pattern analysis.

Instructions

Perform analytical queries and aggregations on log data. Essential for calculating metrics (count, avg, sum, etc.), grouping data by fields, and creating statistical summaries from logs. Use this when you need to analyze patterns or extract metrics from log data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filterNo
computeNo
groupByNo
optionsNo

Implementation Reference

  • The execute function that handles the tool logic: destructures params, constructs the API URL for Datadog logs aggregate endpoint, sends POST request with fetch, handles response and errors.
    execute: async (params: AggregateLogsParams) => {
      try {
        const { filter, compute, groupBy, options } = params;
    
        // Directly call with fetch to use the documented aggregation endpoint
        const apiUrl = `https://${
          process.env.DD_LOGS_SITE || "datadoghq.com"
        }/api/v2/logs/analytics/aggregate`;
    
        const headers = {
          "Content-Type": "application/json",
          "DD-API-KEY": process.env.DD_API_KEY || "",
          "DD-APPLICATION-KEY": process.env.DD_APP_KEY || ""
        };
    
        const body = {
          filter: filter,
          compute: compute,
          group_by: groupBy,
          options: options
        };
    
        const response = await fetch(apiUrl, {
          method: "POST",
          headers: headers,
          body: JSON.stringify(body)
        });
    
        if (!response.ok) {
          throw {
            status: response.status,
            message: await response.text()
          };
        }
    
        const data = await response.json();
        return data;
      } catch (error: any) {
        if (error.status === 403) {
          console.error(
            "Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access log analytics."
          );
          throw new Error(
            "Datadog API authorization failed. Please verify your API and Application keys have the correct permissions."
          );
        } else {
          console.error("Error aggregating logs:", error);
          throw error;
        }
      }
    }
  • src/index.ts:244-290 (registration)
    Registers the 'aggregate-logs' tool with MCP server: defines name, description, Zod input schema, and async handler that calls aggregateLogs.execute and formats response.
    server.tool(
      "aggregate-logs",
      "Perform analytical queries and aggregations on log data. Essential for calculating metrics (count, avg, sum, etc.), grouping data by fields, and creating statistical summaries from logs. Use this when you need to analyze patterns or extract metrics from log data.",
      {
        filter: z
          .object({
            query: z.string().optional(),
            from: z.string().optional(),
            to: z.string().optional(),
            indexes: z.array(z.string()).optional()
          })
          .optional(),
        compute: z
          .array(
            z.object({
              aggregation: z.string(),
              metric: z.string().optional(),
              type: z.string().optional()
            })
          )
          .optional(),
        groupBy: z
          .array(
            z.object({
              facet: z.string(),
              limit: z.number().optional(),
              sort: z
                .object({
                  aggregation: z.string(),
                  order: z.string()
                })
                .optional()
            })
          )
          .optional(),
        options: z
          .object({
            timezone: z.string().optional()
          })
          .optional()
      },
      async (args) => {
        const result = await aggregateLogs.execute(args);
        return {
          content: [{ type: "text", text: JSON.stringify(result) }]
        };
      }
  • TypeScript type definition for the input parameters of the aggregate-logs tool, matching the Zod schema used in registration.
    type AggregateLogsParams = {
      filter?: {
        query?: string;
        from?: string;
        to?: string;
        indexes?: string[];
      };
      compute?: Array<{
        aggregation: string;
        metric?: string;
        type?: string;
      }>;
      groupBy?: Array<{
        facet: string;
        limit?: number;
        sort?: {
          aggregation: string;
          order: string;
        };
      }>;
      options?: {
        timezone?: string;
      };
    };
  • Initializes the Datadog API client configuration with auth keys and logs site, enabling unstable operations for logs aggregation.
    initialize: () => {
      const configOpts = {
        authMethods: {
          apiKeyAuth: process.env.DD_API_KEY,
          appKeyAuth: process.env.DD_APP_KEY
        }
      };
    
      configuration = client.createConfiguration(configOpts);
    
      if (process.env.DD_LOGS_SITE) {
        configuration.setServerVariables({
          site: process.env.DD_LOGS_SITE
        });
      }
    
      // Enable any unstable operations
      configuration.unstableOperations["v2.aggregateLogs"] = true;
    },
Behavior2/5

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

With no annotations provided, the description carries full burden but only mentions what the tool does, not how it behaves. It doesn't disclose performance characteristics, rate limits, authentication requirements, error conditions, or what happens with large datasets. For a complex aggregation tool with 4 parameters, this is a significant gap.

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?

The description is appropriately sized with two sentences that each add value. It's front-loaded with the core purpose and follows with usage guidance. No wasted words, though it could be slightly more structured for a complex tool.

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 complex aggregation tool with 4 parameters (including nested objects), 0% schema description coverage, no output schema, and no annotations, the description is inadequate. It explains the 'what' but not the 'how' - missing crucial details about parameter usage, return format, error handling, and behavioral constraints.

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

Parameters2/5

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

With 0% schema description coverage and 4 complex parameters (including nested objects), the description provides no parameter-specific information. It mentions general concepts like 'calculating metrics' and 'grouping data by fields' but doesn't explain what 'filter', 'compute', 'groupBy', or 'options' parameters actually do or how to structure them.

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 clearly states the tool's purpose with specific verbs ('perform analytical queries and aggregations') and resources ('on log data'). It distinguishes from siblings like 'search-logs' by focusing on aggregation and metrics rather than basic search operations.

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?

The description provides clear context for when to use this tool ('when you need to analyze patterns or extract metrics from log data'), but doesn't explicitly state when NOT to use it or mention specific alternatives like 'search-logs' for non-aggregation queries.

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/GeLi2001/datadog-mcp-server'

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