next-md-negotiate
Content negotiation for Next.js - serve Markdown to LLMs and HTML to browsers from the same URL.
Visit projectThe Problem
Your Next.js app serves HTML. LLMs, crawlers, and AI agents want Markdown. Today you're stuck choosing between separate endpoints that duplicate your routing and go stale, or Markdown-only pages that break the browser experience for human visitors.
The HTTP Accept header already solves this. A browser sends Accept: text/html. An LLM client sends Accept: text/markdown. Your server should respond accordingly - but Next.js has no built-in way to do this.
The Solution
next-md-negotiate intercepts requests that ask for Markdown, rewrites them to an internal API route, and returns the Markdown version you define - all transparently, from the same URL.
- Browser sends
GET /products/42withAccept: text/html- gets your normal Next.js page - LLM agent sends
GET /products/42withAccept: text/markdown- gets your Markdown version
No new URLs. No duplicate routing. The client just sets an Accept header.
Key Features
- Zero-config content negotiation via standard HTTP
Acceptheaders - Works with both App Router and Pages Router
- Type-safe parameters inferred from route patterns
- CLI scaffolding with
npx next-md-negotiate init - Published as an npm package for easy integration
Technologies Used
- Next.js - App Router and Pages Router support
- TypeScript - Fully typed API with route parameter inference
- HTTP Content Negotiation - Standards-based approach using
Acceptheaders