jflap
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@jflap simulate examples/contains_ab_nfa.jff on the strings ab, aabb, bab, and bba"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
JFLAP 7.1 CLI & Model Context Protocol (MCP) Server
A complete, production-grade command-line interface and Model Context Protocol (MCP) server for controlling and automating JFLAP 7.1 (JFLAP7.1.jar).
Standard JFLAP is a legacy Java Swing application without native command-line or headless automation support. This repository bridges directly into JFLAP's internal classes (file.XMLCodec, automata.*, grammar.*) to provide fast, robust, headless execution, simulation, conversion, batch testing, and AI-driven control without popping up Swing dialogs.
Table of Contents
Related MCP server: Fieldkit
Highlights
⚡ Headless Execution: Fast simulation of DFAs, NFAs, Pushdown Automata (PDA), Turing Machines (single and multi-tape), Mealy, and Moore machines.
🔬 Formal Language Transformations:
NFA $\rightarrow$ DFA conversion (
nfa-to-dfa)DFA minimization to canonical states (
minimize)Language Equivalence checking (
equals) using minimization & isomorphism algorithmsFSA to Regular Expression extraction (
convert fsa-to-re)Combine multiple automata into composite machines (
fsa combine)
📝 Grammar Parsing & Transformation:
FIRST and FOLLOW set computation with LL(1) parseability checking (
grammar first-follow)CYK Parser for Chomsky Normal Form (CNF) with derivation tracing
Brute-Force derivation parser
Production cleaner (eliminates $\lambda$/$\epsilon$, unit, and useless rules)
🌿 L-System (Lindenmayer System) Engine:
Deterministic and stochastic parallel rewriting string expansion at arbitrary derivation depth (
lsystem expand)
🔄 Cross-Model Conversions:
FSA $\rightarrow$ Regular Expression
FSA $\leftrightarrow$ Regular Grammar (Right-Linear)
CFG $\rightarrow$ Pushdown Automaton (LL / LR)
PDA $\rightarrow$ Context-Free Grammar (CFG)
🛠️ Programmatic Model Builder: Create valid JFLAP
.jffXML files via CLI flags or JSON definitions.📊 Graphviz Export: Export any automaton to standard Graphviz
.dotformat.🤖 Native MCP Server: Ready-to-use Model Context Protocol server exposing 10 tools to Claude Desktop, Antigravity, Cursor, and other agentic systems.
Quick Start
1. Requirements
Java: JRE/JDK 8 or higher (
java -version).Python: Python 3.8 or higher (
python --version).
2. Installation
Clone the repository:
git clone https://github.com/MatMridul/jflap-cli.git
cd jflap-cliOptional: Install as a Python package to put jflap on your PATH:
pip install -e .Note: On first run, jflap will automatically compile the Java bridge (JFLAPBridge.java) if .class files are missing.
CLI Command Overview
Run commands with jflap (or python jflap_cli.py):
Model Inspection
jflap inspect examples/contains_ab_nfa.jffOutputs an ASCII table showing state coordinates, initial/final flags, transition rules, and determinism.
Batch Simulation
jflap simulate examples/contains_ab_nfa.jff ab aabb bab bba xyzOutputs:
Simulation Results for: contains_ab_nfa.jff
Input String | Result
-------------+---------
'ab' | ACCEPTED
'aabb' | ACCEPTED
'bab' | ACCEPTED
'bba' | REJECTED
'xyz' | REJECTEDExecution Tracing (PDA / Turing Machine)
# Step-by-step trace showing stack evolution on a Pushdown Automaton
jflap trace examples/an_bn_pda.jff aabb
# Step-by-step trace showing tape transformations on a Turing Machine
jflap trace examples/an_bn_cn_turing.jff abcEquivalence Testing
Formally prove whether a student's submission or alternative machine accepts the exact same language:
jflap fsa equals examples/contains_ab_nfa.jff examples/contains_ab_min_dfa.jff
# Result: The two automata ARE EQUIVALENT (accept the exact same language).Conversions & Regular Expressions
# Convert NFA to DFA
jflap fsa nfa-to-dfa examples/contains_ab_nfa.jff dfa.jff
# Minimize DFA
jflap fsa minimize dfa.jff min_dfa.jff
# Extract Regular Expression from FSA
jflap convert fsa-to-re examples/contains_ab_dfa.jff
# Output: Regular Expression: b*(aa*bb*+aa*bb*a(a+bb*a)*(?+bb*))
# Combine Two Automata into One
jflap fsa combine dfa1.jff dfa2.jff combined.jff
# Convert CFG to PDA (LL Mode)
jflap convert cfg-to-pda examples/an_bn_cfg.jff pda.jff --mode ll
# Convert Regular Grammar to FSA
jflap convert rg-to-fsa examples/regular_grammar_ab.jff fsa.jffGrammar Parsing & FIRST / FOLLOW Sets
# Parse string with CYK or Brute-Force
jflap grammar parse examples/regular_grammar_ab.jff aab
# Compute FIRST & FOLLOW Sets and test LL(1) parseability
jflap grammar first-follow examples/an_bn_cfg.jffL-System Expansion
# Expand L-System to level 4
jflap lsystem expand examples/fibonacci_lsystem.jff 4
# Output: ABAABABA (length 8)Graphviz DOT Export
jflap dot examples/contains_ab_min_dfa.jff -o machine.dotProgrammatic Creation
# Create an FSA directly
jflap create fa --states q0,q1,q2 --initial q0 --finals q2 --transitions "q0,q1,0; q1,q2,1; q2,q2,0,1" -o parity.jff
# Or build from a JSON definition
jflap create --from-json examples/sample_spec.json -o generated.jffOfficial GUI Window
# Launch the standard JFLAP 7.1 graphical desktop interface
jflap gui examples/contains_ab_min_dfa.jffModel Context Protocol (MCP) Integration
The built-in MCP server (jflap_mcp.py / jflap mcp) allows AI assistants and autonomous agents to inspect, simulate, convert, and construct automata models directly.
Quick Setup for AI Agents & Clients
1. Google Antigravity / Gemini CLI (~/.gemini/config/mcp_config.json)
{
"mcpServers": {
"jflap": {
"command": "python",
"args": ["<PATH_TO_REPO>/jflap_mcp.py"]
}
}
}2. Claude Desktop (claude_desktop_config.json)
{
"mcpServers": {
"jflap": {
"command": "python",
"args": ["<PATH_TO_REPO>/jflap_mcp.py"]
}
}
}3. Cursor IDE (.cursor/mcp.json or Settings > Features > MCP)
{
"mcpServers": {
"jflap": {
"command": "python",
"args": ["<PATH_TO_REPO>/jflap_mcp.py"]
}
}
}For Windsurf, Zed, and headless subagent shell execution, see the Agent Setup Guide.
Exposed MCP Tools
jflap_inspect: Inspect.jfffile structure, determinism, completeness, unreachable states, and dead states.jflap_simulate: Simulate input strings on any automaton with explicit PDA acceptance mode (final_stateorempty_stack).jflap_simulate_batch: High-performance batch simulation of hundreds or thousands of inputs in a single call.jflap_trace: Step-by-step configuration trace (state, stack, tape, accept verdict).jflap_export_table: Export a plain JSON transition table for DFA/NFA runtime executors.jflap_equivalence_check: Check language equivalence between two FSAs, returning shortest distinguishing string on mismatch.jflap_fsa_operation: NFA $\rightarrow$ DFA, minimization, language equivalence check, and automata combination (combine).jflap_grammar_operation: CYK / Brute-force grammar parsing, rule cleaning, and FIRST / FOLLOW set analysis (first_follow).jflap_convert_model: Cross-formalism conversion (FSA $\rightarrow$ RE, FSA $\leftrightarrow$ RG, CFG $\leftrightarrow$ PDA).jflap_lsystem_expand: Parallel L-System symbol rewriting and derivation to depth $n$.jflap_create_model: Programmatically build a.jfffile from JSON.jflap_export_dot: Export an automaton to Graphviz DOT.jflap_launch_gui: Open the model in the interactive JFLAP 7.1 desktop window.
See docs/MCP_SPECIFICATION.md for full schemas and sample payloads.
Performance & Latency Benchmarks
To meet the zero-latency safety requirements of build-time verification (such as the Chimeric Automaton verifier), the bridge features a warm, long-lived background JVM worker process communicating via line-delimited JSON over stdio pipes.
Measured Latency Comparison (Windows 11, Intel Core i7, warm JVM)
Mode | Calls / Inputs | Total Time | Latency per Call / Input | Speedup |
Spawn-per-call (previous baseline) | 10 calls | 2,743 ms | 274.3 ms (min 252.0ms, max 309.2ms) | 1.0x (baseline) |
Persistent JVM Bridge | 10 calls | 38.9 ms | 3.89 ms (min 1.83ms, max 6.66ms) | ~70x faster |
Batch Mode ( | 1,000 inputs | 628.71 ms | 0.628 ms per input | >400x faster |
All figures are directly measured using time.perf_counter() on the test automaton contains_ab_dfa.jff.
Documentation Index
AI Agent Setup Guide: Configuration instructions for Antigravity, Claude, Cursor, Windsurf, Zed, and subagents.
Architecture & Technical Design: How the Java headless bridge works and how Swing modal blocks were neutralized.
MCP Specification: Tool-by-tool JSON schema, request parameters, and response structures.
CLI Reference Manual: Comprehensive documentation of all subcommands, arguments, and flags.
Architecture & Quirks Resolved
Bypassing Embedded
JOptionPaneDialogs:In JFLAP's
PDAStepByStateSimulator, the constructor pops up a modal dialog asking whether to accept by "Final State" or "Empty Stack". We engineered aHeadlessPDASimulatorextendingAutomatonSimulatorthat operates silently without GUI requirements.In
TransducerFactory, single-tape Turing machines prompt a modal dialog asking whether to open as standard TM or Building Blocks. We preemptively detect Turing models in DOM and instantiateTMTransducerdirectly.
Explicit PDA Acceptance Modes:
PDA simulation evaluates strictly one acceptance criterion:
"final_state"(input consumed AND current state in $F$) or"empty_stack"(input consumed AND stack height is 0). Both criteria are never conflated into an unsound "either/or" check.
Infinite Loop Prevention:
Bounded BFS state exploration ensures that non-deterministic pushdown automata with $\lambda$-transitions or non-terminating Turing machines do not hang or exhaust system memory.
Automated On-Demand Build:
The CLI and MCP server automatically invoke
javacifJFLAPBridge.classis absent or older thanJFLAPBridge.java.
License & Legal Compliance
This repository maintains a clean, transparent license split:
CLI, MCP Server, Python Utilities & Java Bridge Wrappers:
Licensed under the open-source MIT License.
Copyright (c) 2026 Mridul Mathur. Free for commercial and non-commercial use, modification, and integration.
JFLAP 7.1 Upstream Binary & License (
third_party/jflap/):JFLAP 7.1 is academic software developed by Prof. Susan H. Rodger and student contributors at Duke University (https://www.jflap.org/).
Isolated cleanly in
third_party/jflap/JFLAP7.1.jar.Covered by the verbatim third_party/jflap/LICENSE-JFLAP:
Copyright (c) 2002–2009 Susan H. Rodger, Duke University. All rights reserved.
Key Terms:
The verbatim license text is bundled at
third_party/jflap/LICENSE-JFLAP.No fee may be charged for any product containing JFLAP in source or binary form.
Duke University and author names may not be used to endorse or promote derived products without prior written permission.
Available Tools
13 toolsjflap_convert_modelB
Perform cross-formalism conversion: FSA to Regular Expression ('fsa_to_re'), FSA to Regular Grammar ('fsa_to_rg'), Regular Grammar to FSA ('rg_to_fsa'), CFG to PDA ('cfg_to_pda'), or PDA to CFG ('pda_to_cfg').
Inputs: conversion (required), input_file (required), mode, output_file.
jflap_create_modelA
Programmatically generate a new JFLAP .jff file from a JSON model specification (Finite Automaton, PDA, Turing Machine, or Grammar).
Inputs: model (required), output_file (required).
jflap_equivalence_checkA
Verify language equivalence between two automata (modelA, modelB). Returns equivalent boolean, plus the shortest distinguishing string if they differ.
Inputs: modelA (required), modelB (required).
jflap_export_dotC
Export an automaton to Graphviz DOT format for rendering diagrams.
Inputs: file (required), output_file.
jflap_export_tableA
Export a plain JSON transition table (states, alphabet, start_state, accepting_states, transitions) for a DFA/NFA model. Returns a structured error for models that cannot be represented as finite state automata.
Inputs: model (required).
jflap_fsa_operationB
Perform Finite State Automata transformations: convert NFA to DFA ('nfa_to_dfa'), minimize a DFA ('minimize'), verify language equivalence between two FSAs ('equals'), or combine two automata into one ('combine').
Inputs: operation (required), input_file (required), file2, output_file.
jflap_grammar_operationA
Execute grammar operations in JFLAP: parse a string ('parse') using CYK or Brute-force parser, remove lambda, unit, and useless productions ('clean'), or compute FIRST and FOLLOW sets and test LL(1) parseability ('first_follow').
Inputs: file (required), operation (required), input, output_file.
jflap_inspectB
Inspect a JFLAP 7.1 (.jff) file. Returns structure metadata, states, initial/final states, transitions, determinism, or grammar productions.
Inputs: file (required).
jflap_launch_guiB
Launch the interactive JFLAP 7.1 graphical user interface (Swing desktop window), optionally opening a .jff file.
Inputs: file.
jflap_lsystem_expandC
Expand an L-System (Lindenmayer system) to a given recursion depth/level.
Inputs: file (required), level.
jflap_simulateA
Simulate one or more input strings on a JFLAP automaton (DFA, NFA, PDA, Turing Machine, Mealy, Moore). Returns accept/reject verdicts and output strings/final tapes. For PDAs, acceptance mode can be explicitly set to 'final_state' or 'empty_stack'.
Inputs: file (required), inputs (required), acceptance_mode.
jflap_simulate_batchA
High-performance batch simulation of hundreds or thousands of input strings on an automaton in a single call. Returns verdicts[] array.
Inputs: model (required), inputs (required), acceptance_mode.
jflap_traceB
Execute a step-by-step configuration trace of an input string on an automaton. Returns the exact trace of states, remaining input, stack contents (for PDA), or tape contents (for Turing machine). For PDAs, acceptance mode can be explicitly set to 'final_state' or 'empty_stack'.
Inputs: file (required), input, acceptance_mode.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Most tools map cleanly to distinct actions (inspect, create, simulate, trace, convert, export, launch GUI), and the single-vs-batch simulate pair is explicitly differentiated by scale. The main overlap is jflap_equivalence_check versus jflap_fsa_operation's 'equals' mode, which both verify language equivalence between automata.
Every tool uses the same jflap_ prefix followed by a snake_case verb_noun pattern (jflap_inspect, jflap_create_model, jflap_export_dot). The naming is predictable and readable throughout.
13 tools is well within a comfortable range for a domain with several automaton formalisms and operations. Each tool covers a meaningful capability (inspection, simulation, conversion, export, GUI launch) without redundancy bloat.
The surface covers the full lifecycle: create, inspect, simulate/trace, transform, convert between formalisms, export, and GUI launch. Minor gaps remain, such as editing/modifying an existing .jff model in place rather than only creating a new one.
Maintenance
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
JSON healing, O(n) ReDoS defense, XML prompt compilation, and schema verification tools.
AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.
Remote MCP: JSON repair, JSON Schema validation, JSON to TypeScript, CSV to JSON and JSON to CSV.
Related MCP Servers
- AlicenseAqualityDmaintenanceExposes the TLA+ toolchain (TLC, SANY, PlusCal, TLATeX) as structured JSON tools via the Model Context Protocol, enabling AI assistants to parse, check, simulate, and typeset TLA+ specifications.935 npm2MIT
- AlicenseBqualityBmaintenanceEnables a small local AI model to discover, describe, run, undo, and verify deterministic tools over JSON-RPC on stdio, with previews and approval gates for changes.10AGPL 3.0
- AlicenseNot gradedqualityCmaintenanceEnables AI coding agents to inspect and reverse-engineer large binaries through bounded stdio JSON-RPC 2.0 tools for graph queries, SSA facts, path solving, runtime grounding, and mod scaffolding.1AGPL 3.0
- AlicenseAqualityCmaintenanceEnables LLMs and AI coding assistants to programmatically create, rig, animate, import, and export stick figure animation projects through a headless StykAnimate-compatible model and MCP stdio transport.852 npmMIT