get-metrics
Discover and search Datadog metrics to identify relevant data for creating monitors and dashboards.
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-46 (handler)The execute function implements the core logic of the get-metrics tool by querying the Datadog Metrics API to list metrics matching the optional 'q' search 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:152-153 (schema)Zod schema defining the input parameters for the get-metrics tool: optional 'q' string for metric query.q: z.string().optional() },
- src/index.ts:148-160 (registration)Registers the 'get-metrics' tool with the MCP server, providing name, description, input schema, and execution 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:10-25 (helper)Initializes the Datadog API client configuration with API keys and metrics site variable for use in the metrics tool.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/tools/getMetrics.ts:3-5 (schema)TypeScript type definition for the input parameters of the getMetrics tool.type GetMetricsParams = { q?: string; };