Skip to main content
Glama
yun8711

Element-UI MCP Server

by yun8711

Get Component Examples

get_component_examples

Retrieve specific usage examples for Element-UI components to understand implementation patterns and generate accurate Vue 2 code.

Instructions

获取 Element-UI 组件的具体使用示例。直接返回过滤后的文档内容。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tagNameYes组件标签名, 例如:el-button

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYes过滤后的文档内容,包含组件描述和使用示例
tagNameYes组件标签名

Implementation Reference

  • The main handler function for the 'get_component_examples' tool. It checks if the component exists, reads the corresponding Markdown example file from the examples directory, and returns structured content with the example documentation.
    async ({ tagName }) => {
      const component = componentObject[tagName]
    
      if (!component) {
        throw new Error(`Component "${tagName}" not found. Available components: ${Object.keys(componentObject).join(', ')}`)
      }
    
      // 读取过滤后的文档内容
      let content = ''
      try {
        const mdPath = path.join(__dirname, '../examples', `${tagName}.md`)
        if (fs.existsSync(mdPath)) {
          content = fs.readFileSync(mdPath, 'utf8')
        } else {
          content = `未找到 ${tagName} 组件的示例文档。`
        }
      } catch (error) {
        console.warn(`Failed to read examples for ${tagName}:`, error)
        content = `读取 ${tagName} 组件示例文档时出错。`
      }
    
      console.log('content',content)
    
      const result = {
        tagName,
        content,
      }
    
      return {
        structuredContent: result,
        content: [
          {
            type: 'text' as const,
            text: content,
          },
        ],
      }
    }
  • Input and output schemas for the get_component_examples tool: input requires tagName (string), output returns tagName and content (string).
    {
      title: 'Get Component Examples',
      description: '获取 Element-UI 组件的具体使用示例。直接返回过滤后的文档内容。',
      inputSchema: z.object({
        tagName: z.string().describe('组件标签名, 例如:el-button'),
      }),
      outputSchema: z.object({
        tagName: z.string().describe('组件标签名'),
        content: z.string().describe('过滤后的文档内容,包含组件描述和使用示例'),
      }),
    },
  • The registerGetComponentExamples function that registers the 'get_component_examples' tool with the MCP server, including schema and handler.
    export function registerGetComponentExamples(server: McpServer) {
      server.registerTool(
        'get_component_examples',
        {
          title: 'Get Component Examples',
          description: '获取 Element-UI 组件的具体使用示例。直接返回过滤后的文档内容。',
          inputSchema: z.object({
            tagName: z.string().describe('组件标签名, 例如:el-button'),
          }),
          outputSchema: z.object({
            tagName: z.string().describe('组件标签名'),
            content: z.string().describe('过滤后的文档内容,包含组件描述和使用示例'),
          }),
        },
        async ({ tagName }) => {
          const component = componentObject[tagName]
    
          if (!component) {
            throw new Error(`Component "${tagName}" not found. Available components: ${Object.keys(componentObject).join(', ')}`)
          }
    
          // 读取过滤后的文档内容
          let content = ''
          try {
            const mdPath = path.join(__dirname, '../examples', `${tagName}.md`)
            if (fs.existsSync(mdPath)) {
              content = fs.readFileSync(mdPath, 'utf8')
            } else {
              content = `未找到 ${tagName} 组件的示例文档。`
            }
          } catch (error) {
            console.warn(`Failed to read examples for ${tagName}:`, error)
            content = `读取 ${tagName} 组件示例文档时出错。`
          }
    
          console.log('content',content)
    
          const result = {
            tagName,
            content,
          }
    
          return {
            structuredContent: result,
            content: [
              {
                type: 'text' as const,
                text: content,
              },
            ],
          }
        }
      )
    }
  • src/index.ts:32-32 (registration)
    Top-level registration call to registerGetComponentExamples in the main server creation function.
    registerGetComponentExamples(server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions '直接返回过滤后的文档内容' (directly return filtered documentation content), which hints at read-only behavior and filtering, but doesn't disclose important behavioral traits like whether this requires authentication, rate limits, error conditions, or what 'filtered' specifically means. For a tool with no annotation coverage, this is insufficient behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with two clear sentences. The first sentence states the purpose, and the second provides behavioral context about returning filtered content. There's no wasted verbiage, though it could be slightly more structured with explicit separation of purpose and behavior.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool has an output schema (which means the description doesn't need to explain return values) and 100% schema coverage, the description is minimally complete. However, for a tool with no annotations and multiple sibling alternatives, it should provide more context about when to use it and what 'filtered documentation content' specifically entails. The presence of an output schema raises the baseline, but the lack of usage guidance keeps this from being fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the single parameter 'tagName' clearly documented as '组件标签名, 例如:el-button' (component tag name, e.g.: el-button). The description doesn't add any meaningful parameter semantics beyond what the schema already provides. With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '获取 Element-UI 组件的具体使用示例' (Get specific usage examples for Element-UI components). It specifies the verb ('获取' - get) and resource ('Element-UI 组件的具体使用示例' - Element-UI component usage examples). However, it doesn't explicitly differentiate from sibling tools like 'get_component' which might return general documentation rather than examples.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With sibling tools like 'get_component', 'get_component_props', and 'search_components', there's no indication of when examples are needed versus general documentation, properties, or search functionality. The description only states what the tool does, not when it's appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/yun8711/element-ui-mcp'

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