RAG vs MCP in 2026: What Each Solves and How They Fit Together
In this article
Code in this guide is reproduced from the README of the official MCP Python SDK, modelcontextprotocol/python-sdk (MIT licence). Definitions of MCP's primitives come from the MCP specification.
"Should we use RAG or MCP?" is one of the most common architecture questions in AI engineering, and it rests on a category error. RAG is a technique: find the passages in your data that are relevant to a question and put them into the model's context, so the answer is grounded in your information rather than the model's memory. MCP, the Model Context Protocol, is a protocol: a standard way for an LLM application to connect to servers that expose tools, data and prompts. Asking which to choose is like asking whether to use full-text search or HTTP.
The useful questions are different. When does a problem need retrieval? When does it need a standard connection to outside systems? And when the answer is both, which is common, how should retrieval be exposed through MCP? This guide answers those with a working MCP server and client from the official SDK.
What RAG does
A RAG system has two halves. Indexing splits your documents into chunks, embeds them and stores the vectors. Retrieval embeds each question, finds the closest chunks, and places them in the prompt. Everything interesting is in the details: how you chunk, what you store as metadata, how many results you keep, and how you stop retrieved text from carrying instructions into the model.
RAG answers one question: what does my data say about this? It does not send email, query a live API or write a file. For hands-on builds, see our LangChain RAG agent and chain or the multi-tenant Pinecone and Next.js app.
What MCP does
The SDK's README puts it plainly: MCP lets you build servers that expose data and functionality to LLM applications in a secure, standardized way, "like a web API, but designed for LLM interactions." An application that speaks MCP (the host, such as an IDE assistant or a chat app) can connect to any MCP server without custom integration code for each one.
A server offers three kinds of capability, and the specification assigns each one a controller:
| Primitive | Controlled by | What it is | Spec's examples |
|---|---|---|---|
| Prompts | User | Interactive templates invoked by user choice | Slash commands, menu options |
| Resources | Application | Contextual data attached and managed by the client | File contents, git history |
| Tools | Model | Functions exposed to the LLM to take actions | API POST requests, file writing |
That "controlled by" column is the key to the whole RAG-versus-MCP question, as the section after the build shows.
Build an MCP server
Install the SDK with its command-line tool:
uv add "mcp[cli]" # or: pip install "mcp[cli]"
The README's complete server, with one tool and one resource:
from mcp.server import MCPServer
mcp = MCPServer("Demo")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
@mcp.resource("greeting://{name}")
def greeting(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"
Save it as server.py and open it in the MCP Inspector:
uv run mcp dev server.py
Calling add with a=1 and b=2 returns 3. Notice what is missing: no JSON Schema, because the type hints a: int, b: int are the schema; no request parsing; no protocol handling. add is a tool, so a model can decide to call it. greeting://{name} is a templated resource, data an application can read by URI. The SDK requires Python 3.10 or later.
Call it from a client
The same package is a client. Serve the file over HTTP:
uv run mcp run server.py --transport streamable-http
Then call the tool:
import asyncio
from mcp import Client
async def main() -> None:
async with Client("http://localhost:8000/mcp") as client:
result = await client.call_tool("add", {"a": 1, "b": 2})
print(result.structured_content) # {'result': 3}
asyncio.run(main())
A URL means Streamable HTTP, the transport you deploy. The SDK also supports stdio, where the host launches the server as a local subprocess, and SSE.
Where RAG fits: retrieval as a tool or as a resource
Put the two together and the real design decision appears. Your retriever, the search half of RAG, can be exposed through MCP in two ways, and the specification's control column tells you which one you are choosing:
- Retrieval as a tool (model-controlled). A search function decorated with
@mcp.tool()lets the model decide whether to search and what to search for, and to search again with a refined query. This is agentic RAG. It suits open-ended questions and agents that work across several sources. - Context as a resource (application-controlled). Exposing documents with
@mcp.resource(...)leaves the decision with your application, for example always attaching the policy document a user has open. It suits predictable flows where context should be present every time, not when the model thinks to ask.
Our guide to exposing LlamaIndex tool specs as an MCP server with fastmcp does the tool version end to end, and the multi-tool Claude agent with MCP servers shows a host consuming several servers at once.
Choosing between them, and combining them
| RAG | MCP | |
|---|---|---|
| What it is | A technique for grounding answers in your data | A protocol connecting LLM apps to tools, resources and prompts |
| Question it answers | "What does our data say about this?" | "How does the model reach this system or data source?" |
| Typical output | Relevant passages added to the prompt | Tool results, resource contents, prompt templates |
| Can it change things? | No, it only reads | Yes, through tools such as file writing and API POST requests |
| Main risk | Leaking documents to the wrong audience; instructions hidden in retrieved text | Tools acting with too much authority; trusting servers you do not control |
| Use together when | Several applications need the same knowledge base: build one retriever, expose it once over MCP, and every MCP host can use it | |
What to watch out for
MCP tools can act, so scope them. A retriever exposed as a tool only reads, but the same server can expose tools that write files or call APIs. Give each server the least authority it needs, and treat third-party servers like third-party code you are about to run.
Retrieved text is still untrusted. Moving retrieval behind MCP does not remove prompt injection: a document that says "ignore your instructions" reaches the model either way. Keep the defences from your RAG pipeline.
Access control belongs in the server. An MCP server that wraps a shared index serves whoever connects to it. Enforce who may query which data inside the server, not in the client prompt.
Where to go next
To build the retrieval half well, start with the LangChain getting-started guide, then measure it with synthetic RAG test sets from Ragas. For the protocol half in production, APIs vs MCPs vs MCP gateways covers routing many servers through one controlled entry point.
Frequently asked questions
Is MCP a replacement for RAG?
No. RAG is a technique: retrieve relevant passages from your data and put them in the model's context. MCP is a protocol for connecting LLM applications to external tools, data and prompts. A RAG retriever can be exposed over MCP, so the two are often used together rather than chosen between.
What are MCP's three server primitives?
Prompts, resources and tools. The MCP specification assigns each a controller: prompts are user-controlled templates such as slash commands, resources are application-controlled data such as file contents, and tools are model-controlled functions the LLM calls to act or retrieve information.
Should my retriever be an MCP tool or an MCP resource?
Make it a tool when the model should decide when to search and what to search for, as in an agent. Make the data a resource when your application should decide what context to attach, for example always including the open file. The MCP spec defines tools as model-controlled and resources as application-controlled.
How do I build an MCP server in Python?
Install the official SDK with pip install "mcp[cli]", create an MCPServer, and decorate functions with @mcp.tool() or @mcp.resource(...). Type hints become the schema, so no JSON Schema is written by hand. Test it with uv run mcp dev server.py, which opens the MCP Inspector.
Which transports does MCP support?
The official Python SDK supports stdio, Streamable HTTP and SSE. Stdio suits a local server launched by the host application; Streamable HTTP is the transport you deploy, and a client given a URL uses it.
Related Guides

Getting Started with LangChain in 2026: Build a RAG Agent and a RAG Chain
Build retrieval-augmented generation two ways with LangChain 1.x: an agent that calls a retrieval tool, and a chain that injects context every time.
Build Stateful Web Research Agents with Claude Agent SDK
Run one-off and stateful Claude research agents that search the web, cite sources, and read multimodal inputs with the Anthropic Cookbook pattern.

Generate Synthetic RAG Test Sets With Ragas
Build, save and reuse a Ragas knowledge graph to generate single-hop and multi-hop evaluation queries from Markdown documents.