query_nrql
Execute NRQL queries to retrieve and analyze New Relic monitoring data for application performance, infrastructure metrics, and business insights.
Instructions
Execute an NRQL query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| nrql | Yes |
Input Schema (JSON Schema)
{
"properties": {
"account_id": {
"title": "Account Id",
"type": "string"
},
"nrql": {
"title": "Nrql",
"type": "string"
}
},
"required": [
"account_id",
"nrql"
],
"type": "object"
}
Implementation Reference
- newrelic_mcp/server.py:364-375 (handler)MCP tool handler function for 'query_nrql'. This is the entry point for the tool, decorated with @mcp.tool(), which registers it in the FastMCP server. It calls the underlying client method and formats the response as JSON.@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-184 (helper)Core helper method in NewRelicClient class that executes the NRQL query using a NerdGraph GraphQL query. This contains the actual API call logic.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)