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

# Quick Start

> Install AgentXP and serve your first markdown response in minutes.

# Quick Start

> Install AgentXP and serve your first markdown response in minutes.

<Steps>
  <Step title="Install the package">
    Add `@reaganhsu/agentxp-next` to your project.

    ```bash theme={null}
    npm install @reaganhsu/agentxp-next
    ```
  </Step>

  <Step title="Add middleware">
    Create `middleware.ts` in your project root (next to `package.json`). If your project uses a `src/` directory, create `src/middleware.ts` instead.

    ```typescript middleware.ts theme={null}
    import { withAgentXP } from '@reaganhsu/agentxp-next'

    export default withAgentXP()
    ```

    That's all you need for a working installation. AgentXP detects AI agents and serves markdown automatically from this point forward.

    **Already have middleware?** If you use Clerk, next-intl, or any other middleware, pass it as the second argument:

    ```typescript middleware.ts theme={null}
    import { withAgentXP } from '@reaganhsu/agentxp-next'
    import { clerkMiddleware } from '@clerk/nextjs/server'

    export default withAgentXP({}, clerkMiddleware())
    ```

    AgentXP runs first. If the request is from an AI agent, it handles the response. Otherwise, it passes the request to your existing middleware unchanged.
  </Step>

  <Step title="Add the AgentExperience component (optional)">
    Add the `AgentExperience` component to your root layout to inject structured metadata for agents — a JSON-LD WebSite schema, a link to `/llms.txt`, and AI-specific robots directives.

    ```tsx theme={null}
    import { AgentExperience } from '@reaganhsu/agentxp-next'

    export default function RootLayout({ children }) {
      return (
        <html>
          <body>
            {children}
            <AgentExperience siteName="My Site" description="What my site does" />
          </body>
        </html>
      )
    }
    ```

    The component renders no visible UI. It injects:

    * JSON-LD structured data (WebSite schema)
    * A `<link>` to `/llms.txt`
    * AI-specific `meta robots` directives (`noai`, `noimageai`) based on your permissions settings
  </Step>

  <Step title="Verify it works">
    Start your dev server and send a request with `Accept: text/markdown` to any page:

    ```bash theme={null}
    curl -H "Accept: text/markdown" http://localhost:3000/
    ```

    You should see clean markdown instead of HTML:

    ```markdown theme={null}
    # Your Page Title

    Your page content, converted to clean markdown.
    Lists, links, tables, and code blocks are preserved.

    ---

    *Source: [http://localhost:3000](http://localhost:3000)*
    ```

    Check the response headers to confirm AgentXP is active:

    ```bash theme={null}
    curl -I -H "Accept: text/markdown" http://localhost:3000/
    ```

    ```
    content-type: text/markdown; charset=utf-8
    x-agentxp-agent: unknown
    x-agentxp-version: 0.1.0
    x-markdown-tokens: 342
    content-signal: ai-train=no, ai-input=yes, search=yes
    ```

    You can also verify the auto-generated endpoints:

    ```bash theme={null}
    # Site index for AI agents
    curl http://localhost:3000/llms.txt

    # Machine-readable capabilities manifest
    curl http://localhost:3000/.well-known/agent-experience.json
    ```
  </Step>
</Steps>

## Configuration

`withAgentXP()` accepts an optional configuration object. Here is a full example showing the available options:

```typescript theme={null}
export default withAgentXP({
  transform: {
    contentSelector: 'main',
    excludeSelectors: ['.chat-widget', '.cookie-banner'],
    maxTokens: 8000,
  },
  permissions: {
    aiTrain: false,
    aiInput: true,
    search: true,
  },
  llmsTxt: {
    siteName: 'My Site',
    description: 'What my site does',
    pages: [
      { path: '/docs', title: 'Docs', section: 'Documentation' },
      { path: '/pricing', title: 'Pricing', section: 'Product' },
    ],
  },
})
```

See [Configuration overview](/docs/configuration/overview) for the full reference.

<Note>
  AgentXP requires Next.js 14 or later.
</Note>
