All posts

MCP vs RAG: Which Approach for Codebase Knowledge?

RAG indexes a snapshot of your code; MCP lets the agent explore the repository at question time. What each approach sees, what it misses, and when to combine them.

The two don't compete at the same level: RAG is a technique (index text fragments so you can retrieve them by similarity), MCP is a protocol (let an agent query live sources while it reasons). For codebase knowledge, the real choice sits one level down: between an indexed snapshot of your code and an exploration of the repository at the moment the question arrives. The nature of your questions decides it.

Two short definitions, and the trap in the comparison

RAG (retrieval-augmented generation): split a corpus into fragments, turn them into vectors (embeddings), then, for each question, retrieve the closest fragments and hand them to the model as context.

MCP (Model Context Protocol): an open standard that describes how an AI agent connects to external tools and data sources, and queries them on demand, mid-reasoning.

The trap: an MCP server can perfectly well expose… a RAG index. "MCP or RAG?" as people actually mean it is not a duel of acronyms. It is a choice between two regimes of knowledge: precomputed knowledge (a state of the code was indexed, the agent picks from it) and consulted knowledge (the agent goes into the repository for whatever the question needs, when it arrives).

The same question, two mechanics

Take a question from the real life of a product: "Why did this behavior change?" A customer swears the CSV export used to print dates as DD/MM; since Monday they come out as MM/DD. Follow the question through each regime.

In the RAG regime. The index was built from one state of the codebase: every file chunked, embedded, stored. The question comes in, the closest fragments come back: the export module, the date-formatting function, maybe a docs page. All of them describe the current behavior. The behavior before Monday exists nowhere in the index: a snapshot of the present has no yesterday. So the model answers what the fragments allow: "the format is MM/DD, defined here." True. Not the question.

In the exploration regime. The agent has tools: list recent commits touching the export module, read a diff, compare two versions of a file. It works through them: three commits on the module since Monday, one of which swapped the formatting locale while upgrading the date library. The answer cites the commit, its date, its intent. The question was about a transition between two states; only a source that contains transitions could answer it.

This is not a pathological case picked to let exploration win. The whole family — "what changed this week?", "since v2.3?", "does anything break?" — has the same shape: the answer lives in the diffs, not in a snapshot. An index keeps at best an indirect trace; git history is the source.

Where RAG wins, and it should be said

A well-built index remains the right tool in at least three situations.

Large, stable corpora. A public documentation set of several thousand pages, a support knowledge base, years of tickets: similarity search excels there, and nobody wants to explore that commit by commit.

Location questions. "Where do we talk about rate limiting?", "which modules mention this domain term?": semantic similarity finds neighborhoods an exact search misses. That is its native strength.

Cost per question. Once the index is paid for, each question is cheap and fast. Tool-driven exploration consumes more: it reads, compares, cross-checks. For a massive stream of simple questions over a slow-moving corpus, the index wins.

The limit is symmetric to the strength: an index represents states. Its freshness is the freshness of the last indexing run, and it holds no transitions. On a codebase that receives pushes every day, both blind spots get paid for in the window after each release: the moment people ask the most questions is the moment the index just became wrong.

Where exploration at question time wins

Flip the list. Tool-driven exploration wins when freshness matters (today's code, not the last indexing run's), when the question is causal or historical (why, since when, what breaks), and when the answer has to be verified rather than plausible: the agent can re-read the code before asserting, instead of assembling fragments that look alike.

That is the regime DeployIt works in. DeployIt reads your real code (resynced on every push), your git history (commits + diffs) and the customer's data through its own MCP servers, and checks the code before asserting. Each project gets a queryable product expert for your agents: the CSV-export question gets the offending commit back, not a description of the present.

Ready to see what your team shipped?

"I'll build my own RAG over the repository"

It is doable, and for a tooled-up developer it is even a good weekend project: embeddings over the files, re-indexing in CI on every merge, a homemade MCP server on top to serve your agents. If your questions are location questions about the present code, that setup will serve you well.

Two limits come from the principle of the setup, not from how well you execute it. First: re-indexing more often brings the index closer to the present, but never lets the past in. The "what changed?" family of questions stays sourceless, because those questions are answered in the diffs. DeployIt's answers come from them: they hold even when the commits are named "wip" or "fix", where a pipeline built on commit messages inherits their quality. Second: your homemade RAG serves whoever can call it, and it stands on your repository credentials. Your third-party askers (an Intercom Fin agent, an agency client under NDA, an integrator) will never hold those credentials. An answers channel serves them without opening anything.

What DeployIt allows itself on your repository

The mirror objection is just as legitimate: to explore the repository, DeployIt reads it. The perimeter is narrow and checkable: read-only GitHub connection, one server per project, revocable at any time. Answers are sourced from commits and diffs, never raw source restitution: the asker learns that the formatting locale changed on Monday, they don't read your export module. The code never leaves the repository.

Three recurring questions

Does MCP replace RAG? They are two different layers: MCP standardizes the connection between an agent and its sources, RAG is one way of preparing a source. The useful choice is about the regime of knowledge behind the connection.

Can you combine both? Yes, and it is often the right architecture: an index for docs and stable corpora, repository exploration for the code and its history. An agent connected to both picks its source per question.

What about the public libraries my code uses? Others cover that ground: Context7 and DeepWiki cover libraries and public repositories, Mintlify generates an MCP from written docs. DeployIt covers your private product, derived from the code itself, fresh on every deploy. They complement each other inside the same agent.

Choose by the question, not by the acronym

Write down your actual questions. "Where is X handled?" leans toward the index. "Why did this behavior change?", "does the API break this week?" demand exploration. Most teams find their most expensive questions in the second column. That is the column of transitions.

DeployIt's MCP server is in early access / design partner program: if your agents need to answer from your code and its history, the program is open. DeployIt is free during early access; paid plans arrive in January 2027.

Ready to see what your team shipped?

Continue reading