MdGraph is an open-source context storage engine designed to replace traditional vector databases. Rather than chunking text into opaque embeddings and probabilistic cosine similarity, MdGraph implements Google's Open Knowledge Format (OKF) to store explicit, human-readable knowledge trees in Git and query multi-hop relational pathways natively over FastMCP.
Swap parsers, inference providers, and database indexes via clean configuration interfaces.
Ingest local folders (PDFs, HTML, markdown, text), live website URLs, or YouTube video transcripts with timestamped captions into structured Markdown without losing structural layout or table integrity.
Compile knowledge using any LLM—from local Llama models via Ollama to Claude 3.5, Gemini 1.5, or GPT-4o—powered by LiteLLM and strict Pydantic validation. Or compile offline without API keys via deterministic rule extraction.
Markdown with YAML frontmatter is the single, auditable source of truth. Every concept modification is versioned, committed, and diffable in Git. The database index is completely disposable and rebuildable anytime.
Ditches opaque embeddings and drift. Uses SQLite FTS5 (for edge/local) or PostgreSQL JSONB (for enterprise) to index YAML frontmatter, BM25 full-text keyword search, and explicit cross-links into graph edge tables.
Execute topological multi-hop queries via SQL Recursive Common Table Expressions (WITH RECURSIVE). Resolves incoming/outgoing links and shortest paths with
cycle detection in sub-millisecond execution time.
Expose your entire knowledge graph over Model Context Protocol over stdio and sse transports. External
agents in Cursor, Claude Desktop, Google ADK, and LangGraph query context natively.
Optional standalone FastAPI microservice for high-throughput ingestion, multipart document uploads, and
one-shot compilation pipelines (/api/v1/pipeline) executing
off-thread via asyncio.to_thread.
Native workspace isolation via tenant_id. Isolate team
subdirectories, composite primary keys (tenant_id, id), and strictly
enforced CTE graph boundaries with zero cross-tenant leakage.
Natively conforms to Google's Open Knowledge Format v0.2 specification. Includes trust signals, human
attestations (verified), expiration timestamps (stale_after), and forward-compatible Pydantic schema extensibility.
MdGraph enforces a strict separation between the heavy, state-mutating Compiler Layer and the lightweight, read-optimized Query Cache.
PDF, HTML, Web, YouTube
LiteLLM / Offline OKF
Git + Markdown Repo
SQLite FTS5 / Postgres CTE
Autonomous agents in Google ADK, LangGraph, Cursor, and Claude Desktop call standardized graph tools
over stdio or sse.
Asynchronous microservices, CI/CD pipelines, and web frontends consume REST endpoints, upload multipart
files, and inspect Swagger docs at /docs.
How plain Markdown files and relative links map into lightning-fast relational structures.
| Markdown OKF Source | Relational Cache Target | Query Optimization |
|---|---|---|
| YAML Frontmatter | JSON / JSONB Columns | Exact-match scalar filtering, tag intersections
(?&) |
| Markdown Body | SQLite FTS5 / Postgres tsvector | BM25 full-text keyword search and relevance ranking |
Explicit Links [x](./y.md) |
Graph Edge Table (source, target, tenant_id) | Sub-millisecond Recursive Common Table
Expressions (WITH RECURSIVE) |
| File Metadata | Git Commit Hashes | Incremental cache invalidation, freshness verification & time-travel |
Single-file embedded cache with WAL mode. Ideal for local desktop agents, Cursor/Claude pipelines, single-container services, and CI/CD testing.
:memory:db_type: "sqlite"
Enterprise backend for distributed agent swarms, Google Cloud Run, Cloud SQL, and high-concurrency production deployments.
tsvector + ts_rank
full-text searchpip install "mdgraph-ai[postgres]"
Unlike black-box vector databases where data is trapped inside opaque float arrays, MdGraph keeps your core knowledge fully portable. Every document is regular Markdown readable by any text editor, versioned in Git, and instantly queryable.
verified) & expiration guardrails (stale_after)
extra="allow" preserves future OKF fields seamlessly
--- okf_version: "0.2" type: Policy title: Remote Work Hardware Allowance description: Home office equipment stipend rules tags: [hr, hardware, remote] status: stable stale_after: "2027-12-31" generated: by: "agent:gpt-4o" at: "2026-10-17T00:00:00Z" verified: - by: "human:hr_director" at: "2026-10-17T00:00:00Z" notes: "Approved for FY27" sources: - "./raw_docs/hr_handbook_2026.pdf" resource: "https://internal.company.com/policies/hardware" --- # Remote Work Hardware Allowance Employees receive a yearly stipend managed by the [IT Department](./it_department.md). ## Approved Purchases All equipment must be sourced via the [Vendor Portal](./vendor_portal.md).
| Field | Type | Description |
|---|---|---|
| okf_version | str | Specification version ("0.2"). |
| type | str | Semantic concept category: Policy, System,
Service, Entity, Tool,
Article.
|
| title | str | Human-readable concept title. |
| description | str | High-level 1-line concept description. |
| tags | list[str] | Keyword tags for indexed categorical filtering and intersections. |
| status | str | Lifecycle state: stable, draft,
deprecated, expired, archived.
|
| stale_after | str | ISO expiration date triggering automated agent re-attestation warnings. |
| generated | dict | Provenance attribution dictionary: { "by": "agent:gpt-4o", "at": "..." }. |
| verified | list[dict] | Trust attestation list: [{ "by": "human:reviewer", "at": "...", "notes": "..." }].
|
| sources | list[str] | Upstream raw document file paths or URLs from which concept was compiled. |
| tenant_id | str | Workspace isolation identifier ("default" or tenant slug). |
MdGraph exposes deterministic tools over Model Context Protocol (stdio and sse) so any
agent framework can discover, traverse, and read knowledge graphs natively.
| MCP Tool | Signature | Description |
|---|---|---|
| get_concept | (node_id: str, tenant_id: str = None) -> dict | Retrieve metadata, tags, and direct cross-links for a concept. |
| read_concept_body | (node_id: str, tenant_id: str = None) -> str | Read the exact, unmodified OKF markdown body from Git. |
| search_knowledge | (query: str, tags: list = None, limit: int = 10, tenant_id: str = None) -> list[dict] | BM25 full-text keyword search across title, body, and tags. |
| traverse_graph | (node_id: str, max_depth: int = 2, direction: str = "out", tenant_id: str = None) -> dict | Execute Recursive CTE to return topological neighbors and multi-hop pathways. |
| find_path | (source_id: str, target_id: str, max_depth: int = 5, tenant_id: str = None) -> dict | Find the shortest topological path between two concepts. |
| list_concepts | (concept_type: str = None, tag: str = None, tenant_id: str = None) -> list[dict] | Filter concepts by exact semantic type or category tags. |
| get_graph_stats | (tenant_id: str = None) -> dict | Total concepts, edges, commit hash, and tag distribution. |
| reindex | (rebuild: bool = False, tenant_id: str = None) -> dict | Refresh or rebuild relational cache from Git truth. |
Vector similarity fails on multi-step questions spanning non-contiguous files. MdGraph allows agents to seed, traverse, and synthesize with complete accuracy:
Add directly to claude_desktop_config.json or .cursor/mcp.json:
{
"mcpServers": {
"mdgraph": {
"command": "mdgraph",
"args": ["serve", "--transport", "stdio"]
}
}
}
search_knowledge and traverse_graph.
Connect Python agent pipelines directly over MCP:
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
params = StdioServerParameters(
command="mdgraph",
args=["serve", "--transport", "stdio"]
)
async with stdio_client(params) as (r, w):
async with ClientSession(r, w) as session:
await session.initialize()
res = await session.call_tool(
"traverse_graph",
{"node_id": "payment_gateway", "max_depth": 2}
)
Wrap MdGraph tools via langchain_mcp_adapters:
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
client = MultiServerMCPClient()
await client.connect_to_server(
"mdgraph", url="http://localhost:8000/sse"
)
tools = client.get_tools()
agent = create_react_agent(ChatOpenAI(model="gpt-4o"), tools)
ans = await agent.ainvoke({"messages": [...]})
Dedicated asynchronous REST microservice for remote document ingestion, multipart file uploads, and one-shot compilation pipelines with zero overhead on core operations.
/docs
| Method | Endpoint | Description |
|---|---|---|
| GET | /health | Health check, knowledge repository path, and total concept count. |
| POST | /api/v1/ingest | Polymorphic ingestion accepting URLs, YouTube links, local paths, or folders. |
| POST | /api/v1/ingest/url | Ingest a website URL or YouTube video link into normalized Markdown. |
| POST | /api/v1/ingest/file | Multipart file upload (multipart/form-data) supporting PDF, HTML, Markdown, and text.
|
| POST | /api/v1/compile | Compile Markdown into OKF concepts (supports LLM or offline, optional Git commit). |
| POST | /api/v1/pipeline | One-shot pipeline: Ingest any source (URL, YouTube, text) AND compile into OKF concepts in Git in a single call. |
| GET | /api/v1/concepts | Search or list concepts from the relational query cache with tag/type filters. |
| GET | /api/v1/graph/traverse/{node_id} | Execute recursive CTE multi-hop traversal over HTTP with depth & direction parameters. |
| GET | /api/v1/tenants | List all active isolated tenant workspaces. |
curl -X POST "http://localhost:8080/api/v1/ingest/url" \
-H "Content-Type: application/json" \
-d '{"url": "https://docs.python.org/3/tutorial/"}'
curl -X POST "http://localhost:8080/api/v1/ingest/file" \ -F "file=@./specs/architecture.pdf"
curl -X POST "http://localhost:8080/api/v1/pipeline" \
-H "Content-Type: application/json" \
-d '{
"source": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"offline": true,
"save_to_repo": true
}'
curl "http://localhost:8080/api/v1/graph/traverse/remote_work_policy?max_depth=3" curl "http://localhost:8080/api/v1/graph/paths?source=payments&target=ledger"
Different business units, projects, or client organizations can store, index, traverse, and query knowledge graphs within a shared repository and relational database with complete data isolation.
knowledge/ ├── index.md # Root index (default workspace) ├── concepts/ # Default workspace concepts │ ├── api_gateway.md │ └── auth_service.md └── tenants/ # Multi-tenant workspaces ├── team_fintech/ │ └── concepts/ │ ├── payment_router.md # fintech-isolated concept │ └── ledger.md └── team_security/ └── concepts/ └── payment_router.md # Identical ID, zero clash
Both SQLite and PostgreSQL index tables utilize PRIMARY KEY (tenant_id, id). Different teams can name concepts
identically without colliding.
All edges store tenant_id. Recursive CTE traversals enforce
edges.tenant_id = ? across anchor and recursive steps,
ensuring multi-hop paths never jump between tenants.
Pass --tenant team_fintech in CLI, send X-Tenant-ID HTTP header in REST API, or supply tenant_id to any FastMCP agent tool.
From zero to an autonomous, Git-versioned knowledge graph ready for agent swarms.
# Core engine (CLI, Git, FastMCP, SQLite
FTS5)
$ pip install mdgraph-ai
# Or install complete suite (API, PostgreSQL, dev
tools)
$ pip install "mdgraph-ai[all]"
# Ingest local folder of PDFs, HTML,
markdown
$ mdgraph ingest ./raw_documents/ --dest
./normalized/
# Ingest website URL into structured
Markdown
$ mdgraph ingest
https://docs.python.org/3/tutorial/
# Ingest YouTube video
transcript
$ mdgraph ingest
https://www.youtube.com/watch?v=dQw4w9WgXcQ
# Compile via LiteLLM (GPT-4o, Claude 3.5, Gemini
1.5, Ollama)
$ mdgraph compile ./normalized/handbook.md
--model openai/gpt-4o-mini
# Or compile offline without API
keys
$ mdgraph compile ./normalized/handbook.md
--offline
# Full-text BM25 search
$ mdgraph query "hardware allowance"
# Multi-hop topological graph traversal up to 3
hops
$ mdgraph traverse remote_work_policy --depth 3
# FastMCP Server (Cursor, Claude, Google ADK,
LangGraph)
$ mdgraph serve --port 8000
# Standalone FastAPI REST
microservice
$ mdgraph api --port 8080
Deploy containerized MdGraph microservices with automatic scaling to zero and long-lived SSE streaming.
# Build Docker image docker build -t mdgraph:latest . # Run REST API service on port 8080 docker run -p 8080:8080 mdgraph:latest # Or run FastMCP Server over SSE on port 8000 docker run -p 8000:8000 mdgraph:latest \ mdgraph serve --transport sse --port 8000
# Deploy FastMCP Server with SSE session affinity
gcloud run deploy mdgraph-mcp \
--image=$IMAGE_URI \
--command="mdgraph" \
--args="serve,--transport,sse,--host,0.0.0.0,--port,8080" \
--region=us-central1 \
--allow-unauthenticated \
--port=8080 \
--timeout=3600 \
--session-affinity \
--use-http2
Configure MdGraph via YAML (mdgraph.yaml), CLI flags, or
environment variables. CLI flags take highest precedence, followed by MDGRAPH_* variables, YAML, and built-in defaults.
MDGRAPH_REPO_PATH: Git storage path (default: ./knowledge)MDGRAPH_DB_TYPE: SQLite or PostgreSQL backendMDGRAPH_LLM_MODEL: OpenAI, Claude, Gemini, OllamaMDGRAPH_AUTO_COMMIT: Automatic Git audit trail commitsrepo_path: "./knowledge" cache_path: "./.mdgraph/cache.db" db_type: "sqlite" # FastMCP Server settings mcp_host: "0.0.0.0" mcp_port: 8000 # Standalone REST API settings api_host: "0.0.0.0" api_port: 8080 # Compiler LLM (OpenAI, Anthropic, Gemini, Ollama via LiteLLM) llm_model: "openai/gpt-4o-mini" llm_temperature: 0.1 # Automated Git commits git_author_name: "MdGraph Compiler" git_author_email: "compiler@mdgraph.dev" auto_commit: true