Skip to content
Dashboard

MCP vs RAG and when to use both

Retrieval-augmented generation (RAG) and Model Context Protocol (MCP) are often compared as rivals, with RAG for reading and MCP for doing. But an MCP tool can search your docs or file a ticket, so that distinction doesn't hold.

RAG is a pattern for grounding answers in retrieved information. MCP is a protocol for accessing external tools and data. In two-step RAG, your application fetches context before generation. In agentic RAG, the model decides when to retrieve, potentially through an MCP tool.

Who triggers retrieval affects prompt size, the number of model calls per reply, and where you check actions before execution. It also helps you combine RAG and MCP into a single assistant, such as a support bot that answers questions from docs and files tickets.

Copy link to headingWhat are the key differences between MCP and RAG?

MCP is an open standard that connects AI applications to external tools and data for large language models (LLMs). RAG grounds a model's answers in retrieved content from an index, a database, or a live API. Implementations differ in who triggers each call and how much context they add. Clients that preload MCP tool definitions include them in the model's input context.

The table compares preloaded, model-triggered MCP tools with two-step RAG on four axes:

Axis

Preloaded MCP tools

Two-step RAG

Call trigger

The model picks a tool and fills in its arguments

Your application runs retrieval before the model generates

Context cost

Exposed tool definitions and any tool results passed to the model

Retrieved passages, alongside the prompt and conversation history

Model calls

Sequential tool-use steps typically add generations; multiple tools can share a step

One answer-generation pass after retrieval, with possible embedding or reranking model calls

Injection risk

Poisoned tool descriptions or results can steer tool choices and answers

Planted text in retrieved documents can steer answers and any subsequent tool calls

Copy link to headingCall trigger

For model-controlled MCP tools, the model decides during generation whether to call a tool and with which arguments. The MCP specification describes tools as model-controlled and resources as application-controlled. The host application controls execution. In two-step RAG, your application retrieves context before generation. In agentic RAG, the model chooses when to retrieve. A read-only search exposed as a model-controlled tool still follows the model's choice, so consider who triggers each call as well as whether it reads or writes.

Copy link to headingContext cost

A preloading MCP client adds exposed tool definitions to the model's input context before generation. In Anthropic's example from November 2025, GitHub, Slack, Sentry, Grafana, and Splunk exposed 58 tools that used about 55,000 tokens. Two-step RAG sends the retrieved passages along with the prompt and conversation history. Preloading more definitions increases input context, while tool search can load relevant definitions on demand. A RAG prompt also grows with the retrieved content.

Copy link to headingModel calls

Sequential tool-use steps typically add inference passes. Five sequential tool steps followed by a final answer usually take six generations, while multiple independent tools can share a step. The AI SDK makes these loops opt-in. By default, generateText and streamText run one step with isStepCount(1). Two-step RAG retrieves context before generating an answer in one pass, though embedding and reranking models may add calls. This structure is predictable, but cost and latency vary with retrieval, context size, and output length. Sequential tool steps typically add more work.

Copy link to headingInjection risk

Attackers can reach a model through MCP tool descriptions, a technique called tool poisoning. The MCPTox benchmark reported a 72.8% attack success rate against o1-mini, the most vulnerable model setting tested. Retrieved documents can carry the same planted instructions into RAG. The MCP specification treats tool annotations such as readOnlyHint as untrusted unless they come from trusted servers. These hints do not enforce permissions. Your application must control approval for model-triggered actions, using options such as the AI SDK's toolApproval.

Copy link to headingDiving into MCP for developers already running RAG

MCP is a client-server protocol. A host application opens one MCP client per external server. Anthropic created the protocol and donated it to the Agentic AI Foundation, part of the Linux Foundation.

For a team with a working RAG pipeline, MCP tools let the model access live systems alongside the existing index. MCP standardizes discovery and invocation for AI applications. A representational state transfer (REST) endpoint typically needs application-specific integration code.

Copy link to headingKey principles of MCP

Under the 2026-07-28 specification, a remote MCP server can run as a stateless HTTP service with these five principles:

  • Stateless requests: Each request carries its protocol version and client capabilities. A server can answer without earlier setup.

  • Explicit state: Servers can pass cross-call state as explicit handles. The protocol does not require a session that ties a client to one instance.

  • Discovery on demand: A server/discover response lists supported versions and capabilities, so clients can check support up front.

  • Routable headers: Each HTTP request names its method in an Mcp-Method header. A gateway or web application firewall (WAF) can route it without reading the body.

  • Server-driven input: Elicitation and multi-round-trip requests let a server ask a compatible client for missing details before completing a tool call.

Any serverless instance configured to run a stateless handler can answer a request without a shared protocol session store. Platforms can scale these MCP servers like other HTTP endpoints.

Copy link to headingAdvantages and limitations of MCP

MCP gives compatible clients a shared interface. Its costs include tool metadata in the prompt and live calls to external systems.

The shared interface has four strengths:

  • Write once: A provider builds one MCP server. Clients that support its transport, authorization, and capabilities can connect through the same protocol.

  • Live state: Tools can query external systems at the time of the call. Answers can reflect current source data without an index rebuild.

  • Standard authorization: Remote servers that require authorization follow an OAuth-based framework. Clients can use a standard flow, with separate grants for each server.

  • Cacheable catalogs: Under the 2026-07-28 specification, tool lists carry ttlMs and cacheScope cache hints. Clients can reuse a catalog within those limits.

The same design has four downsides:

  • Silent drift: Server-side tool definitions can change without a commit in your repo. Clients that refresh them dynamically can see behavior change unless they review or restrict updates.

  • Token weight: A Vercel measurement from 2025 put GitHub's MCP tool definitions at about 50,000 tokens. Preloading a broad catalog adds input overhead, though current costs depend on the tools loaded and caching.

  • Call-time latency: Live queries wait on downstream systems. A slow API delays the answers it returns.

  • Exposure at registration: Clients that preload tool descriptions expose them to the model before any tool runs. Poisoned instructions can enter the context at that point.

Reviewing tool definitions like code helps control drift and injected instructions. It doesn't remove their token cost or enforce tool permissions.

Copy link to headingCommon MCP use cases

Three MCP deployments on Vercel handle search, product actions, and deployment debugging.

Copy link to headingSearching a code corpus from an agent

Grep's July 2025 announcement described an MCP server that lets AI apps search a million public GitHub repositories, with results typically returning in a fraction of a second. Vercel reported building the server in an afternoon with mcp-handler, which handles schemas, request routing, and response formatting.

Copy link to headingExposing SaaS product actions to agents

Vapi rebuilt its MCP server on Vercel to expose its SaaS product to agents. The case study describes teams using it to create agents, automate testing, analyze transcripts, and build workflows. Agents access Vapi endpoints through the server.

Copy link to headingDebugging failed deployments from the IDE

Vercel MCP, Vercel's official MCP server, gives AI tools access to Vercel projects from an IDE through a remote server with OAuth sign-in. If a deployment started from Cursor, an AI code editor, fails, Vercel MCP can fetch the logs for the coding assistant to analyze, subject to the user's permissions.

Copy link to headingExploring the RAG pattern for apps that call MCP tools

RAG connects a model to retrieved information from sources such as an index of your own content, a database, or a live API.

For a team already calling MCP tools, two-step RAG adds retrieval before answer generation. Your code selects a short set of passages for each question, and the model uses them alongside its training. Agentic RAG lets the model decide when to retrieve.

Copy link to headingCore mechanics of RAG

A common vector-based RAG pipeline separates indexing from answering. Indexing runs ahead of time. It splits documents into chunks, which may overlap, and converts each into an embedding, a vector representation used for similarity search.

When a question arrives, the app embeds it and retrieves the closest chunks. It can discard matches below a similarity threshold, then build a prompt that tells the model to answer from the retrieved context. An optional reranking pass scores a wider candidate set and keeps the highest-scoring results.

Copy link to headingAdvantages and limitations of RAG

In this two-step pipeline, the application controls the corpus and retrieval logic. Retrieval quality and the fixed sequence of steps limit the pipeline as corpora and question types grow.

Control over retrieval has four strengths:

  • Private and recent knowledge: Retrieval can access internal docs and post-cutoff content, letting the model answer questions its training never covered.

  • Traceable answers: Source metadata lets the model cite the documents behind retrieved passages. Citation accuracy still needs evaluation.

  • App-owned selection: Your code chooses the corpus and retrieval budget, controlling the context added to the prompt.

  • Honest gaps: A similarity threshold can filter out weak matches and help the app decline questions the corpus doesn't cover. Abstention behavior still needs evaluation.

The fixed retrieval sequence has four limits:

  • Chunk sizing: Small chunks can lose context, while large ones can bury the relevant line. Chunk size is a trade-off.

  • Context ceiling: Complete documentation sets can exceed a model's context window. Retrieval must select a subset.

  • Index freshness: Index-based answers reflect the latest ingested updates. Fast-changing data can go stale between updates.

  • No actions: Retrieval grounds generation but does not execute changes. Filing a ticket or changing a setting needs an execution path, with or without MCP.

If the problem is how the model behaves rather than what it knows, compare fine-tuning vs RAG, which weighs retraining against retrieval.

Copy link to headingCommon RAG use cases

RAG fits three recurring jobs: grounding v0's code generation, answering support questions, and retrieving agent memory.

Copy link to headingGrounding code generation in framework docs

In its 2025 architecture description, v0, Vercel's AI app builder, retrieved context from documentation, user interface examples, project sources, and internal Vercel knowledge. A frontier base model generated code. A custom AutoFix model corrected errors during and after streaming. Retrieval and generation ran in separate parts of the pipeline.

Copy link to headingAnswering support questions from product docs

A support assistant answers questions from product manuals, help-center articles, and policy pages. Retrieval can ground answers in that published material. Updates to a help-center page become available to future answers once the retrieval source is updated.

Copy link to headingRecalling saved agent notes and decisions

For agent memory, RAG retrieves relevant passages from saved notes, decisions, and documents. It suits collections too large or varied to load in full for every question.

Copy link to headingRAG or MCP? How to choose for your AI app

Choose who triggers each call based on the question. In Vercel's agent evaluation, agents answered questions about GitHub issues and pull requests using SQL queries, bash commands, or both. After fixes to the tools and evaluation, the most reliable setup used SQL queries and checked the results against files. It consistently hit 100% accuracy with roughly twice as many tokens as SQL alone.

The experiment did not directly compare RAG and MCP, but it raises the same question about retrieval and tool use. A fixed sequence of steps can do the main work. Model-chosen tools can justify extra tokens when they verify an answer or take an action that the fixed sequence can't.

Copy link to headingWhen the app knows what to fetch

The application can trigger retrieval when it knows where to look, such as a defined product-docs corpus, policy collection, or database schema.

A model-controlled search tool can add overhead when the app already knows where to retrieve the answer. The model may spend a selection step and tool-definition tokens on a question the app could route itself.

Copy link to headingWhen the model must choose or act

Model-triggered tools fit when the model must choose among options or change something, such as creating a ticket, updating a record, or starting a deployment. Production agents can pin tool definitions in your repo for review. Live MCP discovery suits fast iteration and apps where people bring their own tools.

A focused tool list can help selection accuracy, especially when a larger catalog contains broad, overlapping tools.

Copy link to headingCombine RAG and MCP when an answer should trigger an action

An assistant can combine RAG and MCP to answer questions and act on them. Application tools can also handle actions without MCP. A support assistant can retrieve the refund policy, answer from it, and offer to open a ticket.

In this pattern, application code retrieves context and the model proposes actions. The app fetches policy chunks from a vector index or an MCP server's resources before generation, then instructs the model to ground policy answers in that text. The ticket tool requires approval. The first model call returns an approval request. After the person approves, a second call with the approval response in the messages can run the tool.

This partial AI SDK 7 example keeps retrieval in the route handler and requires approval for a local ticket function. An MCP client or generated MCP tool can provide the equivalent action. The imported helpers are application-specific. The caller must include the current question in messages, retain the returned messages, display the approval request, and append the user's approval response before resuming:

import { generateText, tool, type ModelMessage } from 'ai';
import { z } from 'zod';
import { findPolicyChunks } from '@/lib/retrieval';
import { openTicket } from '@/lib/tickets';
export async function POST(req: Request) {
// Caller supplies full history, the current question, and approval responses
const { question, messages }: { question: string; messages: ModelMessage[] } =
await req.json();
// App-triggered retrieval; helpers implement access-controlled data access
const chunks = await findPolicyChunks(question);
const result = await generateText({
model: 'anthropic/claude-sonnet-5.5',
instructions: `Ground policy answers in these excerpts:\n\n${chunks.join('\n\n')}`,
messages,
tools: {
openTicket: tool({
description: 'Open a support ticket for a refund request',
inputSchema: z.object({ orderId: z.string(), reason: z.string() }),
execute: async ({ orderId, reason }) => openTicket(orderId, reason),
}),
},
// Model-triggered action: returns an approval request instead of running
toolApproval: { openTicket: 'user-approval' },
});
// Return the answer plus any approval request for the UI to show
return Response.json({ text: result.text, messages: result.responseMessages });
}

Manual approval adds a round trip before an action can run. A read-only answer need not take that path. Injected instructions cannot execute this approval-gated tool without an accepted approval response, but they can still mislead the answer or the person reviewing it.

Copy link to headingHow Vercel supports RAG and MCP for teams shipping AI features

An assistant that uses RAG and MCP connects retrieval code, MCP servers, and a model provider. In a two-step pipeline, your app retrieves context before each answer, MCP servers handle the exposed tools, and generation sends requests to a model provider. Vercel hosts retrieval code and MCP servers and routes model requests through AI Gateway. This setup can avoid a protocol session store and the need for separate SDKs for model access. Fluid compute pauses active CPU billing during I/O waits, while memory remains billable.

Copy link to headingVercel runs MCP servers without a session store

MCP servers using session-based transports across serverless instances could require shared storage. Adding one endpoint could mean running a data store beside it. That adds infrastructure to monitor for a tool server exposed through one route.

On Vercel, mcp-handler turns an MCP server definition into a stateless route handler that runs on Vercel Functions. Its 2.x release supports the 2026-07-28 protocol natively and falls back to stateless Streamable HTTP for 2025-era clients. Streamable HTTP is the protocol's HTTP transport. The handler needs no Redis instance or session store. This partial example assumes an application-provided getOrderStatus helper that checks access and returns a string:

import { createMcpHandler } from 'mcp-handler';
import { z } from 'zod';
import { getOrderStatus } from '@/lib/orders';
const handler = createMcpHandler((server) => {
server.registerTool(
'get_order_status',
{
description: 'Look up the current status of an order',
inputSchema: z.object({ orderId: z.string() }),
},
async ({ orderId }) => ({
content: [{ type: 'text', text: await getOrderStatus(orderId) }],
}),
);
});
export { handler as GET, handler as POST };

Framework adapters let you mount the same handler in Nuxt, SvelteKit, and Hono. With opt-in authorization, the handler can verify bearer tokens issued by your authorization server.

Copy link to headingVercel pins MCP tool definitions in your repo

A read-only server can add a delete tool. An agent that loads definitions live may call it after refreshing its catalog if the application exposes and permits it. This can happen without a change in your repo, leaving no local diff to review.

Vercel's mcp-to-ai-sdk tool generates AI SDK tools from an MCP server and writes them into your codebase:

npx mcp-to-ai-sdk https://mcp.grep.app

The generated tools still call the original server at runtime. Their schemas and descriptions are stored locally, so teams can version-control and review them before deployment. Live discovery remains available during development, while production agents can use approved definitions. Remote tool behavior, permissions, and data can still change.

Copy link to headingVercel routes model calls through one gateway

A RAG feature with tools can use an embedding model, a reranker to reorder results, and a chat model to select tools. Using a separate provider SDK for each adds keys, rate limits, and failure handling.

On Vercel, AI Gateway provides embedding models, reranking models, and chat models through a shared gateway. Select a supported model with a provider/model-name string and the appropriate model API. Chat calls support provider routing, retries, configured model fallbacks, and spend monitoring, subject to availability and request configuration. The gateway handles model requests. MCP tools execute through your application and connected servers, as AI Gateway vs MCP explains.

Copy link to headingVercel pauses CPU billing while requests wait

A retrieval call or MCP tool request can spend much of its time waiting on a vector index, a downstream API, or a model provider rather than using the central processing unit (CPU). Billing for total request duration can charge for those waits, so I/O-heavy requests can cost more than their CPU usage alone suggests.

On Vercel, Fluid compute pricing bills active CPU time while code runs and pauses CPU billing during input/output (I/O) waits. Provisioned memory remains billable while the instance handles requests, including those waits. Fluid compute can handle multiple concurrent MCP requests in one instance before adding instances.

Copy link to headingDecide what triggers each call and ship on Vercel

A docs assistant can add ticket filing alongside its existing retrieval architecture. One approach keeps retrieval in the app's fixed sequence, uses a short list of model-triggered tools, and requires approval, authorization, and input validation for writes. This setup shouldn't require a dedicated infrastructure team.

Vercel provides five capabilities for this setup:

  • AI Gateway embeddings and reranking: Indexing and reranking calls share a gateway and authentication setup. Retrieval routes can skip per-provider SDKs.

  • AI Gateway model routing: Chat model calls can fail over across available providers and configured fallback models. This reduces the impact of provider failures but does not guarantee success.

  • Fluid compute: CPU billing pauses during input/output waits. Tool servers and retrieval routes pay for CPU only while code runs.

  • mcp-handler: Configured Vercel Functions instances can serve stateless MCP requests without a protocol session store.

  • mcp-to-ai-sdk: Teams can version-control and review generated tool definitions before deployment. This limits definition drift, though remote execution still depends on server changes.

Start a new project with one retrieval route and one approval-gated tool, or browse templates for RAG and MCP starting points.

Copy link to headingFrequently asked questions about RAG vs MCP

Copy link to headingDoes MCP replace RAG?

No. MCP standardizes how AI applications access external systems. RAG grounds answers in retrieved information. The two can work together. Moving an index behind an MCP server changes how the app accesses retrieval, while preserving the RAG pattern.

Copy link to headingIs MCP better than RAG for real-time data?

For data that changes between index updates, such as stock levels or order status, query the live system at request time. An MCP tool can expose that query, and its results can ground a RAG answer. One answer can use a return policy from an index and an order's status from a tool.

Copy link to headingHow does an app read MCP resources for RAG?

Call listResources on an AI SDK MCP client to see what a server offers. Then call readResource with a resource's uniform resource identifier (URI) to fetch its contents. In two-step RAG, the route handler fetches resources before generation and adds selected text to the prompt, as it does with chunks from a vector index. The resource catalog can be cached where supported.

Copy link to headingDo SSE-based MCP servers still work?

Legacy HTTP plus Server-Sent Events (SSE) servers can still work with compatible clients, but plan the move to Streamable HTTP. The 2026-07-28 specification classifies the legacy transport as deprecated under a minimum twelve-month deprecation policy, with a year-long transition period. mcp-handler 2.x has already removed legacy HTTP+SSE support, so migrate before upgrading. This legacy transport is distinct from SSE streams used within Streamable HTTP.

Ready to deploy?