Skip to main content

Documentation Index

Fetch the complete documentation index at: https://motherfuckingsideproject.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

Core API

Full API reference for @reaganhsu/agentxp-core and @reaganhsu/agentxp-next exports.

withAgentXP(config?)

Next.js middleware factory. Wrap your middleware export with withAgentXP to intercept agent requests and serve optimized markdown automatically.
// middleware.ts
import { withAgentXP } from '@reaganhsu/agentxp-next'

export default withAgentXP()
Returns a Next.js middleware function compatible with the middleware.ts convention.

Config

All fields are optional.
interface AgentXPMiddlewareConfig {
  transform?: {
    contentSelector?: string
    excludeSelectors?: string[]
    handlers?: Record<string, (el: Element) => string>
    maxTokens?: number
  }
  permissions?: {
    aiTrain?: boolean
    aiInput?: boolean
    search?: boolean
  }
  baseUrl?: string
  llmsTxt?: {
    siteName?: string
    description?: string
    pages?: LlmsTxtPage[]
  }
  siteHeader?: SiteHeaderConfig
  overridesDir?: string
}

transform.contentSelector

Type: stringCSS selector for the main content area. When set, AgentXP extracts only the matching element. Auto-detected from main, article, [role="main"], #content, or .content if omitted.

transform.excludeSelectors

Type: string[]Additional CSS selectors for elements to strip before conversion (e.g., cookie banners, chat widgets).

transform.maxTokens

Type: numberMaximum token target for the markdown output. Content is truncated by section when exceeded. Defaults to 8000.

permissions.aiTrain

Type: booleanPermit AI providers to use content for model training. Reflected in the Content-Signal response header. Defaults to false.

permissions.aiInput

Type: booleanPermit AI agents to use content as inference input. Defaults to true.Type: booleanPermit search indexing. Defaults to true.

baseUrl

Type: stringBase URL for resolving relative links in the markdown output. Auto-detected from the incoming request when omitted.

llmsTxt.siteName

Type: stringSite name written to the # Heading of /llms.txt. Defaults to "Site".

llmsTxt.description

Type: stringSite description written as the > blockquote in /llms.txt.

llmsTxt.pages

Type: LlmsTxtPage[]Explicit list of pages to include in /llms.txt. See the LlmsTxtPage type under @reaganhsu/agentxp-core.Type: SiteHeaderConfigManual site navigation header prepended to every markdown response. When omitted, AgentXP auto-extracts navigation from the page’s <header> and <nav> elements.

overridesDir

Type: stringPath (relative to project root) to a directory of hand-written .md files that take priority over auto-generated markdown. Requires Node.js runtime — use createMarkdownHandler instead if you are on Edge.

AgentExperience

React component. Add it to your root layout to inject agent-optimized metadata with no visible UI.
import { AgentExperience } from '@reaganhsu/agentxp-next'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <AgentExperience siteName="My Site" description="Product docs" />
      </body>
    </html>
  )
}
The component renders no visible output. It injects:
  • A JSON-LD WebSite structured data block
  • A <link rel="alternate" type="text/markdown" href="/llms.txt" /> tag
  • A <meta name="robots"> tag with noai / noimageai directives when training or inference is disabled

Props

siteName

Type: stringSite name written into the JSON-LD WebSite schema. Optional.

description

Type: stringSite description written into the JSON-LD WebSite schema. Optional.

aiTrain

Type: booleanWhen false, adds the noai directive to the robots meta tag. Defaults to false.

aiInput

Type: booleanWhen false, adds the noimageai directive to the robots meta tag. Defaults to true.

createMarkdownHandler(config)

Import from @reaganhsu/agentxp-next/route-handler. Creates a Next.js Route Handler GET function that serves markdown with file-based override support. Runs in Node.js runtime (not Edge), so it can read files from disk.
// app/api/md/[[...path]]/route.ts
import { createMarkdownHandler } from '@reaganhsu/agentxp-next/route-handler'

export const GET = createMarkdownHandler({
  overridesDir: 'content/markdown',
  siteHeader: { name: 'My Site', links: [{ text: 'Docs', href: '/docs' }] },
})

Config

interface RouteHandlerConfig {
  overridesDir: string
  baseUrl?: string
  siteHeader?: SiteHeaderConfig
  bypassHeader?: string
}

overridesDir

Type: string (required)Directory for hand-written markdown overrides, relative to process.cwd(). A request to /pricing will check <overridesDir>/pricing.md first. The root path maps to index.md.

baseUrl

Type: stringBase URL for resolving relative links. Defaults to request.nextUrl.origin.

siteHeader

Type: SiteHeaderConfigManual site navigation header prepended to every response. When omitted, AgentXP auto-extracts from the page’s HTML.

bypassHeader

Type: stringInternal header name used to fetch page HTML without triggering the middleware again. Defaults to "x-agentxp-internal".