OKFGraph MCP Server
by ywateba
README.md
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/brand/okfgraph-logo-dark.svg">
<img alt="OKFGraph" src="docs/brand/okfgraph-logo.svg" width="360">
</picture>
</p>
<p align="center">
<img src="docs/brand/okfgraph-icon.svg" width="96" height="96" alt="OKFGraph icon: hexagonal 3-domain knowledge graph hub">
</p>
<h1 align="center">OKFGraph</h1>
<p align="center">
<b>One local, MCP-first Knowledge Graph & Multi-Hop GraphRAG engine linking Specs, Tickets, and Code ASTs.</b><br>
4-way RRF + Personalized PageRank + Louvain communities in ~10 ms with <b>zero cloud LLM API cost</b>.<br>
Works natively with Antigravity, Cursor, Claude Desktop, Ollama, and LM Studio.
</p>
<p align="center">
<img alt="Python 3.10+" src="https://img.shields.io/badge/Python-3.10%2B-3776AB?style=flat-square&logo=python&logoColor=white">
<img alt="MCP Native" src="https://img.shields.io/badge/MCP-First-7C3AED?style=flat-square">
<img alt="Zero Cloud Cost" src="https://img.shields.io/badge/Cloud%20API%20Cost-%240-10B981?style=flat-square">
<img alt="Tests: 96 Passing" src="https://img.shields.io/badge/tests-96%20passing-10B981?style=flat-square">
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-3a3a3a?style=flat-square"></a>
</p>
<p align="center">
<a href="#what-it-does">What it does</a> ·
<a href="#features">Features</a> ·
<a href="#benchmarks">Benchmarks</a> ·
<a href="#quickstart">Quickstart</a> ·
<a href="#mcp-server">MCP Server</a> ·
<a href="#plugin-architecture">Plugins</a> ·
<a href="#run-the-benchmarks-yourself">Run Benchmarks</a>
</p>
> [!NOTE]
> **MCP-First & Zero Cloud API Bills:** OKFGraph runs 100% locally on `NetworkX` + inverted BM25 (no Docker, no Neo4j, no paid LLM pipeline required). Your existing IDE/Host LLM (Antigravity, Cursor, Claude Desktop) or local Ollama/LM Studio drives graph creation and reasoning directly through OKFGraph's MCP tools.
---
## What it does
Software requirements live in `.docx`/`.pptx`/Markdown specs, delivery history lives in Jira/GitHub/GitLab/Azure DevOps tickets, and the actual behavior lives in source code. Plain vector RAG chunks text blindly and loses the structural connections between them.
**OKFGraph** deterministically ingests all three domains into a single local Knowledge Graph, links business rules and tickets directly to classes, methods, and commits, and serves it through:
1. A **Model Context Protocol (MCP) server** (`okfgraph mcp`) for AI coding agents.
2. An **interactive offline HTML Documentation Portal + Knowledge Graph Map** (`okfgraph serve`).
```mermaid
flowchart LR
subgraph Sources["Data Sources"]
T["🎫 Tickets\nJira · GitHub · GitLab\nAzure DevOps · CSV/JSON/MD"]
D["📄 Business Docs\n.docx · .pptx · .md · .txt\nGDrive · OneDrive · Confluence"]
C["💻 Source Code\nPython AST · JS/TS/React\nCustom Language Plugins"]
end
subgraph Engine["OKFGraph Local Engine (Zero Cloud API Cost)"]
B["Graph Builder & Cross-Domain Linker\nFile · imports · inherits · contains · calls\nimplements · applies_to · mentions_entity"]
R["SOTA GraphRAG Retriever (~10 ms)\n4-Way RRF · Inverted BM25\n2-Hop PPR · Louvain Communities"]
end
subgraph Outputs["Interfaces"]
M["🔌 MCP Server\nAntigravity · Cursor · Claude\nOllama · LM Studio"]
P["🗺️ Offline HTML Portal\nSearchable Docs +\nInteractive Graph Map"]
end
T --> B
D --> B
C --> B
B --> R
R --> M
B --> P
```
---
## Features
<table>
<tr>
<td width="33%" valign="top">
<h3>🧠 SOTA 4-Way GraphRAG</h3>
Fuses Exact Symbol Match, Code-Aware Inverted BM25, Dual-Level Edge Triplets, and Dense Vectors via Reciprocal Rank Fusion + 2-hop Personalized PageRank + Louvain community summaries in ~10 ms/query.
</td>
<td width="33%" valign="top">
<h3>🔌 MCP-First ($0 Cloud Cost)</h3>
Bidirectional MCP server (<code>stdio</code> & <code>sse</code>) lets your Host LLM build, update, and query the graph without external cloud API keys. Supports <code>--read-only</code> and locked project roots.
</td>
<td width="33%" valign="top">
<h3>🗺️ Interactive Graph Map Portal</h3>
Exports a 100% offline HTML documentation site with a pure HTML5 Canvas force-directed Knowledge Graph explorer: pan, zoom, filter by node/edge type, search symbols, and inspect 1-hop / 2-hop neighborhoods.
</td>
</tr>
<tr>
<td width="33%" valign="top">
<h3>🔗 Specs ↔ Tickets ↔ Code</h3>
Connects business rules, entities, and issue-tracker tickets (Jira, GitHub, GitLab, Azure DevOps, CSV/JSONL/MD) directly to classes, methods, call chains, and Git commits.
</td>
<td width="33%" valign="top">
<h3>🧩 4-Pillar Plugin Standard</h3>
Extend OKFGraph with standalone pip packages via Python entry points: <code>code_extractors</code>, <code>mcp_plugins</code>, <code>ticket_connectors</code>, and <code>doc_connectors</code> — zero edits to core.
</td>
<td width="33%" valign="top">
<h3>📊 Reproducible Benchmarks</h3>
Ships with strict LocAgent/Agentless localization scorecards (<code>SWE-bench Lite</code> & <code>Loc-Bench_V1</code>) and a configurable N-turn runner for Ollama, LM Studio, or any OpenAI-compatible LLM.
</td>
</tr>
</table>
---
## Benchmarks
All localization scores use the **strict LocAgent / Agentless protocol** (zero partial credit — `1` iff **all** ground-truth modified files or `(file, leaf_function)` pairs appear in the top-`k` predictions).
### 1. Turn-1 Zero-LLM Retrieval (`benchmarks/run_strict_loc_eval.py`)
| Dataset | Engine | N | File Acc@1 | File Acc@3 | File Acc@5 | Func Acc@5 | Func Acc@10 |
|---|---|---:|---:|---:|---:|---:|---:|
| **SWE-bench Lite (`django`)** | Flat Keyword (TF-IDF) | 114 | 15.8% | 28.9% | 34.2% | 6.9% | 9.9% |
| **SWE-bench Lite (`django`)** | **OKFGraph SOTA (Zero-LLM)** | 114 | **39.5%** | **58.8%** | **65.8%** | **25.7%** | **31.7%** |
| **Loc-Bench_V1 (`django`)** | Flat Keyword (TF-IDF) | 35 | 14.3% | 22.9% | 28.6% | 5.9% | 8.8% |
| **Loc-Bench_V1 (`django`)** | **OKFGraph SOTA (Zero-LLM)** | 35 | **42.9%** | **68.6%** | **74.3%** | **47.1%** | **47.1%** |
| **Loc-Bench_V1 (`dask`)** | Flat Keyword (TF-IDF) | 20 | 10.0% | 25.0% | 35.0% | 15.0% | 30.0% |
| **Loc-Bench_V1 (`dask`)** | **OKFGraph SOTA (Zero-LLM)** | 20 | **55.0%** | **60.0%** | **60.0%** | **45.0%** | **60.0%** |
| **Loc-Bench_V1 (`sklearn`)** | Flat Keyword (TF-IDF) | 19 | 5.3% | 10.5% | 15.8% | 5.3% | 10.5% |
| **Loc-Bench_V1 (`sklearn`)** | **OKFGraph SOTA (Zero-LLM)** | 19 | **26.3%** | **36.8%** | **42.1%** | **21.1%** | **21.1%** |
### 2. 2-Turn LLM + OKFGraph vs. Published Baselines (`Loc-Bench_V1`, `django/django`)
Pairing OKFGraph's graph tools with just **2 turns** of a local 4B–8B model or a frontier Host LLM via MCP closes the vocabulary gap without needing a 10-turn custom agent:
| System / Mode | LLM Backbone | Turns / Cost | Scope | File Acc@1 | File Acc@5 | Func Acc@5 | Func Acc@10 |
|---|---|---:|---|---:|---:|---:|---:|
| **OKFGraph SOTA (Turn-1)** | None (Zero-LLM) | 1 (~10 ms) | Django (`N=5` blind) | 40.0% | 60.0% | 40.0% | 40.0% |
| **OKFGraph + `gemma-4-e4b`** | Local 4B (LM Studio) | 2 ($0) | Django (`N=5` blind) | **60.0%*** | **80.0%** | 40.0% | 40.0% |
| **OKFGraph + `llama3.1:8b`** | Local 8B (Ollama) | 2 ($0) | Django (`N=5` blind) | **60.0%*** | **80.0%** | **60.0%** | **60.0%** |
| **OKFGraph + Host LLM (MCP)** | Frontier Host LLM | 2 (MCP) | Django (`N=5` blind) | **60.0%*** | **100.0%** | **80.0%** | **80.0%** |
| *Published Agentless (ref.)* | *GPT-4o / Claude-3.5* | *~4–6 (Paid)* | *Full SWE / Loc-Bench* | *—* | *~78–82%* | *~55–65%* | *~62–70%* |
| *Published LocAgent (ref.)* | *Qwen-2.5-32B (FT)* | *~10 (GPU)* | *Full Loc-Bench (`560`)* | *—* | *~84–88%* | *~65–70%* | *~70–74%* |
| *Published LocAgent (ref.)* | *Claude-3.5-Sonnet* | *~10 (Paid)* | *Full Loc-Bench (`560`)* | *~70–75%* | *~90–93%* | *~70–75%* | *~75–80%* |
<sub>*On the 5-issue blind slice, 2 issues modify 2 files simultaneously, so the theoretical ceiling for strict File `Acc@1` is `60.0%` (3/5). Evaluated against a Django HEAD graph snapshot; see <a href="#run-the-benchmarks-yourself">Run the Benchmarks Yourself</a> to reproduce on larger slices (`N=35+`) with any local or external LLM.</sub>
---
## Quickstart
Requires **Python 3.10+** (and optionally **Node.js 18+** if indexing JS/TS repositories with Graphify).
### 1. Install & Verify
```bash
# Clone and install in editable mode with dev/test dependencies
git clone https://github.com/ywateba/okfgraph.git
cd okfgraph
python -m venv .venv
# Windows (PowerShell): .venv\Scripts\Activate.ps1
# macOS / Linux: source .venv/bin/activate
pip install -e ".[dev]"
# Run the test suite (96 tests)
pytest -q
```
Or install directly into another project:
```bash
pip install git+https://github.com/ywateba/okfgraph.git
```
### 2. Initialize, Build, and Explore Any Project
```bash
cd /path/to/my-project
# 1. Scaffold project.yaml (schema v2), llm_config.json, and .env
okfgraph init --name "My Project"
# 2. Build the Knowledge Graph & cross-domain links
okfgraph build
# 3. Export & launch the offline HTML portal + interactive Knowledge Graph map
okfgraph export --format html
okfgraph serve --port 8080 # Open http://localhost:8080/graph.html
# 4. Query or trace call chains from the CLI
okfgraph chat "Which service handles payment authorizations and refunds?"
okfgraph trace "ProcessPayment" --depth 4
```
<details>
<summary><b>Example <code>project.yaml</code> & <code>llm_config.json</code></b></summary>
```yaml
# project.yaml (schema v2)
schema_version: 2
project_name: "My Project"
project_folder: "."
tickets:
output_dir: "inputs/tickets"
scan_git_log: true
sources:
- name: main
type: github # jira | github | gitlab | azure_devops | file | python
options:
owner: "your-org"
repo: "your-repo"
auth:
token: "${GITHUB_TOKEN}"
inputs:
source_code:
repository_path: "./src"
file_extensions: [".py", ".ts", ".js"]
business:
business_docs_dir: "inputs/business_docs"
structuring_mode: "deterministic" # deterministic | hybrid | llm
artifacts:
knowledge_graph_json: "artifacts/knowledge_graph_nodes_edges.json"
exported_html_dir: "artifacts/exported_html"
```
```json
{
"active_provider": "mcp",
"enforce_mcp_only": true,
"embedding_provider": "ollama",
"providers": {
"mcp": {
"description": "All LLM interactions are routed through the OKFGraph MCP Server",
"active": true
},
"ollama": {
"chat_model": "llama3.1",
"embedding_model": "nomic-embed-text",
"base_url": "http://localhost:11434",
"active": false
}
}
}
```
</details>
---
## MCP Server
Add `okfgraph` to your IDE or AI client MCP configuration (`.mcp.json`, Antigravity, Cursor, Claude Desktop, or LM Studio):
```json
{
"mcpServers": {
"okfgraph": {
"command": "python",
"args": ["-m", "okfgraph.query.mcp_server", "--project", "project.yaml"],
"env": {
"OKFGRAPH_MCP_ONLY": "true",
"PYTHONUTF8": "1"
}
}
}
}
```
Or run over local HTTP SSE (pass `--read-only` to disable mutation tools, or `--disable-plugins` for core-only mode):
```bash
okfgraph mcp --project project.yaml --transport sse --port 8765 --read-only
```
<details>
<summary><b>All Built-in MCP Tools (Query & Ingestion)</b></summary>
**GraphRAG Query & Reasoning Tools**
- `query_subgraph` — 4-way RRF + Personalized PageRank + minimum-cost semantic paths + Louvain communities
- `graph_summary` / `graph_communities` — Topology overview and domain clusters
- `search_nodes` / `get_node_details` / `get_neighbors` — Direct node & edge inspection
- `find_path` — Shortest semantic reasoning path between any two nodes
- `trace_call_hierarchy` — Upstream callers and downstream callees with depth control
- `get_ticket` — Canonical ticket details + connected graph neighborhood
- `read_code_snippet` — Symbol-grounded source code snippets (with path-containment & secret-file guards)
- `list_plugins` — Lists installed `okfgraph.code_extractors` and loaded `okfgraph.mcp_plugins`
**Graph Creation & Mutation Tools** *(disabled in `--read-only` mode)*
- `migrate_project_config` — Upgrades legacy `project.yaml` to schema v2
- `sync_tickets` — Pulls & normalizes tickets into `TicketStore`
- `extract_raw_documents` / `get_raw_document_text` / `submit_structured_document` — MCP-driven document structuring
- `extract_code_ast` — Runs built-in (`python` / `graphify`) or installed `okfgraph.code_extractors` plugins
- `upsert_graph_knowledge` / `build_and_reload_graph` — Live graph updates with hot-reloaded BM25 index
</details>
---
## Plugin Architecture
OKFGraph is a generic core extensible via **4 standard Python entry-point groups** — install any plugin package alongside `okfgraph` with zero core edits.
> **Want to build your own plugin?** Follow the step-by-step guide (package layout, `pyproject.toml`, `CodeExtractor`, MCP tools, security & verification): **[Plugin Authoring & Architecture Guide → `docs/plugin_architecture.md`](docs/plugin_architecture.md)**.
| Entry-Point Group | Base Contract | What It Extends |
|---|---|---|
| `okfgraph.code_extractors` | `CodeExtractor` ABC | Custom language AST extractors (e.g., Rust, Go, Java, proprietary DSLs) |
| `okfgraph.mcp_plugins` | `register_mcp_tools(server, ctx)` | Domain-specific MCP tools with live access to graph, retriever & read-only state |
| `okfgraph.ticket_connectors` | `TicketConnector` ABC | Custom issue trackers (built-ins: `jira`, `github`, `gitlab`, `azure_devops`, `file`) |
| `okfgraph.doc_connectors` | `DocumentConnector` ABC | Remote document sources (built-ins: `gdrive`, `onedrive`, `confluence`, `http`) |
```toml
# In your external plugin package's pyproject.toml
[project.entry-points."okfgraph.code_extractors"]
mylang = "okfgraph_mylang:MyLangExtractor"
[project.entry-points."okfgraph.mcp_plugins"]
mylang = "okfgraph_mylang.mcp:register_mcp_tools"
```
---
## Run the Benchmarks Yourself
### 1. Built-In Offline Golden Benchmark (No Downloads Required)
```bash
python benchmarks/run_benchmark.py
```
### 2. Index Any Python Repo & Run the Strict Turn-1 Scorecard
```python
import json
from pathlib import Path
from okfgraph.ingestion.code.python_ast import extract_python_repo_graph
kg = extract_python_repo_graph("path/to/django/django")
Path("benchmarks/external/django_kg.json").write_text(json.dumps(kg), encoding="utf-8")
```
```bash
python benchmarks/run_strict_loc_eval.py
```
### 3. LocAgent-Protocol N-Turn Runner (Local or External LLM)
Run `benchmarks/run_locagent_bench.py` with any `--turns N` and any OpenAI-compatible endpoint (`File@1/3/5`, `Mod@5/10`, `Func@5/10`, latency & token telemetry):
**Local Ollama (`http://localhost:11434/v1`):**
```bash
python benchmarks/run_locagent_bench.py \
--dataset benchmarks/external/locbench_v1.jsonl \
--kg benchmarks/external/django_kg.json \
--repo django/django --pkg-prefix django \
--turns 3 --limit 35 \
--base-url http://localhost:11434/v1 \
--model llama3.1:latest \
--out benchmarks/external/report_ollama_3t.json
```
**Local LM Studio (`http://localhost:1234/v1`):**
```bash
python benchmarks/run_locagent_bench.py \
--dataset benchmarks/external/locbench_v1.jsonl \
--kg benchmarks/external/django_kg.json \
--repo django/django --pkg-prefix django \
--turns 3 --limit 35 --max-tokens 2048 \
--base-url http://localhost:1234/v1 \
--model google/gemma-4-e4b \
--out benchmarks/external/report_gemma4_3t.json
```
**External OpenAI-Compatible API (requires explicit `--allow-external`):**
```bash
export OPENAI_API_KEY="sk-..."
python benchmarks/run_locagent_bench.py \
--dataset benchmarks/external/locbench_v1.jsonl \
--kg benchmarks/external/django_kg.json \
--repo django/django --pkg-prefix django \
--turns 5 --limit 35 \
--base-url https://api.openai.com/v1 \
--model gpt-4o \
--api-key-env OPENAI_API_KEY \
--allow-external \
--out benchmarks/external/report_gpt4o_5t.json
```
---
## Reference & Security
<details>
<summary><b>Unified CLI Reference (<code>okfgraph</code>)</b></summary>
| Command | Arguments | Description |
|---|---|---|
| `okfgraph init` | `[--name NAME] [--path PATH] [--force]` | Scaffolds `project.yaml` (v2), `llm_config.json`, and `.env` |
| `okfgraph migrate-config` | `[project.yaml] [--dry-run] [--no-backup]` | Migrates legacy `project.yaml` to schema v2 |
| `okfgraph build` | `[--project PATH] [--start 1-6] [--stop 1-6]` | Runs extraction, AST parsing, and cross-domain graph linking |
| `okfgraph export` | `--format html\|docx\|all [--project PATH]` | Exports offline HTML portal (+ Graph Map) and/or Word docs |
| `okfgraph serve` | `[--port PORT] [--project PATH]` | Serves the local HTML portal & Knowledge Graph map |
| `okfgraph mcp` | `[--transport stdio\|sse] [--port PORT] [--read-only]` | Starts the extensible MCP server |
| `okfgraph chat` | `"<query>" [--project PATH]` | Answers questions via Multi-Hop GraphRAG |
| `okfgraph trace` | `"<symbol>" [--depth N] [--upstream]` | Traces downstream callees or upstream callers |
| `okfgraph tickets` | `list-connectors \| test \| sync \| new-connector` | Manages pluggable ticket connectors |
| `okfgraph docs` | `list-connectors \| sync \| new-connector` | Manages remote document connectors |
</details>
<details>
<summary><b>Project Structure</b></summary>
```text
okfgraph/
├── src/okfgraph/
│ ├── cli.py # Unified CLI (`okfgraph`)
│ ├── core/ # Config loader, security guards, LLM/MCP factory
│ ├── ingestion/
│ │ ├── business/ # Spec extraction (.docx/.pptx/.md) & structuring
│ │ ├── code/ # 4-edge Python AST, Graphify & CodeExtractor registry
│ │ └── documents/ # Remote doc connectors (GDrive, OneDrive, Confluence, HTTP)
│ ├── tickets/ # Canonical TicketStore & connectors (Jira/GH/GL/ADO/File)
│ ├── graph/ # Knowledge Graph builder & cross-domain linker
│ ├── docs/export/ # Offline HTML portal, interactive Graph Map & Word export
│ ├── query/ # SOTA RRF/BM25/PPR retriever, MCP server & MCP plugin loader
│ └── pipeline/ # 6-phase pipeline orchestrator
├── benchmarks/ # Golden, strict Loc-Bench/SWE-bench & N-turn runners
├── docs/
│ ├── brand/ # Light/dark SVG logos & icon
│ └── plugin_architecture.md # Official 4-pillar plugin standard
├── tests/ # 96 unit, security, plugin & connector contract tests
├── AGENTS.md # MCP-first agent operational rules
├── SECURITY.md # Security architecture & threat model
├── LICENSE # MIT License
└── pyproject.toml
```
</details>
- **Security:** Path-containment checks, SSRF protection, secret-file filtering, HTML XSS sanitization, and read-only MCP enforcement are built in — see [SECURITY.md](SECURITY.md).
- **License:** Licensed under the [MIT License](LICENSE). Copyright (c) 2026 `ywateba`.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues