MCP vs RAG: pre-indexed retrieval or a live search tool
On this page
RAG (retrieval-augmented generation) is a pattern: fetch relevant text and put it in the prompt before the model answers. MCP is a protocol for connecting an AI application to tools, resources and prompts that a server provides. They aren’t alternatives, because an MCP server can expose retrieval as a tool, whether that tool queries a vector index or calls a source system’s own search live. The real decision is between searching a pre-built index and querying the source at request time, and it comes down to freshness, permissions, cost, context size and auditability.
Checked as of November 2026 against the MCP specification revision 2026-07-28 (tools and resources), the MCP Python SDK and the pgvector README.
RAG is a pattern, MCP is a protocol
The term comes from a 2020 paper by Lewis et al. that paired a retriever over a document index with a generator. The common modern version: split documents into chunks, embed each chunk, store the vectors, and at question time embed the question, take the nearest chunks and add them to the prompt. The application decides when to retrieve, usually on every request.
MCP doesn’t say anything about retrieval. A client lists a server’s tools with tools/list, and the model decides when to call one. Resources work differently: the spec calls them application-driven, so the host decides how to include them, for example through a picker. What is an MCP server walks through the messages.
| RAG pipeline | MCP tool | |
|---|---|---|
| What it is | An application design | A wire protocol between client and server |
| Who decides to retrieve | The application, usually every turn | The model, when it judges a tool useful |
| Where the data is searched | A copy in your index | Wherever the server looks: an index or the live system |
| Freshness | As of the last ingestion run | As of the call, if the server queries live |
| Access control | Whatever filters you store with the chunks | The credential on the request, checked by the server or upstream |
| Can it change anything | No | Yes, if the server has write tools |
A RAG pipeline in an app
A typical in-app retriever with Postgres and pgvector, where <=> is pgvector’s cosine distance operator. embed stands for whichever embedding model you use:
import psycopg
from pgvector import Vector
from pgvector.psycopg import register_vector
conn = psycopg.connect("postgresql://localhost/support")
register_vector(conn)
def retrieve(question: str, team_id: int, k: int = 5) -> list[tuple]:
query = Vector(embed(question))
return conn.execute(
"""
SELECT doc_id, chunk_text
FROM chunks
WHERE team_id = %s
ORDER BY embedding <=> %s
LIMIT %s
""",
(team_id, query, k),
).fetchall()
def build_prompt(question: str, team_id: int) -> str:
context = "\n\n".join(text for _, text in retrieve(question, team_id))
return f"Answer using only this context:\n\n{context}\n\nQuestion: {question}"
Two things to notice. The model never asks for anything; it gets five chunks whether it needs them or not. And the only access control is the team_id column, which is as accurate as the last ingestion run.
The same search as an MCP tool
Wrapping that retriever in an MCP server takes a few lines with the Python SDK, where type hints become the tool’s input schema:
from mcp.server import MCPServer
from rag import retrieve # the retriever above
PUBLIC_TEAM_ID = 1 # the team that owns published articles
mcp = MCPServer("support-search")
@mcp.tool()
def search_help_articles(query: str, limit: int = 5) -> list[dict]:
"""Semantic search over published help articles. Use this when the user
asks how a feature works. Returns article IDs and matching passages."""
rows = retrieve(query, team_id=PUBLIC_TEAM_ID, k=limit)
return [{"doc_id": doc_id, "passage": text} for doc_id, text in rows]
Serve it over Streamable HTTP with uv run mcp run server.py --transport streamable-http, deploy it behind HTTPS, and Claude Code, Cursor, ChatGPT or any other MCP client can call it. The model decides when:
{
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "search_help_articles",
"arguments": { "query": "rotate an API key without downtime", "limit": 3 }
}
}
This is still RAG. The index, the embeddings and the staleness are unchanged; only the delivery is different.
A live search tool instead of an index
The alternative is a tool that queries the source system at call time with the caller’s own credential. A tool definition might look like this:
{
"name": "search_tickets",
"description": "Search support tickets the signed-in user can see. Supports status, priority and assignee filters.",
"inputSchema": {
"type": "object",
"properties": {
"text": { "type": "string" },
"status": { "type": "string", "enum": ["open", "pending", "closed"] },
"assignee": { "type": "string", "description": "Use \"me\" for the current user" }
}
},
"annotations": { "readOnlyHint": true }
}
There is no ingestion pipeline. The result reflects the ticket system as of the call, and the ticket system applies the user’s own permissions.
When pre-indexed retrieval is the better choice
- Meaning over keywords: if the source system only does keyword search, embeddings find “how do I rotate credentials” in an article titled “Replacing API keys”. Live search won’t.
- Large, slow-moving corpora: documentation, policies, past resolved tickets. Staleness costs little when the content changes monthly.
- Context needed on every request: a support assistant that always needs policy text gains nothing from letting the model decide whether to look.
- One round trip: RAG retrieval is a database query before a single model call. A tool call adds at least one more model turn: the model asks, the client calls, the model reads the result.
- Fragile or expensive sources: if the upstream API is rate-limited or billed per call, an index absorbs the query volume.
When a live tool call is the better choice
- Freshness: an index is as old as its last sync. “What’s the status of INC-2291” needs the current answer, not the one from last night’s run.
- Permissions: a shared index has to copy the source’s access rules into its own metadata and keep them in sync. When someone loses access to a private channel or document, their queries can keep matching its chunks until the next re-index. A live call carries the user’s credential, so the source enforces access at the moment of the query. MCP is built around per-request credentials: the spec even lets
tools/listandresources/listreturn different sets depending on the authorization presented on the request. - Structured questions: “Open P1 bugs assigned to me” is a filter, not a similarity search. Vector distance is the wrong tool for it.
- Actions: retrieval only reads. If the agent also needs to comment, assign or close, it needs tools anyway.
- No pipeline to run: chunking, embedding, re-embedding after a model change and deleting removed documents are all ongoing work.
Cost, latency and context size
RAG costs show up as embedding calls during ingestion, vector storage and a fixed amount of context on every request, used or not. Good chunking and a small k keep the last one down.
MCP costs show up elsewhere. Tool definitions take context unless the client loads them on demand, and results can be large. Claude Code warns when MCP tool output exceeds 10,000 tokens and limits it to 25,000 by default (adjustable with MAX_MCP_OUTPUT_TOKENS). A well-designed search tool returns IDs and short passages, plus a separate fetch tool for the full document, so the model reads only what it picks.
Latency follows the same split: one vector query is usually fast, while a live search depends on the upstream API and adds a model turn. For an interactive chat that difference is visible; for an agent working through a task over several minutes it rarely matters.
Auditability
With RAG inside an application, you can log the chunk IDs retrieved for each request. That answers “what did the model see”, but only your application has that log, and the source system sees nothing, because the index was read rather than the source.
With MCP, each retrieval is a named call with arguments, and the tools specification says clients should log tool usage for audit. A live call also shows up in the source system under the user who made it. That answers a different question: what did the agent ask for, and on whose behalf.
Both paths put retrieved text into the model’s context, and that text can contain instructions. An index full of customer emails is as much an injection source as a live inbox tool; the lethal trifecta explains why it matters most when the same agent can also send data out.
Using both
The common production shape combines them:
- Put semantic search over the slow-moving corpus behind an MCP tool, so every client can use it and the model calls it only when needed.
- Use the vendor’s live MCP server for current state, structured filters and actions.
- Expose fixed reference material, such as a schema or a style guide, as an MCP resource the host can attach.
- If the index contains anything permissioned, filter by the caller’s identity in the tool and re-check against the source before returning results.
MCP vs API covers the related question of when an agent should call a service’s API directly instead of a server.
A gateway sits on the MCP side of this. Toolstile handles remote MCP servers, so a search tool on a server you host or a vendor’s live server gets the same per-agent Allow, Require approval or Block rules and the same call log as any other tool. It doesn’t index or embed anything itself. What an MCP gateway is describes the model.