monitoringTechArticle

Query Datadog Metrics and Logs from an MCP Server

Expose Datadog metric queries and log search as MCP tools, with both an API key and an application key.

Quick Answer / TL;DR

A Datadog MCP server uses the official @datadog/datadog-api-client SDK, authenticated with both an API key and an application key, to expose metric queries and log search as read-only tools.

Key Takeaways

  • Datadog requires two credentials, not one: an API key identifies the account, an application key authorizes the specific API call.
  • Metric and log-search endpoints are rate-limited separately from each other, so cache repeated queries within a session where possible.
  • Keep the tool read-only - dashboard and monitor mutation endpoints exist in the same client and should not be wired up without a separate approval step.

Querying metrics and logs

The v1.MetricsApi and v1.LogsApi clients from @datadog/datadog-api-client cover the two most common agent requests: a time-series metric query and a log search. Both need explicit from/to time bounds - an unbounded query is the easiest way to accidentally scan a huge amount of data.

typescript
import { client, v1 } from "@datadog/datadog-api-client";

const configuration = client.createConfiguration({
  authMethods: {
    apiKeyAuth: process.env.DD_API_KEY!,
    appKeyAuth: process.env.DD_APP_KEY!,
  },
});

const metricsApi = new v1.MetricsApi(configuration);
const logsApi = new v1.LogsApi(configuration);

async function queryMetrics(query: string, fromSeconds: number, toSeconds: number) {
  return metricsApi.queryMetrics({ query, from: fromSeconds, to: toSeconds });
}

async function searchLogs(query: string, from: string, to: string, limit = 100) {
  return logsApi.listLogs({
    body: { filter: { query, from, to }, page: { limit }, sort: "-timestamp" },
  });
}

Query Datadog Metrics and Logs from an MCP Server FAQs

Direct answers for developers, operators, and Indian teams evaluating MCP.

M
MCPserver Team

MCP documentation and protocol implementation team

Published: 2026-07-21
Updated: 2026-07-21