Skip to main content
Glama
piekstra

New Relic MCP Server

by piekstra

list_log_parsing_rules

Retrieve all configured log parsing rules for a New Relic account to manage log data processing and structure.

Instructions

List all log parsing rules for an account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_idNo

Implementation Reference

  • MCP tool registration and handler function for 'list_log_parsing_rules'. This is the entry point decorated with @mcp.tool() that handles input validation, client checks, and delegates to the log_parsing module.
    @mcp.tool()
    async def list_log_parsing_rules(account_id: Optional[str] = None) -> str:
        """List all log parsing rules for an account"""
        if not client:
            return json.dumps({"error": "New Relic client not initialized"})
    
        # Use provided account_id or fall back to client's account_id
        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.list_log_parsing_rules(client, acct_id)
            return json.dumps(result, indent=2)
        except Exception as e:
            return json.dumps({"error": str(e)}, indent=2)
  • Core helper function that executes the NerdGraph GraphQL query to fetch and filter log parsing rules for the given account.
    async def list_log_parsing_rules(client, account_id: str) -> List[Dict[str, Any]]:
        """List all log parsing rules for an account"""
        query = """
        query($accountId: Int!) {
            actor {
                account(id: $accountId) {
                    logConfigurations {
                        parsingRules {
                            accountId
                            deleted
                            description
                            enabled
                            grok
                            id
                            lucene
                            nrql
                            updatedAt
                            createdBy {
                                email
                                name
                            }
                        }
                    }
                }
            }
        }
        """
    
        variables = {"accountId": int(account_id)}
        result = await client.nerdgraph_query(query, variables)
    
        if result and "data" in result:
            account_data = result["data"].get("actor", {}).get("account", {})
            if account_data and "logConfigurations" in account_data:
                rules = account_data["logConfigurations"].get("parsingRules", [])
                return [r for r in rules if r and not r.get("deleted", False)]
    
        return []

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