Skip to main content
Glama
us-all

datadog-mcp-server

by us-all

query-metrics

Retrieve time-series metric data from Datadog using metric query syntax. Provide a query, start, and end time to get data for analysis.

Instructions

Query time-series metric data from Datadog. Supports any Datadog metric query syntax (e.g., avg:system.cpu.user{host:myhost} by {env})

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesDatadog metric query. Example: avg:system.cpu.user{host:myhost} by {env}
fromYesStart time as Unix epoch seconds
toYesEnd time as Unix epoch seconds

Implementation Reference

  • Main handler function for the 'query-metrics' tool. Calls Datadog metricsApi.queryMetrics with the provided params (from, to, query), then maps the response series into a structured result with timestamps and values.
    export async function queryMetrics(params: z.infer<typeof queryMetricsSchema>) {
      const response = await metricsApi.queryMetrics({
        from: params.from,
        to: params.to,
        query: params.query,
      });
    
      const series = response.series ?? [];
      const results = series.map((s) => ({
        metric: s.metric,
        displayName: s.displayName,
        unit: s.unit,
        scope: s.scope,
        expression: s.expression,
        pointCount: s.pointlist?.length ?? 0,
        points: s.pointlist?.map(([ts, val]) => ({
          timestamp: new Date((ts ?? 0) * 1000).toISOString(),
          value: val,
        })),
      }));
    
      return {
        query: response.query,
        from: response.fromDate ? new Date(response.fromDate).toISOString() : undefined,
        to: response.toDate ? new Date(response.toDate).toISOString() : undefined,
        seriesCount: series.length,
        series: results,
      };
    }
  • Zod schema for query-metrics input validation. Defines three fields: query (string), from (numeric, start time as Unix epoch seconds), and to (numeric, end time as Unix epoch seconds).
    export const queryMetricsSchema = z.object({
      query: z.string().describe("Datadog metric query. Example: avg:system.cpu.user{host:myhost} by {env}"),
      from: z.coerce.number().describe("Start time as Unix epoch seconds"),
      to: z.coerce.number().describe("End time as Unix epoch seconds"),
    });
  • src/index.ts:172-177 (registration)
    Registration of the 'query-metrics' tool via the local tool() helper. Associates the name, description, schema shape, and wraps the handler with wrapToolHandler.
    tool(
      "query-metrics",
      "Query time-series metric data from Datadog. Supports any Datadog metric query syntax (e.g., avg:system.cpu.user{host:myhost} by {env})",
      queryMetricsSchema.shape,
      wrapToolHandler(queryMetrics),
    );
  • The tool() registration helper that registers the tool with a name, category, and conditionally registers it with the MCP server if the category is enabled.
    function tool(name: string, description: string, schema: any, handler: any): void {
      registry.register(name, description, currentCategory);
      if (registry.isEnabled(currentCategory)) {
        server.tool(name, description, schema, handler);
      }
    }
Behavior2/5

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

With no annotations provided, the description bears full responsibility for behavioral disclosure. It only states that the tool supports any query syntax, but does not mention read-only nature, rate limits, data handling, or what happens on errors or empty results.

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?

Two sentences, highly concise. Front-loaded with the primary action ('Query time-series metric data from Datadog') immediately followed by syntax support statement. No extraneous information.

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

Completeness3/5

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

The description covers the basic purpose and parameter examples, but lacks details on return format (e.g., time-series data points), time range constraints, and limits. Given no output schema and no annotations, it is adequate but not fully comprehensive.

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?

The input schema has 100% description coverage (all parameters described). The description adds value by providing a concrete example of a valid query and clarifying that 'any' syntax is supported, which goes beyond the schema's example.

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 queries time-series metric data from Datadog, specifies it supports standard Datadog metric query syntax, and includes an illustrative example. The verb 'Query' is appropriate and distinct from siblings like 'get-metrics' (list metrics) or 'get-metric-metadata'.

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?

No guidance is given on when to use this tool versus alternative metric tools (e.g., get-metrics, list-active-metrics). There is no explicit mention of prerequisites, limitations, or when not to use it.

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

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