Skip to main content
Glama

get-component-docs

Retrieve detailed documentation for Ant Design components, including API properties and usage examples, to help developers implement UI elements correctly.

Instructions

获取 Ant Design 特定组件的详细文档 适用场景:

  1. 用户询问如何使用特定组件

  2. 用户需要查看该组件的 api 属性

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentNameYes

Implementation Reference

  • The core handler function that retrieves component documentation using the helper function and formats it into the MCP response format with text content.
        async ({ componentName }) => {
          const documentation = await getComponentDocumentation(componentName);
          return {
            content: [
              {
                type: "text",
                text: `${componentName} 组件的文档:
    ${documentation}
    如有版本说明需要提醒用户需要使用某个版本及以上的版本`,
              },
            ],
          };
        },
  • Zod schema defining the input parameter: componentName as a string.
    { componentName: z.string() },
  • The registration function that sets up the 'get-component-docs' tool on the MCP server, including name, description, schema, and handler.
    /** 获取组件文档 */
    const registryTool = (server: McpServer) => {
      server.tool(
        "get-component-docs",
        `获取 Ant Design 特定组件的详细文档
    适用场景:
    1. 用户询问如何使用特定组件
    2. 用户需要查看该组件的 api 属性`,
        { componentName: z.string() },
        async ({ componentName }) => {
          const documentation = await getComponentDocumentation(componentName);
          return {
            content: [
              {
                type: "text",
                text: `${componentName} 组件的文档:
    ${documentation}
    如有版本说明需要提醒用户需要使用某个版本及以上的版本`,
              },
            ],
          };
        },
      );
    }
    
    export default registryTool;
  • Aggregates and invokes registration for all tools, including get-component-docs via its imported registry function.
    export default function registryTools(server: McpServer) {
      [getComponentDocs, listComponentExamples, getComponentChangelog, listComponents].forEach((registryFn) => {
        registryFn(server)
      })
    }
  • Helper function that loads and caches the documentation for a specific component from the extracted data files.
    export const getComponentDocumentation = async (componentName: string) => {
      const component = await findComponentByName(componentName);
    
      if (!component) {
        return ` "${componentName}" 组件文档不存在`;
      }
    
      const docPath = join(EXTRACTED_COMPONENTS_DATA_PATH, component.dirName, DOC_FILE_NAME);
    
      try {
        const cacheComponentDoc = componentCache.get('componentsDoc') || {}
        if (cacheComponentDoc?.[component.name]) {
          return cacheComponentDoc[component.name]
        }
    
        if (existsSync(docPath)) {
          const docResult = await readFile(docPath, "utf-8");
    
          cacheComponentDoc[component.name] = docResult
          componentCache.set('componentsDoc', cacheComponentDoc)
    
          return docResult
        }
    
        return `${component.name} 组件文档不存在`;
      } catch (error) {
        console.error(`获取 ${component.name} 组件文档错误: ${(error as Error).message}`);
        return `获取 ${component.name} 组件文档错误: ${(error as Error).message}`;
      }
    };

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/zhixiaoqiang/antd-components-mcp'

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