[KongchangAI]
· 1 min read· 798 words

Component Library MCP in Practice: Make AI Prioritize Your Components When Writing Pages

Component Library MCP in Practice: Make AI Prioritize Your Components When Writing Pages

Organize component specifications into a queryable MCP service so the model queries components before writing pages.

The article notes that AI tends to use generic components rather than the team's library, not due to model capability but because component information isn't exposed in a tool-queryable way. The solution has three steps: organize component names, parameters, and combination rules into a schema corresponding one-to-one with real interfaces; wrap the query capability into an MCP service for the model to call before generating code; then generate a business page with custom components to validate the chain, focusing on correct component selection and parameter compliance, and run results in real engineering. Finally, components and descriptions must evolve together—once schema diverges from implementation, generated results fail.

AI writing pages always relies on generic components, while the team's existing component library sits idle. The problem isn't model capability—it's that component information isn't exposed in a way the model can invoke. A viable path: organize component specifications into a queryable MCP service, so the model queries components before generating pages, then writes code.

Why the Model Doesn't Use Your Components

When generating pages, the model defaults to a generic route because it doesn't know what components exist in the project, what parameters each accepts, or how to combine them legally. The team's component library documentation is written for humans, not for tools to query. To get existing components involved in AI development, the first step is to extract component information from documentation into a structured, tool-queryable description.

The key here isn't writing longer documentation, but making the component schema correspond to real components—the parameters and combination methods described must be directly usable in engineering. A description the model understands but engineering can't use is as good as none.

Organize Component Specifications into Schema

The core information to organize falls into three categories: component names, acceptable parameters, and usage rules.

Component schema describes what parameters can be passed and how to combine them

The schema description must answer two questions: what parameters this component accepts, and how those parameters combine. Structurally, it needs to correspond one-to-one with the real component's interface—not just natural language explanation. When organizing, base it on the props and combination constraints the component actually exposes, so the model receives an executable description.

Here, schema generally refers to an interface structure described in JSON Schema: each component corresponds to an object containing name (component identifier), description (usage explanation), parameters (parameter list, including type, required status, default value, value range), and combination constraints. Compared to natural language documentation, JSON Schema's advantage is that it can be read by humans, parsed and validated by models, and directly integrated with engineering processes like form validation and type checking. Industry practices like shadcn/ui's registry and Storybook's argTypes essentially extract component metadata from documentation into machine-readable structures; when converting component specifications to schema, these existing metadata sources can be reused to reduce duplicate maintenance costs.

Build Query Capability into an MCP Service

After the component schema is organized, wrap the query capability into an MCP service. When the model needs component information, it calls the tool, which returns clear explanations, and the model uses these to continue generating page code.

Then build the query capability into an MCP service

This step connects "what the model knows" with "what exists in the project." The tool returns specific parameters and rule explanations, not vague suggestions, which the model can directly use for the next step of code generation.

MCP (Model Context Protocol) is an open protocol proposed by Anthropic in late 2024 to establish a standardized invocation interface between models and external data sources and tools. It abstracts capability providers as "servers" and the model side as "clients," with both sides describing available tools, resources, and prompt templates through a unified protocol. For component library scenarios, this means no need to write adapter layers for each model or IDE: just wrap component queries into an MCP-compliant service, and any host supporting the protocol (like Claude Desktop or various AI coding assistants) can call it directly. Tool descriptions in the protocol typically include name, usage explanation, and JSON Schema-formatted input definitions, which the model uses to decide when to call and what parameters to pass—this is the concrete implementation of "exposing component information in a way the model can invoke" mentioned earlier.

Generate Business Pages with Custom Components

With query capability in place, generate a business page using custom components to validate the entire chain. During generation, the model calls the component query tool and selects components and fills parameters based on the returned explanations.

Then continue generating page code based on these explanations

Validation focuses on two things: whether the model selected the correct components, and whether parameters comply with the rules.

Whether parameters comply with the rules

The generated result needs to be run back in the project, not just checked for code resemblance. Only by running it in real engineering can you confirm that the three segments—component specifications, tool queries, and page generation—are truly connected.

Maintenance: When Components Change, Descriptions Must Follow

This workflow integrates existing team components into AI development, but it's not a one-time configuration. When adjusting components later, update the corresponding descriptions in sync. Once schema and real components diverge, the information the model queries becomes wrong, and generated results fail accordingly.

From an engineering perspective, component descriptions should evolve together with component code, treating "update component" and "update description" as the same action—only then can this chain remain usable long-term.

#MCP#component library#JSON Schema#AI page generation#Model Context Protocol#component specifications
Share:

Related articles