Skip to main content
Glama
cloudbring

New Relic MCP Server

by cloudbring

list_alert_policies

Retrieve all alert policies from your New Relic account to review and manage incident notification settings.

Instructions

List all alert policies in your New Relic account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
target_account_idNoOptional New Relic account ID

Implementation Reference

  • The `listAlertPolicies` async method executes a NerdGraph GraphQL query to list all alert policies for a given account ID. It validates the account ID, builds a GraphQL query to fetch policies (id, name, incidentPreference, conditions), and returns the policies array or an empty array.
    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 || [];
    }
  • The `getPoliciesTool()` method defines the tool's name ('list_alert_policies'), description, and input schema. The schema accepts an optional `target_account_id` string parameter.
    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:57-105 (registration)
    The `registerTools()` method registers all tools into a Map. At line 74, `alertTool.getPoliciesTool()` is called to register the 'list_alert_policies' tool.
    private registerTools(): void {
      const nrqlTool = new NrqlTool(this.client);
      const apmTool = new ApmTool(this.client);
      const entityTool = new EntityTool(this.client);
      const alertTool = new AlertTool(this.client);
      const syntheticsTool = new SyntheticsTool(this.client);
      const nerdGraphTool = new NerdGraphTool(this.client);
      const restDeployments = new RestDeploymentsTool();
      const restApm = new RestApmTool();
      const restMetrics = new RestMetricsTool();
    
      // Register all tools
      const tools = [
        nrqlTool.getToolDefinition(),
        apmTool.getListApplicationsTool(),
        entityTool.getSearchTool(),
        entityTool.getDetailsTool(),
        alertTool.getPoliciesTool(),
        alertTool.getIncidentsTool(),
        alertTool.getAcknowledgeTool(),
        syntheticsTool.getListMonitorsTool(),
        syntheticsTool.getCreateMonitorTool(),
        nerdGraphTool.getQueryTool(),
        // REST v2 tools
        restDeployments.getCreateTool(),
        restDeployments.getListTool(),
        restDeployments.getDeleteTool(),
        restApm.getListApplicationsTool(),
        restMetrics.getListMetricNamesTool(),
        restMetrics.getMetricDataTool(),
        restMetrics.getListApplicationHostsTool(),
        {
          name: 'get_account_details',
          description: 'Get New Relic account details',
          inputSchema: {
            type: 'object' as const,
            properties: {
              target_account_id: {
                type: 'string' as const,
                description: 'Optional account ID to get details for',
              },
            },
          },
        },
      ];
    
      tools.forEach((tool) => {
        this.tools.set(tool.name, tool);
      });
  • src/server.ts:205-209 (registration)
    In the `executeTool()` switch statement, the 'list_alert_policies' case dispatches to `AlertTool.listAlertPolicies()` with the resolved account ID.
    case 'list_alert_policies':
      return await new AlertTool(this.client).listAlertPolicies({
        ...args,
        target_account_id: accountId,
      });
  • The `executeNerdGraphQuery` helper method is used by `listAlertPolicies` to make the actual HTTP POST request to the New Relic NerdGraph API. It handles API key validation, sends the GraphQL query, and returns the parsed JSON response.
    async executeNerdGraphQuery<T = unknown>(
      query: string,
      variables?: Record<string, unknown>
    ): Promise<GraphQLResponse<T>> {
      // Check if API key is missing or empty
      if (!this.apiKey || this.apiKey === '' || this.apiKey.length === 0) {
        throw new Error('NEW_RELIC_API_KEY environment variable is not set');
      }
    
      const response = await fetch(NERDGRAPH_URL, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
          'API-Key': this.apiKey,
        },
        body: JSON.stringify({ query, variables }),
      });
    
      if (!response.ok) {
        if (response.status === 401) {
          throw new Error('Unauthorized: Invalid API key');
        }
        throw new Error(`NerdGraph API error: ${response.status} ${response.statusText}`);
      }
    
      return (await response.json()) as GraphQLResponse<T>;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided. Description indicates a read operation but does not mention pagination, rate limits, or any other behaviors beyond listing. Insufficient for a non-annotated tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, no unnecessary words, front-loaded key information. Efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple list tool with one optional parameter and no output schema, the description is minimally adequate. Could mention if results are paginated or the default account context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers the only parameter with a description. Description adds no additional meaning beyond the schema, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states the action (list) and resource (alert policies) with scope (in your New Relic account). Distinguished from siblings like list_apm_applications or list_synthetics_monitors.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives like search_entities or list_open_incidents. Implicitly clear from the resource name, but no explicit context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/cloudbring/newrelic-mcp'

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