graph-mcp-java-gen
graph-mcp-java-gen
グラフ基盤の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マルチエージェントパイプライン
%%{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ライセンスの合成フィクスチャを使用しています。
結果は、保留中の確認分割に対する承認済みの strict_graph_v2 ポリシーによるものです。
サーフェス | 結果 | アーティファクト |
ベンチマーク規模 | 96件のCC0インテント — 32 dev / 32 val / 32 confirmation | |
確認タスク成功率 | 32 / 32 の境界付きタスク | |
生成ソースの検証 | 24 / 24 のサポート対象インテント — 構文 + 契約 + グラウンディング + 安全性 | |
安全な敵対的拒否 | 8 / 8 — 誤受理ゼロ | |
引用精度 | 100% — グラフで引用されたシンボルのみインポート | |
必須シンボルの再現率 | 100% — すべての必須シンボルが存在 | |
ライブNeo4j統合 | Neo4j 5.26.29 — 8シンボル、12メソッドを具体化 | |
公式MCPベンチマーク | 120 / 120 の期待結果 — プロトコルエラーゼロ | |
MCPウォームレイテンシ (p50 / p95 / p99) | 29.13 / 48.61 / 54.23 ms (並行度1) | |
Javaコンパイル | 8 / 8 クラスファイル (Eclipse ECJ 3.21) | |
外部モデル呼び出し (決定論的パス) | 0回 · $0.00 |
レイテンシ数値は、シングルプロセスのローカル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]候補 | タスク成功率 | 生成有効 | 安全拒否 | 引用精度 | 決定 |
| 21.9% | 0% | 87.5% | 0% | 拒否 — グラウンディングなし |
| 75.0% | 100% | 0% | 100% | 拒否 — 誤受理8件 |
| 100% | 100% | 100% | 100% | 選択 |
| 96.9% | 100% | 87.5% | 87.5% | 拒否 — 無関係なコンテキスト + 誤受理1件 |
MCPツール
ツール | タイプ | 動作 |
| 読み取り | フィクスチャのID、出所、ライセンス、バックエンド、シンボル数を返す |
| 読み取り | パラメータ化された名前/メソッド検索; 最大20件の結果 |
| 生成 | 型付きフィールド → グラフ検索 → Java → すべての検証ゲート |
| 生成 | 境界付き3形式文法 → 同じ厳格ポリシー |
| 検証 | 最大20,000文字をチェック; ソースを書き込んだり実行したりしない |
| マルチエージェント | LLMインテントパーサー → ジェネレーター → LLMレビューア; |
Neo4jアダプターは固定のパラメータ化されたCypherを使用し、URI内の資格情報を拒否し、フィクスチャIDの衝突を拒否します。
クイックスタート
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.serverMCPクライアント設定 (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.jsonJavaコンパイル
# 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イメージ、非root 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 (フィクスチャメタデータにラベル付け)。
This server cannot be deployed
Maintenance
Related MCP Connectors
Deterministic validation for AI-generated artifacts: JSON Schema, OpenAPI response, SQL syntax.
Writes adversarial test suites for AI-built code. Your agent's test engineer.
Proves AI-generated Python does what you asked: lint, types, security, sandbox run, exact fixes.
Change-aware CI validation and affected-test guidance for coding agents.