Skip to main content
Glama

list-component-examples

Retrieve code examples for specific Ant Design components to implement features or understand usage. Input the component name to generate relevant code snippets.

Instructions

获取 Ant Design 特定组件的代码示例 适用场景:

  1. 用户询问特定组件的示例时

  2. 用户想要实现某个功能时直接告知可使用的例子

  3. 生成页面前需要获取组件的示例代码

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentNameYes

Implementation Reference

  • The tool handler that fetches component examples using the helper function and returns them formatted as text content.
    async ({ componentName }) => { const componentExamples = await listComponentExamples(componentName); return { content: [ { type: "text", text: `${componentName} 组件的代码示例文档: ${componentExamples || '暂无代码示例'}`, }, ], }; },
  • Input schema validating the componentName parameter as a string using Zod.
    { componentName: z.string() },
  • Registers the 'list-component-examples' tool on the MCP server, including name, description, schema, and handler.
    const registryTool = (server: McpServer) => { server.tool( "list-component-examples", `获取 Ant Design 特定组件的代码示例 适用场景: 1. 用户询问特定组件的示例时 2. 用户想要实现某个功能时直接告知可使用的例子 3. 生成页面前需要获取组件的示例代码`, { componentName: z.string() }, async ({ componentName }) => { const componentExamples = await listComponentExamples(componentName); return { content: [ { type: "text", text: `${componentName} 组件的代码示例文档: ${componentExamples || '暂无代码示例'}`, }, ], }; }, ); }
  • Helper function that finds the component, loads and caches its example markdown file from disk.
    export const listComponentExamples = async (componentName: string) => { const component = await findComponentByName(componentName); if (!component) { return "当前组件不存在"; } const examplesMdPath = join(EXTRACTED_COMPONENTS_DATA_PATH, component.dirName, EXAMPLE_FILE_NAME); if (!existsSync(examplesMdPath)) { return `${component.name} 的示例代码不存在`; } try { const cacheComponentExample = componentCache.get('componentExample') || {} if (cacheComponentExample?.[component.name]) { return cacheComponentExample[component.name] } if (existsSync(examplesMdPath)) { const exampleResult = await readFile(examplesMdPath, "utf-8"); cacheComponentExample[component.name] = exampleResult componentCache.set('componentExample', cacheComponentExample) return exampleResult } return await readFile(examplesMdPath, "utf-8"); } catch (error) { console.error(`${component.name} 的示例代码不存在: ${(error as Error).message}`); return `${component.name} 的示例代码不存在`; } };
  • Central registry function that invokes individual tool registry functions, including this one.
    export default function registryTools(server: McpServer) { [getComponentDocs, listComponentExamples, getComponentChangelog, listComponents].forEach((registryFn) => { registryFn(server) }) }

Other Tools

Related Tools

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