list-components
Retrieve a list of available Ant Design UI components using the MCP server, enabling developers to select and integrate components into their projects effectively.
Instructions
当用户请求一个新的用户界面(UI)使用 Ant Design 组件时使用此工具。 此工具仅返回可用的组件列表。 调用此工具后,你必须编辑或添加文件,以便将代码片段集成到代码库中
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/list-components.ts:10-20 (handler)The main handler function for the 'list-components' tool. It loads the components list using loadComponentsList and formats it as a text response.调用此工具后,你必须编辑或添加文件,以便将代码片段集成到代码库中`, async () => { const components = await loadComponentsList(); return { content: [ { type: "text", text: `以下是可用的组件:${JSON.stringify(components.map(({ dirName, ...restProps }) => restProps))}`, }, ], }; });
- src/tools/list-components.ts:6-21 (registration)Registers the 'list-components' tool on the MCP server, including name, description, and handler.const registryTool = (server: McpServer) => { server.tool( "list-components", `当用户请求一个新的用户界面(UI)使用 Ant Design 组件时使用此工具。 此工具仅返回可用的组件列表。 调用此工具后,你必须编辑或添加文件,以便将代码片段集成到代码库中`, async () => { const components = await loadComponentsList(); return { content: [ { type: "text", text: `以下是可用的组件:${JSON.stringify(components.map(({ dirName, ...restProps }) => restProps))}`, }, ], }; }); }
- src/tools/index.ts:8-12 (registration)Central registration function that calls the individual tool registry functions, including listComponents.export default function registryTools(server: McpServer) { [getComponentDocs, listComponentExamples, getComponentChangelog, listComponents].forEach((registryFn) => { registryFn(server) }) }
- src/utils/components.ts:20-37 (helper)Utility function to load the list of available components from cache or JSON file, used by the tool handler.export async function loadComponentsList() { try { const cacheComponentList = componentCache.get('componentsList') if (cacheComponentList) { return cacheComponentList } const componentList = await readFile(EXTRACTED_COMPONENTS_LIST_PATH, "utf-8"); const componentListJson = JSON.parse(componentList) as ComponentData[] componentCache.set('componentsList', componentListJson) return componentListJson } catch (error) { console.error(`加载组件列表错误: ${(error as Error).message}`); return []; }