Domain Context Graph protocol for grounding AI in verified domain knowledge.
Project description
Domain Context Graph (DCG)
An open protocol for structuring domain knowledge so AI systems reason about your product — not just your code.
The Problem
AI coding assistants write confident code that violates business rules nobody documented. Security scanners flag vulnerabilities without knowing which domain owns the affected service. Incident responders trace call graphs without understanding blast radius across business capabilities.
- LLM training data is generic. Models know what "payments" means in general — not what your Payments domain is, who owns it, or what depends on it.
- Code graphs capture structure, not semantics. They see imports and call chains — not that two modules serve the same bounded context.
- Documentation decays instantly. Wikis are stale, unstructured, and not machine-queryable.
- Knowledge is tool-siloed. Your security scanner's vulnerability data can't connect to your code graph's ownership data because there's no shared schema.
DCG fills this gap: a standard, machine-readable protocol for domain knowledge that any AI system can consume — versioned, git-backed, and federated across teams and repos.
Core Concepts
- Wikibase-compatible entities — same JSON format used by Wikidata's 100M+ items. Labels, descriptions, aliases, and attributes with full snak structure.
- Content-addressed identity — entity UIDs are deterministic hashes (
dcg:sha256:...). Same entity always gets the same ID, regardless of who creates it or when. - Two-axis classification — every entity has a structural type (
instance ofFunction/Class/Endpoint) and domain membership (part ofPayments/Security). These are orthogonal. - Retraction and purge — entities can be retracted (soft-deleted) and later permanently purged from the graph.
- Composition — stack multiple domain graphs via
dcg-stack.ymlmanifests withextendschains. Query across layers; entities resolve upward through the chain. - Federation — multiple graphs reference each other's entities via cross-graph resolution. Each team owns their graph independently.
Install
pip install domain-context-graph
With git-backed persistence:
pip install domain-context-graph[git]
Quick Start
from dcg.core import GraphStore, entity_uid, builders as kb
store = GraphStore()
# Define a domain
payments_uid = entity_uid(name="Payments")
store.add_entity(kb.entity(
uid=payments_uid,
label="Payments",
description="Payment processing domain",
attributes=[kb.attribute("instance of", kb.ref_value("dcg:meta:Domain"))],
))
# Place a code entity in that domain
fn_uid = entity_uid(name="charge_card", path="src/payments/charge.py")
store.add_entity(kb.entity(
uid=fn_uid,
label="charge_card",
attributes=[
kb.attribute("instance of", kb.ref_value("dcg:meta:Function")),
kb.attribute("part of", kb.ref_value(payments_uid)),
kb.attribute("file path", kb.string_value("src/payments/charge.py")),
],
))
# Query
functions = store.query(instance_of="dcg:meta:Function")
CLI
dcg init <name> [--path .] [--description "..."] # Create a new domain graph project
dcg serve --project <path> # Start MCP server (single project)
dcg serve --stack <manifest> # Start MCP server (multi-layer stack)
dcg compose <manifest> # Validate a dcg-stack.yml manifest
dcg purge <path> # Remove retracted entities and relations
dcg query <path> [--type Function] [--domain Pay] # Query entities
MCP Server
DCG includes a built-in Model Context Protocol server with 28 tools for reading, writing, and querying domain graphs.
# Single project
dcg serve --project ./my-graph
# Multi-layer stack (cross-layer queries)
dcg serve --stack ./dcg-stack.yml
Tools include dcg_create_entity, dcg_create_domain, dcg_connect, dcg_query, dcg_snapshot, dcg_bulk_add, and more. Stack-mode adds dcg_stack_info, dcg_query_stack, and dcg_resolve_cross_layer.
Composition
Stack multiple domain graphs with a dcg-stack.yml manifest:
stack: my-appsec-stack
layers:
- name: security
source: ./graphs/security-domain
- name: product
source: ./graphs/product-domain
extends: security
- name: code
source: ./graphs/code
extends: product
The extends chain defines resolution order. When querying the code layer for an entity, DCG walks code → product → security until found. Cross-layer queries deduplicate by UID (nearest layer wins).
Package Structure
src/dcg/
__init__.py # Public API re-exports
cli.py # CLI entry point (dcg command)
project.py # DomainProject — manifest-based project manager
core/
uid.py # Content-addressed entity/relation IDs
model.py # Entity, Relation, Attribute dataclasses
ontology.py # Type and property registries
builders.py # Wikibase JSON entity/attribute construction
store.py # GraphStore — in-memory implementation
compose.py # DcgStack — multi-project composition
federation.py # Cross-graph registry and resolution
purge.py # Retraction purge
git_store.py # GitGraphStore — dulwich-backed persistence
mcp/
server.py # FastMCP server (28 tools)
helpers.py # Shared MCP utilities
Specification
| Document | Description |
|---|---|
| RFC DCG-002 | Formal protocol specification (IETF RFC 2119). Defines Core, Persistent, and Federated conformance levels. |
| Design Spec | Full architecture, entity model, ontology, and integration patterns. |
The RFC is the authoritative source. This Python package is one implementation — others can implement the same spec in any language.
Extensibility
- Custom domains —
register_global_type()to add domain-specific types - Custom properties —
register_property()with Wikidata P-ID aliases - Custom backends — implement
GraphStoreProtocolfor any storage - Federation — implement
GraphRegistryandBoundaryResolverfor cross-graph resolution
Related Projects
| Project | Description |
|---|---|
| appsec-ctx-graph | 3-layer security + product + code domain graph built on DCG |
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file domain_context_graph-0.4.0.tar.gz.
File metadata
- Download URL: domain_context_graph-0.4.0.tar.gz
- Upload date:
- Size: 132.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4068366bf9ce4202831405b16bb0b83c3bacacfae12a685eb0fdc0b8f34c0ed4
|
|
| MD5 |
6256b578a52d0ed918d9221d02284db9
|
|
| BLAKE2b-256 |
46eec78d42db9b0818366ed40436ef7030c16edff043126f6be40d772b91876d
|
Provenance
The following attestation bundles were made for domain_context_graph-0.4.0.tar.gz:
Publisher:
publish.yaml on agentkg/dcg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
domain_context_graph-0.4.0.tar.gz -
Subject digest:
4068366bf9ce4202831405b16bb0b83c3bacacfae12a685eb0fdc0b8f34c0ed4 - Sigstore transparency entry: 2035628886
- Sigstore integration time:
-
Permalink:
agentkg/dcg@aa553ee84aa722a6697705bc7bb000392c9b3556 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/agentkg
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@aa553ee84aa722a6697705bc7bb000392c9b3556 -
Trigger Event:
release
-
Statement type:
File details
Details for the file domain_context_graph-0.4.0-py3-none-any.whl.
File metadata
- Download URL: domain_context_graph-0.4.0-py3-none-any.whl
- Upload date:
- Size: 130.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2ed2aef9dfc49f19fe53e1e3e771252bb09dc0aaf1740b4715886eff092c873
|
|
| MD5 |
edbf882d66ec8d6091b49fed331cf952
|
|
| BLAKE2b-256 |
e60ccb4cac476d43a9545d6598ea124c8520bd4706ccdaa1457d5d233e366294
|
Provenance
The following attestation bundles were made for domain_context_graph-0.4.0-py3-none-any.whl:
Publisher:
publish.yaml on agentkg/dcg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
domain_context_graph-0.4.0-py3-none-any.whl -
Subject digest:
a2ed2aef9dfc49f19fe53e1e3e771252bb09dc0aaf1740b4715886eff092c873 - Sigstore transparency entry: 2035628968
- Sigstore integration time:
-
Permalink:
agentkg/dcg@aa553ee84aa722a6697705bc7bb000392c9b3556 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/agentkg
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@aa553ee84aa722a6697705bc7bb000392c9b3556 -
Trigger Event:
release
-
Statement type: