|
39 | 39 |
|
40 | 40 | ## 💡 What's `mcp-ui`? |
41 | 41 |
|
42 | | -`mcp-ui` is a collection of SDKs comprising: |
| 42 | +`mcp-ui` is a playground for the open spec of UI over MCP. It offers a collection of community SDKs comprising: |
43 | 43 |
|
44 | 44 | * **`@mcp-ui/server` (TypeScript)**: Utilities to generate UI resources (`UIResource`) on your MCP server. |
45 | 45 | * **`@mcp-ui/client` (TypeScript)**: UI components (e.g., `<UIResourceRenderer />`) to render the UI resources and handle their events. |
@@ -143,6 +143,82 @@ Rendered using the internal `<RemoteDOMResourceRenderer />` component, which uti |
143 | 143 |
|
144 | 144 | UI snippets must be able to interact with the agent. In `mcp-ui`, this is done by hooking into events sent from the UI snippet and reacting to them in the host (see `onUIAction` prop). For example, an HTML may trigger a tool call when a button is clicked by sending an event which will be caught handled by the client. |
145 | 145 |
|
| 146 | + |
| 147 | +### Platform Adapters |
| 148 | + |
| 149 | +MCP-UI SDKs includes adapter support for host-specific implementations, enabling your open MCP-UI widgets to work seamlessly regardless of host. Adapters automatically translate between MCP-UI's `postMessage` protocol and host-specific APIs. Over time, as hosts become compatible with the open spec, these adapters wouldn't be needed. |
| 150 | + |
| 151 | +#### Available Adapters |
| 152 | + |
| 153 | +##### Apps SDK Adapter |
| 154 | + |
| 155 | +For Apps SDK environments (e.g., ChatGPT), this adapter translates MCP-UI protocol to Apps SDK API calls (e.g., `window.openai`). |
| 156 | + |
| 157 | +**How it Works:** |
| 158 | +- Intercepts MCP-UI `postMessage` calls from your widgets |
| 159 | +- Translates them to appropriate Apps SDK API calls |
| 160 | +- Handles bidirectional communication (tools, prompts, state management) |
| 161 | +- Works transparently - your existing MCP-UI code continues to work without changes |
| 162 | + |
| 163 | +**Usage:** |
| 164 | + |
| 165 | +```ts |
| 166 | +import { createUIResource } from '@mcp-ui/server'; |
| 167 | + |
| 168 | +const htmlResource = createUIResource({ |
| 169 | + uri: 'ui://greeting/1', |
| 170 | + content: { |
| 171 | + type: 'rawHtml', |
| 172 | + htmlString: ` |
| 173 | + <button onclick="window.parent.postMessage({ type: 'tool', payload: { toolName: 'myTool', params: {} } }, '*')"> |
| 174 | + Call Tool |
| 175 | + </button> |
| 176 | + ` |
| 177 | + }, |
| 178 | + encoding: 'text', |
| 179 | + // Enable adapters |
| 180 | + adapters: { |
| 181 | + appsSdk: { |
| 182 | + enabled: true, |
| 183 | + config: ... |
| 184 | + } |
| 185 | + // Future adapters can be enabled here |
| 186 | + } |
| 187 | +}); |
| 188 | +``` |
| 189 | + |
| 190 | +The adapter scripts are automatically injected into your HTML content and handle all protocol translation. |
| 191 | + |
| 192 | +**Supported Actions:** |
| 193 | +- ✅ **Tool calls** - `{ type: 'tool', payload: { toolName, params } }` |
| 194 | +- ✅ **Prompts** - `{ type: 'prompt', payload: { prompt } }` |
| 195 | +- ✅ **Intents** - `{ type: 'intent', payload: { intent, params } }` (converted to prompts) |
| 196 | +- ✅ **Notifications** - `{ type: 'notify', payload: { message } }` |
| 197 | +- ✅ **Render data** - Access to `toolInput`, `toolOutput`, `widgetState`, `theme`, `locale` |
| 198 | +- ⚠️ **Links** - `{ type: 'link', payload: { url } }` (may not be supported, returns error in some environments) |
| 199 | + |
| 200 | +#### Advanced Usage |
| 201 | + |
| 202 | +You can manually wrap HTML with adapters or access adapter scripts directly: |
| 203 | + |
| 204 | +```ts |
| 205 | +import { wrapHtmlWithAdapters, getAppsSdkAdapterScript } from '@mcp-ui/server'; |
| 206 | + |
| 207 | +// Manually wrap HTML with adapters |
| 208 | +const wrappedHtml = wrapHtmlWithAdapters( |
| 209 | + '<button>Click me</button>', |
| 210 | + { |
| 211 | + appsSdk: { |
| 212 | + enabled: true, |
| 213 | + config: { intentHandling: 'ignore' } |
| 214 | + } |
| 215 | + } |
| 216 | +); |
| 217 | + |
| 218 | +// Get a specific adapter script |
| 219 | +const appsSdkScript = getAppsSdkAdapterScript({ timeout: 60000 }); |
| 220 | +``` |
| 221 | + |
146 | 222 | ## 🏗️ Installation |
147 | 223 |
|
148 | 224 | ### TypeScript |
|
0 commit comments