# mcp — the site's read-only MCP server `createMcpRoute` exposes the client's site as an **MCP (Model Context Protocol)** server — Claude or any MCP client can **connect** to the site and query it directly (search content, fetch a page as Markdown) instead of scraping HTML. It is a "better integration" layer on top of Markdown/llms. Related: [content.md](./content.md) (Markdown per page), [seo.md](./seo.md) (llms.txt, robots). ## Why no SDK The plugin does NOT pull in `@modelcontextprotocol/sdk` — that would be an imposed dependency (A0), and its API changes. `createMcpRoute` implements the minimal JSON-RPC surface a read-only server needs over the Streamable HTTP transport: `initialize`, `tools/list`, `tools/call`, `ping`. Global `Request`/`Response`, no `next/server` import. ## Tools | Tool | Arguments | Returns | |-----------|-----------|--------| | `get_site_info` | `locale?` | site name and description (Site settings), languages, home page and sitemap URLs | | `list_pages` | `locale?`, `limit?` (default 50, max 200) | published pages **and archive-collection entries** (e.g. blog): title, URL, description (a table of contents). The source is the same index as llms.txt (`collectSiteIndex`); `list_pages` reads it with `limit: 1000` (at most 1000 documents per collection; llms.txt reads them all) | | `search_content` | `query` (required), `locale?`, `limit?` (default 10, max 50) | list of pages (only the `collection` collection): title, URL, description (or `summaryField`) | | `get_page` | `path` (e.g. `/pl/o-nas`; without a language prefix → default language) | the page as clean Markdown | **Public on purpose** — it shows exactly what the public site shows, so AI assistants can browse it like a regular visitor. Mandatory in every project (AGENT.md §0b). All tools are **read-only** and return only **published** content (drafts and `meta.noindex` filtered out — the same rule as sitemap/llms). Under-construction mode: with `isPathVisible` (passed automatically by `createContentHelpers` — the `mcpGET`/`mcpPOST` route), pages hidden by Site settings → Maintenance drop out of `list_pages` and `search_content`, and `get_page` answers "No page found". The full `createMcpRoute` variant without `isPathVisible` does not know about construction mode and serves all published content. ## Wiring ```ts // app/api/mcp/route.ts // Usually one line (configured in createContentHelpers({ mcp: { serverName }, summaryField })): // export { mcpGET as GET, mcpPOST as POST } from '@/lib/content' // The full variant below — when the route needs options outside lib/content. import { createMcpRoute } from '@intecion/ipal-kit' import { getCachedPayload, isPathVisible } from '@/lib/content' import { i18nConfig } from '@/i18n.config' export const dynamic = 'force-dynamic' const mcp = createMcpRoute({ getCachedPayload, config: i18nConfig, baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!, serverName: 'acme-site', // name in initialize isPathVisible, // hide pages hidden by under-construction mode // content, // if you have archive collections (get_page for entries) }) export const POST = mcp.POST export const GET = mcp.GET // 405 — no SSE stream (request/response only) ``` ## Connecting in Claude Add it as a custom connector pointing to `https://your-site/api/mcp`. Claude runs `initialize` → `tools/list` → and can then call `get_site_info`, `list_pages`, `search_content`, `get_page`. From then on it "knows" the site without scraping. ## Options | Option | Default | Description | |-------|-----------|------| | `getCachedPayload` | — (required) | `() => Promise` | | `config` | — (required) | `I18nConfig` | | `baseUrl` | — | origin for URLs in results (without it URLs are relative and there is no sitemap link) | | `collection` | `'pages'` | pages collection | | `settingsSlug` | `'site-settings'` | Site settings global slug | | `content` | — | archive collections (`list_pages`, `get_page` for entries) | | `summaryField` | — | field with a richer AI description (`buildSummaryField`), preferred in results | | `isPathVisible` | — (from `createContentHelpers`: set) | `(path, locale) => boolean` — hides pages hidden by under-construction mode | | `serverName` | `'ipal-site'` | name in `initialize` (and fallback site name) | | `serverVersion` | `'1.0.0'` | version in `initialize` | | `rateLimit` | `{ max: 60, windowMs: 60_000 }` | per-IP limit; `false` = off | | `clientIp` | — | `{ header?, trustedProxies? }` — where to read the IP from (see [forms.md](./forms.md#client-ip-and-rate-limit)) | | `maxBatch` | `10` | max messages in one batch | | `maxBytes` | `65536` | largest request body read; a larger one (declared or streamed) → `413` before it is parsed (1.17.1) | Through `createContentHelpers({ mcp })` you pass only `serverName`, `serverVersion`, `rateLimit`, `maxBatch`, `clientIp`, `isPathVisible`; `baseUrl`, `collection`, `content`, `settingsSlug`, `summaryField` and `isPathVisible` (construction mode) come from the helpers' configuration. ## Security - Read-only, published content only — no mutations, no drafts. - `search_content` uses `like` and fails safely (a message) when the field is not queryable — it does not crash the route. - Do not expose anything here beyond the site's public content. - **Rate limit:** 60 JSON-RPC messages/min per IP (a batch counts as as many messages as it contains) → `429` with `Retry-After`. Batch > `maxBatch` → `400`. The limit is in memory, per instance (or in a shared store with `setRateLimitStore`) — behind Cloudflare add a Rate limiting rule in the WAF. A request without a recognized IP **passes** without a limit; set `IAPL_IP_HEADER` (see [forms.md](./forms.md#client-ip-and-rate-limit)). - An error inside a tool → generic message `Tool execution failed.` (`isError`), details only in the server log. - Behind Cloudflare Access the route needs a Bypass (MCP clients will not send a Service Token) — see the Cloudflare Access guide. ## Protocol (for debugging) A single JSON-RPC object or a batch (array). Notifications (`notifications/*`, no `id`) → HTTP 202 with no body. `GET` → `405` (`Allow: POST`). Requests → `{ jsonrpc:'2.0', id, result }` or `error` (`-32601` unknown method, `-32700` parse error, `-32600` batch too large or a message that is not an object — `null`, a number, a string; `-32000` rate limit). `initialize` echoes the client's `protocolVersion` (fallback `2025-06-18`). ## Turn off, override, extend - **Turn off:** MCP is not wired by the plugin — it works only when the project has the route `app/api/mcp/route.ts`. No file = no MCP server. - **Limit:** `rateLimit: false` (e.g. a limiter in Cloudflare WAF), your own `{ max, windowMs }`, `maxBatch`, `clientIp`; shared store: `setRateLimitStore`. - **Override:** `serverName`, `serverVersion`, `collection`, `settingsSlug`, `summaryField`, `content`, `isPathVisible` (through `createContentHelpers({ mcp })` only `serverName`, `serverVersion`, `rateLimit`, `maxBatch`, `clientIp`, `isPathVisible`; the rest — with the full `createMcpRoute` variant). - **Extend:** the tool list is currently fixed (4 tools, no option to add your own). Build your own server from the exported pieces: `searchContent`, `collectSiteIndex`, `createMarkdownRenderer`, `listContent` (root).