From fc2f7210624a252184a72d0f10e368699e4f8072 Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Fri, 26 Sep 2025 23:16:57 +0200 Subject: [PATCH 1/2] Add llms.json API endpoint for MCP --- .../src/routes/llms.json/+server.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 apps/svelte.dev/src/routes/llms.json/+server.ts diff --git a/apps/svelte.dev/src/routes/llms.json/+server.ts b/apps/svelte.dev/src/routes/llms.json/+server.ts new file mode 100644 index 000000000..caa718035 --- /dev/null +++ b/apps/svelte.dev/src/routes/llms.json/+server.ts @@ -0,0 +1,29 @@ +import { docs } from '$lib/server/content'; +import { json } from '@sveltejs/kit'; + +export const prerender = true; + +export async function GET() { + return json(await getLlmDocuments()); +} + +async function getLlmDocuments() { + const documents = []; + + for (const [slug, document] of Object.entries(docs.pages)) { + // Extract the topic and path from the slug (format: docs/topic/path) + const parts = slug.split('/'); + if (parts.length < 3 || parts[0] !== 'docs') continue; + + const topic = parts[1]; + const path = parts.slice(2).join('/'); + + documents.push({ + title: document.metadata.title, + url: `https://svelte.dev/docs/${topic}/${path}/llms.txt`, + use_cases: document.metadata.use_cases || undefined + }); + } + + return documents; +} \ No newline at end of file From a086966dbb95a72b00d6e49df5415aa5a459a167 Mon Sep 17 00:00:00 2001 From: Stanislav Khromov Date: Fri, 26 Sep 2025 23:29:51 +0200 Subject: [PATCH 2/2] Update +server.ts --- apps/svelte.dev/src/routes/llms.json/+server.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/apps/svelte.dev/src/routes/llms.json/+server.ts b/apps/svelte.dev/src/routes/llms.json/+server.ts index caa718035..a502436fb 100644 --- a/apps/svelte.dev/src/routes/llms.json/+server.ts +++ b/apps/svelte.dev/src/routes/llms.json/+server.ts @@ -11,16 +11,9 @@ async function getLlmDocuments() { const documents = []; for (const [slug, document] of Object.entries(docs.pages)) { - // Extract the topic and path from the slug (format: docs/topic/path) - const parts = slug.split('/'); - if (parts.length < 3 || parts[0] !== 'docs') continue; - - const topic = parts[1]; - const path = parts.slice(2).join('/'); - documents.push({ title: document.metadata.title, - url: `https://svelte.dev/docs/${topic}/${path}/llms.txt`, + url: `https://svelte.dev/${slug}/llms.txt`, use_cases: document.metadata.use_cases || undefined }); }