query_nrql
Execute NRQL queries to retrieve monitoring and observability data from New Relic for analysis and insights.
Instructions
Execute an NRQL query
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| nrql | Yes |
Implementation Reference
- newrelic_mcp/server.py:364-374 (handler)The main MCP tool handler function for 'query_nrql'. It validates client initialization, executes the NRQL query via the NewRelicClient, formats the result as JSON, and handles errors.@mcp.tool() async def query_nrql(account_id: str, nrql: str) -> str: """Execute an NRQL query""" if not client: return json.dumps({"error": "New Relic client not initialized"}) try: result = await client.query_nrql(account_id, nrql) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
- newrelic_mcp/server.py:167-183 (helper)Core helper method in NewRelicClient that executes the NRQL query using NerdGraph GraphQL API. Constructs the GraphQL query and variables, then calls nerdgraph_query.async def query_nrql(self, account_id: str, nrql: str) -> Dict[str, Any]: """Execute an NRQL query""" query = """ query($accountId: Int!, $nrql: Nrql!) { actor { account(id: $accountId) { nrql(query: $nrql) { results } } } } """ variables = {"accountId": int(account_id), "nrql": nrql} return await self.nerdgraph_query(query, variables)