AI and LLMs
Serve your docs to AI agents.
Each page has a Markdown version, which an LLM or an agent reads instead of the HTML, and which the AI plugins read too.
The recommended preset serves each page's Markdown, llms.txt and llms-full.txt, like /llms.txt and this page as Markdown on this site. Without the preset, add llmsPlugin():
import { createSite, llmsPlugin } from "vuesho/config";
import { defineDocs } from "vuesho/content";
const docs = defineDocs();
export default createSite(docs.toSource()).plugins(llmsPlugin()); Markdown Version
A page's Markdown is at its URL plus .md, like /guide/install.md, or /index.md for /.
The Markdown is written from what the page renders: the title and description, the heading IDs, resolved expressions, includes and image URLs. A component stays a tag, unless it defines a Markdown form:
---
title: Installation
description: Add Acme to your project.
---
<script setup lang="ts">
import { node } from "../../src/versions";
</script>
## Requirements
Acme runs on Node.js {{ node }} or later.
<Callout type="warn">Restart the dev server after you install.</Callout>A custom page has a Markdown version too, when its component sets markdown in defineOptions(). A plugin's transformPageMarkdown hook changes every page's Markdown.
Content Negotiation
An agent that requests a page with Accept: text/markdown gets its Markdown at the page's URL, without .md:
curl -H "Accept: text/markdown" https://docs.acme.dev/guide/installA server answers these requests for every page, and so do Vercel and Netlify for a static build. Other static hosts, like GitHub Pages, serve the HTML, and the agent finds the Markdown through the page's link and llms.txt.
llms: { negotiate: false } turns off content negotiation, for example to save Worker requests on Cloudflare.
Component Markdown
To give a component its own Markdown form, set markdown in defineOptions(). The function stays out of the browser bundle, and slots.x() gives the Markdown of what the component renders in its slot x:
<script setup lang="ts">
import { md, type MarkdownContext } from "vuesho/client";
defineProps<{ title: string }>();
defineOptions({
markdown: ({ props, slots }: MarkdownContext<{ title: string }>) =>
md.linePrefix("> ")`**${props.title}**\n\n${slots.default?.()}`,
});
</script>
<template>
<aside class="note">
<strong>{{ title }}</strong>
<slot />
</aside>
</template><Note title="Careful">Read this first.</Note> becomes:
> **Careful**
>
> Read this first.The search index takes the component's text from the same function, which then receives target: "search" instead of "markdown".
Prop
Type
md is a template tag that awaits the promises, slots and lists in it. Its methods write Markdown blocks:
import { md } from "vuesho/client";
md.linePrefix("> ")`${text}`; // Each line with a prefix, like "> " for a quote
md.indent(4)`${text}`; // Each line indented, by 2 spaces by default
md.fence(code, "ts"); // A code block, with a fence longer than any run of backticks in `code`
md.code(text); // Inline code
md.table([
["Name", "Type"],
["id", "string"],
]); // A table, with the first row as its header
md.escape(text); // The text with the characters Markdown reads as syntax escaped, like `*` and `[`Rendering Markdown
A page's Markdown has Vuesho syntax, like [#id] after a heading. pageMarkdownSyntax from vuesho/markdown adds this syntax to another markdown-it instance, like one that renders the Markdown on a server:
npm i markdown-itimport markdownIt from "markdown-it";
import { pageMarkdownSyntax } from "vuesho/markdown";
export const md = markdownIt({ html: true, linkify: true }).use(pageMarkdownSyntax);llms.txt
/llms.txt lists the pages in sidebar order, each with a link to its Markdown, and /llms-full.txt holds every page's Markdown:
# Docs
- [Hello World](/index.md): Your first document
- Guide
- [Guide](/guide.md): Learn Acme.
- [Installation](/guide/install.md): Add Acme to your project.A page with noindex is left out of both files, as SEO shows. Change the files with the preset's llms option, or with llmsPlugin()'s options:
createSite(docs.toSource()).plugins(
recommendedPreset({
llms: {
// No `/llms-full.txt`.
full: false,
// Adds a section to `/llms.txt`.
index(text, { path }) {
if (path !== "/llms.txt") return text;
return `${text}\n\n## Optional\n\n- [Blog](https://acme.dev/blog)`;
},
},
}),
);Prop
Type
With multiple languages, each language has these files under its prefix, like /cn/llms.txt.
Sections
Each root folder is a section, with an llms-full.txt at its URL, like /guide/llms-full.txt. section sets which folders are sections, and collapse: true lists a section in /llms.txt as one link to its own llms.txt:
createSite(docs.toSource()).plugins(
recommendedPreset({
llms: { section: (folder) => (folder.root ? { collapse: true } : false) },
}),
);# Docs
- [Hello World](/index.md): Your first document
- [Guide](/guide/llms-full.txt)
- [Guide](/guide.md): Learn Acme.
- [Installation](/guide/install.md): Add Acme to your project.AI Plugins
@vuesho/ai has three plugins for AI agents and readers, each in a separate entry:
mcpPlugin()serves an MCP server, which coding agents like Claude Code and Cursor use to search and read the pages.chatPlugin()adds an AI chat to the docs layouts. The chat answers questions from the pages.webmcpPlugin()registers tools for agents in the browser to search, read and open the pages.
npm i @vuesho/aiThe plugins read the pages' Markdown version, so also keep recommendedPreset() or llmsPlugin(). They search with their own index, not your site's search index.
MCP Server
mcpPlugin() serves the MCP endpoint /mcp over streamable HTTP. The endpoint runs on request, so the site needs a server.
Install the MCP SDK
npm i @modelcontextprotocol/server zodAdd the Plugin
import { mcpPlugin } from "@vuesho/ai/mcp";
import { createSite, recommendedPreset } from "vuesho/config";
export default createSite(docs.toSource()).plugins(
recommendedPreset(),
mcpPlugin(),
);Connect an Agent
An agent connects to your deployed site's /mcp URL:
{
"mcpServers": {
"docs": { "type": "http", "url": "https://docs.acme.dev/mcp" }
}
}Tools
The server has three tools. With Internationalization, search and list_pages take a language, or use the default language.
| Tool | What it returns |
|---|---|
search | The pages that match a query, with their descriptions |
list_pages | Every page, with its URL and description |
get_page | A page's Markdown, by its URL or path |
tools registers more tools on the server, with the site context as this. Its second argument holds the built-in tools, which update() changes and remove() drops:
import { mcpPlugin } from "@vuesho/ai/mcp";
import { z } from "zod";
import { searchAcme } from "./server/search";
mcpPlugin({
path: "/api/mcp",
server: { name: "Acme Docs", version: "2.0.0" },
tools(server, { search }) {
const count = String(this.getPages().length);
server.registerTool("count_pages", { description: "Count the pages" }, async () => ({
content: [{ type: "text", text: count }],
}));
// Replaces the built-in search.
search.remove();
server.registerTool(
"search",
{ description: "Search the docs", inputSchema: z.object({ query: z.string() }) },
async ({ query }) => ({
content: [{ type: "text", text: JSON.stringify(await searchAcme(query)) }],
}),
);
},
});AI Chat
chatPlugin() adds an Ask AI button to the docs layouts, and Ctrl + / opens the chat too. The chat sends questions to POST /_ai/chat, which runs on request, so the site needs a server. create-vuesho --ai-chat <name> sets up a new site with a chat on openrouter, llmgateway or inkeep.
Install the AI SDK
npm i ai @ai-sdk/vue zodAdd the Plugin
model takes a model ID on the AI Gateway, or a model from any AI SDK provider:
import { chatPlugin } from "@vuesho/ai/chat";
createSite(docs.toSource()).plugins(
recommendedPreset(),
chatPlugin({ model: "openai/gpt-5" }),
);AI_GATEWAY_API_KEY=....env.local isn't deployed, so set the key in your host's environment variables. Without it, the chat answers with an error, and the server logs the cause.
Rate Limiting
Public Endpoint
/_ai/chat is public, and each question calls your provider. Add rate limiting before the site goes live.
A plugin's middleware hook can reject requests before they reach the route:
import { isRateLimited } from "./server/rate-limit";
createSite(docs.toSource()).plugins(
recommendedPreset(),
chatPlugin({ model: "openai/gpt-5" }),
{
name: "site:rate-limit",
middleware: {
async handle(request, next, { page }) {
if (page === "/_ai/chat" && (await isRateLimited(request)))
return new Response("Too Many Requests", { status: 429 });
return next();
},
},
},
);Instructions and Tools
The model searches and reads your pages with the search and get_page tools. instructions replaces its system prompt, and tools adds AI SDK tools:
import { chatPlugin } from "@vuesho/ai/chat";
import { tool } from "ai";
import { z } from "zod";
chatPlugin({
model: "openai/gpt-5",
instructions: "Answer questions about Acme from its docs.",
tools: {
status: tool({
description: "Get the status of the Acme API",
inputSchema: z.object({}),
async execute() {
const response = await fetch("https://status.acme.dev/api");
return response.json();
},
}),
},
});Customizing the Chat
The chat panel is the aiChat.panel layout prop, which the theme's layoutProps sets. AIChat takes suggestions, a list of questions for the reader to pick, and the description and renderPart slots:
import { h } from "vue";
import { AIChat } from "@vuesho/ai/theme/chat";
import { defineTheme } from "vuesho/theme";
import defaultTheme from "vuesho/theme/default";
const suggestions = ["How do I deploy?", "What is a plugin?"];
const description = () => "Answers come from the Acme docs.";
export default defineTheme({
extends: defaultTheme,
layoutProps: () => ({
aiChat: { panel: () => h(AIChat, { suggestions }, { description }) },
}),
});useAIChat() opens the chat from any component:
<script setup lang="ts">
import { useAIChat } from "@vuesho/ai/ui";
const { setOpen } = useAIChat();
</script>
<template>
<button type="button" @click="setOpen(true)">Ask AI</button>
</template>@vuesho/ai/ui has the chat's parts, like AIChatPanel, AIChatMessages and AIChatInput, to build your own panel inside AIChatProvider. To render its answers with your own markdown-it instance, add gfm from vuesho/markdown/gfm to it, so task lists and www. links render as in the built-in panel.
To edit the parts, copy them into your project with vuesho add:
npx vuesho add ui --from @vuesho/aiShowing Sources
Some providers, like Inkeep, cite their sources by calling a provideLinks tool. Declare the tool in chatPlugin()'s tools to type the call, and render the links with AIChatSources in renderPart:
npm i @ai-sdk/openai-compatibleimport { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { chatPlugin } from "@vuesho/ai/chat";
import { tool } from "ai";
import { z } from "zod";
const inkeep = createOpenAICompatible({
name: "inkeep",
apiKey: process.env.INKEEP_API_KEY,
baseURL: "https://api.inkeep.com/v1",
});
export const tools = {
provideLinks: tool({
inputSchema: z.object({
links: z.array(z.looseObject({ url: z.string(), title: z.string().nullish() })).nullish(),
}),
}),
};
export default createSite(docs.toSource()).plugins(
recommendedPreset(),
chatPlugin({ model: inkeep("inkeep-qa-expert"), tools }),
);Translations
The chat has language packs for ja, zh-CN and zh-TW, and ui.translations changes any of its texts, as UI Translations shows:
createSite(docs.toSource(), { i18n }).config({
ui: {
translations: { fr: { "Ask AI(AI chat)": "Demander à l'IA" } },
},
});Page Selection
mcpPlugin() and chatPlugin() read every page with a Markdown version and no noindex, including custom pages and views. filter leaves pages out, and getDocument changes the document that the tools read for a page, with the site context as this:
chatPlugin({
model: "openai/gpt-5",
// Leaves out the blog.
filter: ({ path }) => !path.startsWith("/blog/"),
// Adds a page's keywords to its Markdown.
getDocument(document, { page }) {
const keywords = page?.data.keywords;
if (!keywords) return document;
return { ...document, content: `${document.content}\n\nKeywords: ${keywords.join(", ")}` };
},
});filter receives page for a content page, or route for a custom page or a view, with its path and pageData. A view has a Markdown version only when its route sets markdown. To change a page's Markdown for every reader, use the transformPageMarkdown hook.
WebMCP
Experimental
WebMCP is an early browser standard. Chrome supports it behind the flag #enable-webmcp-testing.
webmcpPlugin() registers three tools for an agent in the browser, on a static site or a server:
| Tool | What it does |
|---|---|
search_docs | Searches the pages in the page's language, with summaries |
read_page | Reads a page's Markdown, by its URL |
open_page | Opens a page in the browser |
import { webmcpPlugin } from "@vuesho/ai/webmcp";
createSite(docs.toSource()).plugins(
recommendedPreset(),
webmcpPlugin(),
);The plugin takes no options, and its tools read the same pages as the other AI plugins.
Options
mcpPlugin()
Prop
Type
chatPlugin()
Prop
Type