Skip to main content
Glama
piekstra

New Relic MCP Server

by piekstra

create_log_parsing_rule

Define custom parsing rules to extract structured data from log files using Grok patterns and NRQL queries for New Relic monitoring.

Instructions

Create a new log parsing rule

Input Schema

NameRequiredDescriptionDefault
descriptionYes
grokYes
nrqlYes
enabledNo
luceneNo
account_idNo

Input Schema (JSON Schema)

{ "properties": { "account_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Account Id" }, "description": { "title": "Description", "type": "string" }, "enabled": { "default": true, "title": "Enabled", "type": "boolean" }, "grok": { "title": "Grok", "type": "string" }, "lucene": { "default": "", "title": "Lucene", "type": "string" }, "nrql": { "title": "Nrql", "type": "string" } }, "required": [ "description", "grok", "nrql" ], "type": "object" }

Implementation Reference

  • MCP tool handler for 'create_log_parsing_rule'. Decorated with @mcp.tool() for registration. Defines input schema via type annotations and docstring. Handles client initialization checks, account ID resolution, calls the core implementation in log_parsing.py, and returns JSON results or errors.
    @mcp.tool() async def create_log_parsing_rule( description: str, grok: str, nrql: str, enabled: bool = True, lucene: str = "", account_id: Optional[str] = None, ) -> str: """Create a new log parsing rule""" if not client: return json.dumps({"error": "New Relic client not initialized"}) acct_id = account_id or client.account_id if not acct_id: return json.dumps({"error": "Account ID required but not provided"}) try: result = await log_parsing.create_log_parsing_rule( client, acct_id, description, grok, nrql, enabled, lucene ) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
  • Core implementation of the log parsing rule creation. Constructs and executes a GraphQL mutation via the New Relic NerdGraph API to create the rule, handles response parsing and errors.
    async def create_log_parsing_rule( client, account_id: str, description: str, grok: str, nrql: str, enabled: bool = True, lucene: str = "", ) -> Dict[str, Any]: """Create a new log parsing rule""" # Escape special characters in GROK pattern for GraphQL # grok_escaped = grok.replace("\\", "\\\\") mutation = f""" mutation {{ logConfigurationsCreateParsingRule( accountId: {int(account_id)}, rule: {{ description: "{description}" enabled: {str(enabled).lower()} grok: "{grok}" lucene: "{lucene}" nrql: "{nrql}" }} ) {{ rule {{ id description enabled grok lucene nrql updatedAt }} errors {{ message type }} }} }} """ result = await client.nerdgraph_query(mutation) if result and "data" in result: create_result = result["data"].get("logConfigurationsCreateParsingRule", {}) if create_result.get("errors"): raise Exception(f"Failed to create rule: {create_result['errors']}") return create_result.get("rule", {}) raise Exception("Failed to create parsing rule")

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

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