Skip to main content
Glama

get-monitors

Retrieve Datadog monitors with customizable filters, including status, tags, and result size, to streamline monitoring and alert management.

Instructions

Fetch monitors from Datadog with optional filtering. Use groupStates to filter by monitor status (e.g., 'alert', 'warn', 'no data'), tags or monitorTags to filter by tag criteria, and limit to control result size.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
groupStatesNo
limitNo
monitorTagsNo
tagsNo

Implementation Reference

  • The main handler function 'execute' that performs the API call to list monitors from Datadog with filtering options and handles errors.
    execute: async (params: GetMonitorsParams) => { try { const { groupStates, tags, monitorTags, limit } = params; const apiInstance = new v1.MonitorsApi(configuration); const groupStatesStr = groupStates ? groupStates.join(",") : undefined; const apiParams: v1.MonitorsApiListMonitorsRequest = { groupStates: groupStatesStr, tags: tags, monitorTags: monitorTags }; const response = await apiInstance.listMonitors(apiParams); if (limit && response.length > limit) { return response.slice(0, limit); } return response; } catch (error: any) { if (error.status === 403) { console.error( "Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access monitors." ); throw new Error( "Datadog API authorization failed. Please verify your API and Application keys have the correct permissions." ); } else { console.error("Error fetching monitors:", error); throw error; } } }
  • src/index.ts:88-103 (registration)
    Registers the 'get-monitors' tool on the MCP server, including description, input schema validation, and execution handler.
    server.tool( "get-monitors", "Fetch monitors from Datadog with optional filtering. Use groupStates to filter by monitor status (e.g., 'alert', 'warn', 'no data'), tags or monitorTags to filter by tag criteria, and limit to control result size.", { groupStates: z.array(z.string()).optional(), tags: z.string().optional(), monitorTags: z.string().optional(), limit: z.number().default(100) }, async (args) => { const result = await getMonitors.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
  • The getMonitors module defining initialize and execute methods, with TypeScript type GetMonitorsParams for input.
    export const getMonitors = { 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 }); } }, execute: async (params: GetMonitorsParams) => { try { const { groupStates, tags, monitorTags, limit } = params; const apiInstance = new v1.MonitorsApi(configuration); const groupStatesStr = groupStates ? groupStates.join(",") : undefined; const apiParams: v1.MonitorsApiListMonitorsRequest = { groupStates: groupStatesStr, tags: tags, monitorTags: monitorTags }; const response = await apiInstance.listMonitors(apiParams); if (limit && response.length > limit) { return response.slice(0, limit); } return response; } catch (error: any) { if (error.status === 403) { console.error( "Authorization failed (403 Forbidden): Check that your API key and Application key are valid and have sufficient permissions to access monitors." ); throw new Error( "Datadog API authorization failed. Please verify your API and Application keys have the correct permissions." ); } else { console.error("Error fetching monitors:", error); throw error; } } } };
  • TypeScript type definition for the input parameters of getMonitors.
    type GetMonitorsParams = { groupStates?: string[]; tags?: string; monitorTags?: string; limit?: number; };
  • Initialization function to set up Datadog API client configuration with auth keys and site.
    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 }); } },

Other Tools

Related 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/GeLi2001/datadog-mcp-server'

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