Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(docs): Fix 500 error on .md endpoints
- Change getText('raw') to getText('processed') for compatibility with fumadocs-mdx includeProcessedMarkdown config - Add safety check for when getText function is not available - Wrap entire route handler in try-catch for better error handling - Add try-catch around getPage() call which could throw - Add error handling around openapiPageToMarkdown() - Add console logging to help debug production issues - Properly re-throw Next.js navigation errors (notFound) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
sohamganatra committed
Jan 27, 2026 at 23:34 UTC
e415be0c02217fddfaa849373125985cef76f75a
2 files changed
+94
-46
docs/app/llms.mdx/[[...slug]]/route.ts
+85
-45
@@ -426,60 +426,100 @@ export async function GET(
426
_req: Request,
427
{ params }: { params: Promise<{ slug?: string[] }> }
428
) {
429
- const { slug = [] } = await params;
430
- const [prefix, ...rest] = slug;
431
-
432
- // Find the matching source
433
- const match = sources.find((s) => s.prefix === prefix);
434
- if (!match) notFound();
435
-
436
- // Get the page from that source (MDX pages)
437
- const page = match.source.getPage(rest.length > 0 ? rest : undefined);
438
-
439
- if (page) {
440
- // Check if this is an OpenAPI page
441
- if ('getAPIPageProps' in page.data) {
442
- const markdown = await openapiPageToMarkdown(
443
- page as { url: string; data: OpenAPIPageData }
444
- );
445
- return new Response(markdown, {
446
- headers: {
447
- 'Content-Type': 'text/markdown; charset=utf-8',
448
- },
449
- });
450
- }
429
+ try {
430
+ const { slug = [] } = await params;
431
+ const [prefix, ...rest] = slug;
432
+
433
+ // Find the matching source
434
+ const match = sources.find((s) => s.prefix === prefix);
435
+ if (!match) notFound();
436
452
- // Regular MDX page
437
+ // Get the page from that source (MDX pages)
438
+ let page;
439
try {
454
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
455
- return new Response(await getLLMText(page as any), {
456
- headers: {
457
- 'Content-Type': 'text/markdown; charset=utf-8',
458
- },
459
- });
460
- } catch {
461
- return new Response(
462
- `# ${page.data.title} (${page.url})\n\n${page.data.description || ''}`,
463
- {
440
+ page = match.source.getPage(rest.length > 0 ? rest : undefined);
441
+ } catch (e) {
442
+ console.error('Error in getPage:', e);
443
+ page = null;
444
+ }
445
+
446
+ if (page) {
447
+ // Check if this is an OpenAPI page
448
+ if ('getAPIPageProps' in page.data) {
449
+ try {
450
+ const markdown = await openapiPageToMarkdown(
451
+ page as { url: string; data: OpenAPIPageData }
452
+ );
453
+ return new Response(markdown, {
454
+ headers: {
455
+ 'Content-Type': 'text/markdown; charset=utf-8',
456
+ },
457
+ });
458
+ } catch (e) {
459
+ console.error('Error generating OpenAPI markdown:', e);
460
+ const title = page.data?.title || 'API Reference';
461
+ const description = page.data?.description || '';
462
+ return new Response(
463
+ `# ${title}\n\n${description}`,
464
+ {
465
+ headers: {
466
+ 'Content-Type': 'text/markdown; charset=utf-8',
467
+ },
468
+ }
469
+ );
470
+ }
471
+ }
472
+
473
+ // Regular MDX page
474
+ try {
475
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
476
+ return new Response(await getLLMText(page as any), {
477
headers: {
478
'Content-Type': 'text/markdown; charset=utf-8',
479
},
467
- }
468
- );
480
+ });
481
+ } catch (e) {
482
+ console.error('Error generating LLM text:', e);
483
+ const title = page.data?.title || 'Documentation';
484
+ const description = page.data?.description || '';
485
+ return new Response(
486
+ `# ${title} (${page.url || ''})\n\n${description}`,
487
+ {
488
+ headers: {
489
+ 'Content-Type': 'text/markdown; charset=utf-8',
490
+ },
491
+ }
492
+ );
493
+ }
494
+ }
495
+
496
+ // Special handling for JSON toolkit pages
497
+ if (prefix === 'toolkits' && rest.length === 1) {
498
+ const toolkit = await getToolkit(rest[0]);
499
+ if (toolkit) {
500
+ return new Response(toolkitToMarkdown(toolkit), {
501
+ headers: {
502
+ 'Content-Type': 'text/markdown; charset=utf-8',
503
+ },
504
+ });
505
+ }
506
}
470
- }
507
472
- // Special handling for JSON toolkit pages
473
- if (prefix === 'toolkits' && rest.length === 1) {
474
- const toolkit = await getToolkit(rest[0]);
475
- if (toolkit) {
476
- return new Response(toolkitToMarkdown(toolkit), {
508
+ notFound();
509
+ } catch (e) {
510
+ // Don't catch notFound - let it propagate
511
+ if (e && typeof e === 'object' && 'digest' in e) {
512
+ throw e;
513
+ }
514
+ console.error('Unexpected error in llms.mdx route:', e);
515
+ return new Response(
516
+ '# Error\n\nAn error occurred while generating the markdown content.',
517
+ {
518
+ status: 500,
519
headers: {
520
'Content-Type': 'text/markdown; charset=utf-8',
521
},
480
- });
481
- }
522
+ }
523
+ );
524
}
483
-
484
- notFound();
525
}
docs/lib/source.ts
+9
-1
@@ -165,7 +165,15 @@ function mdxToCleanMarkdown(content: string): string {
165
}
166
167
export async function getLLMText(page: InferPageType<typeof source>) {
168
- const content = await page.data.getText('raw');
168
+ // Use 'processed' mode since that's what includeProcessedMarkdown enables
169
+ // Fall back to description if getText is not available
170
+ if (typeof page.data.getText !== 'function') {
171
+ return `# ${page.data.title} (${page.url})
172
+
173
+${page.data.description || ''}`;
174
+ }
175
+
176
+ const content = await page.data.getText('processed');
177
const cleanContent = mdxToCleanMarkdown(content);
178
179
return `# ${page.data.title} (${page.url})