MCP site tools, Turnstile key alert, required 2FA injection, a11y, more tests

- MCP: new get_site_info and list_pages tools (public by design, published
  and indexable content only); search results collapse the homepage to root.
  New listContent() helper shared with searchContent.
- Dashboard alert when Turnstile is half-configured (it is silently off then).
- twoFactor.plugin is now required; the dynamic-import fallback (which never
  worked under Next and caused a Turbopack warning) is gone.
- a11y: cookie category checkboxes are labelled, buttons have type, test-email
  input is labelled; tab labels keep localized collection labels.
- IPAL_IP_HEADER: one-time production warning when unset, opt-in
  ipalEnvRules({ ipHeader: true }).
- Tests: SEO/robots/sitemap/hreflang, CSP, Markdown, consent, MCP, and a real
  Payload + SQLite integration test for forms and the roles guard (74 total).
- Drop unused mongodb-memory-server; dev .env.example for SQLite.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-16 01:15:19 +02:00
co-authored by Claude Opus 5.5
parent 86e69b0bcf
commit ab854ef37a
36 changed files with 708 additions and 328 deletions
+87 -10
View File
@@ -4,8 +4,9 @@ import type { ContentOption } from '../content/index.js'
import type { I18nConfig } from '../i18n/index.js'
import type { ClientIpOptions } from '../shared/rateLimit.js'
import { createMarkdownRenderer, searchContent } from '../content/index.js'
import { createMarkdownRenderer, listContent, searchContent } from '../content/index.js'
import { getDefaultLocale, isValidLocale } from '../i18n/index.js'
import { readSiteMetaConfig } from '../seo/readSiteMetaConfig.js'
import { clientIp, consumeRateLimit, tooManyRequests } from '../shared/rateLimit.js'
/**
@@ -20,10 +21,15 @@ import { clientIp, consumeRateLimit, tooManyRequests } from '../shared/rateLimit
* transport: initialize, tools/list, tools/call, ping. Uses the global
* Request/Response — no next/server import.
*
* Exposes two tools:
* Exposes four tools:
* - get_site_info({ locale? }) → site name, description, languages, key URLs
* - list_pages({ locale?, limit? }) → every published page (title, url, description)
* - search_content({ query, locale?, limit? }) → matching pages (title, url, description)
* - get_page({ path }) → that page as Markdown
*
* Public on purpose — it exposes exactly what the public site shows (published,
* non-noindex content), so AI assistants can browse it like any visitor.
*
* // app/api/mcp/route.ts
* import { createMcpRoute } from '@intecion/ipal-kit'
* import { getCachedPayload } from '@/lib/content'
@@ -99,7 +105,27 @@ export function createMcpRoute(args: CreateMcpRouteArgs) {
const origin = baseUrl?.replace(/\/$/, '') ?? ''
const renderMarkdown = createMarkdownRenderer({ collection, content, settingsSlug })
const localeProp = { type: 'string', description: `Locale code (default ${config.defaultLocale})` }
const TOOLS = [
{
name: 'get_site_info',
description:
'Overview of the site: name, description, available languages and key URLs. Call this first.',
inputSchema: { type: 'object', properties: { locale: localeProp } },
},
{
name: 'list_pages',
description:
'List all published pages of the site with title, URL and description — the table of contents. Fetch one with get_page.',
inputSchema: {
type: 'object',
properties: {
limit: { type: 'number', description: 'Max results (default 50, max 200)' },
locale: localeProp,
},
},
},
{
name: 'search_content',
description:
@@ -108,7 +134,7 @@ export function createMcpRoute(args: CreateMcpRouteArgs) {
type: 'object',
properties: {
limit: { type: 'number', description: 'Max results (default 10)' },
locale: { type: 'string', description: `Locale code (default ${config.defaultLocale})` },
locale: localeProp,
query: { type: 'string', description: 'Search keywords' },
},
required: ['query'],
@@ -128,21 +154,72 @@ export function createMcpRoute(args: CreateMcpRouteArgs) {
},
]
const pickLocale = (params: Record<string, unknown>): string =>
typeof params.locale === 'string' && isValidLocale(params.locale, config)
? params.locale
: getDefaultLocale(config)
const formatResults = (results: { description?: string; title: string; url: string }[]) =>
results.map((r) => `- ${r.title} (${r.url})${r.description ? ` — ${r.description}` : ''}`).join('\n')
async function siteMeta(payload: BasePayload, locale: string) {
try {
return await readSiteMetaConfig({ locale, pagesSlug: collection, payload, settingsSlug })
} catch {
return null
}
}
async function getSiteInfo(params: Record<string, unknown>): Promise<string> {
const locale = pickLocale(params)
const payload = await getCachedPayload()
const meta = await siteMeta(payload, locale)
// The homepage always collapses to the language root ('/' on single-locale sites).
const home = config.locales.length === 1 ? '/' : `/${locale}`
const lines = [
`Site: ${meta?.siteName || serverName}`,
...(meta?.siteDescription ? [`Description: ${meta.siteDescription}`] : []),
`Languages: ${config.locales.map((l) => `${l.code} (${l.label})`).join(', ')} — default ${config.defaultLocale}`,
`Home: ${origin}${home}`,
...(origin ? [`Sitemap: ${origin}/sitemap.xml`] : []),
'Tools: list_pages (all pages), search_content (keyword search), get_page (one page as Markdown).',
]
return lines.join('\n')
}
async function runList(params: Record<string, unknown>): Promise<string> {
const locale = pickLocale(params)
const limit = typeof params.limit === 'number' ? params.limit : 50
const payload = await getCachedPayload()
const meta = await siteMeta(payload, locale)
const results = await listContent({
baseUrl: origin,
collection,
config,
homeSlug: meta?.homeSlug,
limit,
locale,
payload,
summaryField,
})
if (results.length === 0) {return 'No published pages.'}
return formatResults(results)
}
async function runSearch(params: Record<string, unknown>): Promise<string> {
const query = typeof params.query === 'string' ? params.query.trim() : ''
if (!query) {return 'No query provided.'}
const locale =
typeof params.locale === 'string' && isValidLocale(params.locale, config)
? params.locale
: getDefaultLocale(config)
const locale = pickLocale(params)
const limit = typeof params.limit === 'number' ? params.limit : 10
const payload = await getCachedPayload()
const meta = await siteMeta(payload, locale)
// Shared with the JSON search route — one ranking everywhere.
const results = await searchContent({
baseUrl: origin,
collection,
config,
homeSlug: meta?.homeSlug,
limit,
locale,
payload,
@@ -150,9 +227,7 @@ export function createMcpRoute(args: CreateMcpRouteArgs) {
summaryField,
})
if (results.length === 0) {return `No pages matched "${query}".`}
return results
.map((r) => `- ${r.title} (${r.url})${r.description ? ` — ${r.description}` : ''}`)
.join('\n')
return formatResults(results)
}
async function getPage(params: Record<string, unknown>): Promise<string> {
@@ -193,6 +268,8 @@ export function createMcpRoute(args: CreateMcpRouteArgs) {
const p = (params ?? {}) as { arguments?: Record<string, unknown>; name?: string }
const toolArgs = p.arguments ?? {}
try {
if (p.name === 'get_site_info') {return rpcResult(id, toolText(await getSiteInfo(toolArgs)))}
if (p.name === 'list_pages') {return rpcResult(id, toolText(await runList(toolArgs)))}
if (p.name === 'search_content') {return rpcResult(id, toolText(await runSearch(toolArgs)))}
if (p.name === 'get_page') {return rpcResult(id, toolText(await getPage(toolArgs)))}
return rpcResult(id, toolText(`Unknown tool: ${p.name}`, true))