ANTLR4 MCP Server
MCP server enabling AI assistants to help with ANTLR4 grammar development.
Quick Start
Docker (Recommended)
docker pull sshailabh1/antlr4-mcp-server:latest
Configure your MCP client:
{
"mcpServers": {
"antlr4": {
"command": "docker",
"args": ["run", "-i", "--rm", "sshailabh1/antlr4-mcp-server:latest"]
}
}
}
Build from Source
./mvnw clean package -DskipTests
{
"mcpServers": {
"antlr4": {
"command": "java",
"args": ["-jar", "/path/to/antlr4-mcp-server-0.2.0.jar"]
}
}
}
Tools
| Tool | Purpose |
|---|---|
validate_grammar | Syntax validation with error suggestions |
parse_sample | Parse input, return tree (interpreter mode) |
detect_ambiguity | Find parsing ambiguities |
analyze_left_recursion | Detect recursion patterns |
analyze_first_follow | Compute FIRST/FOLLOW sets |
analyze_call_graph | Rule dependencies, cycles, unused rules |
visualize_atn | ATN state diagrams (DOT/Mermaid) |
compile_grammar_multi_target | Generate parsers (10 languages) |
profile_grammar | Performance profiling |
Usage Example
Validate and parse "2 + 3 * 4":
grammar Calc;
expr: expr ('*'|'/') expr | expr ('+'|'-') expr | NUMBER ;
NUMBER: [0-9]+ ;
WS: [ \t\r\n]+ -> skip ;
Target Languages
Java, Python, JavaScript, TypeScript, C++, C#, Go, Swift, PHP, Dart
Documentation
| Document | Purpose |
|---|---|
| Quick Start | Setup in 5 minutes |
| Tool Usage | Complete tool reference |
| Development | Build, test, contribute |
| Examples | Calculator, JSON grammars |
Constraints
| Constraint | Value |
|---|---|
| Max grammar size | 10 MB |
| Max input size | 1 MB |
| Timeout | 30 seconds |
| Imports | Not supported (inline all rules) |
License
Apache License 2.0