Get content negotiation running in your Next.js app in under 2 minutes.
$ npm install next-md-negotiateOr use your preferred package manager:
$ pnpm add next-md-negotiate
$ yarn add next-md-negotiate
$ bun add next-md-negotiateThe CLI auto-detects your project structure and creates all necessary files:
$ npx next-md-negotiate initThis command will:
app/md-api/[[...path]]/route.tsmd.config.ts--rewrites or --middleware to skip the strategy prompt. Add --add-hints to inject LlmHint components automatically.Open md.config.ts and add a route:
import { createMdVersion } from 'next-md-negotiate';
export const mdConfig = [
createMdVersion('/products/[productId]', async ({ productId }) => {
const product = await getProduct(productId);
return `# ${product.name}\n\n**Price:** $${product.price}`;
}),
];The handler receives fully type-safe parameters extracted from the route pattern. TypeScript knows that '/products/[productId]' gives you { productId: string }.
Start your dev server and test with curl:
# Start the dev server
$ npm run dev
# Request markdown from your route
$ curl -H "Accept: text/markdown" localhost:3000/products/42
# Response:
# Product 42
**Price:** $42.00Help AI agents discover that markdown is available by adding the LlmHint component to your pages:
import { LlmHint } from 'next-md-negotiate';
export default function ProductPage() {
return (
<div>
<LlmHint />
{ /* your page content */ }
</div>
);
}Or run the CLI command to inject hints into all configured pages:
$ npx next-md-negotiate add-hints