LlamaIndex 文档上线原生 MCP 搜索
Native MCP Search For LlamaIndex Docs Guide | LlamaIndex
LlamaIndex 文档现已提供原生 MCP 搜索,地址为 developers.llamaindex.ai/mcp,编码智能体或智能体工作流可直接调用全部文档。该服务暴露三个工具:基于 BM25 的 search_docs、基于正则的精确搜索 grep_docs,以及读取整页内容的 read_doc。文档站由 Astro 和 Starlight 生成并部署在 Vercel,BM25 索引在构建时静态生成。
正文
当前显示原文,中文全文译文尚未就绪。
“How can I use LlamaIndex docs MCP in my work?”; “How do the MCP tools actually work?”; read_doc; grep_docs; search_docs; “Wait, I have feedback on the MCP tools!”
Follow us on
1
Native MCP search over the LlamaIndex documentation is now shipping today! Combined with recent changes to how we host and unify documentation, this means your coding agent or agentic workflow has direct access to search tools over ALL documentation: https://developers.llamaindex.ai/mcp
This change exposes three tools:
search_docs — a basic lexical search using BM25; grep_docs — exact search using regex; read_doc — provides an interface to read the entire contents of any given page path
We believe all documentation sites should be shipping with some kind of native search available to LLMs and agents. Below, we detail how exactly this was implemented and how you can use it.
Explore our free and paid plans today.
Learn more
“How can I use LlamaIndex docs MCP in my work?”
MCP is basically a universal tool adaptor these days. You can search the LlamaIndex documentation using MCP with just about anything. Here’s a few examples.
LlamaIndex Agents To use with LlamaIndex, you can simply install install the needed packages and create an agent using the tools from the MCP endpoint.
python
Claude Code
Adding to Claude Code is a single command:
python
From there, you can use Claude Code and it will retrieve information from the docs as needed.
Anything Else!
Most platforms/frameworks/etc. these days will have some kind of MCP support. Whether its some kind of JSON you configure locally, a special class you import in a framework, or elsewhere, we encourage users to use this docs MCP server anywhere they work.
“How do the MCP tools actually work?”
To start with, our documentation is a dynamically generated Astro and Starlight website, built from docs across many repositories. This is hosted and deployed onto Vercel.
Conveniently, Vercel provides a nice createMCPHandler function for automatically creating MCP endpoints from Vercel functions. This was a great place to start, and from there, we could focus on the actual tool implementations without worrying about specifics around MCP.
As for what tools to provide, we chose search , grep and read tools, as they would align well with LLM agents, especially coding agents like Claude-Code, that are used to these operations.
For the actual tool implementations, we wanted to re-use as much as possible from what was already bundled in the documentation and deployed.
read_doc
Since URLs can come in two forms (either relative/linked from other markdown files) or as URLs/paths, we implemented code to normalize these paths. From there, it was simply a matter of using the normalized path to lookup the docs file and returning its content.
grep_docs
This function was a natural extension of read_doc . Normalize the path, find the doc, and then apply a regex. Some nice utility options like providing context lines and case sensitivity were easy to implement beyond that.
This was the most challenging function to implement. Initially, we thought we could hook into the search index from PageFind that the documentation ships with. And it worked! Or at least, it worked locally. But deployed on Vercel, the index files we needed to load from were missing, and despite some painful debugging we couldn’t track them down.
From here, it was back to the drawing board. To keep keep this extremely lightweight, we ended up going with a BM25 search. While BM25 is typically worse in benchmarks compared to vector search, we’ve also seen LLMs and agents excel in using lexical tools like these and crafting queries that take advantage of the underlying search algorithm.
The BM25 index is statically built at build time. We used the natural package for tokenization and stemming (i.e. for splitting text into words and consolidating duplicates like “like” and “likes”). With our docs split into words, we then build an inverted index that maps tokens to pages they appear in, to efficiently calculate the BM25 scoring method.
At runtime, this index is loaded, searches can run, and the index help can return relevant documentation for a given query. While this loses some accuracy compared to vector search, it was easy enough to do and very lightweight to maintain.
“Wait, I have feedback on the MCP tools!”
Great! We want to hear it! There are a ton of features we can add to this given how flexible the implementation is, and we really want to hear from users how useful they find this feature and what it might be missing.
You can reach out to us on several platforms, come find us!