nerdgraph_query
Execute custom GraphQL queries to retrieve and manage New Relic monitoring data, including APM metrics, alert policies, dashboards, and infrastructure information.
Instructions
Execute a custom NerdGraph GraphQL query
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| variables | No |
Input Schema (JSON Schema)
{
"properties": {
"query": {
"title": "Query",
"type": "string"
},
"variables": {
"anyOf": [
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"default": null,
"title": "Variables"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- newrelic_mcp/server.py:534-547 (handler)The MCP tool handler function for 'nerdgraph_query'. It checks if the client is initialized, executes the client's nerdgraph_query method with the provided query and variables, and returns the JSON-formatted result or error.@mcp.tool() async def nerdgraph_query( query: str, variables: Optional[Dict[str, Any]] = None ) -> str: """Execute a custom NerdGraph GraphQL query""" if not client: return json.dumps({"error": "New Relic client not initialized"}) try: result = await client.nerdgraph_query(query, variables) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
- newrelic_mcp/server.py:158-166 (helper)The NewRelicClient helper method that constructs the GraphQL payload and sends a POST request to the NerdGraph API endpoint using the client's _make_request method.async def nerdgraph_query( self, query: str, variables: Optional[Dict[str, Any]] = None ) -> Dict[str, Any]: """Execute a NerdGraph GraphQL query""" data = {"query": query} if variables: data["variables"] = variables return await self._make_request("POST", self.nerdgraph_url, json=data)
- newrelic_mcp/server.py:534-534 (registration)The @mcp.tool() decorator registers the nerdgraph_query function as an MCP tool.@mcp.tool()