list_alert_policies
Retrieve all alert policies in your New Relic account using a target account ID to monitor and manage notification rules effectively.
Instructions
List all alert policies in your New Relic account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target_account_id | No | Optional New Relic account ID |
Implementation Reference
- src/tools/alert.ts:65-103 (handler)The main handler function that executes the NerdGraph query to list alert policies for the given account ID.async listAlertPolicies(input: { target_account_id?: string; }): Promise<Array<Record<string, unknown>>> { const accountId = input.target_account_id; if (!accountId) { throw new Error('Account ID must be provided'); } if (!/^\d+$/.test(accountId)) { throw new Error('Invalid account ID format'); } const query = `{ actor { account(id: ${accountId}) { alerts { policiesSearch { policies { id name incidentPreference conditions { id name enabled } } } } } } }`; const response = await this.client.executeNerdGraphQuery<{ actor?: { account?: { alerts?: { policiesSearch?: { policies?: Array<Record<string, unknown>> } } }; }; }>(query); return response.data?.actor?.account?.alerts?.policiesSearch?.policies || []; }
- src/tools/alert.ts:11-25 (schema)Defines the tool's name, description, and input schema for validating inputs.getPoliciesTool(): Tool { return { name: 'list_alert_policies', description: 'List all alert policies in your New Relic account', inputSchema: { type: 'object', properties: { target_account_id: { type: 'string', description: 'Optional New Relic account ID', }, }, }, }; }
- src/server.ts:205-209 (registration)Dispatches tool calls to the AlertTool's listAlertPolicies handler in the server's executeTool switch statement.case 'list_alert_policies': return await new AlertTool(this.client).listAlertPolicies({ ...args, target_account_id: accountId, });
- src/server.ts:74-74 (registration)Registers the tool by including alertTool.getPoliciesTool() in the tools array during server initialization.alertTool.getPoliciesTool(),