Skip to main content
Glama
bsmi021

Node Omnibus MCP Server

by bsmi021

generate_component

Create React components with TypeScript support by specifying name, path, type, and props to streamline UI development.

Instructions

Generate a new React component with TypeScript support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesComponent name
pathYesComponent directory path
typeYesComponent type
propsNoComponent props with types

Implementation Reference

  • Main handler function for the 'generate_component' tool. Validates the path, generates the component TypeScript code and Markdown documentation, writes both files to disk, and returns a success message.
    private async handleGenerateComponent(args: GenerateComponentArgs) {
        await this.validatePath(args.path);
    
        const componentContent = this.generateComponentContent(args);
        const fileName = `${args.name}.tsx`;
        const filePath = path.join(args.path, fileName);
    
        try {
            await fs.writeFile(filePath, componentContent);
    
            // Generate component documentation
            const docContent = this.generateComponentDocumentation(args);
            const docPath = path.join(args.path, `${args.name}.md`);
            await fs.writeFile(docPath, docContent);
    
            return {
                content: [
                    {
                        type: 'text',
                        text: `Component ${args.name} created successfully at ${filePath}`,
                    },
                ],
            };
        } catch (error) {
            throw new McpError(
                ErrorCode.InternalError,
                `Failed to generate component: ${error instanceof Error ? error.message : String(error)}`
            );
        }
    }
  • TypeScript interface defining the input arguments for the generate_component tool handler.
    interface GenerateComponentArgs extends Record<string, unknown> {
        name: string;
        path: string;
        type: 'functional' | 'class';
        props?: Record<string, string>;
    }
  • src/index.ts:273-300 (registration)
    Tool registration in the ListToolsRequestSchema handler, including name, description, and JSON input schema.
    {
        name: 'generate_component',
        description: 'Generate a new React component with TypeScript support',
        inputSchema: {
            type: 'object',
            properties: {
                name: {
                    type: 'string',
                    description: 'Component name',
                },
                path: {
                    type: 'string',
                    description: 'Component directory path',
                },
                type: {
                    type: 'string',
                    enum: ['functional', 'class'],
                    description: 'Component type',
                },
                props: {
                    type: 'object',
                    description: 'Component props with types',
                    additionalProperties: { type: 'string' },
                },
            },
            required: ['name', 'path', 'type'],
        },
    },
  • Helper function that generates the TypeScript code for the React component (functional or class-based) based on args.
        private generateComponentContent(args: GenerateComponentArgs): string {
            const propsInterface = args.props
                ? `interface ${args.name}Props {
        ${Object.entries(args.props).map(([key, type]) => `${key}: ${type};`).join('\n    ')}
    }`
                : '';
    
            if (args.type === 'functional') {
                return `import React from 'react';
    
    ${propsInterface}
    
    ${args.props
                        ? `const ${args.name}: React.FC<${args.name}Props> = ({ ${Object.keys(args.props).join(', ')} }) => {`
                        : `const ${args.name}: React.FC = () => {`}
        return (
            <div>
                {/* Add your component content here */}
            </div>
        );
    };
    
    export default ${args.name};
    `;
            } else {
                return `import React, { Component } from 'react';
    
    ${propsInterface}
    
    class ${args.name} extends Component${args.props ? `<${args.name}Props>` : ''} {
        render() {
            return (
                <div>
                    {/* Add your component content here */}
                </div>
            );
        }
    }
    
    export default ${args.name};
    `;
            }
        }
  • Helper function that generates Markdown documentation for the component, including overview, props list, and usage example.
        private generateComponentDocumentation(args: GenerateComponentArgs): string {
            return `# ${args.name} Component
    
    ## Overview
    ${args.type === 'functional' ? 'A functional React component' : 'A class-based React component'}
    
    ## Props
    ${args.props
                    ? Object.entries(args.props)
                        .map(([key, type]) => `- \`${key}\`: ${type}`)
                        .join('\n')
                    : 'This component does not accept any props.'}
    
    ## Usage
    \`\`\`tsx
    import ${args.name} from './${args.name}';
    
    ${args.props
                    ? `// Example usage with props
    <${args.name} ${Object.entries(args.props)
                        .map(([key, type]) => `${key}={${this.getExampleValue(type)}}`)
                        .join(' ')} />`
                    : `// Example usage
    <${args.name} />`}
    \`\`\`
    `;

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/bsmi021/mcp-node-omnibus-server'

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