Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

add-rule

Add lexer or parser rules to ANTLR4 grammars with auto-detection from naming case and options for skip, channel, fragment, return type, and positioning.

Instructions

Add a new lexer or parser rule with automatic type detection and positioning.

Auto-detection: Rule type is determined by naming convention:

  • UPPERCASE = lexer rule (e.g., ID, STRING, NUMBER)

  • lowercase = parser rule (e.g., expression, statement, term)

When to use: Add any rule to your grammar - lexer tokens or parser rules.

Example - Add lexer rule (UPPERCASE): rule_name: "ID" pattern: "[a-zA-Z_][a-zA-Z0-9_]*"

Example - Add parser rule (lowercase): rule_name: "expression" definition: "term ((PLUS | MINUS) term)*"

Example - Add lexer with skip: rule_name: "WS" pattern: "[ \t\n\r]+" skip: true

Example - Add lexer with channel: rule_name: "COMMENT" pattern: "//.*?\n" channel: "COMMENTS"

Example - Add fragment: rule_name: "DIGIT" pattern: "[0-9]" fragment: true

Example - Add with positioning: rule_name: "STRING" pattern: "".*?"" insert_after: "ID"

Example - Add parser with return type: rule_name: "intLiteral" definition: "INT" return_type: "int value"

Features:

  • Auto-detects lexer vs parser from rule name case

  • Default: Alphabetical sorting within rule type

  • Optional: Custom positioning with insert_after/insert_before

  • Lexer-specific: skip, channel, fragment options

  • Parser-specific: return_type option

  • Prevents duplicate rule names

  • Optional file persistence with write_to_file: true

  • Diff output mode for large grammars

Returns: Modified grammar with new rule inserted, success message, position description, file write confirmation if applicable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
skipNoLexer only: If true, adds "-> skip" directive (common for whitespace)
channelNoLexer only: Channel name to route tokens (e.g., "COMMENTS")
patternNoFor lexer rules: The lexer pattern. Examples: [0-9]+, \".*?\", [a-zA-Z_][a-zA-Z0-9_]*
fragmentNoLexer only: If true, marks rule as fragment (reusable pattern, not a token)
from_fileNoOptional: path to a grammar file to read. Required if using write_to_file.
rule_nameYesName of the rule. UPPERCASE for lexer rules (ID, STRING), lowercase for parser rules (expression, term)
definitionNoFor parser rules: The rule definition. Examples: "ID ASSIGN expr", "term (PLUS term)*"
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)
return_typeNoParser only: Return type specification (e.g., "String value", "int result")
insert_afterNoOptional: Insert this rule immediately after the specified rule name. Overrides alphabetical sorting.
insert_beforeNoOptional: Insert this rule immediately before the specified rule name. Overrides alphabetical sorting.
write_to_fileNoIf true, writes modified grammar back to from_file (requires from_file to be set)
grammar_contentNoThe ANTLR4 grammar file content
Behavior5/5

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

With no annotations, the description carries full burden and excels: it discloses automatic type detection, default alphabetical sorting, custom positioning with insert_after/insert_before, duplicate prevention, optional file persistence, diff output mode, and return behavior. This goes far beyond a generic action statement.

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 a core summary, examples, and feature list. However, the Features section partially repeats the examples and the examples are numerous, making it longer than strictly necessary. Still, the content is valuable and front-loaded with the primary purpose.

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?

For a 13-parameter tool with no output schema, the description is remarkably complete: it covers return values, output modes, all parameter categories, file persistence, and provides a variety of examples covering lexer, parser, fragment, skip, channel, positioning, and return types. It leaves no major ambiguity.

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

Parameters5/5

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

Although schema coverage is 100%, the description adds substantial practical meaning by explaining naming conventions for rule_name, giving per-parameter examples (skip, channel, fragment, return_type, positioning), and illustrating lexer vs parser usage. This transforms abstract schema fields into actionable guidance.

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 clearly states 'Add a new lexer or parser rule with automatic type detection and positioning.' The verb 'Add' plus resource 'lexer or parser rule' makes purpose explicit, and the auto-detection and positioning details distinguish it from specialized siblings like add-parser-rules and add-rule-to-mode.

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?

Includes an explicit 'When to use' section: 'Add any rule to your grammar - lexer tokens or parser rules.' This provides clear context but does not mention alternatives or cases where specialized tools like add-parser-rules should be preferred, so it lacks explicit when-not guidance.

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