Skip to main content
Glama
ashios15

MCP Frontend Tools Server

by ashios15

Scaffold React Component

scaffold_react_component

Generates a TypeScript React component with optional tests and Storybook stories, supporting functional, forwardRef, and polymorphic variants.

Instructions

Write a TypeScript React component, optional test, and optional Storybook story into outDir. Supports functional, forwardRef, and polymorphic (as prop) variants.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
outDirYesAbsolute directory to write the component files into. Created if missing.
variantNo
withTestsNo
withStoryNo
propsNo

Implementation Reference

  • The registerScaffoldComponent function registers the 'scaffold_react_component' tool with the McpServer. The handler (lines 108-133) creates the component .tsx file (with variant support: functional, forwardRef, polymorphic), optional test (.test.tsx), and optional Storybook story (.stories.tsx) into outDir.
    export function registerScaffoldComponent(server: McpServer) {
      server.registerTool(
        "scaffold_react_component",
        {
          title: "Scaffold React Component",
          description:
            "Write a TypeScript React component, optional test, and optional Storybook story into outDir. Supports functional, forwardRef, and polymorphic (`as` prop) variants.",
          inputSchema: InputShape,
        },
        async (args) => {
          try {
            const variant = args.variant ?? "functional";
            const withTests = args.withTests ?? true;
            const withStory = args.withStory ?? true;
            const props = args.props ?? [];
            await fs.mkdir(args.outDir, { recursive: true });
            const written: string[] = [];
            const compPath = path.join(args.outDir, `${args.name}.tsx`);
            await fs.writeFile(compPath, renderComponent(args.name, variant, props));
            written.push(compPath);
            if (withTests) {
              const testPath = path.join(args.outDir, `${args.name}.test.tsx`);
              await fs.writeFile(testPath, renderTest(args.name));
              written.push(testPath);
            }
            if (withStory) {
              const storyPath = path.join(args.outDir, `${args.name}.stories.tsx`);
              await fs.writeFile(storyPath, renderStory(args.name));
              written.push(storyPath);
            }
            return jsonResult({ name: args.name, variant, written });
          } catch (err) {
            return errorResult(err instanceof Error ? err.message : String(err));
          }
        }
      );
    }
  • Input schema (InputShape) defines the tool's parameters: name (PascalCase regex), outDir (absolute path), variant (functional/forwardRef/polymorphic), withTests, withStory, and props (array of PropShape with name, type, required, defaultValue).
    import { z } from "zod";
    import { promises as fs } from "node:fs";
    import path from "node:path";
    import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
    import { errorResult, jsonResult } from "../util/optional.js";
    
    const PropShape = z.object({
      name: z.string(),
      type: z.string(),
      required: z.boolean().optional(),
      defaultValue: z.string().optional(),
    });
    
    const InputShape = {
      name: z.string().regex(/^[A-Z][A-Za-z0-9]*$/, "PascalCase"),
      outDir: z
        .string()
        .describe("Absolute directory to write the component files into. Created if missing."),
      variant: z.enum(["functional", "forwardRef", "polymorphic"]).optional(),
      withTests: z.boolean().optional(),
      withStory: z.boolean().optional(),
      props: z.array(PropShape).optional(),
    };
  • src/index.ts:29-30 (registration)
    The tool is registered with the MCP server at src/index.ts line 29 via registerScaffoldComponent(server), imported from src/tools/scaffold-component.js on line 9.
    registerScaffoldComponent(server);
  • Helper functions: propsInterface (generates TypeScript props interface), renderComponent (generates component code for all three variants), renderTest (generates test file), renderStory (generates Storybook story file).
    function propsInterface(name: string, props: Array<z.infer<typeof PropShape>>) {
      if (!props.length) return `export interface ${name}Props {}`;
      const lines = props.map((p) => {
        const opt = p.required ? "" : "?";
        return `  ${p.name}${opt}: ${p.type};`;
      });
      return `export interface ${name}Props {\n${lines.join("\n")}\n}`;
    }
    
    function renderComponent(
      name: string,
      variant: "functional" | "forwardRef" | "polymorphic",
      props: Array<z.infer<typeof PropShape>>
    ): string {
      const iface = propsInterface(name, props);
      if (variant === "forwardRef") {
        return `import { forwardRef } from "react";
    
    ${iface}
    
    export const ${name} = forwardRef<HTMLDivElement, ${name}Props>(function ${name}(props, ref) {
      return <div ref={ref} data-component="${name}" />;
    });
    `;
      }
      if (variant === "polymorphic") {
        return `import type { ElementType, ComponentPropsWithoutRef, ReactNode } from "react";
    
    ${iface}
    
    type PolymorphicProps<E extends ElementType> = ${name}Props & {
      as?: E;
      children?: ReactNode;
    } & Omit<ComponentPropsWithoutRef<E>, keyof ${name}Props | "as" | "children">;
    
    export function ${name}<E extends ElementType = "div">({ as, children, ...rest }: PolymorphicProps<E>) {
      const Tag = (as ?? "div") as ElementType;
      return <Tag data-component="${name}" {...rest}>{children}</Tag>;
    }
    `;
      }
      return `${iface}
    
    export function ${name}(_props: ${name}Props) {
      return <div data-component="${name}" />;
    }
    `;
    }
Behavior2/5

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

No annotations provided, so description must disclose behavioral traits. It mentions file creation and that outDir is created if missing, but does not state whether files are overwritten, side effects, or required permissions. This is insufficient for a write operation.

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 a single sentence, concise and front-loaded, but could benefit from a second sentence to improve clarity without significant length increase.

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?

With 6 parameters, no output schema, and no annotations, the description is incomplete. It does not explain return value, error conditions, or full behavior of the props parameter.

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

Parameters2/5

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

Schema description coverage is low (17%), and the description does not explain parameters like variant, props, withTests, withStory. It mentions variants but does not elaborate on differences between functional, forwardRef, polymorphic.

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

Purpose5/5

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

The description clearly states it writes a TypeScript React component with optional test and Storybook story, and supports three variants. This distinguishes it from sibling tools which are unrelated (auditing, budget, screenshots).

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

Usage Guidelines3/5

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

The description provides basic context but lacks explicit when-to-use or when-not-to-use guidance. Since siblings are in different domains, the need for alternatives is less, but no prerequisites or exclusions are mentioned.

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/ashios15/mcp-frontend-tools'

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