Skip to main content
Glama
21st-dev

Magic Component Platform (MCP)

by 21st-dev

21st_magic_component_refiner

Refines and improves React UI components by redesigning them based on user feedback, providing updated code and implementation instructions for better styling, layout, or responsiveness.

Instructions

"Use this tool when the user requests to re-design/refine/improve current UI component with /ui or /21 commands, or when context is about improving, or refining UI for a React component or molecule (NOT for big pages). This tool improves UI of components and returns redesigned version of the component and instructions on how to implement it."

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userMessageYesFull user's message about UI refinement
absolutePathToRefiningFileYesAbsolute path to the file that needs to be refined
contextYesExtract the specific UI elements and aspects that need improvement based on user messages, code, and conversation history. Identify exactly which components (buttons, forms, modals, etc.) the user is referring to and what aspects (styling, layout, responsiveness, etc.) they want to enhance. Do not include generic improvements - focus only on what the user explicitly mentions or what can be reasonably inferred from the available context. If nothing specific is mentioned or you cannot determine what needs improvement, return an empty string.

Implementation Reference

  • The async execute method implements the core logic of the '21st_magic_component_refiner' tool. It sends a POST request to the '/api/refine-ui' endpoint with user message, file content, and context, then returns the response text in the MCP format.
    async execute({
      userMessage,
      absolutePathToRefiningFile,
      context,
    }: z.infer<typeof this.schema>) {
      try {
        const { data } = await twentyFirstClient.post<RefineUiResponse>(
          "/api/refine-ui",
          {
            userMessage,
            fileContent: await getContentOfFile(absolutePathToRefiningFile),
            context,
          }
        );
    
        return {
          content: [
            {
              type: "text" as const,
              text: data.text,
            },
          ],
        };
      } catch (error) {
        console.error("Error executing tool", error);
        throw error;
      }
    }
  • Zod schema defining the input parameters for the tool: userMessage, absolutePathToRefiningFile, and context.
    schema = z.object({
      userMessage: z.string().describe("Full user's message about UI refinement"),
      absolutePathToRefiningFile: z
        .string()
        .describe("Absolute path to the file that needs to be refined"),
      context: z
        .string()
        .describe(
          "Extract the specific UI elements and aspects that need improvement based on user messages, code, and conversation history. Identify exactly which components (buttons, forms, modals, etc.) the user is referring to and what aspects (styling, layout, responsiveness, etc.) they want to enhance. Do not include generic improvements - focus only on what the user explicitly mentions or what can be reasonably inferred from the available context. If nothing specific is mentioned or you cannot determine what needs improvement, return an empty string."
        ),
    });
  • src/index.ts:25-25 (registration)
    Registers the RefineUiTool instance with the MCP server, making the '21st_magic_component_refiner' tool available.
    new RefineUiTool().register(server);
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. It states the tool 'returns redesigned version of the component and instructions on how to implement it,' which gives some behavioral insight into outputs. However, it lacks details on permissions, side effects, error handling, or performance considerations. For a tool that modifies UI components, this is a significant gap in transparency.

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 concise and front-loaded, with two sentences that directly address usage and purpose. There is no wasted text, and it efficiently communicates key information. However, the first sentence is slightly long and could be split for better readability, preventing a perfect score.

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 no annotations and no output schema, the description provides adequate context for usage and purpose but lacks details on behavioral aspects like error handling or output format. It compensates somewhat with clear guidelines, but for a tool that modifies UI components, more completeness on what 'redesigned version' entails would be beneficial. It meets minimum viability with clear gaps.

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 already documents all three parameters thoroughly. The description does not add any parameter-specific information beyond what's in the schema (e.g., it doesn't clarify how 'context' should be derived or examples of 'userMessage'). With high schema coverage, the baseline score of 3 is appropriate as the description doesn't compensate but doesn't detract either.

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: 'improves UI of components and returns redesigned version of the component and instructions on how to implement it.' It specifies the action (improve/refine/redesign) and resource (UI components), though it doesn't explicitly differentiate from sibling tools like '21st_magic_component_builder' or '21st_magic_component_inspiration' beyond scope limitations.

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

Usage Guidelines5/5

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

The description provides explicit usage guidelines: 'Use this tool when the user requests to re-design/refine/improve current UI component with /ui or /21 commands, or when context is about improving, or refining UI for a React component or molecule (NOT for big pages).' It specifies when to use (UI refinement requests, React components/molecules) and when not to use (big pages), offering clear context and exclusions.

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/21st-dev/magic-mcp'

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