当您将智能体连接到公司数据时,RAG 与 MCP 的选择取决于由谁负责获取数据。在检索增强生成(RAG)中,您的应用程序会在模型看到问题之前,从索引中拉取一次匹配的文本。而在 Model Context Protocol(MCP)中,模型在其回合内调用工具,并按需多次请求它确切需要的记录。
为了看清这种差异如何体现,我们让向量 RAG、混合 RAG 以及拥有两个 MCP 工具的智能体面对相同的产品目录和相同的 40 个问题,并在两个模型上运行了每种设置。本文介绍了每种方法的工作原理、测试结果,以及导致其中一个模型失效的工具设计缺陷,以便您决定何时使用 RAG、MCP 工具或两者兼用。
RAG 和 MCP 有什么区别?
RAG 是一种模式,用于在调用模型之前将检索到的文本放入提示中。MCP 是一种协议,用于描述工具,以便模型可以自行获取数据。
在 RAG 流程中,您先将文档拆分为块,并使用嵌入 API(embeddings API)提前将它们嵌入索引。对于每个问题,您检索最相似的块,使用重排序模型(rerank model)缩小范围,然后将剩余部分发送给大语言模型(LLM)。检索只发生一次。如果这些块遗漏了细节,模型无法请求更多信息。
在 MCP 中,服务器会发布工具,每个工具都有名称、描述以及其参数的 JSON schema。模型选择工具并填入参数,客户端针对数据库、API 或搜索索引执行调用,结果返回给模型。随后模型可以调用另一个工具或直接回答。它在需要时即时获取数据。
RAG 和 MCP 并不竞争。RAG 决定哪些文本进入提示,而 MCP 为模型提供可调用的工具。MCP 服务器甚至可以将 RAG 索引封装为搜索工具。
我们的 Agent SDK(@openrouter/agent)为您运行工具循环。@openrouter/mcp 包通过 Streamable HTTP 连接远程 MCP 服务器,并回退到 Server-Sent Events(SSE),其 createMCPTools 辅助函数将它们的工具传递给 callModel。不支持本地 stdio 服务器。
我们如何测试 RAG 与 MCP
订阅即表示您同意接收 OpenRouter 新闻通讯:包括模型使用数据、产品更新和研究报告,每周约一封电子邮件。您可以通过每封电子邮件中的链接随时取消订阅。请参阅我们的隐私政策。
我们在 2026 年 10 月 22 日通过 API 运行了所有三种设置,针对一个虚构户外品牌生成的目录。该目录有两种规模:3,000 个产品(约 340K tokens)和 80 个产品(约 9K tokens)。每个产品都有一页简短的页面,包含其名称、SKU、类别、价格、重量、保修期和首次销售年份。某些页面还有一行“Compatible with”(兼容于),列出了其他产品名称。
我们为 3,000 个产品的目录编写了 40 个有确切答案的问题(较小规模的是 37 个),分为三种类型:
16 个单事实查询,例如“产品 CX-10101 的保修期是多少?”和“Tundra Ridge Tent 的重量是多少克?”
12 个两跳查询,例如“Willow Cedar Trekking Pole 在‘Compatible with’下首先列出的背包的标价是多少?”
12 个全目录计数或极值查询,例如“有多少帐篷的保修期恰好为 2 年?”和“最轻睡袋的 SKU 是什么?”
每项测试均在两个带有 reasoning.effort: “low” 的回答模型上运行:OpenAI GPT-6 Luna(openai/gpt-6-luna)和 DeepSeek V4.1 Flash(deepseek/deepseek-v4.1-flash)。
对于 RAG,我们使用 mongodb/voyage-4-lite 对页面进行嵌入。纯向量 RAG 取向量相似度最高的前 30 个块。混合 RAG 取前 15 个向量匹配结果加上前 15 个 BM25 关键词匹配结果。两者随后都使用 mongodb/rerank-3-lite 将候选者缩减为 5 个块供模型使用。
对于 MCP,我们针对同一目录编写了一个小型服务器,通过 Streamable HTTP 提供服务,包含两个工具:
get_product(sku_or_name) 返回单个产品的完整记录,包括兼容产品的名称和 SKU。
find_products(category?, warranty_years?, first_sold_year?, name_contains?, sort_by?, limit) 用于筛选和排序产品目录。它返回匹配的总数以及最多 limit 行数据(上限为 50 行)。
智能体使用 Agent SDK 的 callModel 调用这些工具,采用与 RAG 相同的回答规则,并设置停止条件为 stopWhen: stepCountIs(8)。Token 用量和成本数据来自循环中每次模型调用的 getUsage()。RAG 的总成本包括嵌入(embedding)和重排序(rerank)调用的开销。
哪种方法回答了更多问题?
在包含 3,000 款产品的目录上,我们为这三种问题类型构建的、带有两个 MCP 工具的智能体在两款模型上都正确回答了全部 40 个问题。向量 RAG 仅回答了 8 或 9 个,混合 RAG 回答了 16 个。
方法 GPT-6 Luna 正确数 DeepSeek V4.1 Flash 正确数 每 1,000 个问题的成本 (Luna / DeepSeek) 每个问题的输入 Token 数 (Luna / DeepSeek) 每个问题的耗时 (Luna / DeepSeek)
RAG 8/40 9/40 $0.21 / $1.43 633 / 683 7.8 秒 / 12.2 秒
混合 RAG 16/40 16/40 $0.19 / $0.91 638 / 688 5.6 秒 / 9.9 秒
MCP 工具 40/40 40/40 $0.18 / $0.39 1,479 / 2,178 4.1 秒 / 3.8 秒
按问题类型拆分得分,可以看出 RAG 的短板所在(GPT-6 Luna / DeepSeek V4.1 Flash):
问题类型 RAG 混合 RAG MCP 工具
单一事实 (16) 8 / 9 16 / 16 16 / 16
两步推理 (12) 0 / 0 0 / 0 12 / 12
全目录查询 (12) 0 / 0 0 / 0 12 / 12
较小的目录也得出了相同的结论。MCP 工具在两款模型上均获得 37/37 的得分,在 GPT-6 Luna 上每 1,000 个问题的成本为 $0.11,在 DeepSeek V4.1 Flash 上为 $0.29,而向量 RAG 的得分分别为 26/37 和 27/37。
智能体发送的输入 Token 数量是 RAG 的 2 到 3 倍。平均每个问题需要进行 2.3 到 2.4 次模型调用,且每次调用都会重新发送对话历史和工具定义。尽管如此,它在 GPT-6 Luna 上的成本与混合 RAG 大致相同,在 DeepSeek V4.1 Flash 上则更低,因为每个 RAG 问题都需要支付嵌入调用和重排序调用的费用。RAG 在 DeepSeek V4.1 Flash 上的成本远高于在 GPT-6 Luna 上,尽管两者的输入 Token 数相似。这一差距可能源于输出 Token 和推理 Token,而表格中并未显示这些数据。
智能体在两款模型上也更快。RAG 的计时包含了嵌入和重排序调用的时间,这可能解释了部分差距。
为什么 RAG 未能处理 SKU 查询、两步推理问题和计数问题
RAG 仅在模型运行前一次性检索五个文本块。我们的三种问题类型各自触及了该设计的不同限制。
16 个单一事实问题中有 8 个通过 SKU(如 CX-10101)命名了产品。SKU 是一个对嵌入模型而言无意义的字符串,无法用于匹配。对于这些查询,正确的产品页面在向量相似度排名中位于第 276 名到第 2,718 名之间(共 3,000 个),因此从未进入发送给重排序器的前 30 名。GPT-6 Luna 错过了全部 8 个,DeepSeek V4.1 Flash 错过了 7 个。添加 BM25 关键词搜索解决了这一问题,混合 RAG 在两款模型上的单一事实问题得分均为 16/16。我们的《RAG 中的重排序》一文衡量了相同的混合搜索和重排序修复方案。
两种 RAG 设置均未回答任何两步推理或全目录问题。以登山杖查询为例。检索仅针对问题文本运行一次,因此它可以找到登山杖的页面,但找不到背包的页面,而背包的相关性只有在阅读完第一个页面后才会显现。计数失败的原因更为简单:目录中有 375 个帐篷,而检索到的五个文本块无法告诉你其中有多少个带有 2 年保修期。
MCP 智能体逐步解决了同样的问题。对于登山杖查询,它调用 find_products 通过名称定位登山杖,然后调用 get_product 读取其记录并获取兼容背包的 SKU,再次调用 get_product 读取背包的价格。对于帐篷计数,它使用 category 和 warranty_years 参数进行了一次 find_products 调用,并从响应中读取 total_matches。
这 40/40 的得分取决于工具是否契合问题。我们的目录是结构化的,如果某个问题无法通过 get_product 和 find_products 表达,仍然会失败。
是什么导致我们的 MCP 服务器在一个模型上崩溃
40/40 的成绩并非一次跑出来的。在我们服务器的第一个版本中,GPT-6 Luna 在涵盖整个目录的问题上得分为 0/12(完成了 39 个问题中的 27 个;其中一个两步请求遇到了套接字错误),而 DeepSeek V4.1 Flash 则毫无困难地通过了测试。
追踪日志揭示了原因。我们最初的 find_products 函数将所有过滤器描述为可选的,其 JSON Schema 也未标记任何字段为必填。GPT-6 Luna 无论如何都填满了所有字段,当它想表达“无过滤器”时,发送的是 0 或空字符串。以下是它对“有多少帐篷的保修期恰好为 2 年?”这一问题的调用:
find_products({“category”:“tent”,“warranty_years”:2,“first_sold_year”:0,“name_contains”:"",“sort_by”:“weight_asc”,“limit”:50}) -> {“total_matches”:0,“rows”:[]}
服务器将 first_sold_year: 0 和 name_contains: "" 视为真实的过滤器,因此没有找到任何匹配项。GPT-6 Luna 读取了 total_matches 并回答了 0。而真实答案是 79。
DeepSeek V4.1 Flash 在其 117 个测试问题中从未发送过 0 或空的过滤器(其中 40 个针对每个服务器版本,另有 37 个针对小型目录),并且它在两个版本的服务器上均取得了 40/40 的成绩。工具和 Schema 完全相同,因此差异归结为每个模型如何填充可选参数。
我们在服务器端修复了这个问题。现在,它将 0、空字符串和负数视为“无过滤器”,并在工具描述中明确说明:
省略任何不需要的过滤器(0 或空字符串也表示无过滤器)
做出这一更改后,GPT-6 Luna 在涵盖整个目录的问题上从 0/12 提升至 12/12,总体得分也达到了 40/40。
工具描述和 Schema 的作用类似于提示词,而模型对它们的解读方式各不相同。请使用你计划运行的每个模型测试你的 MCP 工具,检查日志中每个模型发送的参数,并使你的服务器对默认值保持宽容。我们之所以能发现这个 bug,是因为我们通过同一个 OpenRouter API 密钥在两个模型上运行了相同的工具集。
何时使用 RAG、MCP 或两者兼用
当数据是结构化的或位于 API 背后(如数据库或产品目录)时,请使用 MCP 工具。当问题需要精确查找、计数或过滤器,或者数据发生变化且必须实时读取时,工具也很适用。
对于非结构化文本,如果问题涉及含义(如政策、文档或支持文章),请使用 RAG。使其成为混合模式,以便仍能找到 SKU 等精确标识符。
当针对非结构化文本的问题需要多次查找时,请同时使用两者。将你的 RAG 索引暴露为 MCP 搜索工具,模型就可以进行搜索、读取片段,然后再次搜索。
无论选择哪种方案,都应在你计划运行的每个模型上,使用具有确切答案的自身问题进行测量。
下一步
要将你自己的数据作为工具暴露出来,请从 Agent SDK MCP 工具文档开始,该文档涵盖了连接远程 Streamable HTTP 和 SSE 服务器,以及 stepCountIs 等设置的停止条件页面。如果你的数据是非结构化文本,请参阅嵌入(embeddings)和重排序(rerank)的 API 参考,并遵循我们的“使用嵌入与重排序进行 RAG”食谱以获取完整代码。我们的 RAG 与 CAG 比较也在同一个目录上运行。在构建过程中,你还可以将 OpenRouter MCP 服务器连接到你的编辑器或编码助手。
常见问题解答
RAG 随着 MCP 的出现而过时了吗?
没有。RAG 检索非结构化文本,而 MCP 是一种为模型提供工具的协议,因此它们解决的是不同的问题。文档、政策手册和其他大量文本仍然需要嵌入、关键词搜索和重排序。你可以将该索引封装在 MCP 工具中,以便模型按需搜索它。
MCP 比 RAG 更好吗?
当问题需要对结构化数据进行精确查找、计数或过滤器时,MCP 工具优于单次传递的 RAG。在我们对 3,000 个产品目录的测试中,一个为测试问题类型构建了两个 MCP 工具的代理回答了 40/40 的问题,每 1,000 个问题花费 $0.18 至 $0.39。混合 RAG 回答了 16/40,每 1,000 个问题花费 $0.19 至 $0.91。当对非结构化文本的一次语义搜索能找到正确的段落时,混合 RAG 单独使用效果也很好。
RAG 管道是否使用 MCP?
并非默认如此。标准的检索增强生成(RAG)流水线会在应用程序代码中先执行检索操作,然后再调用模型。不过,你可以将 RAG 检索器作为工具暴露给 MCP 服务器,从而把原本的一次性前置步骤转变为模型可以根据需要随时调用的搜索工具。
When you connect an agent to company data, the RAG vs MCP choice comes down to who does the fetching. With retrieval-augmented generation (RAG) , your application pulls matching text from an index once, before the model sees the question. With the Model Context Protocol (MCP), the model calls tools during its turn and asks for exactly the records it needs, as many times as it needs.
To see how that difference plays out, we gave vector RAG, hybrid RAG, and an agent with two MCP tools the same product catalog and the same 40 questions, and ran each setup on two models. This article covers how each approach works, what the test showed, and the tool-design bug that broke one of the models, so you can decide when to use RAG, MCP tools, or both.
What is the difference between RAG and MCP?
RAG is a pattern for putting retrieved text into a prompt before you call the model. MCP is a protocol for describing tools so the model can fetch data itself.
In a RAG pipeline, you split documents into chunks and embed them into an index ahead of time with an embeddings API . For each question, you retrieve the most similar chunks, narrow them down with a rerank model , and send what’s left to the LLM. Retrieval happens once. If the chunks miss a detail, the model has no way to ask for more.
With MCP, a server advertises tools, each with a name, a description, and a JSON schema for its arguments. The model picks a tool and fills in the arguments, the client runs the call against a database, API, or search index, and the result goes back to the model. The model can then call another tool or answer. It gets the data at the moment it asks for it.
RAG and MCP don’t compete. RAG decides which text goes into a prompt, and MCP gives the model tools to call. An MCP server can even wrap a RAG index as a search tool.
Our Agent SDK (@openrouter/agent) runs the tool loop for you. The @openrouter/mcp package connects to remote MCP servers over Streamable HTTP, falling back to Server-Sent Events (SSE), and its createMCPTools helper passes their tools to callModel. Local stdio servers aren’t supported.
How we tested RAG vs MCP
By subscribing you agree to receive the OpenRouter newsletter: model usage data, product updates, and research reports, about one email a week. Unsubscribe anytime via the link in every email. See our Privacy Policy .
We ran all three setups through our API on October 22, 2026, against a generated catalog for a fictional outdoor brand. The catalog comes in two sizes: 3,000 products (about 340K tokens) and 80 products (about 9K tokens). Each product has one short page with its name, SKU, category, price, weight, warranty, and first year sold. Some pages also have a “Compatible with” line naming other products.
We wrote 40 questions with exact answers for the 3,000-product catalog (37 for the smaller one), in three types:
16 single-fact lookups, such as “What is the warranty on product CX-10101?” and “How many grams does the Tundra Ridge Tent weigh?”
12 two-hop lookups, such as “What is the list price of the backpack that the Willow Cedar Trekking Pole lists first under Compatible with?”
12 whole-catalog counts or extremes, such as “How many tents have a warranty of exactly 2 years?” and “What is the SKU of the lightest sleeping bag?”
Every test ran on two answer models with reasoning.effort: “low”: OpenAI GPT-6 Luna (openai/gpt-6-luna) and DeepSeek V4.1 Flash (deepseek/deepseek-v4.1-flash).
For RAG, we embedded the pages with mongodb/voyage-4-lite. Plain vector RAG took the top 30 chunks by vector similarity. Hybrid RAG took the top 15 vector matches plus the top 15 BM25 keyword matches. Both then used mongodb/rerank-3-lite to cut their candidates down to 5 chunks for the model.
For MCP, we wrote a small server over the same catalog, served over Streamable HTTP, with two tools:
get_product(sku_or_name) returns one product’s full record, including the names and SKUs of compatible products.
find_products(category?, warranty_years?, first_sold_year?, name_contains?, sort_by?, limit) filters and sorts the catalog. It returns the total number of matches and up to limit rows (max 50).
The agent called the Agent SDK’s callModel with those tools, the same answer rule as RAG, and a stop condition of stopWhen: stepCountIs(8). Token and cost figures come from getUsage() across every model call in the loop. RAG totals include the embedding and rerank calls.
Which approach answered more questions?
On the 3,000-product catalog, the agent with two MCP tools, which we built for these three question types, answered all 40 questions on both models. Vector RAG answered 8 or 9, and hybrid RAG answered 16.
Approach GPT-6 Luna correct DeepSeek V4.1 Flash correct Cost per 1,000 questions (Luna / DeepSeek) Input tokens per question (Luna / DeepSeek) Time per question (Luna / DeepSeek)
RAG 8/40 9/40 $0.21 / $1.43 633 / 683 7.8 s / 12.2 s
Hybrid RAG 16/40 16/40 $0.19 / $0.91 638 / 688 5.6 s / 9.9 s
MCP tools 40/40 40/40 $0.18 / $0.39 1,479 / 2,178 4.1 s / 3.8 s
Splitting the scores by question type shows where RAG fell short (GPT-6 Luna / DeepSeek V4.1 Flash):
Question type RAG Hybrid RAG MCP tools
Single fact (16) 8 / 9 16 / 16 16 / 16
Two-hop (12) 0 / 0 0 / 0 12 / 12
Whole-catalog (12) 0 / 0 0 / 0 12 / 12
The smaller catalog told the same story. MCP tools scored 37/37 on both models, at $0.11 per 1,000 questions on GPT-6 Luna and $0.29 on DeepSeek V4.1 Flash, while vector RAG scored 26/37 and 27/37.
The agent sent two to three times as many input tokens as RAG. It averaged 2.3 to 2.4 model calls per question, and each call resends the conversation and the tool definitions. Even so, it cost about the same as hybrid RAG on GPT-6 Luna and less on DeepSeek V4.1 Flash, because every RAG question also pays for an embedding call and a rerank call. RAG cost far more on DeepSeek V4.1 Flash than on GPT-6 Luna with similar input tokens. That gap likely comes from output and reasoning tokens, which the table doesn’t show.
The agent was also faster on both models. The RAG timings include the embedding and rerank calls, which may account for part of the gap.
Why RAG missed SKU lookups, two-hop questions, and counts
RAG retrieves five chunks once, before the model runs. Our three question types each ran into a different limit of that design.
Eight of the 16 single-fact questions named a product by SKU, such as CX-10101. A SKU is a string with no meaning for an embedding model to match on. For those questions, the right product page ranked anywhere from 276th to 2,718th of 3,000 by vector similarity, so it never made the top 30 sent to the reranker. GPT-6 Luna missed all 8, and DeepSeek V4.1 Flash missed 7. Adding BM25 keyword search fixed this, and hybrid RAG scored 16/16 on single facts with both models. Our Reranking in RAG article measures the same hybrid search and rerank fix.
Neither RAG setup answered any two-hop or whole-catalog question. Take the trekking pole question. Retrieval runs once, on the question text, so it can find the trekking pole’s page but not the backpack’s, which only becomes relevant after you’ve read the first page. Counts fail for a simpler reason. There are 375 tents in the catalog, and five retrieved chunks can’t tell you how many of them carry a 2-year warranty.
The MCP agent worked through the same questions one step at a time. For the trekking pole question, it called find_products to locate the pole by name, then get_product to read its record and get the compatible backpack’s SKU, then get_product again to read the backpack’s price. For the tent count, it made a single find_products call with category and warranty_years and read total_matches from the response.
That 40/40 depends on the tools fitting the questions. Our catalog is structured, and a question that get_product and find_products can’t express would still fail.
What broke our MCP server on one model
The 40/40 didn’t come on the first run. With the first version of our server, GPT-6 Luna scored 0 of 12 on whole-catalog questions (27 of 39 completed questions; one two-hop request hit a socket error), while DeepSeek V4.1 Flash had no trouble.
The trace showed why. Our original find_products described every filter as optional, and its JSON schema marked none as required. GPT-6 Luna filled them all in anyway, sending 0 or an empty string whenever it meant “no filter”. Here’s its call for “How many tents have a warranty of exactly 2 years?”:
find_products({“category”:“tent”,“warranty_years”:2,“first_sold_year”:0,“name_contains”:"",“sort_by”:“weight_asc”,“limit”:50}) -> {“total_matches”:0,“rows”:[]}
The server treated first_sold_year: 0 and name_contains: "" as real filters and found no matches. GPT-6 Luna read total_matches and answered 0. The true answer is 79.
DeepSeek V4.1 Flash never sent a 0 or empty filter in any of its 117 test questions (40 against each server version, plus 37 on the small catalog), and it scored 40/40 against both versions of the server. The tools and schema were identical, so the difference came down to how each model fills in optional arguments.
We fixed it on the server. It now treats 0, empty strings, and negative numbers as “no filter”, and the tool description says so:
leave out any filter you do not need (0 or an empty string also means no filter)
With that change, GPT-6 Luna went from 0/12 to 12/12 on whole-catalog questions and 40/40 overall.
Tool descriptions and schemas work like prompts, and models read them differently. Test your MCP tools with every model you plan to run, check the arguments each one sends in your logs, and make your server forgiving of default values. We only caught this bug because we ran the same tool set on two models through one OpenRouter API key.
When to use RAG, MCP, or both
Use MCP tools when your data is structured or sits behind an API, such as a database or a product catalog. Tools also fit when questions need exact lookups, counts, or filters, or when the data changes and has to be read live.
Use RAG for unstructured text where the question is about meaning, such as policies, documentation, or support articles. Make it hybrid so exact identifiers like SKUs still get found.
Use both when questions over unstructured text need more than one lookup. Expose your RAG index as an MCP search tool, and the model can search, read the chunks, and search again.
Whichever you choose, measure it on your own questions with exact answers, on each model you plan to run.
Next steps
To expose your own data as tools, start with the Agent SDK MCP tools documentation , which covers connecting remote Streamable HTTP and SSE servers, and the stop conditions page for settings like stepCountIs. If your data is unstructured text, see the API reference for embeddings and rerank , and follow our RAG with Embeddings & Rerank cookbook for the full code. Our RAG vs CAG comparison runs on the same catalog. You can also connect the OpenRouter MCP server to your editor or coding assistant while you build.
Frequently asked questions
Is RAG obsolete with MCP?
No. RAG retrieves unstructured text, while MCP is a protocol for giving a model tools, so they solve different problems. Documentation, policy manuals, and other large bodies of prose still need embeddings, keyword search, and reranking. You can wrap that index in an MCP tool so the model searches it on demand.
Is MCP better than RAG?
MCP tools beat single-pass RAG when questions need exact lookups, counts, or filters over structured data. In our test on a 3,000-product catalog, an agent with two MCP tools built for the test’s question types answered 40 of 40 questions for $0.18 to $0.39 per 1,000 questions. Hybrid RAG answered 16 of 40 for $0.19 to $0.91. When one semantic search over unstructured text finds the right paragraph, hybrid RAG works well on its own.
Do RAG pipelines use MCP?
Not by default. A standard RAG pipeline runs retrieval in your application code before it calls the model. You can, however, expose a RAG retriever as a tool on an MCP server, which turns retrieval from one up-front step into a search tool the model can call as often as it needs.
首次收录 · 2026-12-04 · 9.95 分