Skip to main content
Glama

get_component_by_path

Retrieve UI components from the Magic UI design system by specifying their file path, enabling AI assistants and MCP clients to access and use design system elements.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the component file

Implementation Reference

  • The handler function that implements the core logic of the 'get_component_by_path' tool. It extracts the path parameter, fetches the file content via GitHubService.getFileContent, handles errors, and returns the content as MCP text response.
    async (params: any) => {
      const path = params.path as string;
      
      try {
        // Obter o conteúdo do arquivo
        const content = await githubService.getFileContent(path);
        
        if (!content) {
          return {
            content: [{
              type: "text",
              text: `Component file at path '${path}' not found or empty`,
            }],
            isError: true,
          };
        }
        
        return {
          content: [{
            type: "text",
            text: content,
          }],
        };
      } catch (error) {
        return {
          content: [{
            type: "text",
            text: `Error fetching component at path '${path}': ${error}`,
          }],
          isError: true,
        };
      }
    }
  • Zod input schema defining the 'path' parameter for the tool.
    path: z.string().describe("Path to the component file"),
  • src/server.ts:54-54 (registration)
    Registration of the 'get_component_by_path' tool on the MCP server instance.
    "get_component_by_path",
  • Supporting helper method in GitHubService that performs the actual GitHub API call to retrieve file content by path, decodes base64, and handles errors gracefully.
    async getFileContent(path: string): Promise<string> {
      try {
        // Fetch content of a specific file
        const { data } = await this.octokit.repos.getContent({
          owner: this.owner,
          repo: this.repo,
          path,
        });
    
        if ('content' in data) {
          // Decode content from base64
          return Buffer.from(data.content, 'base64').toString('utf-8');
        }
        
        throw new Error(`Could not get content for path: ${path}`);
      } catch (error: any) {
        // Check if it's a rate limit error
        if (error.status === 403 && error.message.includes('API rate limit exceeded')) {
          console.error('GitHub API rate limit exceeded. Consider using a token.');
          // Return empty string instead of throwing
          return '';
        }
        
        console.error(`Error fetching file content for ${path}:`, error);
        return '';
      }
    }
Behavior1/5

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

Tool has no description.

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

Conciseness1/5

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

Tool has no description.

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

Completeness1/5

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

Tool has no description.

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

Parameters1/5

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

Tool has no description.

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

Purpose1/5

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

Tool has no description.

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

Usage Guidelines1/5

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

Tool has no description.

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/idcdev/mcp-magic-ui'

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