How AI agents read your docs, and how to help them
AI-readable documentation means more than good prose. Here are the layers, from llms.txt to an MCP server, that make docs for AI agents easy to read and search.
Point an AI agent at a typical docs site and it gets a pile of navigation markup, cookie banners and script tags with your actual content buried somewhere inside. If you want AI-readable documentation, the fix is to stop making agents guess and hand them the Markdown you already wrote.
There are several ways to do that. They stack, each one adding structure on top of the last, so you can stop wherever the effort stops paying off.
Why scraping HTML loses information
A rendered docs page is built for eyes. Tabs hide content until you click them, code samples sit inside syntax-highlighting spans, and callouts become nested divs. An agent that fetches the HTML has to strip all of that, and it usually loses something: a tab that never rendered, a table flattened into a run of text, a heading level that carried meaning.
The source was Markdown to begin with. Giving the agent that Markdown skips the lossy round trip through HTML and also costs fewer tokens.
Five layers of docs for AI agents
1. llms.txt
A single file at the site root that lists every page with its title, a one-line description and a link. It tells an agent what exists before it fetches anything. We cover the format in What is llms.txt. A companion llms-full.txt puts the full text of every page in one file.
2. A Markdown URL for every page
Append .md to a page URL and you get that page's source, with includes and variables already expanded. The links in llms.txt point at these URLs, so an agent can go from index to content in one hop.
3. Content negotiation
The same page URL can return either HTML or Markdown depending on the Accept header. An agent asks for Markdown and gets it:
curl -H "Accept: text/markdown" https://docs.example.com/getting-started/quickstart
A request gets Markdown when its Accept header ranks text/markdown at least as high as text/html. Browsers keep getting HTML. Static hosts differ here: Cloudflare Pages and Vercel need a middleware file, while GitHub Pages and plain object storage can't negotiate at all. Agents can still fetch the .md URLs directly on those.
4. .well-known/agent.json
A discovery file that tells an agent where everything is, so one request is enough to learn the layout. It lists the llms.txt and search index locations, the Markdown URL pattern, the supported versions and every page. DocsLit follows the Agent-Friendly Documentation Spec for this.
5. An MCP server
The other four layers are files. An MCP server is an interface, and it's the most structured option. Instead of fetching and parsing, the agent calls tools. Ours are:
search_docs: ranked results with a section and a snippetget_page: the full Markdown of one pagelist_pages: every page with its title and descriptionget_docs_overview: the contents ofllms.txt
Search matters most here. Without it, an agent has to pull the index, guess which pages are relevant and fetch several of them. With it, the agent asks a question and gets the right section back.
Hosted MCP on DocsLit Cloud, or run it yourself
Every docslit build writes the first four layers into the output folder. You don't configure anything. The MCP part depends on where you host.
On DocsLit Cloud, each site serves a hosted MCP endpoint at https://{slug}.{base-domain}/mcp. It's stateless Streamable HTTP with JSON responses and no authentication, so a client that speaks HTTP can connect directly. A /.well-known/mcp.json file describes the endpoint and its tools. Cloud also does the Accept: text/markdown negotiation for you.
If you self-host, the build also writes a standalone mcp-server.js into the output folder. It reads the built .md files and search-index.json, needs only Node.js, and offers list_pages, get_page and search_docs:
node dist/mcp-server.js
That one speaks over stdio, so it suits a client that launches a local process. Another option is reader mode, which points at any published DocsLit site by URL and works for clients that launch stdio servers:
docslit mcp https://docs.docslit.com
The tradeoff is simple. Self-hosting costs you some setup, mostly the host middleware for content negotiation, and everything is yours to run. Cloud is early access and set up by hand, so it isn't for everyone yet. Both end up with the same files and tools.
Check what agents actually see
Two habits help more than any feature. First, write a real description in each page's frontmatter, because it becomes the line agents read in llms.txt. The missing-description lint rule checks for it. Second, run an external checker such as afdocs against your live site:
npx afdocs check https://docs.example.com
If some content only makes sense to a model, such as an API base URL a human sees in the sidebar, wrap it in wc-if with for="agents". It lands in the .md files and MCP results but not on the web page.
For the details on each file and endpoint, see How agents read your site, the MCP server page and the DocsLit Cloud page. To try it on your own docs, run npx docslit init. DocsLit is open source, so if your agent needs something the tools don't cover, open an issue on GitHub.