Skip to main content
Glama

generate-docs

Create documentation in multiple formats like markdown, API docs, and README files for tasks including code comments and setup instructions using AI providers.

Instructions

Generate documentation in various formats

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskYesWhat to document (e.g., 'API endpoints', 'setup instructions', 'code comments')
filesNoFile paths to document (optional)
formatNoDocumentation formatmarkdown
providerNoAI provider to usegemini

Implementation Reference

  • Main handler function that executes the generate-docs tool by calling an AI provider to generate documentation based on task, files, and format.
    async handleGenerateDocs(params: z.infer<typeof GenerateDocsSchema>) { // Use provided provider or get the preferred one (Azure if configured) const providerName = params.provider || (await this.providerManager.getPreferredProvider(['openai', 'gemini', 'azure', 'grok'])); const provider = await this.providerManager.getProvider(providerName); const formatPrompts = { markdown: "Generate documentation in markdown format with proper structure and formatting", comments: "Generate inline code comments and docstrings for the specified code", "api-docs": "Generate API documentation with endpoints, parameters, responses, and examples", readme: "Generate README documentation with setup, usage, and project information" }; const systemPrompt = `You are an expert technical writer and documentation specialist. ${formatPrompts[params.format]} Create comprehensive documentation that: - Is clear and easy to understand - Follows proper formatting and structure - Includes relevant examples and usage - Covers all important aspects - Is practical and actionable Ensure documentation is professional and user-friendly.`; let prompt = `Generate documentation for: ${params.task}`; if (params.files) { prompt += `\n\nFiles to document: ${params.files.join(", ")}`; } const response = await provider.generateText({ prompt, systemPrompt, temperature: 0.5, // Balanced temperature for documentation clarity useSearchGrounding: providerName === "gemini", }); return { content: [ { type: "text", text: response.text, }, ], metadata: { provider: providerName, model: response.model, format: params.format, usage: response.usage, ...response.metadata, }, }; }
  • Zod input schema defining parameters for the generate-docs tool: task, files, format, and provider.
    const GenerateDocsSchema = z.object({ task: z.string().describe("What to document (e.g., 'API endpoints', 'setup instructions', 'code comments')"), files: z.array(z.string()).optional().describe("File paths to document (optional)"), format: z.enum(["markdown", "comments", "api-docs", "readme"]).default("markdown").describe("Documentation format"), provider: z.enum(["openai", "gemini", "azure", "grok"]).optional().default("gemini").describe("AI provider to use"), });
  • src/server.ts:324-332 (registration)
    MCP server registration of the generate-docs tool, linking schema and handler implementation.
    // Register generate-docs tool server.registerTool("generate-docs", { title: "Generate Documentation", description: "Generate documentation in various formats", inputSchema: GenerateDocsSchema.shape, }, async (args) => { const aiHandlers = await getHandlers(); return await aiHandlers.handleGenerateDocs(args); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RealMikeChong/ultra-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server