Skip to main content
Glama
xelber

New Relic MCP Server

by xelber

query-apm

Run tailored NRQL queries against New Relic APM data for deep analysis of transactions, metrics, and other APM events. Obtain specific performance insights from your applications.

Instructions

Execute a custom NRQL query against New Relic APM data. Use this for complex queries against Transaction, Metric, or other APM event types. Example: "SELECT average(duration) FROM Transaction WHERE appName = 'MyApp' SINCE 1 HOUR AGO"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNRQL query to execute against APM data

Implementation Reference

  • src/index.ts:127-143 (registration)
    Tool 'query-apm' is registered in ListToolsRequestSchema handler with name, description, and inputSchema.
    {
      name: 'query-apm',
      description:
        'Execute a custom NRQL query against New Relic APM data. ' +
        'Use this for complex queries against Transaction, Metric, or other APM event types. ' +
        'Example: "SELECT average(duration) FROM Transaction WHERE appName = \'MyApp\' SINCE 1 HOUR AGO"',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'NRQL query to execute against APM data',
          },
        },
        required: ['query'],
      },
    },
  • Case 'query-apm' in CallToolRequestSchema: parses input with QueryApmInputSchema, calls newRelicClient.queryApm(), and returns results as JSON.
    case 'query-apm': {
      const { query } = QueryApmInputSchema.parse(args);
      const results = await newRelicClient.queryApm(query);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(results, null, 2),
          },
        ],
      };
    }
  • QueryApmInputSchema: Zod schema defining a required 'query' string parameter for APM NRQL queries.
    export const QueryApmInputSchema = z.object({
      query: z.string().describe('NRQL query to execute against APM data (e.g., "SELECT average(duration) FROM Transaction WHERE appName = \'MyApp\' SINCE 1 HOUR AGO")'),
    });
  • NewRelicClient.queryApm(): executes the APM NRQL query by delegating to the generic executeNRQL() method.
    async queryApm(nrqlQuery: string): Promise<any[]> {
      return this.executeNRQL(nrqlQuery);
    }
  • NewRelicClient.executeNRQL(): core helper that sends the GraphQL query to New Relic's NerdGraph API and returns results.
    async executeNRQL(query: string): Promise<any[]> {
      const graphqlQuery = `
        {
          actor {
            account(id: ${this.accountId}) {
              nrql(query: "${this.escapeQuery(query)}") {
                results
              }
            }
          }
        }
      `;
    
      try {
        const response = await this.client.post<NerdGraphResponse>('', {
          query: graphqlQuery,
        });
    
        if (response.data.errors && response.data.errors.length > 0) {
          const errorMessages = response.data.errors
            .map(err => err.message)
            .join(', ');
          throw new Error(`NerdGraph errors: ${errorMessages}`);
        }
    
        return response.data.data?.actor?.account?.nrql?.results || [];
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(
            `Failed to query New Relic: ${error.message}${
              error.response?.data ? ` - ${JSON.stringify(error.response.data)}` : ''
            }`
          );
        }
        throw error;
      }
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It mentions executing a custom NRQL query, which implies read-only behavior, but does not disclose rate limits, permissions, or error handling. The example gives some transparency but lacks depth.

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?

Two sentences: first states purpose, second provides an example and usage context. No wasted words, essential information is front-loaded.

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?

With no output schema, the description should hint at the return value (e.g., a dataset). It only describes the input and purpose, leaving the agent uncertain about the output format. For a simple tool with one parameter, this is adequate but not complete.

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

Parameters4/5

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

With 100% schema coverage, the baseline is 3. The description adds value by providing an example and specifying event types (Transaction, Metric) that the schema's terse 'NRQL query' does not capture, making the parameter's scope clearer.

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?

The description clearly states the tool executes custom NRQL queries against New Relic APM data. It distinguishes from siblings like get-apm-metrics (specific metrics) and query-logs (logs) by specifying APM event types.

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

Usage Guidelines4/5

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

The description explicitly says 'Use this for complex queries against Transaction, Metric, or other APM event types', providing clear usage context. It doesn't explicitly mention when not to use it, but the example and sibling tools provide enough differentiation.

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

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