How to Serve Markdown to AI Agents (and Why)
Contents
- What “Markdown for agents” means
- Why bother
- Agents already ask for it
- The payload shrinks a lot
- The agent stops guessing
- What it won’t do
- How to do it
- 1. Produce the Markdown
- 2. Send the right headers
- 3. Add content negotiation
- Node.js
- 4. Let agents find it
- No server access? Use Cloudflare
- The caching trap
- Test it
- Ask for the Markdown version with curl
- FAQ
Short answer: publish a clean Markdown copy of each page at the same URL with .md on the end, and return that copy when a request sends Accept: text/markdown. Agents get the article without navigation, scripts and markup, and browsers keep getting HTML.
I added this to markodenic.com on 14 October 2026. Every article now has a Markdown twin: /check-node-version.md sits next to /check-node-version/.
Below: what it is, why it’s worth an afternoon, tested Node code, and the caching mistake that can serve Markdown to your human visitors.
What “Markdown for agents” means
An AI agent that reads your page (a coding assistant looking up docs, a chat app answering with a source, a research agent) doesn’t need your header, footer, cookie banner or 40 KB of inline CSS. It needs the text, the headings, the links and the code.
There are two ways to give it exactly that, and you should do both:
- A
.mdURL./blog/hello/has a Markdown twin at/blog/hello.md. This comes from the llms.txt proposal, which suggests a “clean markdown version” of each page “at the same URL as the original page” with.mdadded. For URLs that end in a slash, the proposal’s exact form is/blog/hello/index.md;/blog/hello.mdis the shorter form this site uses. - Content negotiation. Same URL, different format. The client says what it prefers in the
Acceptheader, and the server answers with the best match. A browser asks fortext/html. An agent that asks fortext/markdowngets Markdown from/blog/hello/itself.
text/markdown is a registered media type (RFC 7763, 2016), so this is plain HTTP. No new standard needed.
Why bother
Agents already ask for it
When Cloudflare launched its own Markdown for Agents feature in February 2026, it said popular coding agents “like Claude Code and OpenCode” already send Accept: text/markdown when they fetch pages. Vercel serves Markdown the same way on its own site. When a site doesn’t support it, the agent gets HTML and converts it itself.
The payload shrinks a lot
I measured the 10 most-read posts on this site (raw response size, 28 October 2026):
| Page | HTML | Markdown | Smaller by |
|---|---|---|---|
| /css-tips/ | 122.3 KB | 25.0 KB | 4.9Ă— |
| /html-tips/ | 85.9 KB | 12.7 KB | 6.8Ă— |
| /use-google-like-a-pro/ | 48.1 KB | 2.8 KB | 17.5Ă— |
| /use-console-log-like-a-pro/ | 68.3 KB | 10.4 KB | 6.6Ă— |
| /free-certifications-for-developers/ | 41.2 KB | 2.4 KB | 17.0Ă— |
| /css-generators/ | 42.1 KB | 2.7 KB | 15.4Ă— |
| /free-courses/ | 44.3 KB | 2.7 KB | 16.7Ă— |
| /make-your-first-open-source-contribution/ | 50.5 KB | 3.6 KB | 14.2Ă— |
| /free-web-development-resources/ | 80.6 KB | 34.5 KB | 2.3Ă— |
| /javascript-tips/ | 63.9 KB | 6.3 KB | 10.2Ă— |
| All 10 | 647.2 KB | 103.0 KB | 6.3Ă— |
Short posts gain the most, because the page chrome is the same size no matter how long the article is. The link-heavy resource list gains the least: links are content, so they stay.
To be fair to HTML: a good agent strips the markup before the model sees it, so the token saving is smaller than these byte numbers. Cloudflare measured its own announcement at 16,180 tokens as HTML and 3,150 as Markdown, a 5Ă— difference.
The agent stops guessing
The bigger win isn’t size. When an agent converts your HTML, it has to guess what the article is. Navigation links end up in the middle of the text, a “Copy” button label lands inside a code sample, and the language of a code block gets lost. Your Markdown has none of that, because you decide what’s in it: title, date, canonical URL, the article, nothing else.
What it won’t do
It won’t help you rank in Google. Google’s AI optimization guide says you don’t need “AI text files, markup, or Markdown to appear in Google Search”, because Search doesn’t use them.
So do this for agents, not for SEO. (For what does move rankings, see my SEO checklist for developers.) And keep one rule: the Markdown must say the same thing as the HTML page. Don’t add text only bots can see, and don’t pick the format by sniffing user agents. Different content for bots is what search engines call cloaking. The same content in another format, chosen by a standard header, is just HTTP.
How to do it
1. Produce the Markdown
- Your content is already Markdown (Astro, Hugo, Eleventy, Jekyll, most docs sites): publish the source files next to the HTML at build time. Strip the front matter or turn it into a short header.
- Your content lives in a CMS or a database: convert the article body (not the whole page) from HTML to Markdown, and cache the result until the post changes. Converting on every request is wasted work.
Start each file with the title, a one-line summary and the canonical URL, so an agent that only reads the top still knows what it has and where it came from. Here’s the top of this site’s Node version guide:
# How to Check and Update Your Node Version (Windows, Mac, Linux)
> Check your Node.js version with node -v, then update it with nvm, fnm, winget, Homebrew or apt. Plus which version to run in late 2026 and how to pin it per project.
Author: [Marko Denic](https://markodenic.com/) | Published: 2026-10-26 | Updated: 2026-10-26 | Topics: JavaScript, Tutorial, Web Development | Canonical: https://markodenic.com/check-node-version/
2. Send the right headers
Every Markdown response needs four headers:
Content-Type: text/markdown; charset=utf-8
Vary: Accept
Cache-Control: private
Link: <https://example.com/blog/hello/>; rel="canonical"
Content-Typewithcharset=utf-8. RFC 7763 makes the charset parameter required and gives it no default, so without it the client has to guess the encoding.Vary: Accepttells caches that this URL has more than one version. Send it on the HTML response too.Cache-Control: privatekeeps shared caches (CDNs, proxies) from storing the Markdown. The caching trap below explains why.Link: rel="canonical"points to the HTML page. Google supports canonical in an HTTP header for non-HTML files, so the.mdcopy won’t compete with your real page. Don’t usenoindexfor this: Google recommends canonical, notnoindex, for duplicates.
3. Add content negotiation
The rules are short:
/blog/hello.mdalways returns Markdown./blog/hello/returns Markdown only when the request asks fortext/markdownand a Markdown version exists. Everything else (pages without a Markdown twin, the home page, CSS, images) is served exactly as before.
Put this in the code that already renders your pages, not in your web server config. Your app knows which pages have a Markdown version, and a mistake there breaks one route instead of the whole site. On this site it’s a small WordPress hook that runs before the theme renders a post.
Here’s the whole idea in Node, tested on Node 22. Replace example.com with your domain.
Node.js
Plain node:http, no dependencies. In a real app the pages object is your database or file system:
import { createServer } from 'node:http';
const SITE = 'https://example.com';
const pages = {
'/blog/hello/': { title: 'Hello', markdown: '# Hello\n\nMarkdown version.\n' },
};
function wantsMarkdown(accept = '') {
const q = {};
for (const part of accept.split(',')) {
const [type, ...params] = part.trim().toLowerCase().split(';');
const weight = params.find((p) => p.trim().startsWith('q='));
q[type] = weight ? parseFloat(weight.trim().slice(2)) : 1;
}
return (q['text/markdown'] ?? 0) > 0 && (q['text/markdown'] ?? 0) >= (q['text/html'] ?? 0);
}
createServer((req, res) => {
const { pathname } = new URL(req.url, SITE);
const isMdUrl = pathname.endsWith('.md');
const path = isMdUrl ? pathname.slice(0, -3) + '/' : pathname;
const page = pages[path];
if (!page) {
res.writeHead(404, { 'Content-Type': 'text/plain; charset=utf-8' });
return res.end('Not found');
}
if (isMdUrl || wantsMarkdown(req.headers.accept)) {
res.writeHead(200, {
'Content-Type': 'text/markdown; charset=utf-8',
'Vary': 'Accept',
'Cache-Control': 'private',
'Link': `<${SITE}${path}>; rel="canonical"`,
});
return res.end(page.markdown);
}
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8', 'Vary': 'Accept' });
res.end(`<!doctype html><title>${page.title}</title><h1>${page.title}</h1>`);
}).listen(3000);
wantsMarkdown() reads the quality values in the header, so text/markdown;q=0 (an explicit “no”) gets HTML, and so does a browser’s */*.
The canonical URL comes from the SITE constant, not from the request’s Host header, which anyone can fake.
Why not nginx or .htaccess rules? I wrote both and tested them on real servers, then left them out. A rewrite rule runs in front of every request on your site, so a small mistake breaks pages that have nothing to do with Markdown. My first nginx version sent agents a 404 on the home page. In your app, the same mistake stays on one route.
4. Let agents find it
Content negotiation works without any discovery: the agent asks, you answer. For agents that don’t send the header, point to the .md file from the page’s <head>:
<link rel="alternate" type="text/markdown" href="https://example.com/blog/hello.md">
This is what the llms.txt proposal recommends. If you have an llms.txt file, link the .md URLs from it instead of the HTML pages. On this site, llms-full.txt lists every article that way.
No server access? Use Cloudflare
If your site is behind Cloudflare on a Pro, Business or Enterprise plan, you can turn on Markdown for Agents under AI Crawl Control. Cloudflare converts your HTML on the fly for requests that send Accept: text/markdown. You don’t control what goes into the Markdown and there’s no .md URL, but it’s one toggle.
The caching trap
Content negotiation means one URL with two versions, so every cache in between has to keep them apart. Vary: Accept is how you tell it to. Not every cache listens.
Cloudflare’s cache, for example, ignores Vary by default (except for Accept-Encoding and images). If it caches your HTML pages and an agent is the first visitor after a purge, Cloudflare can store the Markdown under the page URL. The next human visitor gets a wall of plain text instead of your site.
That’s why the code above sends Cache-Control: private on every Markdown response. Shared caches don’t store private responses, so the worst case is the safe one: a cached HTML page served to an agent, which it can convert itself.
If you cache HTML at the edge, test this after you deploy: request the page with Accept: text/markdown, then load it in a private browser window and make sure you get HTML.
Test it
Ask for the Markdown version with curl
# The .md URL
curl -i https://markodenic.com/check-node-version.md
# Content negotiation on the normal URL
curl -i -H "Accept: text/markdown" https://markodenic.com/check-node-version/
# A browser-style request must still get HTML
curl -sI https://markodenic.com/check-node-version/ | grep -i content-type
Check four things: the second command returns content-type: text/markdown; charset=utf-8, both Markdown responses carry vary: Accept and the canonical link header, and the third command still says text/html.
This works well alongside other agent-facing features. I also added WebMCP to my CSS generators, so agents can call them instead of dragging sliders. If you write for people who paste your articles into ChatGPT or Claude, there’s a client-side version of the same idea: a “Copy for AI” button.
FAQ
Does serving Markdown help SEO?
No. Google says Search doesn’t use Markdown or AI text files, and that they “will neither harm nor help” your rankings. Serve Markdown because agents read your content better, not to rank higher.
Is serving Markdown to bots cloaking?
Not if the Markdown says the same thing as the HTML page and you choose the format by the Accept header, not the user agent. Cloaking means showing bots different content. Keep the text identical, and point the .md copy at the HTML page with a canonical header.
Will the .md pages create duplicate content?
Not with a Link: <...>; rel="canonical" header on every Markdown response. It tells search engines the HTML page is the original, the same way a canonical tag does in HTML.
Which AI agents send Accept: text/markdown?
Cloudflare names Claude Code and OpenCode. Other agents still ask for HTML and convert it themselves, which is why the .md URL and the <link rel="alternate"> tag are worth adding as well.
Do I still need llms.txt?
They do different jobs. llms.txt is a single index of your site for agents; Markdown versions are the pages themselves. If you have both, link the .md URLs from your llms.txt.
Is text/markdown an official MIME type?
Yes. It was registered in RFC 7763 in 2016, with .md and .markdown as file extensions.