MCP vs RAG: Two Different Answers to How a Model Gets Context
A support agent tells a customer that returns close after 30 days, but the product page says 45. Choosing MCP or RAG doesn't fix that, because the two answer different questions.
A support agent tells a customer that returns close after 30 days, but the product page says 45. Choosing MCP or RAG doesn't fix that, because the two answer different questions. RAG is a retrieval pattern: it finds relevant content and puts it in the prompt. MCP is the protocol a model calls during its loop to fetch context. Sanity Context uses both. It serves GROQ or Knowledge Base retrieval through its hosted Context MCP endpoint.
A wrong answer is only part of the risk. Teams that treat this as an either-or choice often attach an MCP server to a stale vector index. Others rebuild a RAG pipeline next to a content system that already holds the source of truth. Either way, the agent quotes outdated prices, misses products that match exact filters, and contradicts the website it is supposed to represent.
In this guide, MCP is the delivery question and RAG is the retrieval question. It compares how Pinecone, Contentful, pgvector, and Sanity Context handle each one. It ends with a framework for choosing which retrieval mode sits behind your endpoint.
What is the difference between MCP and RAG?
MCP and RAG make different decisions. RAG decides which content reaches the model. MCP decides how the model asks for that content. Retrieval-augmented generation is a pattern. Before the model answers, a retriever searches an index, picks the most relevant passages, and inserts them into the prompt. The model doesn't choose what to look up. The pipeline chooses for it, usually once per question.
The Model Context Protocol is an interface standard. Anthropic open-sourced MCP on November 25, 2024, as a JSON-RPC 2.0 protocol for connecting AI assistants to tools and data sources. An MCP server exposes three primitives (tools, resources, and prompts) over stdio or Streamable HTTP. Governance has since moved to the Linux Foundation's Agentic AI Foundation. With MCP, the model controls when retrieval happens. During the agent loop it can call a search tool, inspect a schema, follow up with a narrower query, and stop once it has enough.
That difference is also why the two get confused. An MCP tool named search_docs might run a RAG pipeline underneath. A RAG system might reach an agent through MCP instead of being hardwired into a prompt template. The protocol says nothing about whether the answer will be correct. Retrieval quality still depends on what sits behind the tool: how fresh the index is, whether exact filters hold, and whether keyword and semantic signals are blended.
In short, RAG is a retrieval strategy, and MCP is a transport and tool contract. Comparing them head to head is like comparing SQL to HTTP, and you need an answer for both. The established approach runs retrieval as a fixed step before the model sees the question. The newer approach gives the model tools and lets it decide when to use them. That only works if the tools return reliable results. The rest of this guide covers how to make the second approach reliable without rebuilding the first from scratch.
Why does classic RAG fail in production?
Classic RAG usually fails in production because of the index, not the model. The standard starter stack, a vector database such as Pinecone wired up through a LangChain or Vercel AI SDK template, embeds documents once and searches them by similarity. That works in a demo. It breaks down as soon as content changes or a question carries hard constraints.
The first failure is freshness. Every edit, deletion, and backfill has to flow from the content system into the vector store. When that sync lags, the agent confidently quotes last month's price or a discontinued product. Incremental indexing, re-embedding on change, and deletion handling never really get finished. They stay on the roadmap of whoever owns the pipeline, quarter after quarter.
The second failure is constraint handling. A request like "size L latex gloves, under $200 a pallet" is a filter, not a similarity search. Pure vector search returns documents that sound like gloves, including size M and options over budget. If you add a strict filter afterward, you can end up with no results at all. Vector search alone isn't good retrieval. It needs keyword matching for exact terms and structured predicates for conditions that have to hold.
The third failure is that the model never gets to ask a second question. Classic RAG retrieves once and hands over whatever it found. If that first retrieval missed, the model fills the gap itself, and that's where hallucinations come from.
None of this means RAG is wrong. PostgreSQL with pgvector and full-text search can do hybrid retrieval, and so can Elasticsearch. Algolia is designed for search that combines structure with relevance, and Pinecone can do it with a metadata filter layer. Every one of those options needs a pipeline that keeps the index in step with the content, and teams tend to underestimate that pipeline.

Semantic search ranks, it does not filter
How does Sanity Context use MCP and RAG together?
Sanity Context uses MCP for delivery and runs retrieval inside the Content Lake, so the two stop being separate systems. Context MCP is one part of the product: a hosted, read-only endpoint that any agent loop can connect to. Sanity Context also includes Knowledge Bases and an ingest path, so it does more than an MCP server, but agents reach it through the endpoint.
Context MCP has two retrieval modes behind it, and the mode determines which tools the endpoint serves. GROQ mode queries the dataset at request time. The schema tells the agent where to look, so a request for size L latex gloves under $200 a pallet becomes a filter over product documents. That filter stays exact across hundreds of thousands of records, with no build step and nothing to sync. GROQ mode requires a deployed schema (run sanity schema deploy on Studio v5.1.0 or later). Knowledge Base mode serves a pre-built index instead. A build reads the sources ahead of time, reconciles them, and writes entries that the agent retrieves directly. The agent starts from an outline served by the initial_context tool.
Sanity's documentation reduces the choice to one rule: use GROQ mode for tabular data and Knowledge Bases for knowledge. If useful detail sits in the prose fields of a catalog, turn on dataset embeddings and stay in GROQ mode. One query can then combine structured filters with semantic similarity.
This is what Sanity means when it calls itself the Content Operating System for the AI era. Under the Power anything pillar, the content that runs a website also becomes agent context, stored once and delivered over MCP. Because retrieval is wired into the Content Lake, the content backend owns freshness. Edits, deletions, and re-embedding follow the content instead of depending on a separate sync job. Sanity replaces the usual combination of a headless CMS, a vector database, and glue code rather than adding another layer on top.
What does hybrid retrieval look like behind an MCP endpoint?
Hybrid retrieval behind an MCP endpoint is one query that applies hard filters first, then ranks the remaining results by keyword and semantic relevance. In Sanity Context's GROQ mode, that's a single GROQ query against the Content Lake instead of three services stitched together.
The pattern looks like this: *[_type == "product" && category == $category && price < $maxPrice] | score(boost([title] match text::query($q), 2), text::semanticSimilarity($q)) | order(_score desc)[0...10]. The predicates inside the brackets handle the filtering that must hold. The score() step blends a BM25 match() on the title with text::semanticSimilarity() across the whole document. boost() weights the title match 2x because title hits matter more. Results come back ordered by _score, and the projection can follow references, such as a stock location, in the same request.
For developers, the difference is where the work lives. In a Pinecone setup, the same request needs a metadata filter, a sparse or keyword signal, a dense vector query, and application code that merges and reranks the results. You also need a sync job that keeps the metadata matching the source of truth. With pgvector, you write SQL that combines vector distance with full-text ranking. That's entirely doable, but you then own the embedding refresh and the MCP server that exposes it. With a content backend that adds AI through integrations, retrieval usually happens in an external search service connected through an app or webhook.
One caution applies here too. Semantic similarity in GROQ ranks results but doesn't filter them, so text::semanticSimilarity() only works as an argument to score(). If you skip the predicates and rely on similarity alone, you get the same plausible but wrong results as pure vector RAG. GROQ makes the right query shape easy to write, but it can't stop you from writing the wrong one.
When an agent calls Context MCP in GROQ mode, it can explore the schema, write a query like this one, inspect the results, and refine. That loop is the practical payoff of putting structure-aware retrieval behind MCP.
What operational trade-offs come with MCP-based retrieval?
The main operational trade-off with MCP-based retrieval is that the endpoint's behavior depends on configuration you can get wrong without seeing an error. Sanity Context documents this risk openly. An MCP serves one source type. If you attach both a dataset source and Knowledge Base sources, the dataset source wins: the Knowledge Bases are ignored, the agent gets the GROQ tools, and nothing explains why. The mode is derived from the sources rather than set directly, so a source that fails to resolve can also change what the endpoint serves. To override the mode for a single connection, add ?mode=groq or ?mode=knowledge_base.
The documented fix is to cover the middle ground with dataset embeddings, not by mixing source types. A product catalog with long descriptions stays in GROQ mode with embeddings turned on. A policy and help-content corpus gets its own Knowledge Base connection.
Other operational questions apply to any MCP-plus-RAG stack. The first is who owns index freshness. In a vector database setup, re-embedding on change, deletions, and backfills belong to your pipeline. With pgvector, they belong to your database team and whatever triggers it builds. When retrieval runs inside the Content Lake, the content backend handles indexing and re-embedding as content changes.
The second is how many calls the agent makes. MCP lets the model iterate, which improves accuracy on hard questions but costs latency and tokens. Structured queries tend to be cheap and precise. In Sanity's own production usage, most Context MCP calls are GROQ queries and schema lookups, and semantic search is a small share. Embeddings are opt-in and off by default.
The third is what happens when retrieval misses. Classic RAG fails silently and the model makes up the gap. An agent loop with good tools can notice an empty result and retry with a broader filter. That's one of the strongest reasons to put retrieval behind MCP at all.
Dataset sources win silently
How do Knowledge Bases handle unstructured enterprise knowledge?
Knowledge Bases handle unstructured enterprise knowledge by reconciling sources once, at build time, instead of on every question. In Sanity Context, a Knowledge Base is a pre-built index over material you choose, served to agents through Context MCP. The feature is in beta, opt-in, and may change before general availability. A Knowledge Base belongs to an organization and can draw on sources from more than one project. That matters for enterprises whose policies, documentation, and product content live in different places. An org admin enables Knowledge Bases from the Apps page in Manage.
Each Knowledge Base has a purpose, an outline, entries, issues, and instructions. The outline is the pre-generated index: every entry path plus a one-line summary. It's small enough for an agent to keep in context for a whole conversation, and the initial_context tool serves it. Entries are Markdown with citations back to their sources. They aren't hand-editable, so the source content stays the source of truth.
Issues are the enterprise feature most RAG stacks lack. The same fact often appears in several places, and the copies drift apart. A help center says returns are accepted within 30 days, while a product page says 45. Classic RAG retrieves whichever chunk scores higher, and the agent repeats it. A Knowledge Base build detects the conflict and raises an issue that shows both claims side by side with their sources. A person then decides which one is the ground truth.
Agent platforms that bring their own retrieval, such as Kapa.ai, Decagon, or Sierra AI, work differently. They typically crawl your website or load it into their own index. The agent's knowledge is then a copy of your rendered pages, not your structured content. Any conflicts get resolved, if at all, inside a system your content team doesn't run.
For teams focused on governance, the key question is who makes the reconciliation decision. With Knowledge Bases, the people who own the content make it. Agents inherit that decision through the same Context MCP endpoint every other agent uses.
Conflicts surface before the agent answers
What does each approach cost, and where is the lock-in?
The real cost in the MCP versus RAG decision isn't licensing. It's the pipeline you commit to maintaining. A self-built RAG stack on pgvector or Neon has low software cost and high ownership cost. You own the embedding jobs, change detection, deletion handling, hybrid ranking SQL, evaluation, and an MCP server you write or adopt. That's a reasonable trade for teams with strong database engineering and a narrow corpus.
A vector database such as Pinecone moves infrastructure work to a managed service, but the content sync stays with you. Every source system needs a connector, and the metadata used for filtering has to stay consistent with the system of record. Lock-in tends to sit in the embedding model and the index shape, because changing either means re-embedding the whole corpus.
A content backend that adds AI through integrations, such as Contentful with its App Framework and an external search or vector store, keeps content in one place but splits retrieval across vendors. Contentful publishes an MCP server aimed at content management tasks. Governed agent retrieval with hybrid ranking usually still means adding another service to the path.
With Sanity Context, retrieval runs where the content already lives. Dataset embeddings are tied to the content, so updates propagate without a separate vector pipeline, and the GROQ query that serves the website can also serve the agent. The lock-in question becomes whether you're comfortable with the Content Lake as your system of record. That's a content platform decision rather than a retrieval infrastructure decision. Because Context MCP is a standard MCP endpoint, the agent side stays portable. Any agent loop that speaks MCP can connect, and you can swap models or frameworks without touching retrieval.
The hidden cost in every option is drift. If the agent's index is a copy, someone has to pay to keep that copy accurate. Over several years, the cheapest architecture is usually the one with the fewest copies of your content.
How should you choose between MCP, RAG, or both?
Choose based on the shape of your content and on who decides what to retrieve. Either way, use MCP as the delivery layer. Most production agents need both: a retrieval strategy that respects structure, and an MCP endpoint that lets the model call it as often as the task requires.
Start with four questions.
1. Is the content tabular, or is it knowledge? Product catalogs, prices, inventory, and schedules are tabular and need exact filters. Policies, guides, and support articles are knowledge and need reconciliation and summarization. In Sanity Context, these map to GROQ mode and Knowledge Base mode.
2. Does useful detail live in the prose fields of structured records? If so, enable dataset embeddings and stay in GROQ mode. One query can then apply filters and rank the results with text::semanticSimilarity() inside score().
3. Does the model need to iterate? Single questions over a small corpus can work with classic RAG in a prompt template. Agents that compare options, check stock, or follow references need tool access over MCP.
4. Who owns freshness? If the answer is a pipeline nobody has built yet, include that cost in the decision. Running retrieval inside the content backend removes the sync step entirely.
Next, check the configuration. Decide which source type each Context MCP connection serves. If an agent needs a different mode than its sources would produce, use ?mode=groq or ?mode=knowledge_base. For Knowledge Bases, plan around beta status and assign someone to review build issues, so conflicting facts get resolved by a person rather than by a similarity score.
The established way to give a model context was to retrieve once and stuff the prompt. The newer way is to give the model governed tools over fresh content and let it ask. Sanity Context is built for the newer approach, with hybrid retrieval running inside the Content Lake instead of beside it.
MCP and RAG in practice: Sanity Context vs Pinecone, Contentful, and pgvector
| Feature | Sanity | Pinecone | Contentful | pgvector / Neon |
|---|---|---|---|---|
| Where retrieval runs | Inside the Content Lake. Context MCP serves GROQ mode queries against the live dataset, or a pre-built Knowledge Base, with no separate retrieval service to operate. | In a managed vector index separate from your content system. Content must be embedded and upserted by your own pipeline or connectors. | Content is delivered API-first. Agent retrieval typically runs in an external search or vector store connected through the App Framework. | In your own Postgres database alongside application data. You design the tables, embedding columns, and queries that serve the agent. |
| Hybrid keyword, semantic, and filter ranking | Native: GROQ filters, then score(boost([title] match text::query($q), 2), text::semanticSimilarity($q)) and order(_score desc) in one query. | Supported through metadata filters plus sparse-dense or keyword signals. Merging and reranking logic usually lives in application code. | Assembled: structured filtering comes from Contentful's APIs, and relevance and semantic ranking come from whichever external search service you attach. | Doable in SQL by combining pgvector distance with Postgres full-text ranking and WHERE clauses. You write and tune the blend yourself. |
| Index freshness when content changes | Dataset embeddings are tied to content, so edits and deletions propagate without a sync job. GROQ mode reads the dataset at request time. | Re-embedding on change, deletions, and backfills are your pipeline to build and monitor. Stale vectors persist until you update them. | Webhooks can trigger re-indexing in the external store, but your integration code owns the reliability of that sync. | Stays fresh if embeddings update in the same transaction or through triggers. Embedding generation and backfills remain your responsibility. |
| MCP delivery to agents | Context MCP is a hosted, read-only endpoint. Its mode is derived from attached sources and can be overridden per connection with ?mode=groq or ?mode=knowledge_base. | Pinecone provides MCP servers, including for its Assistant product. The content behind them still arrives through your own ingestion pipeline. | Contentful publishes an MCP server focused on content management tasks, not ranked retrieval for production agents. | No built-in endpoint. You adopt a community Postgres MCP server or write your own, and handle auth, query safety, and read-only access. |
| Conflicting facts across sources | Knowledge Bases (beta) raise issues at build time, showing claims like a 30-day vs a 45-day returns policy side by side with sources for a person to resolve. | Returns whichever chunk scores highest. Conflict detection requires your own deduplication or evaluation layer. | A single content repository reduces duplication within Contentful, but conflicts with outside sources aren't reconciled for agents. | No reconciliation by default. Conflicting rows or chunks come back as they are unless you build detection into ingestion. |
| Unstructured knowledge such as docs and policies | Knowledge Bases (beta) build cited Markdown entries and an outline served by initial_context, drawing on sources from multiple projects. | Well suited to chunked documents. Your team designs and maintains the chunking strategy, metadata, and citations. | Stores rich text and references well. Turning them into agent-ready chunks happens in your external search integration. | Stores chunks and embeddings flexibly. Parsing, chunking, and citation tracking are part of the pipeline you own. |