monitoringTechArticle

Query New Relic with NRQL from an MCP Server

Run NRQL queries against New Relic's NerdGraph API from an MCP tool, for APM and infrastructure telemetry.

Quick Answer / TL;DR

A New Relic MCP server sends NRQL queries through NerdGraph, New Relic's GraphQL API, authenticated with a User API key and scoped to a specific account ID.

Key Takeaways

  • NRQL is SQL-like but specific to New Relic's event data model - FACET for grouping and SINCE/UNTIL for time windows are the two clauses used most often.
  • All access goes through one GraphQL endpoint (NerdGraph), not a REST API with multiple paths.
  • Every query needs an account ID - a single API key can have access to multiple accounts.

Sending an NRQL query through NerdGraph

There's no dedicated New Relic Node SDK for this - NerdGraph is just GraphQL over HTTPS, so a plain fetch with the query embedded in the GraphQL body is the standard approach.

typescript
async function runNrql(accountId: number, nrql: string) {
  const response = await fetch("https://api.newrelic.com/graphql", {
    method: "POST",
    headers: {
      "Api-Key": process.env.NEW_RELIC_API_KEY!,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      query: `query($accountId: Int!, $nrql: Nrql!) {
        actor {
          account(id: $accountId) {
            nrql(query: $nrql) { results }
          }
        }
      }`,
      variables: { accountId, nrql },
    }),
  });

  const { data, errors } = await response.json();
  if (errors?.length) throw new Error(errors[0].message);
  return data.actor.account.nrql.results;
}

// Example: average transaction duration, last hour
await runNrql(accountId, "SELECT average(duration) FROM Transaction SINCE 1 hour ago");

Query New Relic with NRQL from an MCP Server FAQs

Direct answers for developers, operators, and Indian teams evaluating MCP.

M
MCPserver Team

MCP documentation and protocol implementation team

Published: 2026-07-21
Updated: 2026-07-21