The UI Affordance Registration Framework has been successfully implemented with full support for dynamic component loading from any source (MCP files, local files, etc.).
- Central registry for all UI affordances
- Handles component lifecycle (register, mount, unmount)
- Supports loading from MCP sources (like
js_exec
tool) - Fallback to local files when MCP unavailable
- Comprehensive error handling and validation
- OverlayContainer - Modal/popup overlays with backdrop
- SidebarContainer - Collapsible side panels with toggle buttons
- HeaderContainer - Fixed header extensions with priority ordering
- FooterContainer - Footer extensions alongside existing controls
- InlineContainer - Chat-embedded components
register_affordance
- Register components from any sourcecall_affordance_method
- Invoke component methods safelyunregister_affordance
- Remove components cleanlylist_affordances
- List all active affordances
- Primary: MCP file sources using
files-get
tool - Fallback: Local project files
- Pattern: Follows same approach as
js_exec
tool
interface AffordanceComponent {
mount(container: HTMLElement, config: AffordanceConfig): Promise<void>;
unmount(): Promise<void>;
getPublicMethods(): Record<string, Function>;
[customMethod: string]: any;
}
- Overlay: Modal dialogs, forms, image viewers
- Sidebar: Tool palettes, dashboards, navigation
- Header: Status indicators, breadcrumbs, quick actions
- Footer: Progress bars, status info, quick stats
- Inline: Widgets, charts, interactive content
const id = await register_affordance('overlay', 'test-component.js', {
title: 'Test Widget'
});
await call_affordance_method(id, 'ping', []); // Returns "pong!"
const id = await register_affordance('sidebar', 'counter.js', {
title: 'Counter', position: 'right', initialValue: 10
});
await call_affordance_method(id, 'increment', [5]); // Increment by 5
const id = await register_affordance('sidebar', 'dashboard.js', {
title: 'System Status', width: '350px'
});
await call_affordance_method(id, 'addItem', [{
id: 'cpu', label: 'CPU Usage', value: '45%', status: 'success'
}]);
const id = await register_affordance('overlay', 'notifications.js', {
position: 'top', maxNotifications: 10
});
await call_affordance_method(id, 'addNotification', [{
title: 'Success', message: 'Task completed!', type: 'success'
}]);
// 1. Create component using MCP tools
await files_create('components/my-widget.js', componentCode);
// 2. Register the component
const id = await register_affordance('sidebar', 'components/my-widget.js', {
title: 'My Widget', position: 'right'
});
// 3. Interact with component
const methods = await call_affordance_method(id, 'getPublicMethods', []);
await call_affordance_method(id, 'updateData', [newData]);
const id = await register_affordance('overlay',
'/frontend/components/affordances/TestAffordance.tsx',
{ title: 'Local Test' }
);
- File source validation (MCP โ local fallback)
- Module import validation with helpful error messages
- Component interface validation
- Runtime error catching and reporting
- "Failed to import module" โ Syntax error guidance
- "No component found" โ Export structure guidance
- "Component must implement X method" โ Interface requirement guidance
- AFFORDANCE-FRAMEWORK.md - Complete framework overview
- AFFORDANCE-COMPONENT-GUIDE.md - Component development guide
- Clear guidance on file requirements
- Examples of MCP vs local file usage
- Container type explanations
- Configuration options documentation
- Client Tools: New affordance tools added to existing system
- Styling: Uses existing CSS custom properties and design tokens
- Layout: Containers respect existing layout without interference
- Performance: Lazy loading and efficient lifecycle management
- Follows same pattern as
js_exec
tool - Uses
files-get
for MCP file loading - Graceful fallback to local files
- Consistent error handling approach
The framework is now fully operational and ready for the assistant to use. Key capabilities:
- Dynamic Component Registration - Load any JavaScript/TypeScript component from MCP or local sources
- Multiple Container Types - Choose the right UI container for each use case
- Safe Method Invocation - Call component methods with error handling
- Lifecycle Management - Proper mounting, unmounting, and cleanup
- Comprehensive Documentation - Clear guides for component development
โ
Flexible Source Loading - Components can be loaded from any source
โ
Standardized Interface - Consistent component interface
โ
Multiple Container Types - Overlay, sidebar, header, footer, inline
โ
Method Invocation - Safe method calls with error handling
โ
Error Handling - Comprehensive validation and helpful messages
โ
Documentation - Complete guides and examples
โ
Integration - Seamless integration with existing system
The UI Affordance Framework is now ready for production use! ๐