Fumadocs rebuilt on Hamur, the original is fumadocs.dev
Skip to Content
Fumadocs

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 llms

Your 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.md for the page at /.

The CLI adds docsLlms to lib/source.ts, which renders these files:

lib/source.ts
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:

lib/source.ts
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.

AI Page Actions

Add them to your docs page:

import { MarkdownCopyButton, ViewOptionsPopover } from 'fumadocs-ui/layouts/docs/page';

// also served by static deployments
const markdownUrl = `/llms.mdx${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. The middleware from the CLI responds to them, except on prerendered pages, which are served as static files.

Static Output

Static deployments serve the files of pages under /llms.mdx only, 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 mcp

Then 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 webmcp

Render the generated WebMCP component inside <RootProvider />.

Ask AI

AI Search

Add an AI chat to your docs layout:

npx @fumadocs/cli feature ai

Choose 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