import { z } from "zod";
import { getAllSections, getEntriesBySection, SECTIONS, type SectionId } from "../data/docs-index.js";
export const listTopicsSchema = {
section: z
.enum(["all", "cli", "headless", "framework", "mdx", "ui"])
.optional()
.describe("Section to list topics from, or 'all' for overview"),
};
export type ListTopicsParams = {
section?: "all" | SectionId;
};
export async function listTopics(params: ListTopicsParams): Promise<string> {
const { section = "all" } = params;
if (section === "all") {
const sections = getAllSections();
const output: string[] = [
"# Fumadocs Documentation Topics\n",
"Available documentation sections:\n",
];
for (const sec of sections) {
output.push(`## ${sec.name} (${sec.id})`);
output.push(`${sec.entries.length} topics available\n`);
// Show first 5 entries as preview
const preview = sec.entries.slice(0, 5);
for (const entry of preview) {
output.push(`- [${entry.title}](${entry.path}): ${entry.description}`);
}
if (sec.entries.length > 5) {
output.push(`- ... and ${sec.entries.length - 5} more topics`);
}
output.push("");
}
output.push("\n---");
output.push("Use `list_topics` with a specific section to see all topics in that section.");
return output.join("\n");
}
// Specific section
const sectionName = SECTIONS[section as SectionId];
const entries = getEntriesBySection(section as SectionId);
if (entries.length === 0) {
return `No topics found in section: ${section}`;
}
const output: string[] = [
`# ${sectionName} Documentation\n`,
`${entries.length} topics available:\n`,
];
for (const entry of entries) {
output.push(`## ${entry.title}`);
output.push(`Path: ${entry.path}`);
output.push(`${entry.description}\n`);
}
return output.join("\n");
}