Cognitive-Fabric
A unified Python MCP server for a graph "memory bank" on KuzuDB, extended with a Cognitive Fabric layer: in-process symbolic (AST) ingestion, a semantic (vector) search layer, and a "dream"/evolution engine that distills episodic memory into the semantic graph.
This is the single-runtime successor to the split TypeScript-core + Python-sidecar design: there is no Arrow Flight sidecar and no network data-plane port — the tree-sitter, embedding, and LLM work all run in-process.
Provenance: the memory-bank core's tool surface and data model follow the Apache-2.0 project KuzuMem-MCP; the Python implementation — this repository, and the author's own unpublished KuzuMemPy-MCP port it grew from — was written by this project's author. See
NOTICE. Licensed under Apache-2.0 (LICENSE).
Features
- Graph memory bank on KuzuDB — components, decisions, rules, context, files,
tags, metadata; repository + branch isolation via
repo:branch:idkeys. - 13 MCP tools:
memory-bank,entity,context,query,associate,analyze,detect,introspect,bulk-import,search,delete,memory-optimizer, andfabric. - Cognitive Fabric:
- Symbolic ingestion — tree-sitter parses a project into
Symbol/Filenodes +DEFINED_INedges (in-process). - Semantic search — LanceDB vector store over ingested symbols (optional
[semantic]extra); degrades gracefully when not installed. - Dream engine — distills recent
ContextintoDecisionnodes +JUSTIFIESedges via an LLM (skips cleanly when no API key is set). - Provenance graph —
EVOLVED_FROM,JUSTIFIES,DEFINED_IN,REALISED_BY,RECORDS,CONTRAVENESrelationships.
- Symbolic ingestion — tree-sitter parses a project into
- AI memory optimizer with snapshots + rollback; graph algorithms (PageRank, Louvain, k-core, shortest path); stdio MCP transport.
Installation
Requires Python 3.11–3.13. CI runs the suite on all three, on Linux. Python 3.14
is excluded deliberately: kuzu 0.11.3 — the final release, and the version this
package pins — ships no 3.14 wheels for macOS or Windows, so on those platforms
pip would try to build Kùzu's C++ from source.
# Base install (memory bank + fabric ingestion via tree-sitter)
pip install cognitive-fabric
# Semantic search: LanceDB + fastembed local embeddings (pure ONNX, no torch —
# works on every Python this package supports)
pip install 'cognitive-fabric[semantic]'
# Or just the vector store (LanceDB), for an injected embedder
pip install 'cognitive-fabric[vectordb]'
# Talking to a hosted provider: the OpenAI and Anthropic SDKs. Needed by the
# dream engine / memory optimizer, and by the OpenAI embedding backend. Not
# installed by default — a local-first install should not download two vendor
# SDKs it never calls.
pip install 'cognitive-fabric[cloud]'
# Dev tools
pip install 'cognitive-fabric[dev]'
To work from a checkout instead, clone this repository, create a virtualenv, and
use . in place of the package name: pip install -e .,
pip install -e '.[semantic]', and so on.
KuzuDB version
kuzu is pinned to ==0.11.3 in pyproject.toml. Kuzu is archived upstream —
0.11.3 is the final release — and its on-disk format is not stable before 1.0, so a
database written by one Kuzu version may not be readable by another. Treat the pin
as a migration boundary, not a floor: to move versions, upgrade and then re-ingest
(or export/import the graph) rather than pointing the new version at the old file.
Quick start (CLI)
# Create a database
cognitive-fabric init ./data/mem.db
# Ingest a project's symbols/files into the graph (Cognitive Fabric)
cognitive-fabric fabric-ingest ./data/mem.db my-app --path /path/to/project
# Inspect
cognitive-fabric info ./data/mem.db
cognitive-fabric query ./data/mem.db "MATCH (s:Symbol) RETURN s.id LIMIT 10"
Running as an MCP server
The server is a console script, so where it lives depends on how you installed the package. For an MCP client, an isolated tool install is the least fuss: it puts the script somewhere stable that does not move with a project directory.
pipx install cognitive-fabric # or: uv tool install cognitive-fabric
Then ask your shell where it landed:
which cognitive-fabric # macOS, Linux
where cognitive-fabric # Windows
and put the path it prints in your MCP client (e.g. Claude Code), in place of the placeholder below:
{
"mcpServers": {
"cognitive-fabric": {
"command": "/absolute/path/to/bin/cognitive-fabric",
"args": ["serve", "--db-path", "/absolute/path/to/mem.db"]
}
}
}
An MCP client launches the server itself rather than through a shell, so it
does not inherit your PATH — a bare "command": "cognitive-fabric" fails
with No such file or directory even when that directory is on it. That is why
the path is spelled out. --db-path must be absolute too, and on Windows the
script is cognitive-fabric.exe.
From a checkout, pip install -e . puts the script at
.venv/bin/cognitive-fabric (Scripts\cognitive-fabric.exe on Windows), and
that is the path to give the client.
MCP tools
| Tool | Description |
|---|---|
memory-bank |
Initialize and manage memory banks |
entity |
CRUD for all entity types |
context |
Session/episodic context |
query |
Structured graph queries |
associate |
Create relationships between entities |
analyze |
Graph algorithms (PageRank, Louvain, k-core, shortest path) |
detect |
Pattern/anomaly detection (cycles, islands) |
introspect |
Schema inspection |
bulk-import |
Batch entity operations |
search |
fulltext / by-name / by-kind / semantic / hybrid |
delete |
Safe deletion operations |
memory-optimizer |
AI-powered memory optimization + snapshots/rollback |
fabric |
Cognitive Fabric operations (see below) |
The fabric tool
| Operation | Purpose |
|---|---|
ingest-ast |
Scan a project (path) → persist Symbol/File nodes + DEFINED_IN edges (+ index in the vector store) |
query-evolution |
Trace an entity's EVOLVED_FROM lineage (itemId, itemType) |
query-rationale |
Find the Decisions that JUSTIFIES an entity (itemId) |
record-event |
Record an episodic Context event for later distillation |
dream |
Distill recent context into Decisions + JUSTIFIES edges (needs an LLM key) |
link-evolution / link-to-file / link-to-symbol |
Create provenance/lineage edges |
Entity types
Repository, Component, Decision, Rule, Context, File, Tag, Metadata, and the Cognitive Fabric nodes Symbol, Requirement, Trace.
Configuration
Settings load from environment (prefix COGNITIVE_FABRIC_) or a .env file
(see .env.example). Key vars:
COGNITIVE_FABRIC_LLM_PROVIDER(openai|anthropic) +OPENAI_API_KEY/ANTHROPIC_API_KEY— enables the dream engine. Both the provider SDKs come from the[cloud]extra (pip install 'cognitive-fabric[cloud]'); without it the dream engine reports that the SDK is missing rather than raising an import error.COGNITIVE_FABRIC_FABRIC_DATA_DIR— where the LanceDB vector store lives.COGNITIVE_FABRIC_FABRIC_EMBEDDING_PROVIDER(sentence-transformers|openai). Thesentence-transformersbackend needs the[semantic-st]extra; it is the one embedding backend no CI job installs, so it has no test behind it.
Development
pip install -e '.[dev]'
pytest # unit + integration (real kuzu)
pytest -m integration # integration only
ruff check src tests
mypy src
ruff check src tests and pytest are the gates CI enforces. mypy is
configured (strict = true in pyproject.toml) but the tree does not satisfy
it yet, so it is not a gate — running it today reports errors. The
configuration is in place; only the cleanup is outstanding.
Tests that need the optional semantic stack ([semantic]) or a tree-sitter
parser pack are skipped automatically when those are not installed.
Architecture
MCP client (stdio)
│
MCP server ── tool handlers ── domain services ── repositories ── KuzuDB
│ │
│ DataFabricService ── SymbolicIngestor (tree-sitter)
│ DreamService ── LanceDB VectorStore (semantic)
└── fabric / search / entity / ... LLM (openai|anthropic)
Everything runs in one Python process over stdio; the fabric ML runs in-process (no sidecar, no network data plane). See docs/architecture.md and docs/fabric.md.
Project structure
src/cognitive_fabric/
├── agents/ # AI memory optimizer
├── cli/ # Click CLI
├── db/ # KuzuDB client + schema
├── fabric/ # In-process ingestor (tree-sitter) + vector store (LanceDB)
├── mcp/ # MCP server, tools, handlers
├── repositories/ # Data access layer
├── services/ # Domain services (incl. data_fabric, dream)
├── types/ # Pydantic models
└── utils/ # Utilities
License
Apache-2.0 — see LICENSE and NOTICE.
Metadata
Release files for cognitive-fabric 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cognitive_fabric-0.1.0.tar.gz | 210.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cognitive_fabric-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 387.1 kB
Release files / cognitive_fabric-0.1.0.tar.gz
| Download URL | cognitive_fabric-0.1.0.tar.gz |
|---|---|
| Size | 210.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2e20e840fdc1cdebfc1b5dcce6b2818259f3afffd7c6e8944aa38c67a5faab2
|
|
BLAKE2b-256 checksum How to use checksums |
182fc42f51f135f264bcea88da928e55e47abb928fe4a87bd71664ff70e99a9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.
Transparency logRelease files / cognitive_fabric-0.1.0-py3-none-any.whl
| Download URL | cognitive_fabric-0.1.0-py3-none-any.whl |
|---|---|
| Size | 176.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d1d70cd8f17fabd9a3a17e8172a9fb4c5be9889a7686746e7db61a1214cd91e5
|
|
BLAKE2b-256 checksum How to use checksums |
f47004379d1b07e52e75a1f005a0ed83d5c05f3c79e6cff8ab8bdd1c23be73f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.
Transparency log