UICP (User Interface Context Protocol) enables LLM-based agents to describe and render UI components dynamically. This monorepo contains framework-agnostic packages for parsing and creating UICP components, plus a Next.js example application.
Core parsing library for extracting and rendering UICP blocks from LLM output.
npm install @uicp/parserFeatures:
- Extract UICP blocks from markdown
- Validate blocks against component definitions
- Dynamic component loading with configurable base path
- React component rendering
- TypeScript support
Framework-agnostic AI tools for component discovery and creation.
npm install @uicp/toolsFeatures:
- Discover available UI components
- Create UICP blocks with validation
- Load definitions from URLs or file paths
- Built-in caching for performance
- Works with any LLM framework
A full-featured Next.js chat application demonstrating UICP with Vercel AI SDK.
Features:
- Real-time chat with streaming responses
- Dynamic UI component rendering
- Two example components (SimpleCard, DataTable)
- Vercel AI SDK integration
git clone https://github.com/uicp/uicp.git
cd uicp
npm installnpm run buildcd examples/nextjs-chat
cp .env.example .env
# Add your OPENAI_API_KEY to .env
npm run devVisit http://localhost:3000 and try asking:
- "Create a card with a welcome message"
- "Show me sales data in a table"
uicp/
├── packages/
│ ├── parser/ # @uicp/parser
│ └── tools/ # @uicp/tools
└── examples/
└── nextjs-chat/ # Example Next.js app
# Build all packages
npm run build
# Build specific package
npm run build:parser
npm run build:tools
# Run example in dev mode
npm run dev:example
# Clean all builds
npm run clean
# Lint all packages
npm run lintCreate a definitions.json with your UI components:
{
"version": "1.0.0",
"components": [
{
"uid": "SimpleCard",
"type": "card",
"description": "A card component",
"componentPath": "components/uicp/simple-card",
"inputs": {
"title": {
"type": "string",
"required": true
}
}
}
]
}import { getUIComponents, createUIComponent } from '@uicp/tools';
// Discover components
const components = await getUIComponents('./definitions.json');
// Create a UICP block
const result = await createUIComponent('./definitions.json', {
uid: 'SimpleCard',
data: { title: 'Hello World' }
});import { parseUICPContent, registerComponent } from '@uicp/parser';
import { SimpleCard } from './components/simple-card';
// Register your component
registerComponent('SimpleCard', SimpleCard);
// Parse content from LLM
const parsed = await parseUICPContent(content, {
definitions: './definitions.json',
componentsBasePath: '/components/uicp'
});- Dynamic Definitions: Components are defined in JSON, allowing updates without code changes
- Framework Agnostic: Core tools work with any LLM framework (OpenAI, Anthropic, LangChain, etc.)
- Type Safe: Full TypeScript support with generated types
- Flexible Loading: Load components dynamically or pre-register for performance
- Validation: Built-in schema validation for component data
Want to test the packages locally before publishing? We've got you covered!
# Build and link packages
./scripts/link-local.sh # Unix/Mac
.\scripts\link-local.ps1 # Windows
# In your test project
cd /path/to/your/test-project
npm link @uicp/parser @uicp/tools# Terminal 1: Auto-rebuild parser
cd packages/parser && npm run dev
# Terminal 2: Auto-rebuild tools
cd packages/tools && npm run dev
# Terminal 3: Run your test project
cd /path/to/your/test-project
npm run devFor detailed testing strategies, troubleshooting, and alternative methods (npm pack, file protocol), see the Local Development Guide.
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Ensure all packages build successfully
- Submit a pull request
npm install
npm run buildMIT License - see LICENSE for details.
Built with ❤️ by the UICP community