Skip to main content
Glama
graph-mcp-java-gen

graph-mcp-java-gen

graph-mcp-java-gen

CI Python Evidence License MCP Neo4j

Graph-gestützter MCP-Server, der natürlichsprachliche Anfragen in validierte, kompilierbare Java-Testmethoden umwandelt – keine halluzinierten Importe, keine unverankerten Symbole, keine lautlosen Fehler.

Eine natürlichsprachliche oder strukturierte Anfrage gelangt in einen offiziellen Model Context Protocol (MCP)-Stdio-Server. Ein versionierter Graph-Katalog (Neo4j oder JSON-Fixture) liefert die einzigen Symbole, die der Generator zitieren darf. Ein mehrschichtiger Validator prüft Syntax, Framework-Vertrag, Grounding und Regeln für verbotene APIs, bevor irgendein Quellcode zurückgegeben wird. Zwei optionale LLM-Agenten – ein Intent-Normalisator und ein Post-Generierungs-Reviewer – erweitern die Pipeline um frei formulierte Eingaben, ohne die deterministische Sicherheitshülle zu beeinträchtigen.


Architektur

%%{init: {"theme": "base", "themeVariables": {"primaryColor": "#1e3a5f", "primaryTextColor": "#ffffff", "primaryBorderColor": "#0d2137", "lineColor": "#4a9eca", "secondaryColor": "#2d6a4f", "tertiaryColor": "#7b2d8b"}}}%%
flowchart TD
    classDef input    fill:#7b2d8b,stroke:#4a1a54,color:#fff,font-size:13px
    classDef mcp      fill:#e07b00,stroke:#9a5700,color:#fff,font-size:13px
    classDef agent    fill:#1a6b8a,stroke:#0d3f52,color:#fff,font-size:13px
    classDef core     fill:#2d6a4f,stroke:#1b4332,color:#fff,font-size:13px
    classDef graph    fill:#1e3a5f,stroke:#0d1f3c,color:#fff,font-size:13px
    classDef validate fill:#4a6741,stroke:#2d4026,color:#fff,font-size:13px
    classDef ok       fill:#155724,stroke:#0a3015,color:#fff,font-size:13px
    classDef reject   fill:#721c24,stroke:#3d0a0e,color:#fff,font-size:13px

    NL["🌎 Free-form NL\n(generate_java_test_nlp)"]:::input
    SF["📄 Structured fields\n(generate_java_test)"]:::input
    TX["💬 Intent text\n(generate_java_test_from_intent)"]:::input

    MCP["🔌 FastMCP stdio Server\n7 tools · zero raw Cypher"]:::mcp

    A1["🤖 LLMIntentParser\nAgent 1 · gpt-4o-mini\nfield extraction"]:::agent
    INT["✅ GenerationIntent\nclass · package · module\nconfig · version"]:::core
    GDB["📊 Graph Catalog\nNeo4j 5.26 / JSON fixture\n8 symbols · 12 methods"]:::graph
    GEN["⚙️ Template Generator\ndeterministic render"]:::core
    VAL["🛡️ JavaValidator\nTree-sitter AST\ncontract · grounding\nsource-safety"]:::validate
    A2["🤖 ReviewAgent\nAgent 2 · gpt-4o-mini\n6-item checklist"]:::agent

    OK["✅ Accepted Java\nsource + citations\n+ review verdict"]:::ok
    REJ["❌ Typed Rejection\nerror code + message\nno source returned"]:::reject

    NL --> MCP
    SF --> MCP
    TX --> MCP
    MCP -->|"NLP path"| A1
    MCP -->|"direct path"| INT
    A1 -->|"extracted fields"| INT
    INT -->|"invalid"| REJ
    INT -->|"valid"| GDB
    GDB -->|"cited symbols"| GEN
    GEN --> VAL
    VAL -->|"any gate fails"| REJ
    VAL -->|"all gates pass"| A2
    A2 -->|"issues found"| REJ
    A2 -->|"approved"| OK

Related MCP server: MCP Universal Test Suite Generator

Multi-Agenten-Pipeline

%%{init: {"theme": "base", "themeVariables": {"actorBkg": "#1e3a5f", "actorTextColor": "#ffffff", "actorBorderColor": "#4a9eca", "activationBkgColor": "#2d6a4f", "activationBorderColor": "#155724", "noteBkgColor": "#fff8e1", "noteTextColor": "#333", "signalColor": "#4a9eca", "signalTextColor": "#1e3a5f"}}}%%
sequenceDiagram
    autonumber
    actor User
    participant MCP as FastMCP Server
    participant A1  as LLMIntentParser<br/>(Agent 1)
    participant GDB as Graph Catalog<br/>(Neo4j / Fixture)
    participant GEN as Generator +<br/>JavaValidator
    participant A2  as ReviewAgent<br/>(Agent 2)

    User->>MCP: generate_java_test_nlp(free-form NL)
    MCP->>A1: extract intent fields
    Note over A1: gpt-4o-mini · temp=0<br/>strict JSON schema
    A1-->>MCP: {class, package, module, config, version}
    MCP->>GDB: get versioned symbols
    GDB-->>MCP: 7 cited GraphSymbol objects
    MCP->>GEN: render Java + validate
    Note over GEN: Tree-sitter AST<br/>contract · grounding · safety
    GEN-->>MCP: validated Java source
    MCP->>A2: review(source, class, package)
    Note over A2: gpt-4o-mini · temp=0<br/>6-item checklist
    A2-->>MCP: {approved, checklist, issues}
    MCP-->>User: {status, source, citations, review}

Evidenz-Dashboard

Alle Messungen verwenden unabhängig generierte, CC0-lizenzierte synthetische Fixtures. Die Ergebnisse stammen aus der akzeptierten strict_graph_v2-Policy auf dem zurückgehaltenen Bestätigungs-Split.

Messgröße

Ergebnis

Artefakt

Benchmark-Umfang

96 CC0-Intents — 32 Dev / 32 Val / 32 Bestätigung

task_evaluation.json

Erfolg der Bestätigungsaufgaben

32 / 32 begrenzte Aufgaben

evaluation_trace.json

Validierung generierter Quellen

24 / 24 unterstützte Intents — Syntax + Vertrag + Grounding + Sicherheit

task_evaluation.json

Sichere adversarial-Ablehnung

8 / 8 — keine falsch akzeptierten Fälle

task_evaluation.json

Zitat-Präzision

100 % — nur aus dem Graph zitierte Symbole werden importiert

task_evaluation.json

Trefferquote erforderlicher Symbole

100 % — jedes erforderliche Symbol ist vorhanden

task_evaluation.json

Live-Neo4j-Integration

Neo4j 5.26.29 — 8 Symbole, 12 Methoden materialisiert

neo4j_integration.json

Offizieller MCP-Benchmark

120 / 120 erwartete Ergebnisse — keine Protokollfehler

mcp_benchmark.json

MCP-Arm-Latenz (p50 / p95 / p99)

29,13 / 48,61 / 54,23 ms bei Nebenläufigkeit 1

mcp_benchmark.json

Java-Kompilierung

8 / 8 Klassendateien über Eclipse ECJ 3.21

java_compile.json

Externe Modellaufrufe (deterministischer Pfad)

0 Aufrufe · $0,00

mcp_benchmark.json

Die Latenzwerte sind Messungen eines einzelnen lokalen Windows-Prozesses und keine Produktions-SLOs.


Policy-Auswahl

Es wurden vier Generierungs-Policys evaluiert. Das Auswahlziel wurde vor dem Öffnen des Bestätigungs-Splits bekannt gegeben: den Validierungserfolg unter den Kandidaten maximieren, die alle Sicherheitsgates bestehen. Der Bestätigungs-Split wurde genau einmal für den ausgewählt Kandidaten geöffnet.

%%{init: {"theme": "base", "themeVariables": {"quadrant1Fill": "#155724", "quadrant2Fill": "#856404", "quadrant3Fill": "#721c24", "quadrant4Fill": "#856404"}}}%%
xychart-beta
    title "Validation: task success vs safe-rejection recall (%)"
    x-axis ["no_graph_v0", "lenient_repair_v1", "strict_graph_v2 ✓", "wide_context_v3"]
    y-axis "Task success (%)" 0 --> 105
    bar  [21.9, 75.0, 100.0, 96.9]
    line [87.5,  0.0, 100.0, 87.5]

Kandidat

Aufgabe-Erfolg

Gen valideiert

Sicherhe Ablehnung

Zitat-Präzision

Entscheidung

no_graph_v0

21, 9%

0%

8%,5%

0%

Ko-Abonierung - Keine Verankerung

lenient_repair_v1

75,0%

100%

0%

100%

Abgelehnt – 8 falsch akzeptierte Fälle

strict_graph_v2

100%

100%

100%

100%

Ausgewählt

wide_context_v3

96, 9%

100%

6,2 / 5 %

87,5%

Abgelehnt – irrelevant e Kontexte + 1 falsch akzeptiert


MCP-Tools

Tool

Typ

Verhalten

get_fixture_metadata

Lesen

Gibt Fixture-Identität, Herkunft, Lizenz, Backend und Symbolanzahl terug

search_grah

Lesen

Parametrisierte Nam-en-/Methodensuche; maximal 20 Entscheidungen

generate_java_test

Erzeugen

Typisierte Felder → Graph-Suche → Java → alle Valiergates

generate_Java_test_from_intent

Erzeugen

Eingeschrenkte 3-Orme-Grammatik → dieselbe strenge Rchtlinie

valdate_ja_source

Valisierung

Prüft bis zu 20.000 Zeichen; schreib und fürt nie Quellcode

generate_ja_test_np

Multi-Agent

LLM-Intent-Parser → Gen-ator → LLM-Review; erfordert OPENAI_API_Key

Der Ne4j-Adapt verendet fester parametrisierte Cypher, weiget Zugan in daten in URIs zurück und weut Auye-Identitäkollisionen bestätigt.


Schnellstart

python -m venv .venv
# Windows
.\.venv\Scripts\Activate.ps1
# Linux / macOS
source .venv/bin/activate

pip install -r requirements-dev.txt
pip install --no-deps -e .

# Run the offline smoke test (no database needed)
python scripts/container_smoke.py python -m graph_mcp.server

MCP-Client-Konfiguration (VS Code / Claude Desktop)

{
  "mcpServers": {
    "graph-java-gen": {
      "command": "/absolute/path/to/.venv/bin/python",
      "args": ["-m", "graph_mcp.server"],
      "cwd": "/absolute/path/to/repo"
    }
  }
}

Das Multi-Agenten-NLP-Tool aktivier

# Add to your environment or .env file
OPENAI_API_KEY=sk-...
GRAPH_BACKEND=neo4j   # optional; defaults to local JSON fixture

Evidenz reproduktion

# Build the CC0 benchmark fixture
python scripts/build_evaluation_fixture.py

# Run all four candidate policies and select strict_graph_v2
python scripts/evaluate_workflow.py

# Validate the claims ledger and evidence privacy rules
python scripts/validate_evidence.py

# Full test suite
pytest --cov=src --cov-report=term-missing --cov-fail-under=75

# Lint and security
ruff check src tests scripts
bandit -r src scripts -q -ll
pip-audit -r requirements.txt --progress-spinner off

Live-Ne4j-Pfad

# Start a local Neo4j Community instance (Docker)
docker compose up -d neo4j
python scripts/wait_for_neo4j.py

# Seed the synthetic graph fixture and verify retrieval
python scripts/seed_graph.py
python scripts/verify_neo4j.py   # writes evidence/neo4j_integration.json

# Full MCP benchmark over stdio with live graph
python scripts/benchmark_mcp.py  # writes evidence/mcp_benchmark.json

Ja-Kompilierung

# Requires JDK 21 on PATH
python scripts/compile_generated.py --require-compiler
# Writes evidence/java_compile.json

Sicherheitsdesign

  • Kein Roh-Cypher auf der MCP-Oberfläche – alle Graph-Abfragen sind parametrisiert.

  • Strenge Feld-Allowlists – Klassen-, Paket-, Modulname, Versionen und Config-Pfade werden vor jeder Graphen-Abfrage gegen kompilierte Regex-Muster geprüft.

  • Quellcode-Sicherheitsscanner – generierter Java-Code wird abgelehnt, wenn er Runtime.getRuntime, ProcessBuilder, System.exit, java.io, java.nio.file oder java.net referenziert.

  • Schutz vor Path-Traversal – absolute Pfade und ..-Segmente werden in Config-Pfadfelden abgelehnt.

  • Grounding-Erzwingung – jeder Import im generierten Code muss einem für genau diese Version aus dem Graph abgerufenen Sympoln entsprechen.

  • LLM-Ausgabe neu validiert – die vom LLM-Intent-Paser extrahierten Felder durchaufe dieselbe GenerationIntent.from_mapping()-Validierung wie direkte API-Aufrufe.

  • Neo4j-Anmeldedaten – werden ausschließlich aus Umgebungsvariablen geladen, nie protokollier und nie in Evidenz-Artefakten zurückgegeben.

  • XML-Preflight – defusedxml verhindert Entity-Expansion-Angriffe beim Scannen der Projektsruktur.

  • Container – gepinntes Chainguard-Linux-Image, nicht-Root-UID/GID 65532, CI führt einen MCP-über-Container-Stdio-Smoke-Test aus.

Siehe SECURITY.md für die vollständige Bedrohungsgrenze.


Repository-Übersicht

src/graph_mcp/
  workflow.py            intent parsing · graph lookup · Java generation · validation
  graph_store.py         Neo4j catalog adapter (parameterised Cypher)
  llm_intent_parser.py   Agent 1 — LLM free-form NL → GenerationIntent
  review_agent.py        Agent 2 — LLM post-generation checklist reviewer
  server.py              FastMCP stdio server (7 tools)
  evaluation.py          candidate scoring and selection harness

fixtures/
  synthetic_graph.json   CC0 versioned framework symbol catalog (SHA-256 bound)
  evaluation_cases.json  96 CC0 natural-language intents (32/32/32 split)
  java_framework/        7 independently generated Java stub classes

evidence/
  claims.json            machine-readable claims ledger (14 public claims)
  evaluation_protocol.json  pre-declared selection rules and safety gates
  task_evaluation.json   per-candidate, per-split, per-case results
  evaluation_trace.json  confirmation case-level trace
  neo4j_integration.json live Neo4j integration result
  mcp_benchmark.json     MCP protocol benchmark (120 calls)
  java_compile.json      ECJ compilation result

scripts/
  build_evaluation_fixture.py   generate benchmark from seed
  evaluate_workflow.py          run and score all four candidates
  validate_evidence.py          verify claims ledger and privacy rules
  benchmark_mcp.py              official MCP stdio latency benchmark
  verify_neo4j.py               live graph integration check
  compile_generated.py          ECJ compile gate
  seed_graph.py                 materialise fixture into Neo4j

tests/
  test_generation_loop.py       generation + validation unit tests
  test_graph_store.py           Neo4j adapter unit tests
  test_mcp_protocol.py          official MCP protocol conformance
  test_evaluation.py            evaluation harness tests
  test_evidence.py              claims ledger integrity tests
  test_neo4j_live.py            opt-in live graph tests (NEO4J_* env required)

docs/
  ARCHITECTURE.md        component design and data flow
  POLICY_CARD.md         candidate selection details
  DATA_CARD.md           fixture provenance and license
  MCP_INTEGRATION.md     client configuration guide
  DEPLOYMENT.md          Docker and container notes

templates/               MCP prompt templates for VS Code Copilot
examples/                sample project preflight scanner

Abgrenzungen

Das folgende wird von diesem Repository nicht beansprucht:

  • Freie formulierbares, modellversions-unabhängiges Intent-Parsing – die LLM-Pipeline ist opt-in und ihre Ergebnise sind in den eingefroren Evaluktions-Artefakten nicht erfasst.

  • Kompatibilität mit einem beliebigen proprietären ofiellen Java-Test- Framework.

  • Produktions-latenz-SLO – alle Enzeler are Ergebnisse lokale sequentielle Benchmarks eines einzigen Prozesses.

  • Paralleler, verteilter oder Hochverfügbark- Betreib.

  • Automatische Ausführu ng generierten Java gegen Hardware oder ein Zustest instrument.

  • Ein Produktivitäts-, Kosten-, Ertrags- oder Testzeit-Vorteil – dieses Reository ensthält nur Gen- und Validierungs-Evidenz.

Die vollständige maschienenlesbare Abgenzung befindet sich in evidence/claims.json.


Lizenz

Rpository-Code: MIT. Graph-Fixture, Test-Intents und Ja-a-Stubs: CC0-1.0 (in der Fixture-Metadaten als solche gekennzeichnet).

Available Tools

6 tools
generate_java_testD

Generate Java only when graph grounding, syntax, contract, and safety pass.

Inputs: class_name (required), config_path (required), module_name (required), package_name (required), +1 more. Returns: object

generate_java_test_from_intentC

Parse a bounded natural-language request, generate Java, and enforce all gates.

Inputs: request (required). Returns: object

generate_java_test_nlpB

Multi-agent pipeline: LLM parses free-form NL, generates Java, LLM reviews it.

Agent 1 (LLMIntentParser) normalises natural language to a structured intent. The deterministic generator produces graph-cited, validated Java source. Agent 2 (ReviewAgent) audits the result against a six-item checklist. Requires OPENAI_API_KEY in the environment.

Inputs: request (required). Returns: object

get_fixture_metadataA

Return provenance and version information for the active graph fixture.

Inputs: no named parameters. Returns: object

search_graphB

Search the bounded synthetic graph by class, qualified name, or method.

Inputs: query (required), limit, version. Returns: object

validate_java_sourceC

Validate bounded Java source against syntax, graph, contract, and safety gates.

Inputs: source (required), class_name (required), config_path (required), module_name (required), +2 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 6 tools

    Disambiguation4/5

    The tools are mostly distinct: metadata retrieval, graph search, three variations of Java test generation, and validation. The three generate_java_test* tools could be confused, but their descriptions clearly differentiate by input type (structured, bounded NL, free-form NL with review). Minor overlap exists but descriptions resolve ambiguity.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern in snake_case: get_fixture_metadata, search_graph, generate_java_test, generate_java_test_from_intent, generate_java_test_nlp, validate_java_source. The naming is predictable and uniform throughout the set.

    Tool Count5/5

    With 6 tools, the server is well-scoped for its purpose of generating and validating Java tests from a synthetic graph. Each tool serves a clear role in the workflow, and the count feels appropriate—not too few to be inadequate, not too many to be unwieldy.

    Completeness5/5

    The tool surface covers the full lifecycle: metadata retrieval, graph search for grounding, three generation pathways (including NL-based variants), and validation. There are no obvious missing operations for the stated purpose; the server provides a complete pipeline from context gathering to output validation.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers