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} />`}
    \`\`\`
    `;
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. While 'generate' implies a write operation, it doesn't specify file system effects, permissions needed, error handling, or what happens if the component already exists. This is inadequate for a tool that likely creates files.

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 that directly states the tool's purpose without any fluff. It's appropriately sized and front-loaded, making it easy to parse quickly.

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

Completeness2/5

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

Given the complexity of generating code files and the lack of annotations and output schema, the description is insufficient. It doesn't explain what the tool returns, file structure created, or behavioral details, leaving significant gaps for an agent to use it effectively.

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?

Schema description coverage is 100%, so the schema fully documents all 4 parameters. The description adds no parameter-specific information beyond what's in the schema, meeting the baseline for high coverage but not providing additional context like examples or constraints.

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 action ('generate') and resource ('new React component with TypeScript support'), making the purpose immediately understandable. It doesn't distinguish from sibling tools like 'create_project' or 'create_type_definition', but it's specific enough to understand what it creates.

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 prerequisites, when not to use it, or how it differs from sibling tools like 'create_project' or 'create_type_definition', leaving the agent to guess based on tool names alone.

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

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