Skip to content

Commit 2fef682

Browse files
refactor: new simpilfied ui builder api (#158)
* feat: Add auto-transport persistence transformation for Redis configuration * feat: Add auto-transport persistence transformation for Redis configuration * feat: Enhance multi-platform bundling with theme support and metadata injection * feat: Implement build modes for static, dynamic, and hybrid HTML generation * feat: Enhance dynamic data injection with platform-aware handling for OpenAI and non-OpenAI environments * feat: Add documentation for build modes and data injection strategies * refactor: Simplify adapter access and improve error handling in various components * refactor: Remove unused imports and simplify variable declarations across multiple files * refactor: Remove unused imports and simplify variable declarations across multiple files * refactor: Clean up unused capabilities and improve platform handling in various files * feat: Implement package allowlist functionality in TypeFetcher * refactor: Remove ngrok platform references and update platform handling * feat: Add browser-compatible UI components with esbuild integration * feat: Enable widget support for Claude Artifacts platform * feat: Add CSS to Tailwind theme conversion utility and update button styles * feat: Introduce new UI builder architecture with platform-specific preview handlers and esbuild configuration * feat: Update outline button variant styles for improved visibility and interaction * feat: Implement component name validation and sanitization to prevent code injection attacks * feat: Implement component name validation and sanitization to prevent code injection attacks
1 parent be97d34 commit 2fef682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+4119
-5957
lines changed

libs/ui/CLAUDE.md

Lines changed: 77 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
`@frontmcp/ui` provides **React components, hooks, and rendering utilities** for building interactive MCP widgets.
66

7-
This package requires React. For React-free utilities (bundling, build tools, HTML components, platform adapters), use `@frontmcp/uipack`.
7+
This package requires React. For React-free utilities (bundling, build tools, platform adapters, theme), use `@frontmcp/uipack`.
88

99
**Key Principles:**
1010

@@ -17,41 +17,55 @@ This package requires React. For React-free utilities (bundling, build tools, HT
1717

1818
```text
1919
libs/ui/src/
20+
├── bridge/ # MCP bridge runtime and adapters
21+
├── bundler/ # SSR component bundling (re-exports from uipack)
22+
├── components/ # HTML string components (button, card, etc.)
23+
├── layouts/ # Page layout templates
2024
├── react/ # React components and hooks
21-
│ ├── components/ # Button, Card, Alert, Badge, etc.
25+
│ ├── Card.tsx # Card component
26+
│ ├── Button.tsx # Button component
27+
│ ├── Alert.tsx # Alert component
28+
│ ├── Badge.tsx # Badge component
2229
│ └── hooks/ # useMcpBridge, useCallTool, useToolInput
2330
├── render/ # React 19 static rendering utilities
2431
├── renderers/ # React renderer for template processing
2532
│ ├── react.renderer.ts # SSR renderer (react-dom/server)
26-
── react.adapter.ts # Client-side hydration adapter
27-
├── bundler/ # SSR component bundling
33+
── react.adapter.ts # Client-side hydration adapter
34+
│ └── mdx.renderer.ts # MDX server-side renderer
2835
├── universal/ # Universal React app shell
36+
├── web-components/ # Custom HTML elements
2937
└── index.ts # Main barrel exports
3038
```
3139

3240
## Package Split
3341

34-
| Package | Purpose | React Required |
35-
| ------------------ | --------------------------------------------------------- | -------------- |
36-
| `@frontmcp/ui` | React components, hooks, SSR | Yes |
37-
| `@frontmcp/uipack` | Bundling, build tools, HTML components, platform adapters | No |
42+
| Package | Purpose | React Required |
43+
| ------------------ | ----------------------------------------------- | -------------- |
44+
| `@frontmcp/ui` | React components, hooks, SSR, HTML components | Yes |
45+
| `@frontmcp/uipack` | Bundling, build tools, platform adapters, theme | No |
3846

3947
### Import Patterns
4048

4149
```typescript
4250
// React components and hooks (this package)
43-
import { Button, Card, Alert } from '@frontmcp/ui/react';
44-
import { useMcpBridge, useCallTool } from '@frontmcp/ui/react/hooks';
51+
import { Button, Card, Alert, Badge } from '@frontmcp/ui/react';
52+
import { useMcpBridge, useCallTool, useToolInput } from '@frontmcp/ui/react';
4553

4654
// SSR rendering
47-
import { ReactRenderer, reactRenderer } from '@frontmcp/ui/renderers';
55+
import { ReactRenderer, reactRenderer, MdxRenderer, mdxRenderer } from '@frontmcp/ui/renderers';
4856

4957
// Universal app shell
5058
import { UniversalApp, FrontMCPProvider } from '@frontmcp/ui/universal';
5159

60+
// HTML string components
61+
import { button, card, alert, badge } from '@frontmcp/ui/components';
62+
63+
// MCP bridge
64+
import { FrontMcpBridge, createBridge } from '@frontmcp/ui/bridge';
65+
5266
// React-free utilities (from @frontmcp/uipack)
5367
import { buildToolUI } from '@frontmcp/uipack/build';
54-
import { button, card } from '@frontmcp/uipack/components';
68+
import { DEFAULT_THEME } from '@frontmcp/uipack/theme';
5569
import type { AIPlatformType } from '@frontmcp/uipack/adapters';
5670
```
5771

@@ -60,41 +74,50 @@ import type { AIPlatformType } from '@frontmcp/uipack/adapters';
6074
### Available Components
6175

6276
```typescript
63-
import {
64-
Button,
65-
Card,
66-
Alert,
67-
Badge,
68-
// ... more components
69-
} from '@frontmcp/ui/react';
77+
import { Card, Badge, Button, Alert } from '@frontmcp/ui/react';
7078

7179
// Usage
7280
<Button variant="primary" onClick={handleClick}>
7381
Submit
7482
</Button>
7583

76-
<Card title="Welcome">
84+
<Card title="Welcome" variant="elevated">
7785
<p>Card content</p>
7886
</Card>
87+
88+
<Badge variant="success">Active</Badge>
89+
90+
<Alert variant="warning" title="Warning">
91+
Please check your input
92+
</Alert>
7993
```
8094

8195
### MCP Bridge Hooks
8296

8397
```typescript
84-
import { useMcpBridge, useCallTool, useToolInput, useToolOutput } from '@frontmcp/ui/react/hooks';
98+
import {
99+
McpBridgeProvider,
100+
useMcpBridge,
101+
useCallTool,
102+
useToolInput,
103+
useToolOutput,
104+
useTheme,
105+
} from '@frontmcp/ui/react';
85106

86107
function MyWidget() {
87-
const bridge = useMcpBridge();
88-
const { call, loading, error } = useCallTool();
89-
const input = useToolInput();
90-
const output = useToolOutput();
108+
const input = useToolInput<{ location: string }>();
109+
const theme = useTheme();
110+
const [getWeather, { data, loading }] = useCallTool('get_weather');
91111

112+
return <Card title={`Weather for ${input?.location}`}>{loading ? 'Loading...' : data?.temperature}</Card>;
113+
}
114+
115+
// Wrap your app with the provider
116+
function App() {
92117
return (
93-
<div>
94-
<p>Input: {JSON.stringify(input)}</p>
95-
<p>Output: {JSON.stringify(output)}</p>
96-
<button onClick={() => call('my-tool', { data: 'test' })}>Call Tool</button>
97-
</div>
118+
<McpBridgeProvider>
119+
<MyWidget />
120+
</McpBridgeProvider>
98121
);
99122
}
100123
```
@@ -110,6 +133,15 @@ import { ReactRenderer, reactRenderer } from '@frontmcp/ui/renderers';
110133
const html = await reactRenderer.render(MyComponent, context);
111134
```
112135

136+
### MDX Server Rendering
137+
138+
```typescript
139+
import { MdxRenderer, mdxRenderer } from '@frontmcp/ui/renderers';
140+
141+
// Render MDX to HTML with React components
142+
const html = await mdxRenderer.render('# Hello {output.name}', context);
143+
```
144+
113145
### Client-Side Hydration
114146

115147
```typescript
@@ -145,6 +177,8 @@ function App() {
145177

146178
## SSR Bundling
147179

180+
The bundler re-exports utilities from `@frontmcp/uipack/bundler`:
181+
148182
```typescript
149183
import { InMemoryBundler, createBundler } from '@frontmcp/ui/bundler';
150184

@@ -178,15 +212,18 @@ const result = await bundler.bundle(componentPath);
178212

179213
## Entry Points
180214

181-
| Path | Purpose |
182-
| -------------------------- | ------------------------------------------ |
183-
| `@frontmcp/ui` | Main exports (React components, renderers) |
184-
| `@frontmcp/ui/react` | React components |
185-
| `@frontmcp/ui/react/hooks` | MCP bridge hooks |
186-
| `@frontmcp/ui/renderers` | ReactRenderer, ReactRendererAdapter |
187-
| `@frontmcp/ui/render` | React 19 static rendering |
188-
| `@frontmcp/ui/universal` | Universal app shell |
189-
| `@frontmcp/ui/bundler` | SSR component bundler |
215+
| Path | Purpose |
216+
| ----------------------------- | ------------------------------------------ |
217+
| `@frontmcp/ui` | Main exports (React components, renderers) |
218+
| `@frontmcp/ui/react` | React components and hooks |
219+
| `@frontmcp/ui/renderers` | ReactRenderer, MdxRenderer, adapters |
220+
| `@frontmcp/ui/render` | React 19 static rendering |
221+
| `@frontmcp/ui/universal` | Universal app shell |
222+
| `@frontmcp/ui/bundler` | SSR component bundler |
223+
| `@frontmcp/ui/bridge` | MCP bridge runtime |
224+
| `@frontmcp/ui/components` | HTML string components |
225+
| `@frontmcp/ui/layouts` | Page layout templates |
226+
| `@frontmcp/ui/web-components` | Custom HTML elements |
190227

191228
## Anti-Patterns to Avoid
192229

@@ -198,6 +235,6 @@ const result = await bundler.bundle(componentPath);
198235

199236
## Related Packages
200237

201-
- **@frontmcp/uipack** - React-free bundling, build tools, HTML components
238+
- **@frontmcp/uipack** - React-free bundling, build tools, theme, platform adapters
202239
- **@frontmcp/sdk** - Core FrontMCP SDK
203240
- **@frontmcp/testing** - E2E testing utilities

libs/ui/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"dependencies": {
5858
"@mdx-js/mdx": "^3.1.1",
5959
"@swc/core": "^1.5.0",
60-
"enclave-vm": "^1.0.3",
6160
"esbuild": "^0.27.1",
6261
"zod": "^4.0.0"
6362
},

libs/ui/project.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,11 @@
2525
"libs/ui/src/bundler/index.ts",
2626
"libs/ui/src/components/index.ts",
2727
"libs/ui/src/layouts/index.ts",
28-
"libs/ui/src/pages/index.ts",
2928
"libs/ui/src/react/index.ts",
3029
"libs/ui/src/render/index.ts",
3130
"libs/ui/src/renderers/index.ts",
3231
"libs/ui/src/universal/index.ts",
33-
"libs/ui/src/web-components/index.ts",
34-
"libs/ui/src/widgets/index.ts"
32+
"libs/ui/src/web-components/index.ts"
3533
],
3634
"esbuildOptions": {
3735
"outExtension": { ".js": ".js" },
@@ -63,13 +61,11 @@
6361
"libs/ui/src/bundler/index.ts",
6462
"libs/ui/src/components/index.ts",
6563
"libs/ui/src/layouts/index.ts",
66-
"libs/ui/src/pages/index.ts",
6764
"libs/ui/src/react/index.ts",
6865
"libs/ui/src/render/index.ts",
6966
"libs/ui/src/renderers/index.ts",
7067
"libs/ui/src/universal/index.ts",
71-
"libs/ui/src/web-components/index.ts",
72-
"libs/ui/src/widgets/index.ts"
68+
"libs/ui/src/web-components/index.ts"
7369
],
7470
"esbuildOptions": {
7571
"outExtension": { ".js": ".mjs" },

libs/ui/src/bridge/__tests__/iife-generator.test.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
* IIFE Generator Tests
33
*/
44

5-
import {
6-
generateBridgeIIFE,
7-
generatePlatformBundle,
8-
UNIVERSAL_BRIDGE_SCRIPT,
9-
BRIDGE_SCRIPT_TAGS,
10-
} from '../runtime/iife-generator';
5+
import { generateBridgeIIFE, generatePlatformBundle, UNIVERSAL_BRIDGE_SCRIPT, BRIDGE_SCRIPT_TAGS } from '../runtime';
116

127
describe('IIFE Generator', () => {
138
describe('generateBridgeIIFE', () => {

libs/ui/src/bridge/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ export { GenericAdapter, createGenericAdapter } from './adapters/generic.adapter
102102

103103
export { registerBuiltInAdapters } from './adapters';
104104

105-
// Runtime
105+
// Runtime - Re-exported from @frontmcp/uipack (single source of truth)
106106
export {
107107
generateBridgeIIFE,
108108
generatePlatformBundle,
109109
UNIVERSAL_BRIDGE_SCRIPT,
110110
BRIDGE_SCRIPT_TAGS,
111111
type IIFEGeneratorOptions,
112-
} from './runtime/iife-generator';
112+
} from './runtime';

0 commit comments

Comments
 (0)