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.

Return the Markdown URL from your loader, and add them to your docs page:
import { MarkdownCopyButton, ViewOptionsPopover } from 'fumadocs-ui/layouts/docs/page';
// in your loader
return {
path: page.path,
markdownUrl: `${page.url}.md`,
};
// in your page
<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(path)}`}
/>
</div>;Accept Header
Agents can request the Markdown of a page with Accept: text/markdown. Redirect them in a request middleware:
import { createMiddleware, createStart } from '@tanstack/react-start';
import { redirect } from '@tanstack/react-router';
import { isMarkdownPreferred } from 'fumadocs-core/negotiation';
const llmMiddleware = createMiddleware().server(({ next, request }) => {
const url = new URL(request.url);
if (
url.pathname.startsWith('/docs') &&
!/\.(md|txt)$/.test(url.pathname) &&
isMarkdownPreferred(request)
) {
url.pathname += '.md';
// the URL has two representations, don't let caches mix them up
throw redirect({ href: url.href, headers: { Vary: 'Accept' } });
}
return next();
});
export const startInstance = createStart(() => ({
requestMiddleware: [llmMiddleware],
}));Static Output
In SPA mode, prerender the files with Nitro:
import { defineConfig, runnerImport } from 'vite';
import { fumadocsMdx } from 'fumadocs-mdx/vite';
import { nitro } from 'nitro/vite';
// the config is loaded without your Vite plugins
const { docsLlms } = (
await runnerImport<typeof import('./src/lib/source')>('./src/lib/source.ts', {
plugins: [fumadocsMdx()],
resolve: { tsconfigPaths: true },
})
).module;
export default defineConfig({
plugins: [
// other plugins
nitro({
prerender: { routes: await docsLlms.files() },
}),
],
});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
