---
title: Add llms.txt and Markdown endpoints to Next.js App Router
description: Choose between a static llms.txt and generated AI-readable endpoints, run a clean Next.js demo, and verify the production result.
canonical_url: https://nextaiready.com/en/docs/guides/nextjs-llms-txt
url: https://nextaiready.com/en/docs/guides/nextjs-llms-txt
last_updated: 2026-10-01
updated: 2026-10-01
author: next-ai-ready team
summary: Choose between a static llms.txt and generated AI-readable endpoints, run a clean Next.js demo, and verify the production result.
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.

This guide adds those interfaces to an existing Next.js App Router project without changing its UI.

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.

## 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

This documentation site uses the same integration described below:

- [Production llms.txt](https://nextaiready.com/llms.txt)
- [This installation page as Markdown](https://nextaiready.com/en/docs/installation.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.

## 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
```

Also open `https://example.com/llms.txt` and one real page such as
`https://example.com/about.md`. Confirm that canonical URLs point to the production origin and that
normal browser pages still return HTML.

## Common mistakes

- **The endpoint returns the app's HTML shell.** Check that `withAiReady()` wraps the exported
  Next.js config and that the generated route handlers exist.
- **`llms.txt` is empty or misses pages.** Check the `content` globs in `ai-ready.config.*`, then run
  the build again.
- **Local URLs appear in production output.** Set the production `site.baseUrl` and rebuild before
  deployment.
- **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)
