ontology-mcp
Login Query Agent — オントロジーMCP & ナレッジグラフ
OWL/SHACL/SKOSナレッジグラフ + 2つのMCPサーバーを使用して、SQL ServerとMongoDBにまたがるログイン診断クエリをルーティングし、条件付きでNew RelicにエスカレーションするPOCです。
アーキテクチャ概要
User prompt (VS Code Copilot)
│
▼ LLM classifies category natively — no tool call
│
ontology-mcp ──► Fuseki KG (SPARQL)
│ get_diagnosis_plan(category)
│ returns: capability_id, required_entities,
│ validation_sequence, newrelic_tool
▼
data-mcp ──► SQL Server (UM_Users, UM_UserPartnermapping,
│ UM_UserMobileNumberVerified)
├──────► MongoDB (users collection — 9 projected fields)
├──────► SHACL Validator (shapes read from KG shacl graph, evaluated in sequence order)
└──────► New Relic (only when all_shapes_pass=true — 2-step NRQL)Related MCP server: OntoRamp Graph Query
サービス概要
サービス | タイプ | 起動者 | 必要な用途 |
Apache Jena Fuseki | ローカルプロセス | 自分(手動) | ontology-mcp KGクエリ |
| stdio子プロセス | VS Codeが自動起動 | 診断計画 |
| stdio子プロセス | VS Codeが自動起動 | DBクエリ + 検証 |
SQL Server | リモート/LocalDB | 実行中 | データクエリ |
MongoDB | リモートサーバー | 実行中 | データクエリ |
New Relic | クラウドサービス | 常時利用可能 | エスカレーション(すべてのシェイプがパス) |
手動起動が必要なのはFusekiのみです。両方のMCPサーバーはVS Codeによって自動起動されます。
前提条件
1. Java 11+
java -version2. Apache Jena Fuseki JAR
このJARはgitから除外されています(54 MB)。jena.apache.orgからダウンロードして、次の場所に配置してください:
infra/fuseki/fuseki-server.jar3. Python 3.12+
python --version4. Python依存関係
cd c:\Ontology
python -m pip install -r requirements.txt5. SQL Server用ODBCドライバー
まだインストールされていない場合は、MicrosoftからODBC Driver 17 or 18 for SQL Serverをダウンロードしてください。
6. VS CodeとGitHub Copilot(エージェントモード)
GitHub Copilot拡張機能を備えたVS Code 1.99+。
ステップバイステップのローカル起動手順
ステップ1 — Fusekiを起動
cd c:\Ontology
java -jar infra\fuseki\fuseki-server.jar --config infra\fuseki\config\login-kg.ttlこのターミナルは開いたままにしてください。http://localhost:3030で確認できます。
ステップ2 — ナレッジグラフをロード
初回実行時、またはスキーマ/アーティファクトの変更後に必要です。
$env:PYTHONIOENCODING = "utf-8"
python scripts/generate/generate.py --schema login --version 1.0.0
python scripts/kg/load_kg.py --schema login --version 1.0.0
python scripts/kg/promote.py --schema login --version 1.0.0ステップ3 — シークレットを設定
.env.exampleを.envにコピーして、必要な値を入力してください:
SQL_SERVER_HOST=your-server
SQL_SERVER_DATABASE=your-database
SQL_SERVER_TRUSTED_CONNECTION=yes
SQL_SERVER_ENCRYPT=yes
SQL_SERVER_TRUST_CERT=yes
MONGODB_URI=mongodb://your-host:27017
MONGODB_DATABASE=your-database
NEW_RELIC_API_KEY=NRAK-xxxxxxxxxxxxxxxxxxxx
NEW_RELIC_ACCOUNT_ID=your-account-id
NEW_RELIC_REGION=US
APP_ENV=prodステップ4 — 両方のMCPサーバーを登録
ワークスペースのルートに.vscode/mcp.jsonを作成してください:
{
"servers": {
"ontology-mcp": {
"type": "stdio",
"command": "python",
"args": ["-m", "mcp_server.server"],
"cwd": "c:\\Ontology",
"env": {
"PYTHONPATH": "c:\\Ontology\\src",
"PYTHONIOENCODING": "utf-8"
}
},
"data-mcp": {
"type": "stdio",
"command": "python",
"args": ["-m", "mcp_server.diagnostic_server"],
"cwd": "c:\\Ontology",
"env": {
"PYTHONPATH": "c:\\Ontology\\src",
"PYTHONIOENCODING": "utf-8"
}
}
}
}VS Codeをリロードします(Ctrl+Shift+P → Developer: Reload Window)。
完全な診断フロー
User: "testgdpr1235@gep.com can't reset password"
│
│ LLM classifies: category = "password_reset" (no tool call)
│
▼
① ontology-mcp / get_diagnosis_plan(category="password_reset")
Reads x_capability_registry from login.yaml (no Fuseki needed for this step)
Returns: capability_id, required_entities, validation_sequence, newrelic_tool
│
▼ (agent extracts username from user message; asks if missing)
│
② data-mcp / query_sql_user(username, capability_id)
SELECT from UM_Users → islocked, isactive, isdeleted, usertype, emailaddress, ...
│
③ data-mcp / query_sql_mobile_verification(username, capability_id)
SELECT from UM_UserMobileNumberVerified → ismobilenumberverified
│
④ data-mcp / query_sql_partner_mappings(username, capability_id)
SELECT from UM_UserPartnermapping → bpc, partnercode, isactive, contactcode
│
⑤ data-mcp / query_mongo_user(username, capability_id)
db.users.find_one({...}, { 9 diagnostic fields }) → MongoDB document
│
⑥ data-mcp / validate_login_shapes(username, capability_id, validation_sequence)
Runs only the shapes in validation_sequence (plan-scoped)
Returns: per-shape PASS/FAIL, all_shapes_pass, advisories (e.g. dr_012)
│
┌────┴──────────────────────────┐
violations found all_shapes_pass = true
│ │
report per shape ⑦a data-mcp / query_newrelic_login_mfa(username, capability_id)
with mapped rule OR
dr_003..dr_008 ⑦b data-mcp / query_newrelic_reset_password(username, capability_id)
→ Transaction → Log per traceId (max 7 days)
required_entitiesにリストされているエンティティのみが取得されます。ステップ②–⑤は、それらを必要としないカテゴリではスキップされます(例:account_lockedはパートナーおよびモバイルクエリをスキップ)。
MCPツールリファレンス
ontology-mcp — ナレッジグラフ計画ツール(3ツール)
ツール | ステップ | 入力 | 戻り値 |
| 0 — 必須の最初の呼び出し |
|
|
| フォールバックのみ |
|
|
| オンデマンド |
| KGディスクリプタグラフからの完全なカラム/フィールドマッピング |
get_diagnosis_planはケイパビリティレジストリを**login.yamlから直接**読み取ります — Fuseki呼び出しは不要です。get_entity_descriptorはFusekiのディスクリプタグラフをクエリします — Fusekiの実行が必要です。
data-mcp — ライブデータツール(7ツール)
7つすべてのツールは、get_diagnosis_planからのcapability_idを必要とします。これなしで呼び出すと、構造化エラーが返されます。
ツール | ステップ | ソース | 戻り値 |
| 1a |
| userid, username, emailaddress, usertype, authenticationtype, islocked, isactive, isdeleted, issystemuser, mobileno |
| 1b |
| ismobilenumberverified + 実行されたSQL |
| 1c |
| すべてのマッピング行、合計数、アクティブ数 |
| 1d |
| 9つの射影フィールド + 実行されたクエリ |
| 2 | SQL + MongoDB | シェイプごとのPASS/FAIL、 |
| 3a | New Relic NerdGraph |
|
| 3b | New Relic NerdGraph | 3つのリセットURIのトランザクション + ログ(dr_011) |
診断カテゴリ(8)
カテゴリ | トリガー条件 |
| ログイン/認証/アプリへのアクセスができない、SSO障害、資格情報が拒否された |
| リセットリンクまたはパスワード忘れメールが届かない |
| リセット中にOTPメールが届かない |
| SMS OTPが届かない(モバイルは検証済み) |
| アカウントが無効化/非アクティブ/停止/無効になっている |
| 複数回の失敗後、アカウントがロックされている |
| パートナー(BPC)マッピングが存在しない/非アクティブ |
| SQLとMongoDBのフィールド不一致 |
SHACLシェイプ(8、シーケンス順に評価)
# | シェイプ | 条件 | ルール |
1 |
| isLocked=1 OR isActive=0 OR isDeleted=1 | dr_003 |
2 |
| isSystemUser=1 | dr_005 |
3 |
| userType=Buyer AND authenticationType=SSO | dr_006 |
4 |
| アクティブなパートナーマッピング行がない | dr_004 |
5 |
| アクティブな非ゼロBPCがないサプライヤー | dr_007 |
6 |
| 有効な登録メールアドレスがない(リセット/OTPフロー) | — |
7 |
| SQLとMongoDBのisMobileNumberVerifiedの不一致 | dr_002 |
8 |
| SQLとMongoDBのパートナーマッピングフィールドの不一致 | dr_008 |
各カテゴリの
validation_sequenceは、これらのシェイプのうち関連するサブセットのみを実行します。advisories(例:dr_012のメール不一致)はシェイプと一緒に返されますが、all_shapes_passには影響しません。
New Relicクエリ構造(2ステップ)
Step 1: Transaction table (max 7 days lookback, filtered by APP_ENV)
/Account/Login → LoginUserName, traceId, RequiresTwoFactor, TwoFactorDetails
/Account/RecoverPassword → traceId, errorMessage, RecoveryUserName, RecoveryEmail
/Account/PreResetPassword → traceId, errorMessage, PreResetUserName
/Account/ResetPassword → LoginUserName, traceId, errorMessage
Step 2: Log table (per traceId from Step 1)
SELECT * FROM Log WHERE `trace.id` = '{traceId}' SINCE {transaction_timestamp}ナレッジグラフ — 名前付きグラフ
KGはバージョンごとに6つの名前付きグラフと1つのメタグラフを格納します:
名前付きグラフIRI | 内容 | クエリ元 |
| 診断プレイブック — 8カテゴリ、必須エンティティ、検証シーケンス |
|
| エンティティのカラム/フィールドマッピング |
|
| 決定ルール(dr_001..dr_012) |
|
| SHACLノードシェイプ + 制約 |
|
| OWLクラス + プロパティ | 検査用に利用可能 |
| SKOSコンセプトスキーム + ラベル | 検査用に利用可能 |
| アクティブバージョンポインタ | すべてのFusekiクエリ(グラフディスカバリ) |
Fusekiはすべての診断の2つの段階でクエリされます:
get_diagnosis_plan(ステップ0)—get_active_graphs(メタグラフ)+get_capability_plan(ケイパビリティグラフ)→ 完全な診断プレイブックvalidate_login_shapes(ステップ2)— shaclグラフ(シェイプ)、descriptorsグラフ(マテリアライズのためのフィールド/タイプマッピング)、rulesグラフ(シェイプ→ルール)を読み取ります — バリデーターはKG駆動です
フォールバック(それぞれ警告がログに記録されます):Fusekiに到達できない場合、get_diagnosis_planはlogin.yamlからx_capability_registryを読み取り、validate_login_shapesはプログラムによるshacl_validator.pyにフォールバックします。
アーティファクトの再生成
YAMLスキーマファイルが変更された場合:
$env:PYTHONIOENCODING = "utf-8"
python scripts/generate/generate.py --schema login --version 1.0.0
python scripts/kg/load_kg.py --schema login --version 1.0.0
python scripts/kg/promote.py --schema login --version 1.0.0プロジェクト構造
c:\Ontology\
├── src/
│ └── mcp_server/ # PYTHONPATH=c:\Ontology\src
│ ├── server.py # ontology-mcp entrypoint (KG planning tools)
│ ├── diagnostic_server.py # data-mcp entrypoint (DB/NR tools)
│ ├── tool_meta.py # loads config/tool_descriptions.yaml
│ ├── connectors/
│ │ ├── sql_connector.py # pyodbc — UM_Users, UM_UserPartnermapping, ...
│ │ ├── mongo_connector.py # pymongo — users collection (projected)
│ │ └── newrelic_connector.py # NerdGraph GraphQL — 2-step NRQL
│ ├── diagnostics/
│ │ ├── data_fetcher.py # orchestrates SQL + MongoDB fetch
│ │ ├── kg_shacl_validator.py # KG-driven SHACL interpreter (PRIMARY)
│ │ └── shacl_validator.py # programmatic evaluation (Fuseki-down fallback)
│ ├── tools/
│ │ ├── get_diagnosis_plan.py # ontology-mcp: reads x_capability_registry
│ │ ├── list_capabilities.py # ontology-mcp: lists all 8 categories
│ │ ├── get_descriptor.py # ontology-mcp: SPARQL descriptors graph
│ │ ├── fetch_user_data.py # data-mcp: 4 individual SQL/Mongo queries
│ │ ├── validate_shapes.py # data-mcp: shape evaluation + advisories
│ │ └── query_newrelic.py # data-mcp: NR login + reset handlers
│ ├── kg/
│ │ └── sparql_client.py # Fuseki HTTP client + graph discovery
│ └── registry/
│ └── schema_registry.py # registry.yaml + load_capability_registry()
│
├── ontology/
│ ├── schemas/
│ │ ├── registry.yaml
│ │ └── login/v1.0.0/
│ │ ├── login.yaml # root: x_capability_registry + x_shacl_rules + x_decision_rules
│ │ ├── shared/types.yaml
│ │ ├── shared/enums.yaml # AuthenticationTypeEnum, UserTypeEnum
│ │ ├── shared/subsets.yaml
│ │ └── entities/
│ │ ├── abstract_user.yaml
│ │ ├── user.yaml # SQL UM_Users
│ │ ├── partner_mapping.yaml # SQL UM_UserPartnermapping
│ │ ├── mobile_verification.yaml # SQL UM_UserMobileNumberVerified
│ │ └── user_document.yaml # MongoDB users collection
│ └── sparql/
│ ├── get_entity_descriptor.sparql
│ └── get_decision_rules.sparql
│
├── artifacts/login/v1.0.0/
│ ├── owl/login.owl.ttl
│ ├── shacl/login.shacl.ttl
│ ├── skos/login.skos.ttl
│ ├── rules/login.rules.ttl
│ ├── descriptors/login.descriptors.json
│ └── jsonld/login.context.jsonld + login.agent_template.json
│
├── scripts/
│ ├── generate/generate.py + gen_*.py + _yaml_loader.py
│ └── kg/load_kg.py + promote.py
│
├── config/
│ └── tool_descriptions.yaml # single source of truth for all MCP tool descriptions
│
├── infra/fuseki/
│ ├── fuseki-server.jar # not committed — download separately
│ ├── config/login-kg.ttl
│ └── data/ # TDB2 storage — gitignored
│
├── .github/copilot-instructions.md # Copilot workspace instructions (auto-loaded)
├── CLAUDE.md # Claude Code workspace instructions (auto-loaded)
├── .vscode/mcp.json # MCP server registration (2 servers)
├── .env / .env.example # secrets — .env never committed to git
└── requirements.txtトラブルシューティング
エラー | 原因 | 修正 |
| Fusekiが起動していない | Fusekiを起動する(ステップ1) |
| エージェントが | 会話をやり直す; |
|
|
|
|
|
|
SQL Server接続エラー |
|
|
| 依存関係が不足している |
|
| Windowsコンソールのエンコーディング |
|
Fusekiのグラフが空 | 再起動後のFusekiの新規起動 |
|
日常ワークフロー
# 1. Start Fuseki
java -jar infra\fuseki\fuseki-server.jar --config infra\fuseki\config\login-kg.ttl
# 2. Load KG (only after schema or artifact changes)
$env:PYTHONIOENCODING = "utf-8"
python scripts/kg/load_kg.py --schema login --version 1.0.0
python scripts/kg/promote.py --schema login --version 1.0.0
# 3. Open VS Code — both MCP servers start automaticallyスキーマの拡張
新しいエンティティの追加(新しいSQLテーブルまたはMongoDBコレクション)
ontology/schemas/login/v1.0.0/entities/new_entity.yamlを作成する- entities/new_entityをlogin.yamlのインポートに追加するgenerate + load + promote を実行する
診断カテゴリの追加または変更
login.yaml内のx_capability_registryを編集するlogin.yaml内のx_shacl_rulesで対応するシェイプを追加/更新する — KG駆動のバリデータはshaclグラフからそのシェイプを読み取ります;sh_in/sh_property/sparql/cross_sourceシェイプには Pythonの編集は不要ですgenerate + load + promote を実行する(新しいシェイプ/ルールがKGに反映されるように)
MCPサーバーを再起動する
SHACLシェイプの追加または変更
シェイプはコードではなくKGから実行されます。login.yaml 内の x_shacl_rules を編集し、再生成+再読み込みしてください。kg_shacl_validator.py(汎用エンジン)は、まったく新しい制約 タイプ を導入しない限り変更の必要はありません。
新しいスキーマバージョンの追加
ontology/schemas/login/v1.0.0/をv1.1.0/にコピーするv1.1.0/内のエンティティファイルを編集するv1.1.0に対して generate + load + promote を実行する
両バージョンはKG内で共存します — ロールバックは常に promote.py で可能です。
This server cannot be deployed
Maintenance
Related MCP Connectors
Knowledge graph for AI agents. Query concepts, walk edges, get advisories.
Knowledge graph ingestion, entity search, ontology analysis, and CoSync scoring.
LLM Orchestration Observability Agent
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to query and record SOC analyst reasoning via a knowledge graph, allowing access to institutional memory from Splunk.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to query organizational architecture and governance constraints, returning evidence-grounded answers from documented structures.MIT
- FlicenseNot gradedqualityCmaintenanceLets AI agents query a computerized system inventory as a knowledge graph using Cypher, enabling blast radius, data lineage, regulation checks, and change impact assessments while preventing hallucinated regulatory claims.-
- FlicenseNot gradedqualityCmaintenanceEnables manufacturing traceability queries and analysis through GraphRAG, supporting semantic search, graph traversal, natural language to Cypher, defect chain retrieval, requirement traceability, and product health dashboards.-