Skip to main content
Glama
ceorkm

ReactBits MCP Server

by ceorkm

get_component_demo

Retrieve example code and usage demonstrations for ReactBits components to implement animated UI elements in React applications.

Instructions

Get usage example and demo code for a ReactBits component

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the component

Implementation Reference

  • The core handler function that implements the 'get_component_demo' tool logic. It retrieves the component code and wraps it in a complete demo with React imports and usage example.
      async getComponentDemo(componentName: string): Promise<string> {
        const component = await this.getComponent(componentName);
        
        // Extract component name from the code
        const componentNameMatch = component.match(/(?:export\s+default\s+function|const)\s+(\w+)/);
        const extractedName = componentNameMatch ? componentNameMatch[1] : componentName.replace(/\s+/g, '');
        
        // Create a demo wrapper
        return `// Demo for ${componentName}
    import React from 'react';
    
    ${component}
    
    // Usage Example:
    export default function Demo() {
      return (
        <div className="min-h-screen bg-gray-100 p-8">
          <h1 className="text-2xl font-bold mb-4">${componentName} Demo</h1>
          <${extractedName} />
        </div>
      );
    }`;
      }
  • src/index.ts:91-104 (registration)
    The tool registration in the tools list, including name, description, and input schema, used by the MCP server for ListTools requests.
    {
      name: 'get_component_demo',
      description: 'Get usage example and demo code for a ReactBits component',
      inputSchema: {
        type: 'object',
        properties: {
          name: {
            type: 'string',
            description: 'Name of the component',
          },
        },
        required: ['name'],
      },
    },
  • src/index.ts:184-200 (registration)
    The dispatch handler in the switch statement that routes 'get_component_demo' calls to the ReactBitsService method and formats the MCP response.
    case 'get_component_demo': {
      const componentName = args?.name as string;
      
      if (!componentName) {
        throw new Error('Component name is required');
      }
    
      const demo = await reactBitsService.getComponentDemo(componentName);
      return {
        content: [
          {
            type: 'text',
            text: demo,
          },
        ],
      };
    }
  • Supporting helper method called by getComponentDemo to fetch the raw component code from cache, GitHub, or web scraper.
      async getComponent(componentName: string, style?: 'css' | 'tailwind' | 'default'): Promise<string> {
        // Normalize component name to slug format
        const slug = componentName.toLowerCase().replace(/\s+/g, '-');
        
        // Check component health status
        const categoryEntry = Object.entries(componentHealth.componentHealth).find(([_, category]) => 
          (category as any).components && slug in (category as any).components
        );
        
        if (categoryEntry) {
          const [categoryName, category] = categoryEntry;
          const componentStatus = ((category as any).components as any)[slug];
          
          if (componentStatus === 'placeholder' || componentStatus === 'incomplete') {
            const warningMessage = `
    // ⚠️ WARNING: This component has incomplete implementation
    // Component: ${componentName} (${slug})
    // Category: ${categoryName}
    // Status: ${componentStatus}
    // Quality Score: ${(category as any).quality}/10
    //
    // This is a known issue with ReactBits. The following components are incomplete:
    // - All Button components (Button 1-8)
    // - All Form components (Form 1-3)  
    // - All Loader components (Loader 1-9)
    //
    // For production use, please implement your own version or use components from:
    // - Backgrounds (9.8/10 quality)
    // - Animations (9.5/10 quality)
    // - Text Animations (9.0/10 quality)
    
    export default function ${componentName.replace(/\s+/g, '')}() {
      return (
        <div className="p-4 border-2 border-dashed border-gray-300 rounded-lg bg-gray-50">
          <p className="text-gray-600">⚠️ {Component "${componentName}" has incomplete implementation}</p>
          <p className="text-sm text-gray-500 mt-2">Please check ReactBits.dev for updates</p>
        </div>
      );
    }`;
            return warningMessage;
          }
        }
        
        // Check cache first
        const cacheKey = `component:${slug}:${style || 'default'}`;
        const cached = this.cache.get<string>(cacheKey);
        if (cached) return cached;
    
        // Use the component path map
        const componentPath = componentPathMap[slug];
        
        if (!componentPath) {
          throw new Error(`Component "${componentName}" not found in registry`);
        }
    
        try {
          console.error(`Fetching ${slug} from GitHub at ${componentPath}...`);
          const githubComponent = await this.github.getComponentFromGitHub(componentPath);
          
          if (githubComponent.code) {
            this.cache.set(cacheKey, githubComponent.code, 3600000);
            return githubComponent.code;
          }
        } catch (error) {
          console.error(`Failed to fetch ${slug} from GitHub:`, error);
          
          // Fallback to web scraping
          try {
            console.error(`Attempting to scrape ${slug} from ReactBits.dev...`);
            const componentContent = await this.scraper.getComponentCode(slug, style);
            const code = componentContent.code;
            this.cache.set(cacheKey, code, 3600000);
            return code;
          } catch (scraperError) {
            console.error(`Scraping failed for ${slug}:`, scraperError);
          }
        }
    
        // Last resort: return a helpful error message
        throw new Error(`Unable to fetch component "${componentName}". Please check your internet connection and try again.`);
      }
  • The input schema defining the expected parameters for the 'get_component_demo' tool.
    inputSchema: {
      type: 'object',
      properties: {
        name: {
          type: 'string',
          description: 'Name of the component',
        },
      },
      required: ['name'],
    },
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves 'usage example and demo code,' implying a read-only operation, but doesn't clarify aspects like error handling (e.g., what happens if the component name is invalid), response format, or any rate limits. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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

Conciseness5/5

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

The description is a single, efficient sentence: 'Get usage example and demo code for a ReactBits component.' It is front-loaded with the core purpose, has zero redundant words, and appropriately sized for a simple tool. Every part of the sentence earns its place by conveying essential information.

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's low complexity (one parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on usage guidelines, behavioral traits, and output expectations. Without annotations or an output schema, the agent might struggle with error cases or response handling, making this description incomplete for optimal use.

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 'name' parameter documented as 'Name of the component.' The description adds no additional semantic context beyond this, such as format examples (e.g., case sensitivity) or how it relates to the output. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, though the description could have enhanced understanding.

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: 'Get usage example and demo code for a ReactBits component.' It specifies the verb ('Get'), resource ('usage example and demo code'), and target ('ReactBits component'), making it easy to understand what the tool does. However, it doesn't explicitly distinguish this from sibling tools like 'get_component' (which likely retrieves component metadata rather than demo code).

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. It doesn't mention sibling tools like 'get_component' or 'search_components', nor does it specify prerequisites, constraints, or ideal use cases. The agent must infer usage from the tool name and description alone, which is insufficient for optimal selection.

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/ceorkm/reactbits-mcp-server'

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