DEV Community

Abdeljabbar Elassali
Abdeljabbar Elassali

Posted on Originally published at dev.to

Turn a Codebase or Document Pile Into a Queryable Knowledge Graph Over MCP

Turn a Codebase or Document Pile Into a Queryable Knowledge Graph Over MCP

Every developer has a folder like this: a repo nobody fully documented, a pile of meeting notes, a wiki that stopped being true somewhere in Q2. You can grep it, but grep does not understand it. Vector search over it gets you relevant passages, but not the relationships between them.

There is an open-source project that takes a different approach: Cognee, an AI memory engine that ingests your documents and code and builds a knowledge graph out of them, then exposes that graph over the Model Context Protocol so your AI tools can query it. Here is what the setup looks like, what the moving parts are, and what to watch for.

The two pieces, briefly

MCP is the open standard Anthropic introduced on November 25, 2024. Before it, every AI tool needed a custom connector for every data source, which meant N tools times M sources of integration work. MCP standardized the interface: data platforms expose an MCP server, AI apps act as MCP clients, and they negotiate capabilities at connection time. It is the USB-C of AI tooling: one plug shape, many devices.

Cognee is the memory engine that sits behind one of those plugs. It ingests text, PDFs, audio transcripts, and source code, then constructs a knowledge graph: entities (people, services, modules, decisions) linked by relationships (owns, depends on, replaced). The advertised design rationale is a hybrid: a vector database handles semantic similarity (fuzzy, meaning-based lookup) while the graph handles structure (who owns what, what changed, how things connect). The project presents the combination as cutting hallucinations more than either alone. Treat that as the design thesis, not a measured guarantee: the graph is only as good as the extraction that built it.

The setup shape

The repo lives at github.com/topoteretes/cognee. Getting it running follows a shape that will be familiar to anyone who has wired up an MCP server:

  1. Clone the repository to your machine. This is the server you will run; your AI client talks to it over MCP.
  2. Install uv, the Python package manager the project uses for its dependency setup. The README walks through the install for your platform.
  3. Add a server entry to your MCP client's config. For Claude Desktop, that means editing claude_desktop_config.json and adding a server definition that points at the Cognee MCP server, with an LLM_API_KEY environment variable so the engine can call a language model for extraction and graph building. That env var is the one thing people forget, and the server fails quietly without it, so set it first.
  4. Restart the client so it picks up the new server. When it connects, the model can discover and call the memory operations.

No custom connector code on your side. That is the whole point of MCP: the server speaks the protocol, the client already speaks the protocol, and the config entry is the integration.

The two advertised operations

Cognee exposes its memory work as named operations your AI tools can call. Two are documented for the headline integrations:

cognee.cognify (via Claude Desktop). This is the ingestion path. Point it at your documents or data sources and it processes them into the knowledge graph: extracting entities, resolving relationships, and indexing everything for both semantic and graph queries. Think of it as "memorize this" for your codebase or document set. After cognify runs, the material is no longer a pile of files. It is a queryable structure.

cognee.remember(repo_path) (via Cline). This is the query path for code work. You pass the path to a repository, and the coding agent gets memory-backed context about that codebase: what depends on what, who owns what, how the pieces fit. The agent stops grepping blind and starts asking the graph questions.

A concrete way to picture it: you hand a new coding agent a legacy service you inherited. Without memory, it greps for function names and guesses. With a graph built from the repo, it can ask "which services call the billing API and who owns them" and get an answer grounded in extracted structure rather than keyword luck. The difference shows up most on multi-hop questions, the ones where flat retrieval has to intersect two or three chunks and hope the model joins them correctly.

What to watch for

This is the part that separates a weekend demo from something you rely on.

Ingest quality decides everything. The graph is an extraction artifact. Clean, well-structured inputs produce clean graphs. A folder of contradictory notes, half-finished docs, and ambiguous references produces a graph that faithfully preserves your contradictions. Garbage in, structured garbage out. Curate what you ingest.

Graphs go stale, and stale graphs are confidently wrong. Code rots, people change teams, decisions get reversed. A vector store with stale chunks degrades gracefully (old passages just rank lower). A graph with stale edges gives structural answers that are flat-out wrong: it will tell you Priya owns billing long after she handed it to Marcus. Plan a re-ingestion cadence for anything that changes, and check whether old edges get retired or just pile up.

Watch the extraction bill. Building a knowledge graph means running LLM calls over your corpus, once for extraction and again on every re-ingestion. For a personal codebase that is trivial. For a company wiki, it is a real line item. Estimate it before you commit, and measure whether the accuracy improvement justifies the spend for your workload.

Verify the answers, not the architecture. The hybrid design is sound on paper: vectors for meaning, graphs for structure. But "reduces hallucinations" is the project's framing of its own rationale, and your mileage depends on your data. Test it on questions you know the answers to, especially ownership, dependency, and "what changed" questions, before you let an agent act on the graph's answers unattended.

Why this matters beyond one project

Even if you never run Cognee, the pattern is worth understanding, because it is where AI memory is headed. Plain RAG gave models a way to look things up. Graph-backed memory gives them a way to keep track: of relationships, of state, of what changed. For agents that run for hours or days, that is the load-bearing part.

And the MCP angle is the part that makes it practical. Memory stops being a feature bolted into each tool and becomes infrastructure any tool can plug into. Your graph, built once, queryable from Claude Desktop, Cline, and anything else that speaks the protocol. That is a meaningful shift from "each AI remembers its own slice" to "one memory, every tool."

If you like this architecture but do not want to run the pipeline yourself, I build Vilix AI, a managed shared memory layer for AI tools. It is MCP-native, stores your context server-side with per-user isolation, and you can list, update, delete, or export every memory from any connected tool. Free tier, seven-day Pro trial, no credit card, about ten minutes per tool to set up.

Top comments (0)