@assistant-ui/mcp-docs-server 0.1.31 → 0.1.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.docs/organized/code-examples/waterfall.md +23 -25
- package/.docs/organized/code-examples/with-a2a.md +28 -28
- package/.docs/organized/code-examples/with-ag-ui.md +35 -30
- package/.docs/organized/code-examples/with-ai-sdk-v6.md +16 -14
- package/.docs/organized/code-examples/with-artifacts.md +44 -38
- package/.docs/organized/code-examples/with-assistant-transport.md +68 -56
- package/.docs/organized/code-examples/with-browser-extension.md +357 -0
- package/.docs/organized/code-examples/with-chain-of-thought.md +425 -90
- package/.docs/organized/code-examples/with-cloud-standalone.md +30 -29
- package/.docs/organized/code-examples/with-cloud.md +16 -14
- package/.docs/organized/code-examples/with-custom-thread-list.md +19 -17
- package/.docs/organized/code-examples/with-elevenlabs-conversational.md +29 -26
- package/.docs/organized/code-examples/with-elevenlabs-scribe.md +20 -18
- package/.docs/organized/code-examples/with-expo.md +37 -31
- package/.docs/organized/code-examples/with-external-store.md +13 -11
- package/.docs/organized/code-examples/with-ffmpeg.md +327 -290
- package/.docs/organized/code-examples/with-generative-ui.md +1195 -194
- package/.docs/organized/code-examples/with-google-adk.md +13 -11
- package/.docs/organized/code-examples/with-heat-graph.md +16 -14
- package/.docs/organized/code-examples/with-image-generation.md +456 -0
- package/.docs/organized/code-examples/with-interactables.md +322 -244
- package/.docs/organized/code-examples/with-langchain.md +18 -16
- package/.docs/organized/code-examples/with-langgraph.md +95 -88
- package/.docs/organized/code-examples/with-livekit.md +30 -27
- package/.docs/organized/code-examples/with-mcp.md +754 -0
- package/.docs/organized/code-examples/with-opencode.md +70 -70
- package/.docs/organized/code-examples/with-react-hook-form.md +24 -22
- package/.docs/organized/code-examples/with-react-ink.md +4 -4
- package/.docs/organized/code-examples/with-react-router.md +20 -18
- package/.docs/organized/code-examples/with-resumable-stream.md +661 -0
- package/.docs/organized/code-examples/with-store.md +22 -20
- package/.docs/organized/code-examples/with-tanstack.md +18 -19
- package/.docs/organized/code-examples/with-tap-runtime.md +31 -28
- package/.docs/raw/docs/(docs)/architecture.mdx +43 -2
- package/.docs/raw/docs/(docs)/cli.mdx +2 -2
- package/.docs/raw/docs/(docs)/copilots/model-context.mdx +34 -26
- package/.docs/raw/docs/(docs)/copilots/motivation.mdx +32 -26
- package/.docs/raw/docs/(docs)/index.mdx +2 -2
- package/.docs/raw/docs/(docs)/installation.mdx +2 -2
- package/.docs/raw/docs/(reference)/api-reference/adapters/attachments.mdx +26 -24
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/index.mdx +20 -12
- package/.docs/raw/docs/(reference)/api-reference/adapters/model.mdx +44 -0
- package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +41 -16
- package/.docs/raw/docs/(reference)/api-reference/adapters/runtime.mdx +12 -23
- package/.docs/raw/docs/(reference)/api-reference/adapters/suggestions.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/context-providers/assistant-runtime-provider.mdx +37 -8
- package/.docs/raw/docs/(reference)/api-reference/context-providers/index.mdx +11 -9
- package/.docs/raw/docs/(reference)/api-reference/context-providers/scoped-providers.mdx +64 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +52 -0
- package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +46 -0
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/index.mdx +18 -0
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/rendering.mdx +33 -0
- package/.docs/raw/docs/(reference)/api-reference/generative-ui/spec.mdx +45 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +98 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/index.mdx +18 -13
- package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +31 -52
- package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +640 -0
- package/.docs/raw/docs/(reference)/api-reference/hooks/runtimes.mdx +15 -28
- package/.docs/raw/docs/(reference)/api-reference/hooks/state.mdx +64 -18
- package/.docs/raw/docs/(reference)/api-reference/hooks/utilities.mdx +434 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/cloud-ai-sdk.mdx +24 -0
- package/.docs/raw/docs/(reference)/api-reference/integrations/index.mdx +11 -12
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +109 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +58 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/model-context/registry.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/overview.mdx +109 -132
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar-more.mdx +78 -221
- package/.docs/raw/docs/(reference)/api-reference/primitives/action-bar.mdx +127 -242
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-if.mdx +39 -20
- package/.docs/raw/docs/(reference)/api-reference/primitives/assistant-modal.mdx +66 -87
- package/.docs/raw/docs/(reference)/api-reference/primitives/attachment.mdx +50 -58
- package/.docs/raw/docs/(reference)/api-reference/primitives/branch-picker.mdx +80 -48
- package/.docs/raw/docs/(reference)/api-reference/primitives/chain-of-thought.mdx +67 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/composer.mdx +323 -461
- package/.docs/raw/docs/(reference)/api-reference/primitives/error.mdx +36 -43
- package/.docs/raw/docs/(reference)/api-reference/primitives/index.mdx +29 -24
- package/.docs/raw/docs/(reference)/api-reference/primitives/message-part.mdx +63 -245
- package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +202 -588
- package/.docs/raw/docs/(reference)/api-reference/primitives/queue-item.mdx +65 -0
- package/.docs/raw/docs/(reference)/api-reference/primitives/selection-toolbar.mdx +35 -22
- package/.docs/raw/docs/(reference)/api-reference/primitives/suggestion.mdx +57 -140
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item-more.mdx +70 -161
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list-item.mdx +84 -108
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread-list.mdx +77 -96
- package/.docs/raw/docs/(reference)/api-reference/primitives/thread.mdx +173 -349
- package/.docs/raw/docs/(reference)/api-reference/runtimes/assistant-runtime.mdx +9 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/attachment-runtime.mdx +10 -21
- package/.docs/raw/docs/(reference)/api-reference/runtimes/composer-runtime.mdx +15 -70
- package/.docs/raw/docs/(reference)/api-reference/runtimes/index.mdx +18 -13
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-part-runtime.mdx +25 -28
- package/.docs/raw/docs/(reference)/api-reference/runtimes/message-runtime.mdx +11 -63
- package/.docs/raw/docs/(reference)/api-reference/runtimes/queue-state.mdx +20 -0
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-item-runtime.mdx +11 -48
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-list-runtime.mdx +10 -47
- package/.docs/raw/docs/(reference)/api-reference/runtimes/thread-runtime.mdx +18 -30
- package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +85 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +39 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +127 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/status.mdx +42 -0
- package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +91 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/assistant-transport.mdx +48 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/frame.mdx +62 -0
- package/.docs/raw/docs/(reference)/api-reference/transport/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/utilities/index.mdx +19 -0
- package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +143 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/index.mdx +22 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/session.mdx +54 -0
- package/.docs/raw/docs/(reference)/api-reference/voice/speech-dictation.mdx +36 -0
- package/.docs/raw/docs/cloud/ai-sdk.mdx +1 -3
- package/.docs/raw/docs/cloud/index.mdx +2 -2
- package/.docs/raw/docs/guides/attachments.mdx +4 -4
- package/.docs/raw/docs/guides/branching.mdx +1 -1
- package/.docs/raw/docs/guides/chain-of-thought.mdx +12 -14
- package/.docs/raw/docs/guides/context-api.mdx +6 -5
- package/.docs/raw/docs/guides/dictation.mdx +2 -2
- package/.docs/raw/docs/guides/editing.mdx +1 -1
- package/.docs/raw/docs/guides/image-generation.mdx +74 -0
- package/.docs/raw/docs/guides/index.mdx +5 -14
- package/.docs/raw/docs/guides/latex.mdx +2 -2
- package/.docs/raw/docs/guides/mentions.mdx +6 -6
- package/.docs/raw/docs/guides/message-timing.mdx +38 -5
- package/.docs/raw/docs/guides/quoting.mdx +1 -1
- package/.docs/raw/docs/guides/resumable-stream-deployment.mdx +212 -0
- package/.docs/raw/docs/guides/resumable-stream-stores.mdx +152 -0
- package/.docs/raw/docs/guides/resumable-streams.mdx +210 -0
- package/.docs/raw/docs/guides/slash-commands.mdx +2 -2
- package/.docs/raw/docs/guides/speech.mdx +2 -2
- package/.docs/raw/docs/guides/suggestions.mdx +89 -5
- package/.docs/raw/docs/guides/voice.mdx +2 -2
- package/.docs/raw/docs/ink/adapters.mdx +37 -1
- package/.docs/raw/docs/ink/custom-backend.mdx +59 -8
- package/.docs/raw/docs/ink/hooks.mdx +98 -85
- package/.docs/raw/docs/ink/index.mdx +10 -11
- package/.docs/raw/docs/ink/migration.mdx +1 -1
- package/.docs/raw/docs/ink/primitives.mdx +350 -9
- package/.docs/raw/docs/integrations/auth/better-auth.mdx +1 -1
- package/.docs/raw/docs/integrations/auth/clerk.mdx +1 -1
- package/.docs/raw/docs/integrations/auth/next-auth.mdx +1 -1
- package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +3 -3
- package/.docs/raw/docs/integrations/frameworks/cloudflare-agents/overview.mdx +282 -0
- package/.docs/raw/docs/integrations/frameworks/mastra/overview.mdx +2 -2
- package/.docs/raw/docs/integrations/frameworks/mastra/separate-server.mdx +1 -1
- package/.docs/raw/docs/integrations/gateways/index.mdx +9 -4
- package/.docs/raw/docs/integrations/index.mdx +17 -5
- package/.docs/raw/docs/integrations/observability/langfuse.mdx +8 -1
- package/.docs/raw/docs/integrations/observability/langsmith.mdx +8 -4
- package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +17 -2
- package/.docs/raw/docs/migrations/toolkit-tools.mdx +226 -0
- package/.docs/raw/docs/primitives/chain-of-thought.mdx +10 -16
- package/.docs/raw/docs/primitives/composer.mdx +53 -0
- package/.docs/raw/docs/primitives/index.mdx +2 -2
- package/.docs/raw/docs/primitives/message.mdx +9 -10
- package/.docs/raw/docs/primitives/suggestion.mdx +9 -0
- package/.docs/raw/docs/react-native/hooks.mdx +57 -82
- package/.docs/raw/docs/react-native/index.mdx +4 -4
- package/.docs/raw/docs/react-native/migration.mdx +1 -1
- package/.docs/raw/docs/react-native/primitives.mdx +2 -2
- package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +7 -4
- package/.docs/raw/docs/runtimes/a2a/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ag-ui/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +32 -1
- package/.docs/raw/docs/runtimes/ai-sdk/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/ai-sdk/v4-legacy.mdx +7 -2
- package/.docs/raw/docs/runtimes/ai-sdk/v5-legacy.mdx +1 -1
- package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +129 -1
- package/.docs/raw/docs/runtimes/concepts/threads.mdx +7 -1
- package/.docs/raw/docs/runtimes/custom/data-stream.mdx +27 -2
- package/.docs/raw/docs/runtimes/custom/external-store.mdx +9 -1
- package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +18 -7
- package/.docs/raw/docs/runtimes/custom/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +108 -38
- package/.docs/raw/docs/runtimes/google-adk/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/langchain.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +1 -1
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +64 -50
- package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +98 -86
- package/.docs/raw/docs/runtimes/opencode/overview.mdx +2 -2
- package/.docs/raw/docs/runtimes/opencode/quickstart.mdx +1 -1
- package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +12 -5
- package/.docs/raw/docs/tools/backend.mdx +136 -0
- package/.docs/raw/docs/tools/defining-tools.mdx +413 -0
- package/.docs/raw/docs/tools/dynamic-tools.mdx +110 -0
- package/.docs/raw/docs/tools/generative-ui.mdx +214 -0
- package/.docs/raw/docs/tools/index.mdx +76 -0
- package/.docs/raw/docs/{guides → tools}/interactables.mdx +3 -3
- package/.docs/raw/docs/tools/mcp-apps.mdx +231 -0
- package/.docs/raw/docs/{integrations/tools → tools}/mcp.mdx +77 -50
- package/.docs/raw/docs/{guides → tools}/multi-agent.mdx +19 -21
- package/.docs/raw/docs/tools/tool-ui.mdx +967 -0
- package/.docs/raw/docs/tools/user-managed-mcp.mdx +337 -0
- package/.docs/raw/docs/ui/composer-trigger-popover.mdx +11 -1
- package/.docs/raw/docs/ui/directive-text.mdx +3 -3
- package/.docs/raw/docs/ui/mcp-config.mdx +102 -0
- package/.docs/raw/docs/ui/model-selector.mdx +8 -8
- package/.docs/raw/docs/ui/part-grouping.mdx +84 -50
- package/.docs/raw/docs/ui/reasoning.mdx +4 -5
- package/.docs/raw/docs/ui/sources.mdx +17 -0
- package/.docs/raw/docs/ui/streamdown.mdx +34 -2
- package/.docs/raw/docs/ui/thread-list.mdx +2 -2
- package/.docs/raw/docs/ui/thread.mdx +2 -2
- package/.docs/raw/docs/ui/tool-group.mdx +5 -6
- package/.docs/raw/docs/utilities/heat-graph.mdx +1 -1
- package/README.md +14 -72
- package/dist/constants.d.ts +12 -9
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +13 -9
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +25 -24
- package/dist/index.js.map +1 -1
- package/dist/prepare-docs/code-examples.d.ts +4 -1
- package/dist/prepare-docs/code-examples.d.ts.map +1 -1
- package/dist/prepare-docs/code-examples.js +109 -121
- package/dist/prepare-docs/code-examples.js.map +1 -1
- package/dist/prepare-docs/copy-raw.d.ts +4 -1
- package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
- package/dist/prepare-docs/copy-raw.js +45 -42
- package/dist/prepare-docs/copy-raw.js.map +1 -1
- package/dist/prepare-docs/prepare.d.ts +1 -2
- package/dist/prepare-docs/prepare.js +17 -17
- package/dist/prepare-docs/prepare.js.map +1 -1
- package/dist/stdio.d.ts +1 -3
- package/dist/stdio.js +6 -3
- package/dist/stdio.js.map +1 -1
- package/dist/tools/docs.d.ts +20 -15
- package/dist/tools/docs.d.ts.map +1 -1
- package/dist/tools/docs.js +140 -161
- package/dist/tools/docs.js.map +1 -1
- package/dist/tools/examples.d.ts +20 -15
- package/dist/tools/examples.d.ts.map +1 -1
- package/dist/tools/examples.js +74 -86
- package/dist/tools/examples.js.map +1 -1
- package/dist/tools/tests/test-setup.d.ts +5 -2
- package/dist/tools/tests/test-setup.d.ts.map +1 -1
- package/dist/tools/tests/test-setup.js +21 -28
- package/dist/tools/tests/test-setup.js.map +1 -1
- package/dist/utils/logger.d.ts +8 -5
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +17 -17
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/mcp-format.d.ts +8 -5
- package/dist/utils/mcp-format.d.ts.map +1 -1
- package/dist/utils/mcp-format.js +9 -9
- package/dist/utils/mcp-format.js.map +1 -1
- package/dist/utils/mdx.d.ts +8 -6
- package/dist/utils/mdx.d.ts.map +1 -1
- package/dist/utils/mdx.js +22 -22
- package/dist/utils/mdx.js.map +1 -1
- package/dist/utils/paths.d.ts +9 -6
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +66 -76
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/security.d.ts +4 -1
- package/dist/utils/security.d.ts.map +1 -1
- package/dist/utils/security.js +19 -40
- package/dist/utils/security.js.map +1 -1
- package/package.json +5 -5
- package/.docs/organized/code-examples/with-parent-id-grouping.md +0 -596
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +0 -151
- package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +0 -230
- package/.docs/raw/docs/(reference)/api-reference/adapters/feedback-speech.mdx +0 -41
- package/.docs/raw/docs/(reference)/api-reference/context-providers/text-message-part-provider.mdx +0 -40
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-data-stream.mdx +0 -260
- package/.docs/raw/docs/(reference)/api-reference/integrations/react-hook-form.mdx +0 -103
- package/.docs/raw/docs/(reference)/api-reference/integrations/vercel-ai-sdk.mdx +0 -254
- package/.docs/raw/docs/guides/tool-ui.mdx +0 -858
- package/.docs/raw/docs/guides/tools.mdx +0 -675
- package/dist/prepare-docs/prepare.d.ts.map +0 -1
- package/dist/stdio.d.ts.map +0 -1
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/deprecation-policy.mdx +0 -0
- /package/.docs/raw/docs/{(reference) → migrations}/react-compatibility.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/react-langgraph-v0-7.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-11.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-12.mdx +0 -0
- /package/.docs/raw/docs/{(reference)/migrations → migrations}/v0-14.mdx +0 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Generative UI (JSON spec)
|
|
3
|
+
description: Render agent-described React UI from a JSON spec with a consumer-provided component allowlist.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
`MessagePrimitive.GenerativeUI` is a first-class primitive for rendering UI
|
|
7
|
+
described by the agent at runtime as a JSON spec. Instead of hard-coding a
|
|
8
|
+
component per tool, the agent emits a `generative-ui` message part containing
|
|
9
|
+
a tree of components by name. assistant-ui resolves each name against a
|
|
10
|
+
**consumer-provided allowlist** and renders the result.
|
|
11
|
+
|
|
12
|
+
> The allowlist controls **which** components the agent may render: any name
|
|
13
|
+
> not in it throws a typed `GenerativeUIRenderError` (no implicit fallback). It
|
|
14
|
+
> does not constrain the props passed to those components; see [Security](#security).
|
|
15
|
+
|
|
16
|
+
> **Opt-in feature:** The default shadcn `Thread` does **not** render
|
|
17
|
+
> `generative-ui` parts. You must wire the primitive explicitly — see
|
|
18
|
+
> [Opt-in wiring](#opt-in-wiring).
|
|
19
|
+
|
|
20
|
+
## Which generative UI pattern?
|
|
21
|
+
|
|
22
|
+
assistant-ui uses "generative UI" in three different places. Pick the one that
|
|
23
|
+
matches your integration:
|
|
24
|
+
|
|
25
|
+
| Pattern | API | Best for | Streaming |
|
|
26
|
+
|---------|-----|----------|-----------|
|
|
27
|
+
| **Generative UI primitive** | `MessagePrimitive.GenerativeUI` + allowlist | Composing dashboards, cards, and layouts from a component vocabulary you ship | Native `generative-ui` parts update progressively when the part spec changes incrementally |
|
|
28
|
+
| **Tool UI** | `Tools({ toolkit })` with `render` | Interactive widgets tied to a known tool (forms, pickers, charts) | Tool **args** stream while the model fills them in |
|
|
29
|
+
| **LangGraph data UI** | `makeAssistantDataUI` + `ui_message` | LangGraph agents emitting UI via the LangGraph stream | UI messages arrive on the LangGraph custom channel |
|
|
30
|
+
|
|
31
|
+
See also: [Tool UI guide](/docs/tools/tool-ui), [LangGraph generative UI](/docs/runtimes/langgraph/generative-ui).
|
|
32
|
+
|
|
33
|
+
## When not to use the primitive
|
|
34
|
+
|
|
35
|
+
- **User input and two-way interaction** → [Tool UI](/docs/tools/tool-ui) or [Interactables](/docs/tools/interactables)
|
|
36
|
+
- **LangGraph `push_ui_message`** → [LangGraph data UI](/docs/runtimes/langgraph/generative-ui)
|
|
37
|
+
- **Untrusted HTML or third-party widgets** → [MCP Apps](/docs/tools/mcp-apps) (sandboxed frames)
|
|
38
|
+
|
|
39
|
+
## Quick start
|
|
40
|
+
|
|
41
|
+
### 1. Define your component allowlist
|
|
42
|
+
|
|
43
|
+
```tsx title="components/gui.tsx"
|
|
44
|
+
const Card = ({ title, children }) => (
|
|
45
|
+
<div className="rounded-xl border bg-card p-4 shadow-sm">
|
|
46
|
+
<div className="text-base font-semibold">{title}</div>
|
|
47
|
+
<div className="mt-2">{children}</div>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const Button = ({ label }) => (
|
|
52
|
+
<button className="rounded-md bg-primary px-3 py-1.5 text-primary-foreground">
|
|
53
|
+
{label}
|
|
54
|
+
</button>
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const componentsAllowlist = { Card, Button };
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 2. Wire the primitive into your message renderer
|
|
61
|
+
|
|
62
|
+
See [Opt-in wiring](#opt-in-wiring) for all three integration patterns.
|
|
63
|
+
|
|
64
|
+
### 3. Have the agent emit UI
|
|
65
|
+
|
|
66
|
+
**ExternalStore / manual messages** attach a native part:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
{
|
|
70
|
+
type: "generative-ui",
|
|
71
|
+
spec: {
|
|
72
|
+
root: {
|
|
73
|
+
component: "Card",
|
|
74
|
+
props: { title: "Welcome" },
|
|
75
|
+
children: [
|
|
76
|
+
{ component: "Button", props: { label: "Get started" } },
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**AI SDK (`useChatRuntime`)** — the adapter maps tool results to `tool-call`
|
|
84
|
+
parts, not `generative-ui` parts. Use the [AI SDK interim bridge](#pattern-3--ai-sdk-interim-bridge) until a native emission helper ships.
|
|
85
|
+
|
|
86
|
+
Live examples in [`examples/with-generative-ui`](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-generative-ui): Tool UI demo (`/`), static primitive (`/primitive`), GUI chat (`/gui-chat`).
|
|
87
|
+
|
|
88
|
+
## Opt-in wiring
|
|
89
|
+
|
|
90
|
+
The stock `@assistant-ui/ui` `Thread` switch returns `null` for unknown part
|
|
91
|
+
types — including `generative-ui`. Add one of these patterns in **your**
|
|
92
|
+
assistant message renderer (~15 lines).
|
|
93
|
+
|
|
94
|
+
### Pattern 1 — `MessagePrimitive.Parts`
|
|
95
|
+
|
|
96
|
+
```tsx
|
|
97
|
+
<MessagePrimitive.Parts
|
|
98
|
+
components={{
|
|
99
|
+
generativeUI: {
|
|
100
|
+
components: componentsAllowlist,
|
|
101
|
+
Fallback: UnknownComponentFallback,
|
|
102
|
+
},
|
|
103
|
+
}}
|
|
104
|
+
/>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Pattern 2 — `GroupedParts` case (shadcn Thread fork)
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
case "generative-ui":
|
|
111
|
+
return (
|
|
112
|
+
<MessagePrimitive.GenerativeUI
|
|
113
|
+
components={componentsAllowlist}
|
|
114
|
+
Fallback={UnknownComponentFallback}
|
|
115
|
+
/>
|
|
116
|
+
);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Also exclude `render_gui` from tool-group chrome in `groupBy` if you use the
|
|
120
|
+
AI SDK bridge (return `null` for that tool name).
|
|
121
|
+
|
|
122
|
+
### Pattern 3 — AI SDK interim bridge
|
|
123
|
+
|
|
124
|
+
When using `useChatRuntime`, map a dedicated tool result to the renderer:
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
case "tool-call":
|
|
128
|
+
if (part.toolName === "render_gui") {
|
|
129
|
+
const spec = parseRenderGuiResult(part.result);
|
|
130
|
+
if (spec) {
|
|
131
|
+
return (
|
|
132
|
+
<MessagePrimitive.GenerativeUI
|
|
133
|
+
spec={spec}
|
|
134
|
+
components={componentsAllowlist}
|
|
135
|
+
Fallback={UnknownComponentFallback}
|
|
136
|
+
/>
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return part.toolUI ?? <ToolFallback {...part} />;
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
The message store still holds a `tool-call` on this path — not a
|
|
144
|
+
`generative-ui` part. See `examples/with-generative-ui/app/gui-chat` for a
|
|
145
|
+
working reference.
|
|
146
|
+
|
|
147
|
+
Bare strings act as inline text leaves.
|
|
148
|
+
|
|
149
|
+
## Spec shape
|
|
150
|
+
|
|
151
|
+
```ts
|
|
152
|
+
type GenerativeUINode =
|
|
153
|
+
| string
|
|
154
|
+
| {
|
|
155
|
+
component: string; // resolved against the allowlist
|
|
156
|
+
props?: Record<string, unknown>;
|
|
157
|
+
children?: GenerativeUINode[];
|
|
158
|
+
key?: string; // optional stable React key
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
type GenerativeUISpec = {
|
|
162
|
+
root: GenerativeUINode | GenerativeUINode[];
|
|
163
|
+
};
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
The spec is plain JSON — easy for any agent to emit, and easy to validate
|
|
167
|
+
on the server before delivery.
|
|
168
|
+
|
|
169
|
+
## Streaming
|
|
170
|
+
|
|
171
|
+
When a message contains native `generative-ui` parts whose `spec` updates
|
|
172
|
+
incrementally (for example via ExternalStore), the primitive renders
|
|
173
|
+
progressively as nodes and props arrive.
|
|
174
|
+
|
|
175
|
+
The AI SDK `render_gui` tool path returns the full spec at **tool completion**
|
|
176
|
+
— not incrementally during the tool execute step. For args streaming during
|
|
177
|
+
generation, use [Tool UI](/docs/tools/tool-ui) instead.
|
|
178
|
+
|
|
179
|
+
## Security
|
|
180
|
+
|
|
181
|
+
The allowlist is the boundary on **which** components render: a spec can only instantiate components you put in the registry, with no `eval` and no dynamic import (names are looked up in the registry and nothing else). An unknown name throws `GenerativeUIRenderError` or invokes your `Fallback`.
|
|
182
|
+
|
|
183
|
+
It does **not** constrain the `props` the agent supplies. Spec props are spread directly onto your allowlisted components, so treat every allowlisted component as receiving untrusted input: never forward agent-supplied props into `dangerouslySetInnerHTML`, validate or reject `href` / `src` values (for example block `javascript:` URLs), and avoid passing spec props anywhere they become executable. The safest allowlisted components accept only primitive, display-oriented props.
|
|
184
|
+
|
|
185
|
+
## Error handling
|
|
186
|
+
|
|
187
|
+
Unknown component names throw `GenerativeUIRenderError` with a typed
|
|
188
|
+
`componentName` field. Catch it with a React error boundary, or pass a
|
|
189
|
+
`Fallback` component to opt into a soft-fail UX:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
<MessagePrimitive.GenerativeUI
|
|
193
|
+
components={componentsAllowlist}
|
|
194
|
+
Fallback={({ component }) => (
|
|
195
|
+
<span className="rounded bg-muted px-1.5 py-0.5 font-mono text-xs">
|
|
196
|
+
unknown component: {component}
|
|
197
|
+
</span>
|
|
198
|
+
)}
|
|
199
|
+
/>
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Composing with other primitives
|
|
203
|
+
|
|
204
|
+
`generative-ui` is a regular `MessagePart` type, so it composes cleanly with
|
|
205
|
+
`MessagePrimitive.Parts`, `MessagePrimitive.PartByIndex`, and
|
|
206
|
+
`MessagePrimitive.GroupedParts`. Render it alongside text, tool calls, and
|
|
207
|
+
reasoning in the same message.
|
|
208
|
+
|
|
209
|
+
## Why a primitive (not just a tool)
|
|
210
|
+
|
|
211
|
+
Tool-call UI is great when the agent already invoked a known tool. Generative
|
|
212
|
+
UI flips it: the agent _composes_ UI from a vocabulary you ship. Useful for
|
|
213
|
+
dashboards, status panels, and structured layouts — not for collecting user
|
|
214
|
+
input (use Tool UI for that).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Tools
|
|
3
|
+
description: Give the model callable capabilities with assistant-ui toolkits — define frontend, backend, human, and provider tools, render tool calls as interactive UI, and connect MCP servers.
|
|
4
|
+
platforms: ["react"]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
Tools are how the model takes action: fetch data, call an API, query a database, drive your UI, or run a workflow. In assistant-ui you declare tools in a **toolkit** — a named map where each key is the tool name the model sees and each value describes the tool's schema, where it runs, and how its call renders in the chat.
|
|
8
|
+
|
|
9
|
+
## Start here
|
|
10
|
+
|
|
11
|
+
<Cards>
|
|
12
|
+
<Card title="Defining Tools" href="/docs/tools/defining-tools">
|
|
13
|
+
Author a toolkit with the `"use generative"` directive — frontend, backend, human, and provider tools, with the schema, executor, and renderer in one file.
|
|
14
|
+
</Card>
|
|
15
|
+
<Card title="Backend Tools" href="/docs/tools/backend">
|
|
16
|
+
Wire a toolkit into your AI SDK route with `generativeTools` / `frontendTools`, mix client and server tools, and round-trip multi-modal results.
|
|
17
|
+
</Card>
|
|
18
|
+
<Card title="Tool UI" href="/docs/tools/tool-ui">
|
|
19
|
+
Render tool calls as custom components — loading and result states, human-in-the-loop, approvals, and streaming.
|
|
20
|
+
</Card>
|
|
21
|
+
<Card title="Dynamic Tools" href="/docs/tools/dynamic-tools">
|
|
22
|
+
Tools whose executor closes over React state, via `stubTool()` + `useAuiToolOverrides`.
|
|
23
|
+
</Card>
|
|
24
|
+
</Cards>
|
|
25
|
+
|
|
26
|
+
## Two ways to define a toolkit
|
|
27
|
+
|
|
28
|
+
<Callout type="info">
|
|
29
|
+
**`"use generative"` + `defineToolkit`** — for tools you author yourself
|
|
30
|
+
(browser or your own backend). The compiler co-locates the schema, executor,
|
|
31
|
+
and renderer in one file and splits them across the client/server boundary.
|
|
32
|
+
|
|
33
|
+
**Plain `satisfies Toolkit`** — for tools that already execute elsewhere (an
|
|
34
|
+
MCP server, a separate backend route, a LangGraph node) where you only attach a
|
|
35
|
+
renderer.
|
|
36
|
+
</Callout>
|
|
37
|
+
|
|
38
|
+
In a `"use generative"` file every tool declares an `execute` and the kind is
|
|
39
|
+
**inferred** from it (you never write `type`). In a plain toolkit you author
|
|
40
|
+
`type` and write render-only `{ type: "backend", render }` entries. See
|
|
41
|
+
[Defining Tools](/docs/tools/defining-tools#two-ways-to-define-a-toolkit).
|
|
42
|
+
|
|
43
|
+
## Rendering AI output as UI
|
|
44
|
+
|
|
45
|
+
assistant-ui has a few ways to turn model output into React UI. Pick by **who decides what renders**:
|
|
46
|
+
|
|
47
|
+
| You want… | Use | The decider |
|
|
48
|
+
| --- | --- | --- |
|
|
49
|
+
| A custom component for a known tool call (form, picker, chart, status) | [Tool UI](/docs/tools/tool-ui) — `render` on a toolkit entry | the **model**, by calling the tool |
|
|
50
|
+
| Persistent, out-of-thread state the AI can read and write | [Interactables](/docs/tools/interactables) | the **model + the user**, bidirectionally |
|
|
51
|
+
| UI composed from a component vocabulary you ship, described as a JSON spec | [Generative UI (JSON spec)](/docs/tools/generative-ui) — `MessagePrimitive.GenerativeUI` | the **model**, composing a tree |
|
|
52
|
+
| UI pushed by a LangGraph node alongside messages | [LangGraph Generative UI](/docs/runtimes/langgraph/generative-ui) — `makeAssistantDataUI` | the **backend / orchestrator** |
|
|
53
|
+
|
|
54
|
+
## Connect external tools
|
|
55
|
+
|
|
56
|
+
<Cards>
|
|
57
|
+
<Card title="MCP (server-side)" href="/docs/tools/mcp">
|
|
58
|
+
Wire one or more MCP servers into your API route as a tool catalog.
|
|
59
|
+
</Card>
|
|
60
|
+
<Card title="User-managed MCP" href="/docs/tools/user-managed-mcp">
|
|
61
|
+
Let end users add and authenticate MCP servers from the browser.
|
|
62
|
+
</Card>
|
|
63
|
+
<Card title="MCP Apps" href="/docs/tools/mcp-apps">
|
|
64
|
+
Render MCP UI resources (`ui://`) inline in sandboxed frames.
|
|
65
|
+
</Card>
|
|
66
|
+
<Card title="Multi-Agent" href="/docs/tools/multi-agent">
|
|
67
|
+
Render sub-agent conversations inside a tool call.
|
|
68
|
+
</Card>
|
|
69
|
+
</Cards>
|
|
70
|
+
|
|
71
|
+
## Reference & components
|
|
72
|
+
|
|
73
|
+
- [Tools API Reference](/docs/api-reference/tools) — `tool`, `Toolkit`, `Tools`, and the tool-status hooks.
|
|
74
|
+
- [`ToolFallback`](/docs/ui/tool-fallback) — a default tool card for tools with no custom UI.
|
|
75
|
+
- [`ToolGroup`](/docs/ui/tool-group) — collapse consecutive tool calls into one container.
|
|
76
|
+
- [Migrating Tools to Toolkits](/docs/migrations/toolkit-tools) — move off the deprecated `makeAssistantTool` / `useAssistantToolUI` APIs.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
|
-
title:
|
|
3
|
-
description:
|
|
2
|
+
title: Interactable Components
|
|
3
|
+
description: Build persistent UI elements whose state the AI can read and update — copilot interactables in React with assistant-ui for forms, dashboards, and tools.
|
|
4
4
|
platforms: ["react"]
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -399,5 +399,5 @@ See the complete [with-interactables example](https://github.com/assistant-ui/as
|
|
|
399
399
|
|
|
400
400
|
## Related
|
|
401
401
|
|
|
402
|
-
- [
|
|
402
|
+
- [Tool UI](/docs/tools/tool-ui) — Inline tool call UIs rendered inside messages
|
|
403
403
|
- [LangGraph Generative UI](/docs/runtimes/langgraph/generative-ui) — Structured UI components emitted by a LangGraph graph alongside messages
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: MCP Apps
|
|
3
|
+
description: Render MCP App UI resources inline in chat. Native renderer for the Model Context Protocol Apps spec — sandboxed iframes, JSON-RPC bridge, AI SDK integration.
|
|
4
|
+
platforms: ["react"]
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
[MCP Apps](https://apps.extensions.modelcontextprotocol.io/) lets a Model Context Protocol server ship a UI resource alongside a tool — a self-contained HTML widget that the chat host renders inline when the tool is called. assistant-ui ships a native renderer that mounts the widget in a sandboxed iframe via [`SafeContentFrame`](/safe-content-frame) and runs a JSON-RPC postMessage bridge so the widget can call tools, send messages, request a display mode, and read host context.
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
When an MCP server attaches a `_meta.ui.resourceUri` (the [`text/html;profile=mcp-app`](https://apps.extensions.modelcontextprotocol.io/api/index.html) MIME) to a tool, AI SDK forwards that metadata through the message stream. assistant-ui's renderer picks it up off the `mcp` field on `ToolCallMessagePart`, fetches the resource through your backend route, and mounts it.
|
|
12
|
+
|
|
13
|
+
The renderer only acts on URIs that start with `ui://` (per the MCP Apps spec). Tools whose `resourceUri` uses any other scheme are treated as non-MCP-Apps tools and fall through to your regular tool UI.
|
|
14
|
+
|
|
15
|
+
The widget communicates back through a JSON-RPC bridge:
|
|
16
|
+
|
|
17
|
+
- **widget → host requests**: `ui/initialize`, `tools/call`, `resources/read`, `resources/list`, `openLink`, `sendMessage`, `requestDisplayMode`, `updateModelContext`
|
|
18
|
+
- **host → widget notifications**: tool input streaming, tool result, host context changes
|
|
19
|
+
- **widget → host notifications**: initialized, size changed, log, error, request teardown
|
|
20
|
+
|
|
21
|
+
Capability presence is determined at mount time by which handlers you provide. Unknown methods return JSON-RPC `-32601`; bad params return `-32602`.
|
|
22
|
+
|
|
23
|
+
## Quick start
|
|
24
|
+
|
|
25
|
+
The renderer talks to a backend route you expose — the MCP client lives server-side so credentials and transport stay out of the browser. The route receives `{ method, params }` POSTs and dispatches to your MCP client.
|
|
26
|
+
|
|
27
|
+
### Client
|
|
28
|
+
|
|
29
|
+
Compose `McpAppRenderer({...})` into your `Tools` resource. Provide `host.url` pointing at your route. Any tool-call part carrying `mcp.app` metadata renders the MCP App widget automatically.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import {
|
|
33
|
+
useAui,
|
|
34
|
+
Tools,
|
|
35
|
+
McpAppRenderer,
|
|
36
|
+
McpAppsRemoteHost,
|
|
37
|
+
} from "@assistant-ui/react";
|
|
38
|
+
|
|
39
|
+
function MyAssistant() {
|
|
40
|
+
useAui({
|
|
41
|
+
tools: Tools({
|
|
42
|
+
toolkit: myToolkit,
|
|
43
|
+
mcpApp: McpAppRenderer({
|
|
44
|
+
host: McpAppsRemoteHost({ url: "/api/mcp-apps" }),
|
|
45
|
+
hostInfo: { name: "my-app", version: "1.0.0" },
|
|
46
|
+
hostContext: { theme: "light" },
|
|
47
|
+
}),
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
// ...
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`McpAppsRemoteHost` is the default host strategy — it POSTs `{ method, params }` to your route. A different strategy (e.g. a client-side MCP client) can be plugged in by writing a custom resource that returns the same `McpAppsHost` shape (`{ loadResource, callTool, readResource, listResources }`).
|
|
55
|
+
|
|
56
|
+
`openLink` is auto-wired to `window.open(url, "_blank", "noopener,noreferrer")`. `sendMessage` is auto-wired to append a user message to the current thread (accepts `string`, `{ prompt }`, `{ text }`, or `{ message }`).
|
|
57
|
+
|
|
58
|
+
### Route handler
|
|
59
|
+
|
|
60
|
+
The route accepts `POST` requests with `{ method, params }` JSON bodies. Dispatch by method name and return the result as JSON. Example for Next.js App Router:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// app/api/mcp-apps/route.ts
|
|
64
|
+
import { experimental_createMCPClient } from "ai";
|
|
65
|
+
|
|
66
|
+
let clientPromise: ReturnType<typeof experimental_createMCPClient> | undefined;
|
|
67
|
+
const getClient = () => {
|
|
68
|
+
clientPromise ??= experimental_createMCPClient({
|
|
69
|
+
transport: { type: "sse", url: process.env.MCP_SERVER_URL! },
|
|
70
|
+
});
|
|
71
|
+
return clientPromise;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export async function POST(req: Request) {
|
|
75
|
+
const { method, params } = await req.json();
|
|
76
|
+
const client = await getClient();
|
|
77
|
+
|
|
78
|
+
switch (method) {
|
|
79
|
+
case "mcp-apps/read-resource": {
|
|
80
|
+
const { contents } = await client.readResource({ uri: params.uri });
|
|
81
|
+
const c = contents.find((x: { uri: string }) => x.uri === params.uri);
|
|
82
|
+
return Response.json({
|
|
83
|
+
uri: params.uri,
|
|
84
|
+
mimeType: "text/html;profile=mcp-app",
|
|
85
|
+
html: c?.text ?? "",
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
case "tools/call": {
|
|
89
|
+
const tools = await client.tools();
|
|
90
|
+
const tool = tools[params.name];
|
|
91
|
+
if (!tool?.execute) {
|
|
92
|
+
return Response.json({ error: "Tool not callable" }, { status: 400 });
|
|
93
|
+
}
|
|
94
|
+
return Response.json(
|
|
95
|
+
await tool.execute(params.arguments ?? {}, {
|
|
96
|
+
toolCallId: `mcp-apps-bridge-${crypto.randomUUID()}`,
|
|
97
|
+
messages: [],
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
case "resources/read":
|
|
102
|
+
return Response.json(await client.readResource({ uri: params.uri }));
|
|
103
|
+
case "resources/list":
|
|
104
|
+
return Response.json(await client.listResources(params));
|
|
105
|
+
default:
|
|
106
|
+
return Response.json({ error: "Unsupported method" }, { status: 400 });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The renderer POSTs four method names: `mcp-apps/read-resource`, `tools/call`, `resources/read`, `resources/list`. Reject anything else server-side and apply your own auth / rate limiting in the route.
|
|
112
|
+
|
|
113
|
+
Per-name `setToolUI` registrations always win over the MCP fallback — you can still customize specific tools.
|
|
114
|
+
|
|
115
|
+
## AI SDK integration
|
|
116
|
+
|
|
117
|
+
`@assistant-ui/react-ai-sdk` forwards `callProviderMetadata.mcp.app` from AI SDK tool UI parts into `ToolCallMessagePart.mcp.app`. With AI SDK 5.x and an MCP-Apps-capable MCP server, no extra wiring is required on the part shape.
|
|
118
|
+
|
|
119
|
+
The rich UI comes from the MCP server's metadata, not from the model, so the path is identical whichever provider drives the conversation. Running Claude is just a different `model:` in `streamText` (`anthropic("claude-sonnet-4-6")` via `@ai-sdk/anthropic`); the MCP server, `splitMcpAppTools`, and the renderer are unchanged. MCP Apps is an open standard in the MCP ecosystem (Claude is one of its hosts), so a standard MCP-Apps server renders out of the box. The bridge below is only needed for servers that use OpenAI's `openai/outputTemplate` convention, again independent of which model you run.
|
|
120
|
+
|
|
121
|
+
On the chat route, use `splitMcpAppTools()` (from `@ai-sdk/mcp`) to keep app-only tools out of the model's view:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
import { splitMcpAppTools } from "@ai-sdk/mcp";
|
|
125
|
+
|
|
126
|
+
const tools = await client.listTools();
|
|
127
|
+
const { modelVisible } = splitMcpAppTools(tools);
|
|
128
|
+
|
|
129
|
+
const result = streamText({
|
|
130
|
+
model: openai("gpt-5.4-nano"),
|
|
131
|
+
tools: modelVisible.tools,
|
|
132
|
+
// ...
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### OpenAI Apps SDK servers
|
|
137
|
+
|
|
138
|
+
[OpenAI Apps SDK](https://developers.openai.com/apps-sdk) servers carry the same `ui://` template under a different convention: the pointer is `_meta["openai/outputTemplate"]` on the tool definition (not `_meta.ui.resourceUri`), and the resource is served as `text/html+skybridge` rather than `text/html;profile=mcp-app`. `@ai-sdk/mcp` does not recognize `openai/outputTemplate`, so it never populates `callProviderMetadata.mcp.app` and the renderer stays idle.
|
|
139
|
+
|
|
140
|
+
The renderer needs no change; you only have to surface the pointer. assistant-ui already reads `result._meta["ui/resourceUri"]` off tool results, so the smallest bridge is to copy the template onto the result by tool name. Build the map once from the tool listing, then stamp it inside each tool's `execute`:
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import type { Tool } from "ai";
|
|
144
|
+
|
|
145
|
+
// reuse the listTools() result from the AI SDK integration step above; no second round-trip
|
|
146
|
+
const templateByTool = new Map(
|
|
147
|
+
tools.tools
|
|
148
|
+
.filter((t) => typeof t._meta?.["openai/outputTemplate"] === "string")
|
|
149
|
+
.map((t) => [t.name, t._meta["openai/outputTemplate"] as string]),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const withTemplateUri = (tool: Tool, name: string): Tool => {
|
|
153
|
+
const uri = templateByTool.get(name);
|
|
154
|
+
const exec = tool.execute;
|
|
155
|
+
if (!uri || !exec) return tool;
|
|
156
|
+
return {
|
|
157
|
+
...tool,
|
|
158
|
+
execute: async (args, options) => {
|
|
159
|
+
const result = (await exec(args, options)) as { _meta?: Record<string, unknown> };
|
|
160
|
+
return { ...result, _meta: { ...result._meta, "ui/resourceUri": uri } };
|
|
161
|
+
},
|
|
162
|
+
} satisfies Tool;
|
|
163
|
+
};
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Wrap the AI SDK tool objects before handing them to `streamText`:
|
|
167
|
+
|
|
168
|
+
```ts
|
|
169
|
+
const aiTools = await client.tools();
|
|
170
|
+
const wrappedTools = Object.fromEntries(
|
|
171
|
+
Object.entries(aiTools).map(([name, t]) => [name, withTemplateUri(t, name)]),
|
|
172
|
+
);
|
|
173
|
+
// pass wrappedTools to streamText
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Your `mcp-apps/read-resource` handler reads the `ui://` resource as in the route example above. Set the response `mimeType` to the `text/html;profile=mcp-app` literal that `McpAppResource` expects and keep the server's HTML in `html`; don't forward the raw `text/html+skybridge` value, which the type rejects.
|
|
177
|
+
|
|
178
|
+
The cleaner long-term fix is upstream: if `@ai-sdk/mcp`'s `getMCPAppToolMeta` also read `openai/outputTemplate`, then `callProviderMetadata.mcp.app` would populate automatically and this bridge would be unnecessary.
|
|
179
|
+
|
|
180
|
+
## Bridge protocol
|
|
181
|
+
|
|
182
|
+
The bridge implements the MCP UI JSON-RPC protocol over `window.postMessage`, filtered by both `event.source === frame.iframe.contentWindow` AND `event.origin === frame.origin` — the cross-origin domain `SafeContentFrame` issues per render. Messages from any other origin or window are dropped silently.
|
|
183
|
+
|
|
184
|
+
### Widget → host requests
|
|
185
|
+
|
|
186
|
+
| Method | Notes |
|
|
187
|
+
|---|---|
|
|
188
|
+
| `ui/initialize` | Returns `{ protocolVersion, host, hostContext, capabilities }`. Always supported. |
|
|
189
|
+
| `tools/call` | Routed to `host.url` with method `tools/call`. Optional `handlers.allowedTools` allowlist. Invalid `arguments` shape → `-32602`. |
|
|
190
|
+
| `resources/read` | Routed to `host.url` with method `resources/read`. |
|
|
191
|
+
| `resources/list` | Routed to `host.url` with method `resources/list`. |
|
|
192
|
+
| `openLink` | Requires `handlers.openLink`. Rejects non-`http(s)` URLs with `-32602`. |
|
|
193
|
+
| `sendMessage` | Requires `handlers.sendMessage`. |
|
|
194
|
+
| `requestDisplayMode` | Requires `handlers.requestDisplayMode`. Modes: `inline`, `fullscreen`, `pip`. |
|
|
195
|
+
| `updateModelContext` | Requires `handlers.updateModelContext`. |
|
|
196
|
+
|
|
197
|
+
When a handler isn't provided, the bridge returns JSON-RPC `-32601` (method not found) — which is also how `capabilities` is reported in the `ui/initialize` response.
|
|
198
|
+
|
|
199
|
+
### Host → widget notifications
|
|
200
|
+
|
|
201
|
+
- `notifications/tools/call/input` — sent whenever `part.args` (the streaming tool input) changes
|
|
202
|
+
- `notifications/tools/call/result` — sent when the tool result lands (including error envelopes)
|
|
203
|
+
- `notifications/host_context/changed` — sent when `hostContext` changes (e.g. user toggles theme)
|
|
204
|
+
|
|
205
|
+
### Widget → host notifications
|
|
206
|
+
|
|
207
|
+
`notifications/initialized`, `notifications/size_changed`, `notifications/log`, `notifications/error`, `notifications/request_teardown` — wire them via `handlers.onInitialized`, `onSizeChange`, `onLog`, `onError`, `onRequestTeardown` respectively.
|
|
208
|
+
|
|
209
|
+
If the widget never sends `notifications/initialized` (broken or non-spec-compliant), the host flushes its queued notifications after a 5-second safety timeout so the iframe doesn't appear hung.
|
|
210
|
+
|
|
211
|
+
## Sandboxing
|
|
212
|
+
|
|
213
|
+
The iframe is built with [`SafeContentFrame`](/safe-content-frame), which serves each widget from a content-hashed cross-origin so the host page is not reachable by `same-origin` references. Default sandbox flags are `allow-same-origin allow-scripts`. Tune via the `sandbox` field on `McpAppRendererOptions`:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
McpAppRenderer({
|
|
217
|
+
// ...
|
|
218
|
+
sandbox: {
|
|
219
|
+
sandbox: ["allow-forms", "allow-popups"],
|
|
220
|
+
enableBrowserCaching: true,
|
|
221
|
+
className: "my-mcp-app",
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Security notes
|
|
227
|
+
|
|
228
|
+
- Widgets run cross-origin in a sandboxed iframe. The bridge filters incoming messages by both source window and origin.
|
|
229
|
+
- The host route is your auth boundary — apply session checks, rate limiting, and per-tool allowlists there. The renderer trusts whatever the route returns.
|
|
230
|
+
- `openLink` rejects non-`http(s)` URLs at the bridge layer, but your `openLink` handler should still treat the URL as untrusted (e.g. always use `noopener,noreferrer`).
|
|
231
|
+
- Keep `host` and `handlers` references stable across renders (e.g. module-scope constants or `useMemo`); an unstable identity will tear down and refetch the widget on every parent re-render.
|