@42a/ael-next
v0.1.1
Published
Next.js (App Router) adapter for the 42a Agentic Enablement Layer: markdown page variants, llms.txt and an MCP server for your site in three small files.
Readme
@42a/ael-next
Next.js (App Router) adapter for the 42a Agentic Enablement Layer: markdown page variants, llms.txt, and an on-site MCP server in three small files.
Requires Next.js ≥ 14 with the App Router (Pages Router is not supported).
Install
npm install @42a/ael @42a/ael-next1. ael.config.ts (project root)
import { defineAelConfig } from "@42a/ael";
export default defineAelConfig({
siteUrl: "https://example.com",
});2. middleware.ts
import { createAelMiddleware, AEL_MATCHER } from "@42a/ael-next/middleware";
import aelConfig from "./ael.config";
export const middleware = createAelMiddleware(aelConfig);
export const config = { matcher: AEL_MATCHER };Already have middleware (Clerk, next-intl, …)? Compose instead:
import { withAel } from "@42a/ael-next/middleware";
export const middleware = withAel(aelConfig, existingMiddleware);3. app/api/ael/[[...path]]/route.ts
import { createAelRouteHandlers } from "@42a/ael-next";
import aelConfig from "../../../../ael.config";
export const dynamic = "force-dynamic";
export const { GET, POST } = createAelRouteHandlers(aelConfig);That's it. The middleware rewrites /llms.txt, /llms-full.txt, <path>.md, ?format=markdown, Accept: text/markdown, /.well-known/mcp*, and POST /api/mcp into the route handler, and adds a Link: <…?format=markdown>; rel="alternate" header to your HTML pages so the markdown variants are discoverable — no layout edits.
Verify with:
npx @42a/ael doctor https://example.comConnect to 42a (optional)
npx @42a/ael connectMints a site token; add it as the FORTYTWOA_SITE_TOKEN environment variable and redeploy. Domain verification happens automatically via /.well-known/42a.json.
Notes
- Runtime: Node by default; the core is edge-clean, so
export const runtime = "edge"works too. - Caching: llms outputs get
s-maxage=43200(12 h); converted markdown is cached in an in-memory KV per instance (passcache:in the config for a persistent store). - Content: defaults to self-render (sitemap + own HTML). Pass a custom
providerfor CMS-backed sites — see the@42a/aelREADME.
