# llms.txt and Markdown twins

Serve llms.txt, llms-full.txt, .md page twins, Accept: text/markdown content negotiation, robots.txt Content-Signal, and sitemap.xml from one Surface declaration.

When an external assistant fetches a normal HTML page, it spends context tokens parsing navigation bars, footers, scripts, and layout markup before it reaches the actual product copy. With the `agent-ready` source package, you declare your application's pages once in a `Surface` and implement `PageSource`. Ferrite serves `llms.txt`, `llms-full.txt`, clean Markdown page twins, `robots.txt` with `Content-Signal`, and `sitemap.xml` directly from that same source so human pages and agent copies stay in sync on every release.

## Add the package and forward `accept`

Install `agent-ready` into your application:

```bash
ferrite add agent-ready
```

Forward the `accept` header on your application route in `ferrite.json`. The gateway strips unlisted request headers before forwarding requests to your app, so `Accept: text/markdown` content negotiation requires `accept` in `forward_headers`:

```json filename="ferrite.json (excerpt)"
{
  "prefix": "/",
  "binding": "requests",
  "kind": "api",
  "forward_headers": [
    "accept",
    "origin",
    "mcp-protocol-version",
    "mcp-method",
    "mcp-name"
  ]
}
```

If `accept` is omitted, `.md` URLs and `?format=md` still work, while requests to canonical page URLs with `Accept: text/markdown` receive HTML instead of Markdown.

## Declare pages and supply their Markdown

Declare each public page in `Surface` and return its content from `PageSource`. If your `PageSource` returns HTML, `agent-ready` converts it to Markdown; returning clean Markdown directly avoids stripping navigation chrome during conversion.

```rust filename="src/agent.rs"
use crate::agent_ready::surface::{Page, Surface};
use crate::agent_ready::well_known::{self, PageBody, PageSource};

fn build_surface(origin: &str) -> Surface {
    let mut surface = Surface::new(
        "northlight-yoga",
        "studio",
        origin,
        "Class schedules and booking for Northlight Yoga.",
        "1.0.0",
    );
    surface.pages.push(Page {
        path: "/".into(),
        title: "Northlight Yoga".into(),
        description: "Weekly class timetable and online booking.".into(),
        core: true,
    });
    surface.pages.push(Page {
        path: "/classes".into(),
        title: "Class schedule".into(),
        description: "Live seat availability and session times.".into(),
        core: true,
    });
    surface
}
```

Dispatch incoming requests through `agent_ready::well_known::handle_h` ahead of your application's catch-all router and preserve every response header it produces, including `Vary: Accept` and `Content-Type: text/markdown; charset=utf-8`.

When your application serves traffic on a custom domain in addition to its generated host, construct the surface per request with `Surface::served_at(verified_host)` using the gateway-attested `verified_host`. Never build canonical links from an unverified `Host` header.

## Endpoints served from one declaration

| Path | Content type | Behavior |
| --- | --- | --- |
| `/llms.txt` | `text/markdown; charset=utf-8` | Concise index of your application description, pages, operations, and discovery links |
| `/llms-full.txt` | `text/markdown; charset=utf-8` | Full Markdown corpus concatenating core pages so an assistant can read the product in one fetch |
| `/index.md`, `/<path>.md` | `text/markdown; charset=utf-8` | Clean Markdown twin of a declared page |
| `/<path>?format=md` | `text/markdown; charset=utf-8` | Query-parameter alias returning the same Markdown twin |
| `/<path>` with `Accept: text/markdown` | `text/markdown; charset=utf-8` | Content-negotiated Markdown at the canonical URL with `Vary: Accept` |
| `/robots.txt` | `text/plain; charset=utf-8` | Crawler rules, sitemap pointer, and `Content-Signal: search=yes, ai-input=yes, ai-train=yes` |
| `/sitemap.xml` | `application/xml; charset=utf-8` | Canonical URLs for declared human and machine endpoints |

Include an alternate link tag in your HTML `<head>` (or an HTTP `Link` response header such as `</classes.md>; rel="alternate"; type="text/markdown"`) so browsers and crawlers discover the Markdown twin directly from the HTML document.

## Caching, policy, and security boundaries

- Preserve `Vary: Accept` on every route that negotiates Markdown. Dropping `Vary: Accept` causes shared caches to serve Markdown to browsers or HTML to assistants.
- Keep private or user-specific content out of `Surface.pages`. Every declared page in `llms.txt` and `llms-full.txt` is treated as public discovery content.
- To serve a stricter `Content-Signal` or crawler policy in `/robots.txt`, answer `/robots.txt` in your own router before dispatching to `well_known::handle_h`.
- `llms.txt` is an emerging convention rather than a formal RFC. Pair it with [OpenAPI and structured errors](/developers/openapi/) and [MCP Servers](/developers/mcp-servers/) when assistants need to invoke operations, not only read pages.

## Verify locally

Start your application with `ferrite dev` and check each representation:

```bash
curl -s http://127.0.0.1:8787/llms.txt
curl -s http://127.0.0.1:8787/index.md
curl -i -H 'Accept: text/markdown' http://127.0.0.1:8787/
curl -s http://127.0.0.1:8787/robots.txt
```

Confirm that the negotiated request returns `Content-Type: text/markdown; charset=utf-8` and `Vary: Accept`, and that the Markdown body matches the `.md` path without navigation chrome.

## Next steps

- Expose typed HTTP schemas and machine-readable errors with [OpenAPI and structured errors](/developers/openapi/).
- Add browser-context tools with [WebMCP](/developers/webmcp/).
- Run the automated readiness checks in [Verify agent readiness](/developers/agent-readiness-verification/).
