Skip to content

Conversation

aryasaatvik
Copy link

@aryasaatvik aryasaatvik commented Oct 7, 2025

Summary

Adds HTTP content negotiation support to the Zod documentation site, enabling AI agents (like Claude Code) to receive markdown instead of HTML while maintaining HTML for regular browsers.

This implementation follows the pattern established in fumadocs PRs:

Changes

  • Upgraded fumadocs-core from 15.1.0 to 15.8.3 to access the new negotiation API
  • Added dynamic route handler at /llms.mdx/[[...slug]]/ that serves markdown versions of documentation pages

Content negotiation middleware

  • Detects markdown preference via Accept header
  • Rewrites requests to serve markdown when appropriate
  • Non-intrusive: browsers continue receiving HTML

Static rewrites for extensions

  • Added Next.js rewrites to handle explicit .md and .mdx extension requests
  • Examples: /basics.md → markdown, /library-authors.mdx → markdown

How it works

For AI agents:

  • Request with Accept: text/markdown header → receives markdown
  • Request to /basics.md or /basics.mdx → receives markdown

For browsers:

  • Request without markdown preference → receives HTML (unchanged behavior)

References

Upgrade fumadocs-core from 15.1.0 to 15.8.3 to access the new
negotiation API for HTTP content negotiation support. This enables
serving markdown to AI agents while maintaining HTML for browsers.
Add dynamic route handler at /llms.mdx/[[...slug]]/ that serves
markdown versions of documentation pages. This enables AI agents
to fetch markdown content for specific pages with proper
text/markdown Content-Type headers.

- Uses existing getLLMText() helper for content processing
- Supports static generation via generateStaticParams()
- Returns 404 for non-existent pages
Implement Next.js middleware that detects when clients prefer
markdown (via Accept header) and rewrites requests to serve
markdown instead of HTML. This enables AI agents like Claude Code
to seamlessly access documentation in markdown format.

- Uses fumadocs-core negotiation API
- Excludes API routes and static assets
- Non-intrusive: browsers continue receiving HTML
Add Next.js rewrites to handle explicit .md and .mdx extension
requests, routing them to the markdown handler. This allows users
to append .md or .mdx to any doc URL to get markdown content.

Examples:
- /basics.md → /llms.mdx/basics
- /library-authors.mdx → /llms.mdx/library-authors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant