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

graph-mcp-java-gen

graph-mcp-java-gen

CI Python Evidence License MCP Neo4j

グラフ基盤で MCP サーバーが、自然言語のリクエスとを、検証済みでコンパイル可能な Java テスト・メソッドに変換します —— 幻想的なインポートなし、根拠のないシンボボルなし、暗厳の失敗なし。

自然言語または構造化されたリクエスとは、公式の Model Context Protocol (MCP) stdio サーバーに入ります。バージョン管理されたグラフ・カタログ(Neo4j まとは JSON フィクスチャ)が、ジェネレータが引用できる唯一のシンボルを提供します。多層バリアダは、ソースが返される前に、構文、フレームワーク契約、グラウンディング、禁APIの二則を検証します。2つのオプショナルな LLM エージェント —— インテント正規化器と生成後のレビュワ —— は、決定的な安全エンロープを損なわずに、パイプラインをフリーォーム入力にまで拡張します。


アーキテクチャ

%%{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

マルチーエージェント・パイプライン

%%{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}

エビデンス・ダッシュボード

すべての計測値は、独立に生成され、CC0ライセンスの合成フィクスチャを使用しています。 結果は、ホールドウト(held-out)の確認分割(confirmation split)における、採択された strict_graph_v2 ポリシーに基づきます。

| 表 | 結果 | アーティファクト | | :벤―――――: | :――――――: | :――――――: | | ベンーチマーク規模 | 96 件の CC0 インテント — 32 dev / 32 val / 32 確認 | task_evaluation.json | | 確認タスケ成功 | 32 / 32 の制約付きタス • 達成 | evaluation_trace.json | | 生成ソーリーの検証 | 24 / 24 のサポト対象インテント — 構文 + 契約 + グラウンディング + 安全性 | task_evaluation.json | | 安全な対応的拒否 | 8 / 8 — 誤受理ゼロ | task_evaluation.json | | 引用精度 | 100% — グラフで参照されたシンボボルのみインポート | task_evaluation.json | | 必須シンボル再ス | 100% — 必要とされるすべてのシンボボルが存在 | task_evaluation.json | | ランニイブ Neo4j 統合 | Neo4j 5.26.29 — 8 シンボボル、12 メソッドを一体素化 | neo4j_tegration.json | | 公式 MCP ベンーブーマーク | 120 / 120 の期待結果 — プロトコル・エラー 0 | mcp_benchark.json | | MCP ウオーム・レテンシ(p50 / p95 / p99) | 29.13 / 48.61 / 54.23 ms(コンカレンシー 1) | mcp_benchark.json | | Java コンパイル | 8 / 8 のクラスファイル(Eclipse ECJ 3.21) | java_compile.json | | 外部モデル呼び出し(決定的パス) | 0 回 · $0.00 | mcp_benchark.json |

レテンシの値は、単一プロセスでのローカル Windows 計測であり、本番の SLO ではありません。


ポリシー選ー

4つの生成ポリシーを評価しました。選択目標は、確認分割を開く前に前置しまた:すべての安全スゲートを通過する候補の中から、検証タスク成功率を最大化します。確認分割は、選された候補に対して一度だけ開かれました。

%%{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]

候補

タスク成功

生成物の妥当性

安全拒否

引用精度

決定

no_graph_v0

21.9%

0%

87.5%

0%

却下 — グラウンディング無し

lenient_repair_v1

75.0%

100%

0%

100%

却下 — 誤受理 8 件

strict_graph_v2

100%

100%

100%

100%

採用

wide_context_v3

96.9%

100%

87.5%

87.5%

却下 — 無関係な文脈 + 誤受理 1 件


MCP ツール

ツール

種別

動作

get_fixture_metadata

読み取り

フィクスチャの識別、プロ文ネンス、ライセンス、バックエンド、シンボブルの数を返します

search_graph

読み取り

名称/メソッドの条件付きおり、最大 20 件

generate_java_test

生成

型付きフィールド → グラフ照合 → 検証済み Java → すべての検証ゲート

generate_java_test_from_intend

生成

有界 3 形式文法 → 同二の厳密ポリシー

validate_java_source

検証

最大 20 000 文字をチェック;ソースの書込み・実行を一切しません

generate_java_test_nlp

マルチーエージェント

意味解析 → 生成 → 検証;OPENAI_API_KEY が必要

Neo4j アダプタは、固定のパラメータ化 Cypher を使用し、URI 内の認証情報を却否し、フィクスチャ識別の衝突を排除します。


クイックスタート

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 クライアント設定(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"
    }
  }
}

マルチーエージェント NLP ツールの有効化

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

エビデンスの再現

# 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

ランブブ Neo4j パス

# 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

Java コンパイル

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

セキュリティ設計

  • MCP サーフェス上に生の Cypher を晒なさない — すべてのグラフ問合せはパラメータ化されています。

  • 厳密なフィールド許可リスト — クラス名、パッケージ名、モジュール名、バージョン、構成パスは、グラフ検索の前にコンパイル済みの正規表現パタンと照合されす。

  • ソース安全スキャナー — 生成された Java が Runtime.getRuntime、ProcessBuilder、System.exit、java.io、java.nio.file、java.net を参照する場合、拒否されます。

  • パス横断の防 — 絶対パスと .. セグメントは構成パスのフィールドで拒否されます。

  • グランディングの強制 — 生成さされるすソース内のすべてのインポートは、その正確なバージョンについてグラフから得られたシンボブルに対応しなければなりません。

  • LLM 出力の再検証 — LLM 意図パーサーが抽出したフィールドは、直接 API 呼び出しと同二に GenerationIntent.from_mapping() の検証を通過します。

  • Neo4j 認証情報 — 環境関数からのみ読込み、ログやエビデンス・アーティファクトには決して出ません。

  • XML 事前チェック — defusedxml が、アロジェクト構造スキャンの実体拡張攻撃を防ぎます。

  • コンテナ — 固定の Chainguard Linux イメージ、非ルート UID/GID 65532;CI は MCP をコンテナ内の stdio スモークテストを実施します。

完全な脅威境界については SECURITY.md を参照してください。


リポジトリ・マッ

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

境界(対象外)

本リポジトリが 主スしないものは以下です:

  • モデル番号に依存しない自由形式の意図解の質 — LLM パイプラインはオプションであり、その結果は凍結された評価アーティファクトには含まれません。

  • 専有・秘密の Java テストフレームワークとの互換。

  • プロ・ダクションのテンシ SLO — すべての計測は単一プロセス・ローカルなヘンチマークです。

  • コンカレンシティ・分、散イン、高可用性の動作。

  • 生成した Java をハードウェアや検証環境に対して自動実行すること。

  • あらゆる生産性、コスト、收性、テ測定時間の短縮 — 本リポジトリには発成と検証の証拠のみ。

完全な機械読取可能な境界は evidence/claims.json にあります。


ライセンス

リポジトリのコード:MIT。 ラフ・フィクスチャ、インテント・ケース、Java スタブ:CC0-1.0(フィクスチャ・メタデータ記載)。

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.

    Related MCP Connectors

    Related MCP Servers