Skip to main content
Glama
xelber

New Relic MCP Server

by xelber

query-logs

Execute custom NRQL queries on New Relic logs for complex filtering and aggregation, such as searching for error patterns or recent entries.

Instructions

Execute a custom NRQL query against New Relic logs. Use this for complex queries with specific filtering and aggregations. Example: "SELECT * FROM Log WHERE message LIKE '%error%' SINCE 1 HOUR AGO LIMIT 100"

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNRQL query to execute against New Relic logs

Implementation Reference

  • The main handler case for 'query-logs' tool. It parses the input using QueryLogsInputSchema, calls newRelicClient.queryLogs(query), and returns the results as JSON text.
    case 'query-logs': {
      const { query } = QueryLogsInputSchema.parse(args);
      const results = await newRelicClient.queryLogs(query);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(results, null, 2),
          },
        ],
      };
    }
  • Zod schema for the query-logs tool input. Defines a required 'query' string parameter representing an NRQL query.
    export const QueryLogsInputSchema = z.object({
      query: z.string().describe('NRQL query to execute (e.g., "SELECT * FROM Log WHERE message LIKE \'%error%\' SINCE 1 HOUR AGO")'),
    });
  • src/index.ts:59-75 (registration)
    Registration of the 'query-logs' tool under ListToolsRequestSchema. Includes name, description, and inputSchema for the tool listing.
    {
      name: 'query-logs',
      description:
        'Execute a custom NRQL query against New Relic logs. ' +
        'Use this for complex queries with specific filtering and aggregations. ' +
        'Example: "SELECT * FROM Log WHERE message LIKE \'%error%\' SINCE 1 HOUR AGO LIMIT 100"',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'NRQL query to execute against New Relic logs',
          },
        },
        required: ['query'],
      },
    },
  • The queryLogs method on NewRelicClient. Delegates to the generic executeNRQL method which makes a GraphQL request to New Relic's NerdGraph API.
     */
    async queryLogs(nrqlQuery: string): Promise<any[]> {
      return this.executeNRQL(nrqlQuery);
    }
  • The core executeNRQL helper method that sends the NRQL query to New Relic's GraphQL 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 provided, so description must disclose behavior. It explains input but does not mention output format, error handling, or rate limits. For a query tool, this is minimal but acceptable.

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?

Very concise: one sentence for purpose, one for usage, one example. No wasted words. Front-loaded with action.

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

Completeness4/5

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

For a simple tool with one parameter and full schema coverage, the description is sufficient. Missing output format, but not critical given simplicity.

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 single param with a description. Description adds an example query, which adds value. Baseline 3 is appropriate due to full 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 it executes a custom NRQL query against New Relic logs. Differentiates from siblings like get-recent-logs and search-logs, which are simpler or less flexible.

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?

Explicitly says use for complex queries with filtering and aggregations, and provides a concrete example. Does not explicitly state when not to use, but context implies simpler tasks can use sibling tools.

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