Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

test-parser-rule

Test if input text matches an ANTLR4 parser rule, providing match result, parse tree, and errors. Uses native runtime, falls back to simulation if unavailable.

Instructions

Test if input text matches a specific parser rule. Now with native ANTLR4 support!

πŸš€ Native ANTLR4 Support: Automatically uses native ANTLR4 runtime if available for 100% accurate parsing including:

  • βœ… Lexer modes (pushMode, popMode)

  • βœ… Semantic predicates ({...?})

  • βœ… Actions ({...})

  • βœ… All complex parser patterns

  • βœ… Multi-file grammars with imports

Falls back to simulation if ANTLR4 is not installed.

When to use:

  • Rapid iteration on rule syntax during development

  • Verify if text matches a parser rule structure

  • Test rules with complex features (modes, predicates)

  • Test rules that reference imported tokens/rules

  • Debug parsing issues in complex grammars

Setup for 100% accuracy (optional):

  1. Install Java: brew install openjdk

  2. Install ANTLR4: wget https://www.antlr.org/download/antlr-4.13.1-complete.jar

  3. Set env: export ANTLR4_JAR=/path/to/antlr-4.13.1-complete.jar

How it works:

  • Native mode: Compiles and executes actual ANTLR4 parser (100% accurate)

  • Simulation mode: Best-effort matching (~70-90% accuracy)

Example - Test expression rule: rule_name: "expression" input: "x + y * 2"

Example - Test with multi-file grammar: from_file: "/path/to/MyParser.g4" base_path: "/path/to/grammar/dir" load_imports: true rule_name: "expression" input: "x + y"

Example - Show parse tree: rule_name: "statement" input: "if (x) y = 1;" show_tree: true

Returns:

  • Match result (βœ… matches or ❌ doesn't match)

  • Parse tree (if show_tree enabled)

  • Parse errors with line/column information

  • Mode indicator (πŸš€ Native or ⚠️ Simulation)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputYesInput text to test against the rule
base_pathNoOptional: base directory for resolving imports and tokenVocab. Required for multi-file grammars.
from_fileNoOptional: path to a grammar file to read
rule_nameYesName of the parser rule to test (e.g., "expression", "statement")
show_treeNoOptional: if true, displays the parse tree (native mode only). Default: false.
load_importsNoOptional: if true, automatically load imported grammars and lexer vocabulary. Default: true.
grammar_contentNoThe ANTLR4 grammar file content
Behavior5/5

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

With no annotations provided, the description fully carries the transparency burden. It discloses the native ANTLR4 vs. simulation fallback, accuracy differences (100% vs. 70-90%), optional setup requirements (Java, ANTLR4 jar), and the return payload (match result, parse tree, errors, mode indicator). This goes well beyond the schema and gives the agent critical behavioral context.

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 longer than average, but it is well-structured with headings, bullet points, and examples. The main purpose is front-loaded. Some content, like the setup instructions and feature list, could be trimmed or moved to a help page, but given the tool's complexity, the length is mostly justified and scannable.

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?

The description covers the tool's purpose, usage scenarios, mode behavior, setup, examples, and return values. It is nearly complete for a tool with 7 parameters and no output schema. However, it does not clarify where the grammar comes from when neither from_file nor grammar_content is providedβ€”it only shows usage with rule_name/input alone, implying a default grammar context that is not explicitly explained.

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%, so the baseline is 3. The description adds value by including examples that show how parameters like from_file, base_path, load_imports, and show_tree work together in realistic scenarios, such as multi-file grammars. While it does not elaborate on grammar_content beyond the schema, the examples clarify parameter relationships and edge cases.

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 clear, specific statement: 'Test if input text matches a specific parser rule.' This uses a precise verb+resource structure and immediately distinguishes the tool from siblings like validate-grammar or compile-grammar. The rest of the description reinforces this purpose with detailed feature explanations and examples.

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?

An explicit 'When to use:' section lists concrete scenarios such as rapid iteration, verifying text structure, and testing complex features like modes or predicates. It also explains the native vs. simulation mode tradeoff, which helps set expectations. However, it does not explicitly mention when NOT to use this tool or name alternative sibling tools, so it stops 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