Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

rename-rule

Rename an ANTLR4 grammar rule and automatically update all references throughout the grammar, including imported files, to keep the grammar consistent.

Instructions

Safely rename a rule and automatically update ALL references throughout the grammar.

When to use: Refactor rule names for clarity, fix naming conventions, or improve code readability.

Example usage: old_name: "expr" new_name: "expression" write_to_file: true

Multi-file example: from_file: "MyGrammar.g4" base_path: "/path/to/grammars" load_imports: true write_to_file: true

Features:

  • Uses whole-word matching (prevents "expr" from matching "subexpr")

  • Updates rule definition and ALL references in other rules

  • Preserves rule position in grammar

  • Reports number of references updated

  • Multi-file support: Set load_imports=true to rename across imported grammars

Recommended workflow:

  1. find-rule-usages with load_imports=true to see full impact

  2. rename-rule with load_imports=true to perform refactoring

  3. validate-grammar to verify correctness

Returns: Modified grammar with rule and all references renamed, update count, file write confirmation if applicable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
new_nameYesNew name for the rule (must follow ANTLR4 naming: uppercase for lexer, lowercase for parser)
old_nameYesCurrent name of the rule (case-sensitive)
base_pathNoOptional: base directory for resolving imports. Required for multi-file grammars.
from_fileNoOptional: path to a grammar file to read. Required if using write_to_file or load_imports.
output_modeNoOutput format: "full" returns entire modified grammar, "diff" returns git-style unified diff (default for modification tools), "none" returns no content (useful for write-only operations)
load_importsNoIf true, loads all imported grammar files and renames the rule across all files. Requires from_file to be set.
write_to_fileNoIf true, writes modified grammar back to from_file (and all imported files if load_imports is true)
grammar_contentNoThe ANTLR4 grammar file content (ignored if from_file and load_imports are set)
Behavior5/5

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

With no annotations provided, the description takes on full responsibility for disclosing side effects. It details whole-word matching, updating all references, preserving rule position, reporting update count, and supporting multi-file modification via load_imports. It also clarifies the write_to_file behavior and return value, giving a thorough picture of the tool's impact.

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

Conciseness4/5

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

The description is well-structured with clear sections (purpose, when to use, examples, features, workflow, returns) and is front-loaded with the core purpose. However, there is minor redundancy: the opening statement that all references are updated is repeated in the features list. Overall, it is efficient and earns its length.

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's complexity (8 parameters, multi-file support, file writing), the description is highly complete. It covers use cases, provides examples, outlines a workflow, lists features, and describes return values. The absence of an output schema is compensated by explicitly stating what the tool returns. Error scenarios are not mentioned, but that is not required for this level of completeness.

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

Parameters3/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds usage examples (e.g., old_name/new_name combos, multi-file parameters) that illustrate parameter interplay but does not reveal new semantics beyond the schema. It does not compensate for missing parameter details because none are missing.

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 opening sentence clearly states the tool's purpose: 'Safely rename a rule and automatically update ALL references throughout the grammar.' This specifies the verb (rename), resource (rule), and scope (all references), distinguishing it from sibling tools like update-rule or remove-rule. The 'When to use' section further clarifies its role in refactoring.

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

Usage Guidelines4/5

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

The description provides an explicit 'When to use' section and a recommended workflow that involves find-rule-usages and validate-grammar, giving clear context for usage. However, it does not explicitly state when not to use the tool or directly compare it to alternatives like update-rule, so it falls just short of a 5.

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