ui-context
Extract component metadata from your React and Angular libraries and expose them via an MCP server — giving AI assistants deep knowledge of your design system.
Features
Multi-Framework
First-class support for React and Angular with an extensible parser registry for adding new frameworks.
Universal Schema
Framework-agnostic metadata representation — props, events, methods, slots, examples, and design tokens.
MCP Integration
Stdio-based MCP server compatible with Claude Desktop, Cursor, and other AI-powered tools.
Intelligent Search
Find components by name, category, props, or free-text query with relevance scoring.
Auto-Discovery
Automatically extracts examples from Storybook stories and JSDoc tags.
Design Tokens
Captures colors, spacing, typography, and other design tokens from your library.
Architecture
ui-context is a TypeScript monorepo with five focused packages that work together:
| Package | Description |
|---|---|
@ui-context/core | Universal component schema, parser interface, and plugin registry |
@ui-context/parser-react | Parses React components using react-docgen (TSX, JSX, TS, JS) |
@ui-context/parser-angular | Parses Angular components using ts-morph (decorators + signal APIs) |
@ui-context/mcp-server | Creates and runs MCP servers from extracted metadata |
@ui-context/cli | CLI to generate, validate, and serve component metadata |
Quick Start
Get up and running in under 5 minutes.
Install the CLI
npm install @ui-context/cli
Or run directly with npx (no install needed).
Generate metadata from your components
# React
npx ui-context generate -s ./path/to/components -p react -o ./output
# Angular
npx ui-context generate -s ./path/to/components -p angular -o ./output
This produces components.json (metadata) and mcp-config.json (config snippet).
Validate the output
npx ui-context validate -d ./output/components.json
Start the MCP server
npx ui-context serve -d ./output/components.json
Connect to your AI tool
Copy the generated config into Claude Desktop or Cursor's MCP configuration.
Installation
Prerequisites
- Node.js ≥ 18
- npm (comes with Node.js)
From npm (recommended)
# Install the CLI globally
npm install -g @ui-context/cli
# Or use directly with npx (no install needed)
npx @ui-context/cli generate -s ./src/components -p react
You can also install individual packages:
npm install @ui-context/core
npm install @ui-context/parser-react
npm install @ui-context/parser-angular
npm install @ui-context/mcp-server
From source (for contributors)
git clone https://github.com/oluizcarvalho/ui-context.git
cd ui-context
npm install
npm run build
Try with the example libraries
After cloning the repository, you can test with the included sample libraries:
# React example
npx ui-context generate -s ./examples/react-sample-lib/src/components -p react
# Angular example
npx ui-context generate -s ./examples/angular-sample-lib/src/components -p angular
CLI Commands
ui-context generate
Extract component metadata from source files.
| Option | Description | Required |
|---|---|---|
-s, --source <path> | Source directory with components | Yes |
-p, --parser <name> | Parser to use: react or angular | Yes |
-o, --output <path> | Output directory | No (default: ./ui-context-output) |
--name <name> | Library name | No (defaults to dir name) |
--include <patterns...> | Glob patterns to include | No |
--exclude <patterns...> | Glob patterns to exclude | No |
# Basic usage
npx ui-context generate -s ./src/components -p react
# With options
npx ui-context generate \
-s ./src/components \
-p react \
-o ./docs/metadata \
--name "My Design System" \
--exclude "**/*.test.*" "**/__mocks__/**"
ui-context serve
Start an MCP server from generated metadata.
| Option | Description | Required |
|---|---|---|
-d, --data <path> | Path to components.json | Yes |
ui-context validate
Check metadata for completeness and quality issues.
| Option | Description | Required |
|---|---|---|
-d, --data <path> | Path to components.json | Yes |
validate after generate to check for missing descriptions, untyped props, and missing examples.
MCP Tools
Once the server is running, AI assistants can query your component library using these tools:
| Tool | Description | Parameters |
|---|---|---|
list_components |
List all components, optionally filtered by category | category?: string |
get_component |
Get detailed metadata for a specific component | name: string |
search_components |
Search components by keyword with relevance scoring | query: string |
get_usage_example |
Get code examples for a component | name: string |
get_design_tokens |
Retrieve design tokens (colors, spacing, etc.) | category?: string |
Search scoring
The search_components tool uses weighted matching:
| Match Type | Score |
|---|---|
| Exact name match | +20 |
| Partial name match | +10 |
| Selector match | +8 |
| Description match | +5 |
| Category match | +4 |
| Prop/event name match | +2 |
| Prop description match | +1 |
Configuration
After running generate, connect the MCP server to your AI tool.
Claude Desktop
Add to ~/.claude/claude_desktop_config.json:
{
"mcpServers": {
"my-design-system": {
"command": "npx",
"args": [
"-y",
"@ui-context/cli",
"serve",
"-d",
"path/to/components.json"
]
}
}
}
Cursor
Add to .cursor/mcp.json in your project root:
{
"mcpServers": {
"my-design-system": {
"command": "npx",
"args": [
"-y",
"@ui-context/cli",
"serve",
"-d",
"path/to/components.json"
]
}
}
}
mcp-config.json file generated by the generate command contains a ready-to-use configuration snippet. You can copy it directly into your tool's config.
Programmatic API
Use ui-context packages directly in your TypeScript/JavaScript code.
Core Schema
import { ParserRegistry } from "@ui-context/core";
import type {
ComponentMetadata,
PropMetadata,
EventMetadata,
LibraryMetadata,
} from "@ui-context/core";
Using Parsers
import { createParser } from "@ui-context/parser-react";
const parser = createParser();
const components = await parser.parse({
sourcePath: "./src/components",
include: ["**/*.tsx"],
exclude: ["**/*.test.*"],
});
Creating an MCP Server
import { createMcpServer, startServer } from "@ui-context/mcp-server";
// From a metadata object
const server = createMcpServer(libraryMetadata);
// Or start directly from a file
await startServer("./output/components.json");
Parser Registry
import { ParserRegistry } from "@ui-context/core";
const registry = new ParserRegistry();
// Register a custom parser
registry.register(myCustomParser);
// Resolve a parser by name (supports auto-discovery)
const parser = await registry.resolve("react");
const components = await parser.parse({ sourcePath: "./src" });
Examples
The repository includes sample component libraries to help you get started.
React Example
// examples/react-sample-lib/src/components/Button.tsx
export interface ButtonProps {
/** The button label text */
label: string;
/** Visual variant */
variant?: "primary" | "secondary" | "danger";
/** Size of the button */
size?: "sm" | "md" | "lg";
/** Whether the button is disabled */
disabled?: boolean;
/** Click handler */
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
}
export const Button: React.FC<ButtonProps> = ({
label,
variant = "primary",
size = "md",
disabled = false,
onClick,
}) => { /* ... */ };
Angular Example
// examples/angular-sample-lib/src/components/button.component.ts
@Component({
selector: "ui-button",
template: `
<button [class]="variant" (click)="handleClick($event)">
<ng-content></ng-content>
{{ label }}
</button>
`,
})
export class ButtonComponent {
@Input() label: string = "";
@Input() variant: "primary" | "secondary" | "danger" = "primary";
@Output() clicked = new EventEmitter<MouseEvent>();
focus(): void { /* ... */ }
}
Running the examples
# Parse the React sample library
npx ui-context generate \
-s ./examples/react-sample-lib/src/components \
-p react \
--name "React Sample Lib"
# Parse the Angular sample library
npx ui-context generate \
-s ./examples/angular-sample-lib/src/components \
-p angular \
--name "Angular Sample Lib"
# Validate the output
npx ui-context validate -d ./ui-context-output/components.json
# Start the MCP server
npx ui-context serve -d ./ui-context-output/components.json
Parsers
React Parser
Uses react-docgen to analyze React components:
- Supported extensions:
.tsx,.jsx,.ts,.js - Extracts props from TypeScript interfaces and PropTypes
- Props starting with
on+ uppercase letter are classified as events - Discovers examples from
.stories.tsxfiles and@exampleJSDoc tags - Ignores test, spec, and story files by default
Angular Parser
Uses ts-morph for TypeScript AST analysis:
- Parses
@Componentand@Directivedecorators - Extracts
@Input()and@Output()metadata - Supports Angular 14+ signal APIs (
input(),output()) - Extracts
<ng-content>slots from templates - Filters lifecycle hooks (ngOnInit, ngOnDestroy, etc.)
- Ignores spec, module, and routing files by default
Custom Parsers
Implement the ComponentParser interface to add support for other frameworks:
import type { ComponentParser, ParserOptions, ComponentMetadata } from "@ui-context/core";
export class VueParser implements ComponentParser {
name = "vue";
supportedExtensions = [".vue"];
async parse(options: ParserOptions): Promise<ComponentMetadata[]> {
// Your parsing logic here
}
}
Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Write tests for your changes
- Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Development setup
# Install dependencies
npm install
# Build all packages
npm run build
# Run tests
npm test
# Watch mode
npm run test:watch