Skip to main content
Glama

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
NameRequiredDescriptionDefault
qNo

Implementation Reference

  • 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;
        }
      }
    };
  • 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) }]
        };
      }
    );
  • 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
        });
      }
    },
  • TypeScript type definition for the input parameters of the getMetrics tool.
    type GetMetricsParams = {
      q?: string;
    };

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