Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

sort-rules

Reorder ANTLR4 grammar rules using alphabetical, type, dependency, or usage strategies to clean up messy files, group related rules, and improve readability.

Instructions

Reorder rules in a grammar according to various sorting strategies.

When to use:

  • Clean up messy grammar files

  • Organize rules logically

  • Improve readability and maintenance

  • Group related rules together

Sorting Strategies:

  1. alphabetical (default)

    • Sorts parser rules alphabetically

    • Then sorts lexer rules alphabetically

    • Most common for general organization

  2. type

    • Groups by rule type

    • parser_first: true (default) - parser rules first

    • parser_first: false - lexer rules first

  3. dependency

    • Orders rules based on relationship to anchor rule

    • Requires anchor_rule option

    • Order: dependencies → anchor → dependents → rest

    • Useful for understanding rule relationships

  4. usage

    • Most-referenced rules first

    • Helps identify "core" rules

    • Useful for understanding grammar structure

Example - Alphabetical: strategy: "alphabetical"

Example - Dependency-based: strategy: "dependency" anchor_rule: "expression"

Example - Type-based: strategy: "type" parser_first: false // Lexer rules first

Features:

  • Preserves multi-line rule formatting

  • Maintains blank lines after rules

  • Preserves header (grammar declaration, imports, options)

  • Handles all rule types (parser, lexer, fragment)

Returns:

  • Reordered grammar

  • Statistics (total rules, strategy used)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
strategyNoSorting strategy: alphabetical (default), type, dependency, or usage
from_fileNoOptional: path to a grammar file to read. Required if using write_to_file.
anchor_ruleNoFor dependency strategy: the rule to use as anchor (rules used by this rule come first)
parser_firstNoFor type strategy: if true (default), parser rules come before lexer rules
write_to_fileNoIf true, writes modified grammar back to from_file (requires from_file to be set)
grammar_contentNoThe ANTLR4 grammar file content
Behavior4/5

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

With no annotations provided, the description carries full transparency burden. It discloses key behaviors: preserves multi-line rule formatting, maintains blank lines after rules, preserves the header, and handles all rule types. It also explains that it returns reordered grammar and statistics. It doesn't mention error handling or side effects of write_to_file, but the coverage is strong.

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 headings, bullet points, and examples. It front-loads the core purpose, then logically separates usage, strategies, features, and return values. Every section provides necessary detail without redundancies, making it easy for an agent to parse.

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 (six parameters, four sorting strategies), the description covers all essential aspects: when to use, strategy details with examples, formatting preservation features, and return values. No output schema exists, but the description explicitly states what is returned. This is comprehensive for an AI agent to invoke correctly.

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 description coverage is 100%, so baseline is 3. The description enhances this by explaining each strategy in detail with examples, including how anchor_rule and parser_first affect behavior. This adds semantic clarity beyond the schema's short field descriptions.

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 description opens with a specific verb+resource: 'Reorder rules in a grammar according to various sorting strategies.' It clearly distinguishes this tool from siblings like format-grammar (formatting whitespace) and list-rules (listing) by focusing on reordering logic. The detailed strategies further refine the scope.

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?

A dedicated 'When to use' section lists concrete scenarios (clean up messy files, organize rules logically, improve readability, group related rules). It provides clear context for when to employ this tool, though it does not explicitly mention alternatives or exclusion cases, which would push it to 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