get-monitors
Fetch Datadog monitors with filters for status, tags, or result size to manage monitoring alerts effectively.
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
| Name | Required | Description | Default |
|---|---|---|---|
| groupStates | No | ||
| tags | No | ||
| monitorTags | No | ||
| limit | No |
Implementation Reference
- src/tools/getMonitors.ts:30-64 (handler)Executes the tool logic by calling Datadog's MonitorsApi.listMonitors with provided filters (groupStates, tags, monitorTags), applies limit if specified, handles 403 authorization errors specifically, and returns the list of monitors.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/tools/getMonitors.ts:3-8 (schema)TypeScript type definition for the input parameters of the getMonitors tool.type GetMonitorsParams = { groupStates?: string[]; tags?: string; monitorTags?: string; limit?: number; };
- src/index.ts:88-103 (registration)Registers the 'get-monitors' tool with the MCP server, including description, Zod input schema validation, and a thin wrapper handler that invokes the tool's execute method and formats the result as MCP text content.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) }] }; } );
- src/tools/getMonitors.ts:13-28 (helper)Initializes the Datadog API client configuration with API keys and optional site variable for metrics endpoint.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 }); } },