---
title: Add llms.txt and Markdown endpoints to Next.js App Router
description: Add llms.txt and per-page Markdown to an existing Next.js App Router site. Keep the browser UI and verify all three public responses with curl.
canonical_url: https://nextaiready.com/en/docs/guides/nextjs-llms-txt
url: https://nextaiready.com/en/docs/guides/nextjs-llms-txt
last_updated: 2026-11-24
updated: 2026-11-24
author: next-ai-ready team
summary: Add llms.txt and per-page Markdown to an existing Next.js App Router site. Keep the browser UI and verify all three public responses with curl.
topics: [nextjs, app-router, ai-search, llms.txt, markdown, tutorial]
---

# Add llms.txt and Markdown endpoints to Next.js App Router

The smallest implementation is a hand-written `public/llms.txt`. That is enough for a small,
rarely changing site. Use a build integration when the file must stay synchronized with many
pages, page summaries, Markdown representations, structured data, or agent tools.

Keep your existing App Router pages for browsers. Add an index at `/llms.txt` and serve each
page's Markdown at a separate `.md` URL. [Try the three HTTP checks](#see-a-production-example)
on this site before running them against your deployment.

Using a documentation framework? Follow the dedicated [Nextra 4 guide](./nextra-ai-ready) or
[Fumadocs guide](./fumadocs-ai-ready) for content paths, plugin composition, and deployment limits.

## Choose the smallest setup that fits

| Situation                            | Recommended approach                                                                     |
| ------------------------------------ | ---------------------------------------------------------------------------------------- |
| A small site with a few stable pages | Hand-write `public/llms.txt` and review it when content changes.                         |
| A documentation or content site      | Generate `llms.txt`, `llms-full.txt`, and page Markdown from the content source.         |
| A multilingual site                  | Generate locale-aware routes and verify that each language returns the intended content. |
| Agents need to perform operations    | Add authenticated actions only after the readable content layer works.                   |

Do not add MCP, a database, or callable actions just to claim that a site is AI-ready. Start with
content discovery and retrieval, verify them in production, and add capabilities when a real use
case requires them.

## Compare the tools before installing

These tools work at different layers. This is a needs-based selection guide, not a scorecard or a
claim that another project lacks a feature. Upstream references were checked on 2026-10-02.

| What you need                                                        | Start with                                                                                                                                                                                                                    | When to consider next-ai-ready                                                                                                                        |
| -------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| Titles, descriptions, canonical URLs, and social cards in App Router | [Native Next.js Metadata](https://nextjs.org/docs/app/getting-started/metadata-and-og-images).                                                                                                                                | Not for metadata alone. Keep that implementation and add a machine-facing layer only when needed.                                                     |
| Reusable JSON-LD components                                          | [Next SEO](https://github.com/garmeeh/next-seo#readme), which recommends native Metadata for App Router metadata.                                                                                                             | Only if you also need generated discovery or Markdown. Keep one owner for each JSON-LD entity.                                                        |
| A small, stable public content index                                 | A hand-written `public/llms.txt`, served through the [Next.js public folder](https://nextjs.org/docs/app/api-reference/file-conventions/public-folder).                                                                       | When manual synchronization becomes a real problem. A static file alone does not generate page Markdown.                                              |
| AI-readable documentation already using Fumadocs                     | [Fumadocs' native LLM integration](https://www.fumadocs.dev/docs/integrations/llms), including discovery, Markdown, and MCP examples.                                                                                         | Only for an unmet requirement. Do not install a second generator just to obtain the same endpoints.                                                   |
| A Nextra documentation UI                                            | Keep Nextra, including its [Copy Page implementation](https://github.com/shuding/nextra/blob/main/packages/nextra-theme-docs/src/components/copy-page.tsx). Check your installed version's machine-facing outputs separately. | If you need this SDK's build-time graph and handlers; inspect the [tested Nextra fixture and screenshots](./nextra-ai-ready) before changing the app. |
| An existing Nuxt application                                         | [nuxt-ai-ready](https://github.com/harlan-zw/nuxt-ai-ready), a Nuxt module.                                                                                                                                                   | Not a reason to migrate frameworks: next-ai-ready targets Next.js App Router, not Nuxt.                                                               |

For this SDK, the default path is a build-time content graph with generated discovery and page
representations. Actions, OpenAPI, and MCP are an explicit capability upgrade, not installation
requirements. It is not a replacement for a documentation UI, native metadata, or a complete SEO
suite. The [Fumadocs guide](./fumadocs-ai-ready) explains the overlapping responsibilities.

### Keep one owner per output

Before adding any integration, list what the deployed site already serves:

- `/llms.txt`, `/llms-full.txt`, and each page Markdown URL: choose one generator and one route owner.
- Metadata and JSON-LD: preserve the existing implementation; do not emit duplicate entities for the same page.
- Search and MCP: Fumadocs also documents AI-facing access. Choose the endpoint and authentication model your clients actually need.

If the current setup already returns the correct public content, production canonical URLs, and
language variants, keep it. Test a missing page and a private page too: an HTTP `200` by itself is
not proof of correct retrieval. None of these tools guarantees Google indexing or AI citation.

## Try a clean runnable demo first

Create a minimal App Router project before changing an existing application:

```bash
npm create next-ai-ready@alpha next-ai-ready-demo
cd next-ai-ready-demo
npm install
npx next-ai-ready init
```

Create `content/docs/example.mdx` with this content:

```markdown
---
title: Example documentation
summary: A non-root page for checking the Markdown endpoint.
---

# Example documentation

This page verifies that the content source is served as Markdown.
```

Then build, validate the local wiring, and start the app:

```bash
npm run build
npx next-ai-ready doctor --score
npm run dev
```

Then open:

- `http://localhost:3000/llms.txt`
- `http://localhost:3000/llms-full.txt`
- `http://localhost:3000/docs/example.md`

In another terminal, check the non-root page directly:

```bash
curl -i http://localhost:3000/docs/example.md
```

Expect `200`, `Content-Type: text/markdown`, and the example page's title and body, not a
missing-page recovery document. `content/index.mdx` maps to `/` in the graph; `/index.md` is not
an alias for that root page in the current adapter, so this demo checks an explicit non-root route.

The alpha.21 default `init` is Knowledge-only. It does not create `/openapi.json` or `/tools.json`;
use the optional capability setup below when you need them.

The generated directory is an ordinary Next.js TypeScript project. You can commit it, deploy it,
or compare its small integration diff with your existing app. The generator itself is covered by
the repository's clean-install and production-build release checks.

## See a production example

Run these commands against this guide's public URLs:

```bash
origin=https://nextaiready.com
page=/en/docs/guides/nextjs-llms-txt

curl -fsS -o /dev/null -w '%{http_code} %{content_type}\n' -H 'Accept: text/html' "$origin$page"
curl -fsS "$origin/llms.txt" | grep -F "$origin$page"
curl -fsS -i "$origin$page.md" | grep -Ei '^(HTTP/|content-type:|link:|# Add llms\.txt and Markdown endpoints to Next\.js App Router$)'
```

The page should return `200 text/html`. The index should list the guide's production URL.
The Markdown request should return `200`, `Content-Type: text/markdown`, the guide heading,
and a canonical `Link` header pointing to the HTML page.

- [Production llms.txt](https://nextaiready.com/llms.txt)
- [This guide as Markdown](https://nextaiready.com/en/docs/guides/nextjs-llms-txt.md)
- [Production OpenAPI document](https://nextaiready.com/openapi.json)
- [Production tool manifest](https://nextaiready.com/tools.json)
- [Source for the deployed documentation site](https://github.com/mustcanbedo/next-ai-ready/tree/main/examples/docs-site)

The production site also passes all 25 checks in the pinned Vercel Agent Readability CLI baseline.
That score measures technical readability, not search position or citation.

### Inspect the implementation evidence

This is a first-party production dogfood case, not an external customer testimonial. Review the
implementation and its assertions directly instead of relying on a marketing screenshot:

- [Production configuration](https://github.com/mustcanbedo/next-ai-ready/blob/main/examples/docs-site/ai-ready.config.mjs)
- [Content used to generate this guide](https://github.com/mustcanbedo/next-ai-ready/blob/main/examples/docs-site/content/en/docs/guides/nextjs-llms-txt.mdx)
- [Production route smoke checks](https://github.com/mustcanbedo/next-ai-ready/blob/main/examples/docs-site/scripts/docs-site-route-smoke.mjs)
- [Executable Nextra 4 fixture](https://github.com/mustcanbedo/next-ai-ready/tree/main/examples/nextra-docs)

The route smoke checks verify the HTML page, `llms.txt`, explicit Markdown URLs, content
negotiation, canonical headers, search, MCP retrieval, and separate browser/agent missing-page
behavior. External adoption is tracked separately and will be presented as a customer case only
after another project deploys and verifies the integration.

## 1. Install the package

From an existing Next.js App Router project:

```bash
pnpm add next-ai-ready
pnpm exec next-ai-ready init
```

`init` creates explicit Knowledge Plane route handlers, an AI-ready configuration file, and the
Next.js rewrite configuration with Agent Markdown negotiation. Existing page components remain unchanged.

## 2. Add AI-readable content

Create an MDX source such as `content/about.mdx`:

```markdown
---
title: About Acme
summary: Acme helps support teams find verified product answers.
author: Acme team
updatedAt: 2026-08-02
questions:
  - q: What does Acme do?
    a: Acme helps support teams search verified product documentation.
---

# About Acme

Acme gives support teams one searchable source for verified product answers.
```

Clear titles, summaries, authorship, freshness, and direct answers are useful to people as well as
AI consumers. Do not add claims or FAQ answers that the visible page cannot support.

For a collection of pages, follow the [MDX content collection guide](./mdx-content) to match the
source directory and verify how each file maps to a public route before generating the interfaces.

## 3. Generate the interfaces

```bash
pnpm exec next-ai-ready build
pnpm exec next-ai-ready doctor --score
```

The build produces discovery files and the semantic graph used by the runtime handlers. A basic
deployment exposes:

- `/llms.txt` for concise site discovery.
- `/llms-full.txt` for combined site context.
- `/<page>.md` for clean retrieval of matched non-root content pages.
- `/sitemap.md` for agent-readable navigation.

`/openapi.json`, `/tools.json`, and `/api/mcp` belong to the optional Capability Plane; they are
not part of the default `init` setup.

The setup is ready when `doctor` reports zero errors and `llms.txt` lists the intended pages.
Warnings describe optional quality or production settings that still need attention.

## Check the expected responses

Use HTTP checks so a successful-looking page cannot hide a redirect or HTML fallback:

```bash
curl -i http://localhost:3000/llms.txt
curl -i http://localhost:3000/about.md
```

Both requests should return `200`. `llms.txt` should be plain text and the page endpoint should
return Markdown derived from the intended content source, not a missing-page recovery document.
If your application already serves `/about`, a normal request should still return its original HTML.
Adding `content/about.mdx` alone does not create that browser page.

## 4. Verify the deployed site

After deploying, inspect the real public responses rather than relying only on build artifacts:

```bash
pnpm exec next-ai-ready audit https://example.com --version 3
```

Repeat the [public HTTP example](#see-a-production-example) with your production origin, a real page
path, and the expected Markdown heading.

## Common mistakes

### A Markdown endpoint returns HTML

**Symptom:** `/about.md` returns `text/html` or the app's HTML shell instead of the source page.
The Markdown request is reaching the app rather than the AI handler.

**Fix:** check that `withAiReady()` wraps the exported Next.js config and that the Markdown route
handler generated by `init` exists. Preserve existing plugins and customized config; do not create
a second config file. Rebuild the app and restart its server before repeating the request:

```bash
curl -i -H 'Accept: text/markdown' http://localhost:3000/about.md
```

**Verify:** expect `200`, `Content-Type: text/markdown`, the `About Acme` title, and its actual body.
If the app already serves `/about` as a browser page, also request it with `Accept: text/html` and
confirm it still returns HTML. A source file alone does not create that browser route.

### A page returns 200 but is missing

**Symptom:** the Markdown response has `document_status: "not_found"` and `X-Robots-Tag: noindex`.
This is the handler's missing-page recovery document, not the requested page, even though its HTTP
status is `200`.

**Fix:** find the intended route in `.next-ai-ready/graph.json` and `public/llms.txt`. If it is absent,
check the matched source files and [MDX route mapping](./mdx-content). For this guide,
`content/about.mdx` maps to `/about`; do not guess the URL from the source filename. Rebuild and
restart after correcting the source or route.

```bash
curl -i http://localhost:3000/llms.txt
curl -i http://localhost:3000/about.md
```

**Verify:** the index lists `/about` and the page response contains the expected title and body,
without the `not_found` marker. A genuinely missing page should still return the recovery document;
do not remove that safeguard just to make a test pass.

For an empty content index or local URLs in production, use the [MDX collection troubleshooting
steps](./mdx-content). Repeat the same GET checks against your deployed origin after fixing them.

- **Private content appears in a generated artifact.** Remove it from the content source or apply an
  explicit exclusion; generated files are public unless the deployment protects them.
- **The audit is high but citations do not increase.** Readability is an input, not a ranking or
  citation guarantee. Measure real crawler visits and referrals separately.

## Add callable actions later

`llms.txt` and Markdown solve the first problem: helping AI systems discover and read content.
Callable actions are a separate production decision. Add them only when an agent needs to perform a
specific operation, then configure authentication, input validation, and audit logging.

To opt in from the initialized project:

```bash
pnpm add zod@^4 @modelcontextprotocol/sdk mcp-handler
pnpm exec next-ai-ready init --with-capabilities
```

Before building, check `ai-ready.config.*`. The initializer patches its generated config, but
leaves a customized config unchanged when it cannot safely locate the insertion point. If the
`actions` option is missing, add it to the existing `defineConfig` object yourself:

```ts
actions: "./actions/index.ts", // Use index.mjs in a JavaScript project.
```

Then build the capability artifacts and check the wiring:

```bash
pnpm exec next-ai-ready build
pnpm exec next-ai-ready doctor --score
```

Restart the dev server, then check in another terminal:

```bash
curl -i http://localhost:3000/openapi.json
curl -i http://localhost:3000/tools.json
```

Both should return `200` with JSON containing the generated public `ping` action. For MCP
retrieval and invocation checks, continue with the [MCP integration guide](./mcp-integration).

## What this does not guarantee

Technical AI-readiness cannot guarantee that an AI product will crawl, index, rank, quote, or cite a
page. Treat these endpoints as reliable machine-facing access to good source content, then measure
actual visits, retrievals, citations, and business outcomes separately.

## Related Next.js AI discovery guides

- [Configure robots.txt for AI crawlers in Next.js](./robots-txt)
- [How to add an MCP server to Next.js App Router](./mcp-integration)
- [Add llms.txt and Markdown endpoints to Fumadocs](./fumadocs-ai-ready)
- [Nextra llms.txt and Markdown endpoint setup](./nextra-ai-ready)
