///
import type { Tool, Resource } from "jsonv-ts/mcp";
import { rimraf } from "rimraf";
import { writeFile, readFile } from "node:fs/promises";
const config = {
mcpConfig: "./mcp.json",
outFile: "./content/docs/(documentation)/usage/mcp/tools-resources.mdx",
};
async function generate() {
console.info("Generating MCP documentation...");
await cleanup();
const mcpConfig = JSON.parse(await readFile(config.mcpConfig, "utf-8"));
const document = await generateDocument(mcpConfig);
await writeFile(config.outFile, document, "utf-8");
console.info("MCP documentation generated.");
}
async function generateDocument({
tools,
resources,
}: {
tools: ReturnType[];
resources: ReturnType[];
}) {
return `---
title: "Tools & Resources"
description: "Tools & Resources of the built-in full featured MCP server."
tags: ["documentation"]
---
import { JsonSchemaTypeTable } from '@/components/McpTool';
## Tools
${tools
.map(
(t) => `
### \`${t.name}\`
${t.description ?? ""}
`,
)
.join("\n")}
## Resources
${resources
.map(
(r) => `
### \`${r.name}\`
${r.description ?? ""}
`,
)
.join("\n")}
`;
}
async function cleanup() {
await rimraf(config.outFile);
}
void generate();