Merge main (security-perf + SEO) into docs; finish English docs and agent guide

- Resolve conflicts in analytics, consent, content, i18n, mcp and stats,
  keeping the docs fixes and the new code behaviour, verified against src
- Translate the remaining 14 module pages, ipal-seo-check skill and script
- Integrate the security-perf and SEO agent-guide text: getRobots,
  isPathVisible, Search & AI (DNS verification first, meta fields optional),
  sitemap index/cache/503, consentMode basic/advanced, policyVersion,
  globalOverrides, revalidatePath / buildGlobalRevalidateHook, authAccess,
  firstUserAdmin, allowCollectionMismatch, unknown-IP rate limit; stale
  claims fixed across AGENT.md, skills, frontend, developer guide, vibe
- docsConsistency: pending list removed (all docs English); relative links
  now also check #anchors

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 17:59:52 +02:00
co-authored by Claude Opus 5.5
107 changed files with 5476 additions and 2541 deletions
+87 -82
View File
@@ -1,47 +1,49 @@
# mcp — read-only serwer MCP strony
# mcp — the site's read-only MCP server
`createMcpRoute` wystawia stronę klienta jako serwer **MCP (Model Context
Protocol)** — czyli Claude / dowolny klient MCP może się **podłączyć** do strony
i odpytywać ją bezpośrednio (wyszukać treść, pobrać stronę jako Markdown),
zamiast scrapować HTML. To warstwa „lepszej integracji" na wierzchu Markdown/llms.
`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.
Powiązane: [content.md](./content.md) (Markdown per strona), [seo.md](./seo.md)
Related: [content.md](./content.md) (Markdown per page), [seo.md](./seo.md)
(llms.txt, robots).
## Dlaczego bez SDK
## Why no SDK
Plugin NIE wciąga `@modelcontextprotocol/sdk` — to byłaby narzucona zależność
(A0), a jej API się zmienia. `createMcpRoute` implementuje minimalną powierzchnię
JSON-RPC, jakiej potrzebuje read-only serwer po transporcie Streamable HTTP:
`initialize`, `tools/list`, `tools/call`, `ping`. Globalne `Request`/`Response`,
bez importu `next/server`.
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.
## Narzędzia
## Tools
| Narzędzie | Argumenty | Zwraca |
| Tool | Arguments | Returns |
|-----------|-----------|--------|
| `get_site_info` | `locale?` | nazwa i opis strony (Site Settings), języki, URL strony głównej i sitemapy |
| `list_pages` | `locale?`, `limit?` (domyślnie 50, max 200) | opublikowane strony **i wpisy kolekcji-archiwów** (np. blog): tytuł, URL, opis (spis treści). Źródło to ten sam indeks co llms.txt (`collectSiteIndex`), który czyta max 1000 dokumentów na kolekcję |
| `search_content` | `query` (wymagane), `locale?`, `limit?` (domyślnie 10, max 50) | lista stron (tylko kolekcja `collection`): tytuł, URL, opis (lub `summaryField`) |
| `get_page` | `path` (np. `/pl/o-nas`; bez prefiksu języka → język domyślny) | strona jako czysty Markdown |
| `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`), which reads at most 1000 documents per collection |
| `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 |
**Publiczny celowo** — pokazuje dokładnie to, co publiczna strona, żeby asystenci AI
mogli ją przeglądać jak zwykły odwiedzający. Obowiązkowy w każdym projekcie (AGENT.md §0b).
**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).
Wszystkie **read-only** i tylko **opublikowane** treści (drafty i `meta.noindex`
odfiltrowane — ta sama zasada co sitemap/llms). Tryb budowy (construction) **nie**
blokuje MCP — jest egzekwowany tylko w trasie strony (`pageRoute`), więc w trybie
budowy MCP nadal serwuje opublikowane treści.
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 → Under construction 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.
## Wpięcie
## Wiring
```ts
// app/api/mcp/route.ts
// Zwykle jedna linia (konfiguracja w createContentHelpers({ mcp: { serverName }, summaryField })):
// Usually one line (configured in createContentHelpers({ mcp: { serverName }, summaryField })):
// export { mcpGET as GET, mcpPOST as POST } from '@/lib/content'
// Niżej pełny wariant — gdy trasa potrzebuje opcji spoza lib/content.
// The full variant below — when the route needs options outside lib/content.
import { createMcpRoute } from '@intecion/ipal-kit'
import { getCachedPayload } from '@/lib/content'
import { getCachedPayload, isPathVisible } from '@/lib/content'
import { i18nConfig } from '@/i18n.config'
export const dynamic = 'force-dynamic'
@@ -50,74 +52,77 @@ const mcp = createMcpRoute({
getCachedPayload,
config: i18nConfig,
baseUrl: process.env.NEXT_PUBLIC_SERVER_URL!,
serverName: 'acme-site', // nazwa w initialize
// content, // jeśli masz kolekcje-archiwa (get_page dla wpisów)
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 — brak strumienia SSE (request/response only)
export const GET = mcp.GET // 405 — no SSE stream (request/response only)
```
## Podłączenie w Claude
## Connecting in Claude
Dodaj jako custom connector wskazujący na `https://twoja-strona/api/mcp`. Claude
wykona `initialize` → `tools/list` → i będzie mógł wołać `get_site_info`,
`list_pages`, `search_content`, `get_page`. Od tej chwili „zna" stronę bez scrapowania.
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.
## Opcje
## Options
| Opcja | Domyślnie | Opis |
| Option | Default | Description |
|-------|-----------|------|
| `getCachedPayload` | — (wymagane) | `() => Promise<Payload>` |
| `config` | — (wymagane) | `I18nConfig` |
| `baseUrl` | — | origin do URL-i w wynikach (bez niego URL-e są względne, brak linku do sitemapy) |
| `collection` | `'pages'` | kolekcja stron |
| `settingsSlug` | `'site-settings'` | slug globala Site Settings |
| `content` | — | kolekcje-archiwa (`list_pages`, `get_page` dla wpisów) |
| `summaryField` | — | pole z bogatszym opisem AI (`buildSummaryField`), preferowane w wynikach |
| `serverName` | `'ipal-site'` | nazwa w `initialize` (i fallback nazwy strony) |
| `serverVersion` | `'1.0.0'` | wersja w `initialize` |
| `rateLimit` | `{ max: 60, windowMs: 60_000 }` | limit na IP; `false` = wyłączony |
| `clientIp` | — | `{ header?, trustedProxies? }` — skąd czytać IP (patrz [forms.md](./forms.md#ip-klienta-i-rate-limit)) |
| `maxBatch` | `10` | max wiadomości w jednym batchu |
| `getCachedPayload` | — (required) | `() => Promise<Payload>` |
| `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 |
Przez `createContentHelpers({ mcp })` przekazujesz tylko `serverName`, `serverVersion`,
`rateLimit`, `maxBatch`, `clientIp`; `baseUrl`, `collection`, `content`,
`settingsSlug`, `summaryField` idą z konfiguracji helperów.
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.
## Bezpieczeństwo
## Security
- Tylko odczyt, tylko opublikowane treści — żadnych mutacji, żadnych draftów.
- `search_content` używa `like` i odpada bezpiecznie (komunikat), gdy pole nie
jest odpytywalne — nie wywala route'a.
- Nie wystawiaj tu niczego spoza publicznej treści strony.
- **Limit zapytań:** 60 wiadomości JSON-RPC/min na IP (batch liczy się jako tyle
wiadomości, ile zawiera) → `429` z `Retry-After`. Batch > `maxBatch` → `400`. Limit jest w
pamięci, per instancja (albo we wspólnym store z `setRateLimitStore`) — za Cloudflare
dołóż regułę Rate limiting w WAF. Żądanie bez rozpoznanego IP **przechodzi** bez
limitu; ustaw `IPAL_IP_HEADER` (patrz [forms.md](./forms.md#ip-klienta-i-rate-limit)).
- Błąd wewnątrz narzędzia → ogólny komunikat `Tool execution failed.` (`isError`),
szczegóły tylko w logu serwera.
- Za Cloudflare Access route musi mieć Bypass (klienci MCP nie wyślą Service Token)
— patrz instrukcja Cloudflare Access.
- 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 `IPAL_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.
## Protokół (dla debugowania)
## Protocol (for debugging)
Pojedynczy obiekt JSON-RPC albo batch (tablica). Notyfikacje (`notifications/*`,
bez `id`) → HTTP 202 bez ciała. `GET` → `405` (`Allow: POST`). Żądania → `{ jsonrpc:'2.0', id, result }` albo
`error` (`-32601` nieznana metoda, `-32700` parse error, `-32600` batch za duży,
`-32000` limit zapytań). `initialize` odbija
`protocolVersion` klienta (fallback `2025-06-18`).
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`).
## Wyłączenie, nadpisanie, rozszerzenie
## Turn off, override, extend
- **Wyłączenie:** MCP nie jest wpinany przez plugin — działa tylko, gdy projekt ma trasę
`app/api/mcp/route.ts`. Brak pliku = brak serwera MCP.
- **Limit:** `rateLimit: false` (np. limiter w Cloudflare WAF), własne `{ max, windowMs }`, `maxBatch`,
`clientIp`; wspólny store: `setRateLimitStore`.
- **Nadpisanie:** `serverName`, `serverVersion`, `collection`, `settingsSlug`, `summaryField`, `content`
(przez `createContentHelpers({ mcp })` tylko `serverName`, `serverVersion`, `rateLimit`, `maxBatch`,
`clientIp`; resztę — pełnym wariantem `createMcpRoute`).
- **Rozszerzenie:** lista narzędzi jest obecnie stała (4 narzędzia, brak opcji dodania własnych).
Własny serwer złożysz z eksportowanych klocków: `searchContent`, `collectSiteIndex`,
- **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).