AI & LLMs
Make your docs readable for AI agents, and add an AI chat.
Markdown for LLMs
Serve your docs as Markdown for AI agents:
npx @fumadocs/cli feature llmsYour site then serves:
/llms.txt: an index of your docs, linking the Markdown of each page./llms-full.txt: every page in one file./docs/ui.md: the Markdown of a page,/index.mdfor the page at/.
The CLI adds docsLlms to lib/source.ts, which renders these files:
import { llms } from 'fumadocs-core/source';
export const docsLlms = llms(source, {
// the Markdown of a page
renderPage: async (page) => `# ${page.data.title} (${page.url})
${await page.data.getText('processed')}`,
// leave drafts out, `llms.txt` links them to their HTML page instead
filter: (page) => page.slugs[0] !== 'drafts',
});MDX components stay as JSX in the Markdown. To render them as Markdown, give them a Markdown form and pass them as page props.
Sections
Each root folder is a section with its own llms-full.txt, like /docs/ui/llms-full.txt, so agents can read large docs one part at a time. Choose other sections with section:
export const docsLlms = llms(source, {
section(folder) {
// collapsed: listed in `llms.txt` as one link to its own `llms.txt`
if (folder.root) return { collapse: true };
return folder.index !== undefined;
},
// ...
});Page Actions
Page actions let readers copy the Markdown of a page, or open it in AI apps.

Add them to your docs page:
import { MarkdownCopyButton, ViewOptionsPopover } from 'fumadocs-ui/layouts/docs/page';
// `/llms.mdx${page.url}.md` with static export
const markdownUrl = `${page.url}.md`;
<div className="flex flex-row gap-2 items-center border-b pt-2 pb-6">
<MarkdownCopyButton markdownUrl={markdownUrl} />
<ViewOptionsPopover
markdownUrl={markdownUrl}
githubUrl={`https://github.com/${owner}/${repo}/blob/main/content/docs/${encodeURI(page.path)}`}
/>
</div>;Accept Header
Agents can request the Markdown of a page with Accept: text/markdown. Respond to them in your proxy:
import { NextRequest, NextResponse } from 'next/server';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
const { rewrite: rewriteDocs } = rewritePath('/docs{/*path}', '/llms.mdx/docs{/*path}.md');
export default function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
const result =
isMarkdownPreferred(request) && !/\.(md|txt)$/.test(pathname) && rewriteDocs(pathname);
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl), {
// the URL has two representations, don't let caches mix them up
headers: { Vary: 'Accept' },
});
}
return NextResponse.next();
}Next.js drops Vary from the HTML responses of pages. Set it at your CDN if a shared cache serves your docs.
Static Output
With output: 'export', the files of pages are served under /llms.mdx, like /llms.mdx/docs/ui.md.
MCP Server
Let AI agents list, search and read your docs through an MCP server:
npx @fumadocs/cli feature mcpThen connect an agent to it:
{
"mcpServers": {
"docs": { "url": "https://your-site.com/api/mcp" }
}
}To customize the tools, see fumadocs-core/mcp.
WebMCP
Experimental
WebMCP is an early web standard, available in
Chrome 149+ behind the #enable-webmcp-testing flag and an origin trial.
WebMCP gives the AI agent in the reader's browser tools to search and read your docs:
npx @fumadocs/cli feature webmcpRender the generated WebMCP component inside <RootProvider />.
Ask AI

Add an AI chat to your docs layout:
npx @fumadocs/cli feature aiChoose a provider, and set its API key in .env.local, like OPENROUTER_API_KEY for OpenRouter. To use another model, edit the generated /api/chat route.
The CLI adds the chat to your docs layout. If it can't find your layout, add the chat by hand:
'use client';
import { DocsLayout as Layout, type DocsLayoutProps } from 'fumadocs-ui/layouts/docs';
import { AIChat, AIChatPanel, useAIChat } from './search';
export function DocsLayout(props: DocsLayoutProps) {
return (
<AIChat>
<ChatLayout {...props} />
</AIChat>
);
}
function ChatLayout(props: DocsLayoutProps) {
const { open, setOpen } = useAIChat();
return (
<Layout
{...props}
aiChat={{ open, onOpenChange: setOpen, panel: <AIChatPanel />, trigger: true }}
/>
);
}How is this guide?
Last updated on
