Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

refactor(docs): simplify .md routes with single catch-all

Sushmithamallesh56ec74e23c72
diff --git a/docs/app/llms.mdx/[[...slug]]/route.ts b/docs/app/llms.mdx/[[...slug]]/route.ts
new file mode 100644
index 000000000..1627d2ee4
--- /dev/null
+++ b/docs/app/llms.mdx/[[...slug]]/route.ts
@@ -0,0 +1,52 @@
+import {
+ source,
+ toolRouterSource,
+ referenceSource,
+ examplesSource,
+ getLLMText,
+} from '@/lib/source';
+import { notFound } from 'next/navigation';
+
+export const revalidate = false;
+
+// Map URL prefixes to their sources
+const sources = [
+ { prefix: 'docs', source },
+ { prefix: 'tool-router', source: toolRouterSource },
+ { prefix: 'reference', source: referenceSource },
+ { prefix: 'examples', source: examplesSource },
+];
+
+export async function GET(
+ _req: Request,
+ { params }: { params: Promise<{ slug?: string[] }> }
+) {
+ const { slug = [] } = await params;
+ const [prefix, ...rest] = slug;
+
+ // Find the matching source
+ const match = sources.find((s) => s.prefix === prefix);
+ if (!match) notFound();
+
+ // Get the page from that source
+ const page = match.source.getPage(rest.length > 0 ? rest : undefined);
+ if (!page) notFound();
+
+ try {
+ return new Response(await getLLMText(page), {
+ headers: {
+ 'Content-Type': 'text/markdown; charset=utf-8',
+ },
+ });
+ } catch {
+ // Graceful fallback
+ return new Response(
+ `# ${page.data.title} (${page.url})\n\n${page.data.description || ''}`,
+ {
+ headers: {
+ 'Content-Type': 'text/markdown; charset=utf-8',
+ },
+ }
+ );
+ }
+}
diff --git a/docs/app/llms.mdx/docs/[[...slug]]/route.ts b/docs/app/llms.mdx/docs/[[...slug]]/route.ts
deleted file mode 100644
index 912b0af34..000000000
--- a/docs/app/llms.mdx/docs/[[...slug]]/route.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { getLLMText, source } from '@/lib/source';
-import { notFound } from 'next/navigation';
-
-export const revalidate = false;
-
-export async function GET(
- _req: Request,
- { params }: { params: Promise<{ slug?: string[] }> }
-) {
- const { slug } = await params;
- const page = source.getPage(slug);
- if (!page) notFound();
-
- return new Response(await getLLMText(page), {
- headers: {
- 'Content-Type': 'text/markdown; charset=utf-8',
- },
- });
-}
-
-export function generateStaticParams() {
- return source.generateParams();
-}
diff --git a/docs/app/llms.mdx/examples/[[...slug]]/route.ts b/docs/app/llms.mdx/examples/[[...slug]]/route.ts
deleted file mode 100644
index 24fd699eb..000000000
--- a/docs/app/llms.mdx/examples/[[...slug]]/route.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { examplesSource } from '@/lib/source';
-import { getLLMText } from '@/lib/source';
-import { notFound } from 'next/navigation';
-
-export const revalidate = false;
-
-export async function GET(
- _req: Request,
- { params }: { params: Promise<{ slug?: string[] }> }
-) {
- const { slug } = await params;
- const page = examplesSource.getPage(slug);
- if (!page) notFound();
-
- return new Response(await getLLMText(page), {
- headers: {
- 'Content-Type': 'text/markdown; charset=utf-8',
- },
- });
-}
-
-export function generateStaticParams() {
- return examplesSource.generateParams();
-}
diff --git a/docs/app/llms.mdx/reference/[[...slug]]/route.ts b/docs/app/llms.mdx/reference/[[...slug]]/route.ts
deleted file mode 100644
index bc3f499da..000000000
--- a/docs/app/llms.mdx/reference/[[...slug]]/route.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { referenceSource } from '@/lib/source';
-import { getLLMText } from '@/lib/source';
-import { notFound } from 'next/navigation';
-
-export const revalidate = false;
-
-export async function GET(
- _req: Request,
- { params }: { params: Promise<{ slug?: string[] }> }
-) {
- const { slug } = await params;
- const page = referenceSource.getPage(slug);
- if (!page) notFound();
-
- return new Response(await getLLMText(page), {
- headers: {
- 'Content-Type': 'text/markdown; charset=utf-8',
- },
- });
-}
-
-export function generateStaticParams() {
- return referenceSource.generateParams();
-}
diff --git a/docs/app/llms.mdx/tool-router/[[...slug]]/route.ts b/docs/app/llms.mdx/tool-router/[[...slug]]/route.ts
deleted file mode 100644
index fb933fbe6..000000000
--- a/docs/app/llms.mdx/tool-router/[[...slug]]/route.ts
+++ /dev/null
@@ -1,24 +0,0 @@
-import { toolRouterSource } from '@/lib/source';
-import { getLLMText } from '@/lib/source';
-import { notFound } from 'next/navigation';
-
-export const revalidate = false;
-
-export async function GET(
- _req: Request,
- { params }: { params: Promise<{ slug?: string[] }> }
-) {
- const { slug } = await params;
- const page = toolRouterSource.getPage(slug);
- if (!page) notFound();
-
- return new Response(await getLLMText(page), {
- headers: {
- 'Content-Type': 'text/markdown; charset=utf-8',
- },
- });
-}
-
-export function generateStaticParams() {
- return toolRouterSource.generateParams();
-}
diff --git a/docs/next.config.mjs b/docs/next.config.mjs
index 9c7f5441a..cd1bbedfa 100644
--- a/docs/next.config.mjs
+++ b/docs/next.config.mjs
@@ -13,27 +13,9 @@ const config = {
},
async rewrites() {
return [
- // Support .md and .mdx extensions for AI agents across all sections
- // Docs
- { source: '/docs/:path*.mdx', destination: '/llms.mdx/docs/:path*' },
- { source: '/docs/:path*.md', destination: '/llms.mdx/docs/:path*' },
- { source: '/docs.md', destination: '/llms.mdx/docs' },
- { source: '/docs.mdx', destination: '/llms.mdx/docs' },
- // Tool Router
- { source: '/tool-router/:path*.mdx', destination: '/llms.mdx/tool-router/:path*' },
- { source: '/tool-router/:path*.md', destination: '/llms.mdx/tool-router/:path*' },
- { source: '/tool-router.md', destination: '/llms.mdx/tool-router' },
- { source: '/tool-router.mdx', destination: '/llms.mdx/tool-router' },
- // Examples
- { source: '/examples/:path*.mdx', destination: '/llms.mdx/examples/:path*' },
- { source: '/examples/:path*.md', destination: '/llms.mdx/examples/:path*' },
- { source: '/examples.md', destination: '/llms.mdx/examples' },
- { source: '/examples.mdx', destination: '/llms.mdx/examples' },
- // Reference
- { source: '/reference/:path*.mdx', destination: '/llms.mdx/reference/:path*' },
- { source: '/reference/:path*.md', destination: '/llms.mdx/reference/:path*' },
- { source: '/reference.md', destination: '/llms.mdx/reference' },
- { source: '/reference.mdx', destination: '/llms.mdx/reference' },
+ // Serve markdown for AI agents: /any/path.md → /llms.mdx/any/path
+ { source: '/:path*.md', destination: '/llms.mdx/:path*' },
+ { source: '/:path*.mdx', destination: '/llms.mdx/:path*' },
];
},
async redirects() {