Skip to main content
Glama
natl-set

ANTLR4 MCP Server

by natl-set

analyze-grammar

Extract the complete structure of ANTLR4 grammar files, including rules, dependencies, imports, and validation issues. Supports multi-file grammars with automatic import resolution.

Instructions

Analyze an ANTLR4 grammar file and extract its complete structure.

When to use: First step when exploring an unfamiliar grammar, understanding architecture, or extracting metadata.

Multi-file support: Set load_imports=true to automatically resolve and analyze imported grammars.

Example usage: from_file: "examples/MyGrammar.g4"

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

Returns:

  • Grammar name and type (parser/lexer/combined)

  • All parser rules with definitions and line numbers

  • All lexer rules with patterns

  • Rule references and dependencies (which rules reference which)

  • Import declarations

  • Grammar options

  • Validation issues (undefined rules, unused rules, recursion)

  • With load_imports=true: Includes rules from all imported grammars

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_pathNoOptional: base directory for resolving imports. Defaults to directory of from_file.
from_fileNoOptional: path to a grammar file to read (overrides grammar_content). Recommended for file-based workflows.
load_importsNoOptional: if true, automatically load and merge imported grammars. Default: true.
summary_onlyNoOptional: if true, returns only summary statistics without full rule details. Default: false. Use this for large multi-file grammars.
grammar_contentNoThe content of the ANTLR4 grammar file
Behavior4/5

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

Since annotations are not provided, the description carries the full burden of behavioral transparency. It details the return types such as 'All parser rules with definitions and line numbers' and 'Validation issues,' and explicitly describes the effect of load_imports on merging rules. It does not mention any side effects or error behavior, but for a read-only analysis tool this is sufficient – no contradictions.

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 structured in sections (goal, when to use, multi-file support, examples, returns) and is front-loaded with the core purpose. It is somewhat lengthy but each section contains useful information; the returns list is particularly informative. It earns a 4 rather than 5 because it could be tightened without losing meaning.

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?

With no output schema, the description compensates by enumerating the categories of results (grammar name/type, parser rules, lexer rules, references, imports, options, validation issues) and noting behavioral flags like load_imports. It also provides concrete example usage for file-based and multi-file workflows. However, it does not specify the exact output structure (e.g., field names), leaving some ambiguity for the agent, so a 4 is appropriate.

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%, with all five parameters already documented in the schema. The description adds an example of using from_file and base_path together and notes that load_imports=true resolves imported grammars, but this does not go beyond the schema's explanation of 'automatically load and merge imported grammars.' Thus it provides only marginal additional value.

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 it 'Analyze an ANTLR4 grammar file and extract its complete structure,' using a specific verb and resource. It further distinguishes itself as the 'First step when exploring an unfamiliar grammar,' which sets it apart from siblings like list-rules or validate-grammar by emphasizing complete structural extraction.

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 'When to use' section explicitly positions this as the first step for exploring unfamiliar grammars, understanding architecture, or extracting metadata. However, it does not name specific alternative tools or exclusion conditions, so it lacks explicit when-not-to-use guidance, making it clear context but no exclusions.

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