Skip to main content
Glama

genapi

Generate API documentation from code in Markdown, OpenAPI, or JSDoc formats to streamline development workflows and maintain project documentation.

Instructions

【生成文档】为代码生成 API 文档(支持 Markdown、OpenAPI、JSDoc 格式)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeNo需要生成文档的代码
formatNo文档格式:markdown, openapi, jsdoc(默认 markdown)

Implementation Reference

  • Main handler function for the 'genapi' tool. It constructs a detailed prompt for generating API documentation from provided code and format, returning it as MCP content.
    export async function genapi(args: any) { try { const code = args?.code || ""; const format = args?.format || "markdown"; // markdown, openapi, jsdoc const message = `请为以下代码生成 API 文档: 📝 **代码**: ${code || "请提供需要生成文档的代码(函数、类、API 端点等)"} 📖 **文档格式**:${format} --- 🎯 **API 文档生成指南**: **基础信息**: - API 名称和描述 - 版本信息 - 基础 URL **详细文档**(每个端点/函数): 1. **功能描述** - 简短说明(一句话) - 详细描述(用途、场景) 2. **请求参数** | 参数名 | 类型 | 必填 | 描述 | 示例 | |--------|------|------|------|------| | id | string | 是 | 用户 ID | "12345" | | name | string | 否 | 用户名 | "张三" | 3. **返回值** - 成功响应(状态码、数据结构、示例) - 错误响应(错误码、错误信息) 4. **示例代码** \`\`\`typescript // 请求示例 const response = await fetch('/api/users/123'); const data = await response.json(); // 响应示例 { "code": 200, "data": { "id": "123", "name": "张三" } } \`\`\` 5. **注意事项** - 权限要求 - 速率限制 - 废弃信息 - 相关链接 --- **Markdown 格式模板**: \`\`\`markdown # API 文档 ## 用户管理 ### 获取用户信息 **接口地址**:\`GET /api/users/:id\` **功能描述**:根据用户 ID 获取用户详细信息 **请求参数**: | 参数 | 类型 | 必填 | 描述 | |------|------|------|------| | id | string | 是 | 用户 ID | **返回示例**: \`\`\`json { "code": 200, "data": { "id": "123", "name": "张三", "email": "zhangsan@example.com" } } \`\`\` **错误码**: - 404: 用户不存在 - 403: 无权限访问 \`\`\` --- **OpenAPI 3.0 格式模板**: \`\`\`yaml openapi: 3.0.0 info: title: User API version: 1.0.0 paths: /api/users/{id}: get: summary: 获取用户信息 parameters: - name: id in: path required: true schema: type: string responses: '200': description: 成功 content: application/json: schema: type: object properties: code: type: integer data: type: object \`\`\` --- 现在请根据上述代码生成完整的 API 文档,并将文档保存到项目的 \`docs/api/\` 目录。`; return { content: [ { type: "text", text: message, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `❌ 生成 API 文档失败: ${errorMessage}`, }, ], isError: true, }; } }
  • Schema definition for the genapi tool in the ListToolsRequest handler, specifying input parameters: code (string) and format (string).
    { name: "genapi", description: "【生成文档】为代码生成 API 文档(支持 Markdown、OpenAPI、JSDoc 格式)", inputSchema: { type: "object", properties: { code: { type: "string", description: "需要生成文档的代码", }, format: { type: "string", description: "文档格式:markdown, openapi, jsdoc(默认 markdown)", }, }, required: [], }, },
  • src/index.ts:474-475 (registration)
    Registration of the genapi handler in the CallToolRequest switch statement, dispatching calls to the genapi function.
    case "genapi": return await genapi(args);
  • src/tools/index.ts:6-6 (registration)
    Re-export of the genapi function from its implementation file for use in the main index.
    export { genapi } from "./genapi.js";

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/mybolide/mcp-probe-kit'

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