get-metrics
Discover and list available metrics from Datadog to use in monitors or dashboards. Optionally search for specific metrics by pattern using the q parameter.
Instructions
List available metrics from Datadog. Optionally use the q parameter to search for specific metrics matching a pattern. Helpful for discovering metrics to use in monitors or dashboards.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | No |
Implementation Reference
- src/tools/getMetrics.ts:27-44 (handler)The execute function implementing the core logic of the get-metrics tool, using Datadog's MetricsApi to list metrics based on an optional query parameter.execute: async (params: GetMetricsParams) => { try { const { q } = params; const apiInstance = new v1.MetricsApi(configuration); const queryStr = q || "*"; const apiParams: v1.MetricsApiListMetricsRequest = { q: queryStr }; const response = await apiInstance.listMetrics(apiParams); return response; } catch (error) { console.error("Error fetching metrics:", error); throw error; }
- src/index.ts:148-160 (registration)Registration of the 'get-metrics' tool in the MCP server, including name, description, input schema, and wrapper handler.server.tool( "get-metrics", "List available metrics from Datadog. Optionally use the q parameter to search for specific metrics matching a pattern. Helpful for discovering metrics to use in monitors or dashboards.", { q: z.string().optional() }, async (args) => { const result = await getMetrics.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
- src/tools/getMetrics.ts:3-5 (schema)TypeScript type definition for the input parameters of the getMetrics tool.type GetMetricsParams = { q?: string; };
- src/tools/getMetrics.ts:10-25 (helper)Initialization function that sets up the Datadog client configuration, including auth and site variables for metrics API.initialize: () => { const configOpts = { authMethods: { apiKeyAuth: process.env.DD_API_KEY, appKeyAuth: process.env.DD_APP_KEY } }; configuration = client.createConfiguration(configOpts); if (process.env.DD_METRICS_SITE) { configuration.setServerVariables({ site: process.env.DD_METRICS_SITE }); } },
- src/index.ts:152-153 (schema)Zod schema for input validation of the get-metrics tool, defining the optional 'q' query parameter.q: z.string().optional() },