Skip to main content
Glama
piekstra

New Relic MCP Server

by piekstra

test_log_parsing_rule

Validate log parsing rules against sample logs to ensure accurate data extraction in New Relic monitoring. Automatically generates patterns when needed.

Instructions

Test a log parsing rule against sample logs.
If no grok_pattern is provided, it will generate one automatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
log_samplesYes
grok_patternNo
account_idNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler decorated with @mcp.tool(). Handles input validation for client and account_id, delegates to core helper in log_parsing.py, serializes result to JSON.
    @mcp.tool()
    async def test_log_parsing_rule(
        log_samples: List[str],
        grok_pattern: Optional[str] = None,
        account_id: Optional[str] = None,
    ) -> str:
        """
        Test a log parsing rule against sample logs.
        If no grok_pattern is provided, it will generate one automatically.
        """
        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.test_log_parsing_rule(
                client, acct_id, log_samples, grok_pattern
            )
            return json.dumps(result, indent=2)
        except Exception as e:
            return json.dumps({"error": str(e)}, indent=2)
  • Core helper function implementing the log parsing rule testing logic: generates or converts GROK pattern to NRQL, executes test query on New Relic logs, returns patterns and test results.
    async def test_log_parsing_rule(
        client, account_id: str, log_samples: List[str], grok_pattern: Optional[str] = None
    ) -> Dict[str, Any]:
        """
        Test a log parsing rule against sample logs
        If no grok_pattern is provided, it will generate one automatically
        """
        generator = GrokPatternGenerator()
    
        if not grok_pattern:
            # Generate pattern from samples
            grok_pattern, nrql_pattern = generator.generate_grok_pattern(log_samples)
        else:
            # Generate NRQL pattern from existing GROK
            nrql_pattern = grok_pattern
            # Simple conversion - replace GROK patterns with %
            nrql_pattern = re.sub(r"%\{[^}]+\}", "%", nrql_pattern)
    
        # Test the pattern by querying logs
        test_query = f"""
        SELECT count(*) as matching_logs
        FROM Log
        WHERE message LIKE '{nrql_pattern}'
        SINCE 1 hour ago
        """
    
        result = await client.query_nrql(account_id, test_query)
    
        return {
            "grok_pattern": grok_pattern,
            "nrql_pattern": nrql_pattern,
            "test_results": result,
            "sample_count": len(log_samples),
        }
  • Registration of the tool using @mcp.tool() decorator.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the automatic generation of a grok_pattern when not provided, which is useful behavioral context. However, it lacks details on permissions, rate limits, response format, or error handling for a testing tool with 3 parameters, leaving significant gaps in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and front-loaded: two sentences with zero waste. The first sentence states the core purpose, and the second adds critical behavioral context. Every word earns its place, making it easy to scan and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which handles return values) and no annotations, the description is partially complete. It covers the basic purpose and one behavioral trait but misses parameter details and broader context like error scenarios or integration with siblings. For a testing tool with 3 parameters, this leaves room for improvement.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It only addresses 'grok_pattern' by noting it can be omitted for auto-generation, but it doesn't explain 'log_samples' (e.g., format, size limits) or 'account_id' (e.g., purpose, when required). With 3 parameters and low coverage, this is insufficient.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Test a log parsing rule against sample logs.' It specifies the verb ('Test') and resource ('log parsing rule') with context ('against sample logs'). However, it doesn't explicitly differentiate from sibling tools like 'generate_log_parsing_rule' or 'create_log_parsing_rule' beyond the testing focus.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage guidance: 'If no grok_pattern is provided, it will generate one automatically.' This suggests when to omit the parameter, but it doesn't explicitly state when to use this tool versus alternatives like 'generate_log_parsing_rule' or 'create_log_parsing_rule', nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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