Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

add-rule-to-mode

Add a lexer rule to a specific mode in an ANTLR4 grammar, enabling tokens for that lexical context and ensuring correct placement.

Instructions

Add a lexer rule to a specific mode in an ANTLR4 grammar.

When to use: Adding tokens that only apply in specific lexical contexts.

Features:

  • Places rule in the correct mode section

  • Validates mode exists

  • Supports all lexer rule options (skip, channel, fragment)

  • Auto-sorts within the mode

Example - Add rule to STRING_MODE: rule_name: "INTERPOLATION_START" pattern: "\{" mode_name: "STRING_MODE" write_to_file: true

Example - Add with pushMode action: rule_name: "INTERPOLATION_START" pattern: "\{" mode_name: "STRING_MODE" action: "pushMode(EXPRESSION_MODE)" write_to_file: true

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
skipNoIf true, adds "-> skip" directive
actionNoLexer action (e.g., "pushMode(MODE)", "popMode", "type(TYPE)")
channelNoChannel name to route tokens
patternYesThe lexer pattern
fragmentNoIf true, marks rule as fragment
from_fileNoOptional: path to a grammar file to read. Required if using write_to_file.
mode_nameYesName of the mode to add the rule to
rule_nameYesName of the lexer rule (UPPER_CASE)
output_modeNoOutput format: "full", "diff", or "none"
write_to_fileNoIf true, writes modified grammar back to from_file
grammar_contentNoThe ANTLR4 grammar file content
Behavior4/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 discloses useful behaviors: places rule in correct mode, validates mode exists, supports all lexer rule options, and auto-sorts within the mode. It also shows example usages with action. It does not mention potential error behavior or return format, but the key behavioral traits are covered.

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 clear opening statement, a 'When to use' section, a bulleted feature list, and two illustrative examples. It is not overly verbose, and the front-loaded purpose makes it easy to grasp quickly. The examples add useful detail but could be seen as slightly redundant.

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

Completeness4/5

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

Given the complexity of the tool (11 parameters, no annotations, no output schema), the description does a good job of covering the essential usage context. It explains what the tool does, when to use it, and provides examples. It doesn't fully explain edge cases like the relationship between from_file and grammar_content, or the meaning of output_mode, but the schema covers these and the description is reasonably complete for practical use.

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?

The input schema already provides 100% coverage of parameter descriptions, so the baseline is 3. The description adds value by providing concrete examples that show how rule_name, pattern, mode_name, action, and write_to_file are used together. This clarifies the intended semantics beyond individual schema 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 clearly states the tool's purpose: 'Add a lexer rule to a specific mode in an ANTLR4 grammar.' It uses a specific verb (add) and resource (lexer rule to a mode), and this distinguishes it from siblings like add-rule (general) and move-rule-to-mode (moving existing rules).

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 a 'When to use' section: 'Adding tokens that only apply in specific lexical contexts.' This gives clear guidance on when this tool is appropriate, and the examples illustrate usage. It doesn't explicitly state when not to use it or mention alternatives, but the context strongly implies it's for mode-specific rules rather than global rules.

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