get-component-docs
Retrieve detailed documentation for specific Ant Design components, including API properties and usage instructions, to streamline development and integration.
Instructions
获取 Ant Design 特定组件的详细文档 适用场景:
用户询问如何使用特定组件
用户需要查看该组件的 api 属性
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| componentName | Yes |
Implementation Reference
- src/tools/get-component-docs.ts:14-26 (handler)The handler function that executes the tool logic: fetches component documentation using the helper function and formats it into MCP response content.async ({ componentName }) => { const documentation = await getComponentDocumentation(componentName); return { content: [ { type: "text", text: `${componentName} 组件的文档: ${documentation} 如有版本说明需要提醒用户需要使用某个版本及以上的版本`, }, ], }; },
- src/tools/get-component-docs.ts:6-28 (registration)Registers the 'get-component-docs' tool on the MCP server, including name, description, input schema { componentName: z.string() }, and inline 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} 如有版本说明需要提醒用户需要使用某个版本及以上的版本`, }, ], }; }, ); }
- src/tools/index.ts:8-12 (registration)Central registry function that invokes the individual tool registry functions, including the one for get-component-docs.export default function registryTools(server: McpServer) { [getComponentDocs, listComponentExamples, getComponentChangelog, listComponents].forEach((registryFn) => { registryFn(server) }) }
- src/utils/components.ts:51-80 (helper)Key helper function that retrieves and caches the documentation for a specific Ant Design component from 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}`; } };