Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

inline-rule

Replace a grammar rule with its definition at all reference sites, removing helper rules and simplifying ANTLR4 grammars.

Instructions

Inline a rule by replacing all references with its definition, then delete the original rule.

When to use:

  • Remove "pass-through" or helper rules

  • Simplify grammar structure

  • Clean up unnecessary indirection

  • Inverse of extract-fragment refactoring

How it works:

  1. Validates rule can be inlined (no circular references, not recursive, actually used)

  2. Extracts rule body (removes labels, actions preserved)

  3. Finds all references to the rule

  4. Replaces references with rule body (adds parentheses if needed)

  5. Removes original rule definition

Example - Simple pass-through: rule_name: "additiveExpression" // Before: expression: additiveExpression; // additiveExpression: term ((PLUS | MINUS) term); // After: expression: term ((PLUS | MINUS) term);

Example - Helper rule: rule_name: "value" // Before: assignment: ID ASSIGN value SEMI; // value: NUMBER | STRING | ID; // After: assignment: ID ASSIGN (NUMBER | STRING | ID) SEMI;

Features:

  • Circular reference detection

  • Smart parenthesization

  • Multi-reference support

  • Dry-run mode available

  • Detailed statistics

Returns:

  • Modified grammar with rule inlined

  • Number of references replaced

  • List of affected rules

  • Original rule definition

Validates:

  • Rule exists

  • Not self-recursive

  • No circular dependencies

  • Actually used somewhere

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dry_runNoIf true, shows what would change without modifying grammar
from_fileNoOptional: path to a grammar file to read. Required if using write_to_file.
rule_nameYesName of the rule to inline (e.g., "helper", "value")
write_to_fileNoIf true, writes modified grammar back to from_file (requires from_file to be set)
grammar_contentNoThe ANTLR4 grammar file content
preserve_parenthesesNoIf true, always wrap inlined body in parentheses (safer but verbose). Default: auto-detect
Behavior5/5

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

With no annotations provided, the description carries the full burden, and it excels. It details validation steps (no circular refs, not recursive, actually used), the replacement process including parenthesization, and deletion of the original rule. It also mentions dry-run mode and statistics, giving a thorough picture of side effects.

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 well-structured with clear headers, bullet points, and concrete examples. It front-loads the core purpose, then flows into usage, behavior, and return values. Every section provides distinct value and nothing is redundant or verbose.

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

Completeness5/5

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

Given the tool has 6 parameters and no output schema, the description covers all necessary context: what it does, when to use, how it works internally, validation checks, return values, and examples. The agent can confidently invoke this tool and interpret its effects without additional information.

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

Parameters4/5

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

Schema coverage is 100%, giving a baseline of 3. The description adds context beyond the schema: it explains the effect of preserve_parentheses ('Smart parenthesization', 'adds parentheses if needed'), the dry-run concept, and the relationship between from_file and write_to_file through usage examples. It doesn't deeply explain every parameter but adds meaningful nuance.

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

Purpose5/5

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

The first sentence precisely explains the operation: 'Inline a rule by replacing all references with its definition, then delete the original rule.' This names a specific verb and resource, and the description differentiates it from siblings like extract-fragment by labeling itself as the inverse. No ambiguity.

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

Usage Guidelines5/5

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

The 'When to use' section explicitly lists scenarios (pass-through rules, simplifying structure, reducing indirection) and states it is the inverse of extract-fragment. This directly guides the agent on when to choose this tool over alternatives.

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/natl-set/antlr4-mcp'

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