@assistant-ui/mcp-docs-server 0.1.32 → 0.1.34

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.
Files changed (134) hide show
  1. package/.docs/organized/code-examples/waterfall.md +20 -22
  2. package/.docs/organized/code-examples/with-a2a.md +24 -24
  3. package/.docs/organized/code-examples/with-ag-ui.md +30 -25
  4. package/.docs/organized/code-examples/with-ai-sdk-v6.md +11 -9
  5. package/.docs/organized/code-examples/with-artifacts.md +49 -37
  6. package/.docs/organized/code-examples/with-assistant-transport.md +63 -51
  7. package/.docs/organized/code-examples/with-browser-extension.md +22 -10
  8. package/.docs/organized/code-examples/with-chain-of-thought.md +406 -87
  9. package/.docs/organized/code-examples/with-cloud-standalone.md +25 -24
  10. package/.docs/organized/code-examples/with-cloud.md +11 -9
  11. package/.docs/organized/code-examples/with-custom-thread-list.md +14 -12
  12. package/.docs/organized/code-examples/with-elevenlabs-conversational.md +23 -21
  13. package/.docs/organized/code-examples/with-elevenlabs-scribe.md +14 -13
  14. package/.docs/organized/code-examples/with-expo.md +44 -29
  15. package/.docs/organized/code-examples/with-external-store.md +9 -7
  16. package/.docs/organized/code-examples/with-ffmpeg.md +322 -285
  17. package/.docs/organized/code-examples/with-generative-ui.md +1066 -256
  18. package/.docs/organized/code-examples/with-google-adk.md +10 -8
  19. package/.docs/organized/code-examples/with-heat-graph.md +13 -11
  20. package/.docs/organized/code-examples/with-image-generation.md +19 -17
  21. package/.docs/organized/code-examples/with-interactables.md +317 -239
  22. package/.docs/organized/code-examples/with-langchain.md +14 -12
  23. package/.docs/organized/code-examples/with-langgraph.md +91 -83
  24. package/.docs/organized/code-examples/with-livekit.md +24 -22
  25. package/.docs/organized/code-examples/with-mcp.md +18 -12
  26. package/.docs/organized/code-examples/with-opencode.md +66 -66
  27. package/.docs/organized/code-examples/with-react-hook-form.md +19 -17
  28. package/.docs/organized/code-examples/with-react-ink.md +297 -102
  29. package/.docs/organized/code-examples/with-react-router.md +17 -15
  30. package/.docs/organized/code-examples/with-resumable-stream.md +15 -14
  31. package/.docs/organized/code-examples/with-store.md +78 -76
  32. package/.docs/organized/code-examples/with-tanstack.md +13 -14
  33. package/.docs/organized/code-examples/with-tap-runtime.md +26 -24
  34. package/.docs/raw/docs/(docs)/architecture.mdx +94 -42
  35. package/.docs/raw/docs/(docs)/cli.mdx +1 -2
  36. package/.docs/raw/docs/(docs)/installation.mdx +1 -1
  37. package/.docs/raw/docs/(reference)/api-reference/adapters/persistence.mdx +5 -1
  38. package/.docs/raw/docs/(reference)/api-reference/external-store/message-conversion.mdx +15 -15
  39. package/.docs/raw/docs/(reference)/api-reference/external-store/runtime.mdx +14 -1
  40. package/.docs/raw/docs/(reference)/api-reference/generative-ui/index.mdx +18 -0
  41. package/.docs/raw/docs/(reference)/api-reference/generative-ui/rendering.mdx +33 -0
  42. package/.docs/raw/docs/(reference)/api-reference/generative-ui/spec.mdx +45 -0
  43. package/.docs/raw/docs/(reference)/api-reference/hooks/composer-triggers.mdx +41 -41
  44. package/.docs/raw/docs/(reference)/api-reference/hooks/model-context.mdx +19 -1
  45. package/.docs/raw/docs/(reference)/api-reference/hooks/primitives.mdx +122 -122
  46. package/.docs/raw/docs/(reference)/api-reference/integrations/react-ai-sdk.mdx +43 -2
  47. package/.docs/raw/docs/(reference)/api-reference/model-context/context.mdx +6 -0
  48. package/.docs/raw/docs/(reference)/api-reference/overview.mdx +4 -6
  49. package/.docs/raw/docs/(reference)/api-reference/primitives/message.mdx +30 -0
  50. package/.docs/raw/docs/(reference)/api-reference/tools/component-tools.mdx +20 -3
  51. package/.docs/raw/docs/(reference)/api-reference/tools/index.mdx +8 -8
  52. package/.docs/raw/docs/(reference)/api-reference/tools/rendering.mdx +52 -4
  53. package/.docs/raw/docs/(reference)/api-reference/tools/toolkits.mdx +100 -10
  54. package/.docs/raw/docs/(reference)/api-reference/utilities/miscellaneous.mdx +7 -59
  55. package/.docs/raw/docs/cloud/ai-sdk.mdx +0 -2
  56. package/.docs/raw/docs/{(docs)/copilots → copilots}/model-context.mdx +34 -26
  57. package/.docs/raw/docs/{(docs)/copilots → copilots}/motivation.mdx +32 -26
  58. package/.docs/raw/docs/guides/chain-of-thought.mdx +7 -9
  59. package/.docs/raw/docs/guides/context-api.mdx +2 -1
  60. package/.docs/raw/docs/guides/index.mdx +3 -12
  61. package/.docs/raw/docs/guides/mentions.mdx +4 -4
  62. package/.docs/raw/docs/guides/slash-commands.mdx +1 -1
  63. package/.docs/raw/docs/guides/suggestions.mdx +1 -1
  64. package/.docs/raw/docs/ink/adapters.mdx +23 -1
  65. package/.docs/raw/docs/ink/hooks.mdx +101 -85
  66. package/.docs/raw/docs/ink/migration.mdx +1 -1
  67. package/.docs/raw/docs/ink/primitives.mdx +2 -2
  68. package/.docs/raw/docs/integrations/frameworks/ai-sdk.mdx +1 -1
  69. package/.docs/raw/docs/integrations/index.mdx +2 -2
  70. package/.docs/raw/docs/integrations/persistence/custom-adapter.mdx +17 -2
  71. package/.docs/raw/docs/migrations/toolkit-tools.mdx +232 -0
  72. package/.docs/raw/docs/primitives/chain-of-thought.mdx +10 -16
  73. package/.docs/raw/docs/primitives/message.mdx +9 -10
  74. package/.docs/raw/docs/react-native/hooks.mdx +62 -79
  75. package/.docs/raw/docs/react-native/migration.mdx +1 -1
  76. package/.docs/raw/docs/react-native/primitives.mdx +2 -2
  77. package/.docs/raw/docs/runtimes/a2a/client-and-hooks.mdx +3 -0
  78. package/.docs/raw/docs/runtimes/ag-ui/runtime-options.mdx +41 -0
  79. package/.docs/raw/docs/runtimes/ai-sdk/v6.mdx +122 -1
  80. package/.docs/raw/docs/runtimes/concepts/architecture.mdx +46 -4
  81. package/.docs/raw/docs/runtimes/concepts/threads.mdx +7 -1
  82. package/.docs/raw/docs/runtimes/custom/assistant-transport.mdx +54 -12
  83. package/.docs/raw/docs/runtimes/custom/external-store.mdx +62 -4
  84. package/.docs/raw/docs/runtimes/custom/local-runtime.mdx +30 -7
  85. package/.docs/raw/docs/runtimes/google-adk/hooks.mdx +108 -38
  86. package/.docs/raw/docs/runtimes/langgraph/generative-ui.mdx +2 -2
  87. package/.docs/raw/docs/runtimes/langgraph/streaming.mdx +14 -1
  88. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +64 -50
  89. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +98 -86
  90. package/.docs/raw/docs/tools/backend.mdx +144 -0
  91. package/.docs/raw/docs/tools/defining-tools.mdx +538 -0
  92. package/.docs/raw/docs/tools/dynamic-tools.mdx +110 -0
  93. package/.docs/raw/docs/tools/generative-ui.mdx +214 -0
  94. package/.docs/raw/docs/tools/index.mdx +71 -0
  95. package/.docs/raw/docs/{guides → tools}/interactables.mdx +1 -1
  96. package/.docs/raw/docs/{integrations/tools → tools}/mcp.mdx +145 -50
  97. package/.docs/raw/docs/{guides → tools}/multi-agent.mdx +15 -17
  98. package/.docs/raw/docs/tools/tool-ui.mdx +967 -0
  99. package/.docs/raw/docs/{integrations/tools/react-mcp.mdx → tools/user-managed-mcp.mdx} +7 -7
  100. package/.docs/raw/docs/ui/directive-text.mdx +3 -3
  101. package/.docs/raw/docs/ui/mcp-config.mdx +4 -4
  102. package/.docs/raw/docs/ui/mermaid.mdx +16 -9
  103. package/.docs/raw/docs/ui/part-grouping.mdx +84 -50
  104. package/.docs/raw/docs/ui/reasoning.mdx +4 -5
  105. package/.docs/raw/docs/ui/tool-fallback.mdx +16 -0
  106. package/.docs/raw/docs/ui/tool-group.mdx +5 -6
  107. package/.docs/raw/docs/utilities/heat-graph.mdx +1 -1
  108. package/.docs/raw/docs/utilities/react-o11y.mdx +2 -2
  109. package/dist/constants.js.map +1 -1
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js.map +1 -1
  112. package/dist/prepare-docs/code-examples.d.ts.map +1 -1
  113. package/dist/prepare-docs/code-examples.js.map +1 -1
  114. package/dist/prepare-docs/copy-raw.d.ts.map +1 -1
  115. package/dist/prepare-docs/copy-raw.js.map +1 -1
  116. package/dist/prepare-docs/prepare.js.map +1 -1
  117. package/dist/stdio.js.map +1 -1
  118. package/dist/tools/docs.js.map +1 -1
  119. package/dist/tools/examples.js.map +1 -1
  120. package/dist/tools/tests/test-setup.js.map +1 -1
  121. package/dist/utils/mdx.js.map +1 -1
  122. package/dist/utils/paths.d.ts.map +1 -1
  123. package/dist/utils/paths.js.map +1 -1
  124. package/package.json +5 -5
  125. package/.docs/organized/code-examples/with-parent-id-grouping.md +0 -596
  126. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool-ui.mdx +0 -151
  127. package/.docs/raw/docs/(docs)/copilots/make-assistant-tool.mdx +0 -230
  128. package/.docs/raw/docs/guides/generative-ui.mdx +0 -142
  129. package/.docs/raw/docs/guides/tool-ui.mdx +0 -858
  130. package/.docs/raw/docs/guides/tools.mdx +0 -736
  131. /package/.docs/raw/docs/{(docs)/copilots → copilots}/assistant-frame.mdx +0 -0
  132. /package/.docs/raw/docs/{(docs)/copilots → copilots}/make-assistant-visible.mdx +0 -0
  133. /package/.docs/raw/docs/{(docs)/copilots → copilots}/use-assistant-instructions.mdx +0 -0
  134. /package/.docs/raw/docs/{guides → tools}/mcp-apps.mdx +0 -0
@@ -0,0 +1,538 @@
1
+ ---
2
+ title: Defining Tools
3
+ description: Define tools for your AI chat with assistant-ui toolkits and the "use generative" directive — frontend, backend, human, and provider tools with type safety and streaming.
4
+ platforms: ["react"]
5
+ ---
6
+
7
+ Tools let the model take actions: 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.
8
+
9
+ This page covers how to **author** tools. To render a tool call as a custom component, see [Tool UI](/docs/tools/tool-ui). To wire tools into your server, see [Backend tools](/docs/tools/backend).
10
+
11
+ ## Define tools with `"use generative"`
12
+
13
+ Use `"use generative"` + `defineToolkit` for toolkits. The compiler co-locates
14
+ the schema, executor, and renderer in one file and splits them across the
15
+ client/server boundary for you.
16
+
17
+ <Callout type="info">
18
+ You can still use the generative toolkit pattern when a tool executes
19
+ elsewhere:
20
+
21
+ - for MCP servers, spread `defineMcpToolkit({ ... })`;
22
+ - for non-MCP tools defined by another backend or runtime, write
23
+ `execute: externalTool()` and provide a renderer.
24
+ </Callout>
25
+
26
+ In a `"use generative"` file every tool declares an `execute`, and you never
27
+ write `type` yourself — the compiler infers it. For render-only external tools,
28
+ `externalTool()` is the escape hatch that satisfies the compiler without
29
+ emitting schema or executable code on the server.
30
+
31
+ ## Quick start (`"use generative"`)
32
+
33
+ A `"use generative"` file is a single module that holds a tool's schema, its executor, and its renderer together. A build plugin splits it into a server build (schema + backend executors) and a client build (schema + renderers + browser executors), so a backend `execute` never reaches the browser and a `render` never reaches your server.
34
+
35
+ <Steps>
36
+ <Step>
37
+
38
+ ### Add the build plugin
39
+
40
+ The directive does nothing without a compiler. Wrap your Next.js config with `withAui`:
41
+
42
+ ```ts title="next.config.ts"
43
+ import { withAui } from "@assistant-ui/next";
44
+
45
+ export default withAui({
46
+ /* ...your Next config... */
47
+ });
48
+ ```
49
+
50
+ For Vite / TanStack Start, add the `aui()` plugin instead:
51
+
52
+ ```ts title="vite.config.ts"
53
+ import { aui } from "@assistant-ui/vite";
54
+
55
+ export default defineConfig({
56
+ plugins: [aui()],
57
+ });
58
+ ```
59
+
60
+ For Expo, wrap your Metro config with `withAui`:
61
+
62
+ ```js title="metro.config.js"
63
+ const { getDefaultConfig } = require("expo/metro-config");
64
+ const { withAui } = require("@assistant-ui/metro");
65
+
66
+ module.exports = withAui(getDefaultConfig(__dirname));
67
+ ```
68
+
69
+ For a bare React Native app, import `getDefaultConfig` from `@react-native/metro-config` instead of `expo/metro-config`.
70
+
71
+ </Step>
72
+ <Step>
73
+
74
+ ### Write the toolkit
75
+
76
+ The file's first line is `"use generative"`, and its default export is `defineToolkit({ ... })`. Each tool is an inline object literal with a `parameters` schema, an `execute`, and a `render` (or `renderText`):
77
+
78
+ ```tsx title="app/toolkit.tsx"
79
+ "use generative";
80
+
81
+ import { defineToolkit } from "@assistant-ui/react";
82
+ import { z } from "zod";
83
+
84
+ export default defineToolkit({
85
+ get_weather: {
86
+ description: "Get current weather for a location.",
87
+ parameters: z.object({
88
+ location: z.string().describe("City name or zip code"),
89
+ unit: z.enum(["celsius", "fahrenheit"]).default("celsius"),
90
+ }),
91
+ execute: async ({ location, unit }) => {
92
+ "use client";
93
+ return fetchWeatherAPI(location, unit);
94
+ },
95
+ render: ({ args, result }) => {
96
+ if (!result) return <div>Fetching weather for {args.location}…</div>;
97
+ return (
98
+ <div className="weather-card">
99
+ <h3>{args.location}</h3>
100
+ <p>
101
+ {result.temperature}° {args.unit}
102
+ </p>
103
+ <p>{result.conditions}</p>
104
+ </div>
105
+ );
106
+ },
107
+ },
108
+ });
109
+ ```
110
+
111
+ The inner `"use client"` inside `execute` marks this as a **frontend** tool — its executor runs in the browser. (Omit it to run on the server; see [Tool kinds](#tool-kinds).)
112
+
113
+ </Step>
114
+ <Step>
115
+
116
+ ### Register the toolkit
117
+
118
+ Import the toolkit in your runtime provider and pass it to `useAui` via `Tools`:
119
+
120
+ ```tsx title="app/MyRuntimeProvider.tsx"
121
+ "use client";
122
+
123
+ import { AssistantRuntimeProvider, Tools, useAui } from "@assistant-ui/react";
124
+ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
125
+ import toolkit from "./toolkit";
126
+
127
+ export function MyRuntimeProvider({ children }: { children: React.ReactNode }) {
128
+ const runtime = useChatRuntime({ api: "/api/chat" });
129
+ const aui = useAui({ tools: Tools({ toolkit }) });
130
+
131
+ return (
132
+ <AssistantRuntimeProvider aui={aui} runtime={runtime}>
133
+ {children}
134
+ </AssistantRuntimeProvider>
135
+ );
136
+ }
137
+ ```
138
+
139
+ </Step>
140
+ <Step>
141
+
142
+ ### Expose the toolkit to the model on your server
143
+
144
+ The same import resolves to the **server build** inside a route handler. Wrap it in an `AISDKToolkit` so the model is configured with every tool's schema:
145
+
146
+ ```ts title="app/api/chat/route.ts"
147
+ import { AISDKToolkit } from "@assistant-ui/react-ai-sdk";
148
+ import { streamText, convertToModelMessages } from "ai";
149
+ import { openai } from "@ai-sdk/openai";
150
+ import toolkit from "../../toolkit";
151
+
152
+ const aiToolkit = new AISDKToolkit({ toolkit });
153
+
154
+ export async function POST(req: Request) {
155
+ const { messages, tools } = await req.json();
156
+
157
+ const result = streamText({
158
+ model: openai("gpt-5.4-nano"),
159
+ messages: await convertToModelMessages(messages),
160
+ tools: await aiToolkit.tools({ frontend: tools }),
161
+ });
162
+
163
+ return result.toUIMessageStreamResponse();
164
+ }
165
+ ```
166
+
167
+ See [Backend tools](/docs/tools/backend) for the full server setup.
168
+
169
+ </Step>
170
+ </Steps>
171
+
172
+ ## How the compiler splits a generative file
173
+
174
+ You author one file; the plugin forks it per build target. The schema (`description` + `parameters`) is kept on **both** builds, so the model contract is identical and authoritative on the backend. The client marks its frontend/human schemas as backend-known and skips re-uploading them.
175
+
176
+ The tool's **kind is inferred from its `execute`** and written back as a `type` field — you never author `type` in a `"use generative"` file:
177
+
178
+ | `execute` you write | Inferred kind | Server build keeps | Client build keeps |
179
+ | --- | --- | --- | --- |
180
+ | plain `async () => …` | **backend** | schema + `execute` (guarded `server-only`) | schema + `render` |
181
+ | `async () => { "use client"; … }` | **frontend** | schema only | schema + `execute` + `render`/`renderText` |
182
+ | `humanTool()` | **human** | schema only | schema + `render` |
183
+ | `stubTool()` | **frontend** (executor supplied at runtime) | schema only | schema + `render`/`renderText` |
184
+ | `providerTool({ … })` | **provider** | schema + provider config | schema + provider config |
185
+ | `externalTool()` | **backend** (defined elsewhere) | omitted | `type: "backend"` + `render`/`renderText` |
186
+
187
+ The compiler also enforces, at build time:
188
+
189
+ - every tool declares an `execute`;
190
+ - a **frontend** tool declares a `render` or `renderText`;
191
+ - a **human** tool declares a `render`.
192
+
193
+ ## Tool kinds
194
+
195
+ ### Backend tools
196
+
197
+ Run on your server. Author a plain `execute` (no `"use client"`); the compiler moves it to the server build behind `import "server-only"` and keeps only the schema and `render` on the client. A backend tool can still carry a `render` to show its call as a trace:
198
+
199
+ ```tsx
200
+ geocode_location: {
201
+ description: "Geocode a location name into latitude/longitude.",
202
+ parameters: z.object({ query: z.string() }),
203
+ execute: async ({ query }) => geocodeLocation(query),
204
+ render: GeocodeToolUI,
205
+ },
206
+ ```
207
+
208
+ <Callout type="tip">
209
+ A backend tool authored this way **has** an `execute`. To attach a renderer to
210
+ a tool whose execution lives entirely elsewhere (an MCP server, a different
211
+ backend route) — where there is no real executor to write — use
212
+ `externalTool()` or `defineMcpToolkit()`.
213
+ </Callout>
214
+
215
+ ### Frontend tools
216
+
217
+ Run in the browser. Author a real `execute` with a leading `"use client"`:
218
+
219
+ ```tsx
220
+ copy_to_clipboard: {
221
+ description: "Copy text to the user's clipboard.",
222
+ parameters: z.object({ text: z.string() }),
223
+ execute: async ({ text }) => {
224
+ "use client";
225
+ await navigator.clipboard.writeText(text);
226
+ return { copied: true };
227
+ },
228
+ renderText: {
229
+ running: "Copying text…",
230
+ complete: "Copied text to clipboard",
231
+ },
232
+ },
233
+ ```
234
+
235
+ ### Human tools
236
+
237
+ Pause the run until the user supplies a result through the rendered UI. Author `execute: humanTool()` and a `render` that calls `addResult` exactly once:
238
+
239
+ ```tsx
240
+ select_date: {
241
+ description: "Ask the user to select a date.",
242
+ parameters: z.object({ prompt: z.string() }),
243
+ execute: humanTool(),
244
+ render: ({ args, result, addResult }) => {
245
+ if (result) return <p>Selected {result.date}</p>;
246
+ return (
247
+ <DatePicker
248
+ prompt={args.prompt}
249
+ onChange={(date) => addResult({ date })}
250
+ />
251
+ );
252
+ },
253
+ },
254
+ ```
255
+
256
+ `humanTool` is imported from `@assistant-ui/react`. See [Tool UI → Human-in-the-loop](/docs/tools/tool-ui#user-input-collection) for the full pattern.
257
+
258
+ ### Provider tools
259
+
260
+ Executed by the model provider (e.g. OpenAI web search). Author `execute: providerTool({ … })`; the compiler lifts the config onto the tool entry:
261
+
262
+ ```tsx
263
+ web_search: {
264
+ execute: providerTool({
265
+ providerId: "openai.web_search_preview",
266
+ args: { searchContextSize: "low" },
267
+ }),
268
+ },
269
+ ```
270
+
271
+ ### Externally defined tools
272
+
273
+ Use `externalTool()` when a non-MCP tool is already defined and executed by
274
+ another system (for example a separate backend route or LangGraph node), but you
275
+ want assistant-ui to render its tool calls. Import `externalTool` from
276
+ `@assistant-ui/react`:
277
+
278
+ ```tsx
279
+ web_search: {
280
+ parameters: z.object({ query: z.string() }),
281
+ execute: externalTool(),
282
+ render: ({ args, result }) => (
283
+ <SearchResults query={args.query} results={result?.results ?? []} />
284
+ ),
285
+ },
286
+ ```
287
+
288
+ The compiler omits this entry from the server build, so the model still gets
289
+ the tool definition from the external system. The client build keeps only
290
+ `type: "backend"` and the renderer (or `renderText`) for matching tool-call
291
+ message parts.
292
+
293
+ ### Tool stubs (supply the executor elsewhere)
294
+
295
+ Sometimes a tool's executor can't live in the build-split `"use generative"` file, usually because it has to close over React state (a `useState` setter, a ref). Declare the model-facing contract with `execute: stubTool()`, then supply the real executor at runtime with `useAuiToolOverrides` from the component that owns the state:
296
+
297
+ ```tsx title="app/toolkit.tsx"
298
+ "use generative";
299
+
300
+ import { defineToolkit, stubTool } from "@assistant-ui/react";
301
+ import { manageTasksParameters } from "./state";
302
+
303
+ export default defineToolkit({
304
+ manage_tasks: {
305
+ description: "Add, toggle, or clear tasks on the board.",
306
+ parameters: manageTasksParameters,
307
+ execute: stubTool(),
308
+ renderText: { running: "Updating tasks…", complete: "Tasks updated" },
309
+ },
310
+ });
311
+ ```
312
+
313
+ ```tsx title="app/TaskBoard.tsx"
314
+ import { useAuiToolOverrides } from "@assistant-ui/react";
315
+
316
+ function TaskBoardToolOverrides({ setTasks }) {
317
+ useAuiToolOverrides({
318
+ manage_tasks: {
319
+ execute: async ({ action, title }) => {
320
+ // close over setTasks here, then return a payload for the model
321
+ },
322
+ },
323
+ });
324
+ return null;
325
+ }
326
+ ```
327
+
328
+ `stubTool()` has no runtime implementation: it marks the executor as supplied later, while the compiler still ships the schema to the backend so the model can call the tool. The override registers above the toolkit default, so its `execute` wins for that name. To turn a tool off at runtime instead, see [Disabling a tool](#disabling-a-tool). See [Dynamic tools](/docs/tools/dynamic-tools) for the full walkthrough.
329
+
330
+ <Callout type="warn">
331
+ `useAuiToolOverrides` is experimental and its API may change.
332
+ </Callout>
333
+
334
+ ## Rendering a tool call
335
+
336
+ `render` receives the live `args`, `result`, and `status` of the call and returns a React node. For a one-line status instead of a component, use `renderText` with a `running` and/or `complete` value (each a string or an `({ args, result }) => …` function):
337
+
338
+ ```tsx
339
+ renderText: {
340
+ running: ({ args }) => `Searching for ${args.query}…`,
341
+ complete: "Search complete",
342
+ },
343
+ ```
344
+
345
+ If you don't provide a renderer, add the [`ToolFallback`](/docs/ui/tool-fallback) component to render a default tool card. The full rendering API — status states, streaming args, deferred rendering, approvals — is covered in [Tool UI](/docs/tools/tool-ui).
346
+
347
+ ## Render-only tools (for externally-executed tools)
348
+
349
+ Prefer `"use generative"` with `externalTool()` for non-MCP tools, or
350
+ `defineMcpToolkit()` for MCP servers. If a file cannot go through the generative
351
+ compiler, declare a `"use client"` toolkit object with an explicit
352
+ `type: "backend"` and only a `render`:
353
+
354
+ ```tsx title="app/tool-ui.tsx"
355
+ "use client";
356
+
357
+ import { defineToolkit } from "@assistant-ui/react";
358
+
359
+ export const toolkit = defineToolkit({
360
+ web_search: {
361
+ type: "backend",
362
+ render: ({ args, result }) => (
363
+ <SearchResults query={args.query} results={result?.results ?? []} />
364
+ ),
365
+ },
366
+ });
367
+ ```
368
+
369
+ Register it exactly like a generative toolkit: `useAui({ tools: Tools({ toolkit }) })`. The key must match the tool name your backend or MCP server publishes. Render-only entries upload no schema and run no browser code — they only attach UI to matching tool-call message parts.
370
+
371
+ <Callout type="warn">
372
+ This `{ type: "backend", render }` shape is **plain-toolkit only**. Inside a
373
+ `"use generative"` file, use `execute: externalTool()` instead; generative
374
+ tools must declare an `execute`, and you never author `type` there.
375
+ </Callout>
376
+
377
+ ## Organizing toolkits
378
+
379
+ ### Keep schemas in a separate module
380
+
381
+ Importing your Zod schemas (and the `z.infer` arg types) from a plain `.ts` file keeps them out of the compiled boundary and lets your route handler and components share the same types:
382
+
383
+ ```ts title="app/tools/schemas.ts"
384
+ import { z } from "zod";
385
+
386
+ export const getWeatherParameters = z.object({ location: z.string() });
387
+ export type GetWeatherArgs = z.infer<typeof getWeatherParameters>;
388
+ ```
389
+
390
+ ### Split tools across files and merge them
391
+
392
+ Each file you split into is its own `"use generative"` module that default-exports a `defineToolkit(...)`:
393
+
394
+ ```tsx title="app/tools/weather.tsx"
395
+ "use generative";
396
+
397
+ import { defineToolkit } from "@assistant-ui/react";
398
+
399
+ export default defineToolkit({
400
+ get_weather: {
401
+ /* description, parameters, execute, render */
402
+ },
403
+ });
404
+ ```
405
+
406
+ Merge them by spreading their default imports into a parent toolkit:
407
+
408
+ ```tsx title="app/toolkit.tsx"
409
+ "use generative";
410
+
411
+ import { defineToolkit } from "@assistant-ui/react";
412
+ import weatherTools from "./tools/weather";
413
+ import databaseTools from "./tools/database";
414
+
415
+ export default defineToolkit({
416
+ ...weatherTools,
417
+ ...databaseTools,
418
+ });
419
+ ```
420
+
421
+ The compiler splits each file across the client/server boundary on its own, then checks that the spread import resolves to a `"use generative"` module before allowing it, so a backend `execute` can't leak to the client. Two rules follow:
422
+
423
+ - **Spread a default import** (`import weatherTools from "./tools/weather"`). Relative paths and `tsconfig` path aliases like `@/tools/weather` both resolve. Only the default export crosses the generative-module boundary, so a named import (or any opaque, non-generative import) is rejected.
424
+ - You can also spread a local `defineToolkit(...)` or `defineMcpToolkit(...)` binding declared in the same file.
425
+
426
+ ### Add MCP server tools
427
+
428
+ `defineMcpToolkit` exposes tools from an MCP server. For an MCP-only toolkit, export it directly:
429
+
430
+ ```tsx title="app/mcp-toolkit.tsx"
431
+ "use generative";
432
+
433
+ import { defineMcpToolkit } from "@assistant-ui/react";
434
+
435
+ export default defineMcpToolkit({
436
+ docs: { type: "http", url: "https://mcp.example.com/mcp" },
437
+ });
438
+ ```
439
+
440
+ To expose MCP tools alongside your own, spread it into a `defineToolkit`:
441
+
442
+ ```tsx
443
+ "use generative";
444
+
445
+ import { defineToolkit, defineMcpToolkit } from "@assistant-ui/react";
446
+
447
+ export default defineToolkit({
448
+ ...defineMcpToolkit({
449
+ docs: { type: "http", url: "https://mcp.example.com/mcp" },
450
+ }),
451
+ // ...your own tools
452
+ });
453
+ ```
454
+
455
+ See [MCP](/docs/tools/mcp) for the full server-side and user-managed MCP flows.
456
+
457
+ ## Advanced
458
+
459
+ ### Multi-modal tool results
460
+
461
+ By default a tool's `execute` result is sent to the model as a JSON blob. When the useful output is a file or image, add `toModelOutput` to project the result into the multi-modal content the model sees — your `render` still receives the rich, typed `result`:
462
+
463
+ ```tsx
464
+ read_pdf: {
465
+ description: "Fetch a PDF from a URL and return it.",
466
+ parameters: z.object({ url: z.string().url() }),
467
+ execute: async ({ url }) => {
468
+ const buf = new Uint8Array(await (await fetch(url)).arrayBuffer());
469
+ return { mediaType: "application/pdf", base64: toBase64(buf) };
470
+ },
471
+ toModelOutput: ({ output }) => [
472
+ { type: "text", text: "PDF contents:" },
473
+ { type: "file", data: output.base64, mediaType: output.mediaType },
474
+ ],
475
+ },
476
+ ```
477
+
478
+ `ToolModelContentPart` is a union of `{ type: "text"; text }` and `{ type: "file"; data; mediaType; filename? }`. With the AI SDK runtime, also pass the tool registry to `convertToModelMessages` so `toModelOutput` fires on round-tripped results — see [Backend tools](/docs/tools/backend#multi-modal-results).
479
+
480
+ ### Per-tool provider options
481
+
482
+ Every tool accepts a `providerOptions` field. assistant-ui serializes it verbatim under the tool entry; the AI SDK route forwards it; the provider SDK reads the keys it cares about. This is how you opt into provider-specific behaviors (such as Anthropic's progressive tool disclosure) without provider-aware code:
483
+
484
+ ```tsx
485
+ search_docs: {
486
+ description: "Search the documentation index.",
487
+ parameters: z.object({ query: z.string() }),
488
+ providerOptions: { anthropic: { deferLoading: true } },
489
+ execute: async ({ query }) => {
490
+ "use client";
491
+ return searchIndex(query);
492
+ },
493
+ renderText: { running: "Searching…", complete: "Done" },
494
+ },
495
+ ```
496
+
497
+ The outer key is the provider name; the inner object is whatever that provider's AI SDK package expects under `tool.providerOptions[provider]`.
498
+
499
+ ### Cancellation
500
+
501
+ `execute` receives a context object whose `abortSignal` fires when the user stops the run. Pass it to any async I/O so the work stops immediately:
502
+
503
+ ```tsx
504
+ execute: async ({ query }, { abortSignal }) => {
505
+ "use client";
506
+ const res = await fetch(`/api/search?q=${query}`, { signal: abortSignal });
507
+ return res.json();
508
+ },
509
+ ```
510
+
511
+ The context also carries `toolCallId` and a `human()` function for requesting input mid-execution.
512
+
513
+ ### Streaming arguments
514
+
515
+ While a tool runs, its arguments arrive as partial JSON. Use [`useToolArgsStatus`](/docs/tools/tool-ui#field-level-streaming-state) inside a renderer to react to each field as it streams in.
516
+
517
+ ### Disabling a tool
518
+
519
+ Set `disabled: true` to keep a tool known to the client but hidden from the model in the current scope.
520
+
521
+ To toggle a tool off at runtime without editing the toolkit, register the same flag through `useAuiToolOverrides`:
522
+
523
+ ```tsx
524
+ import { useAuiToolOverrides } from "@assistant-ui/react";
525
+
526
+ function GuestModeTools() {
527
+ useAuiToolOverrides({
528
+ delete_account: { disabled: true },
529
+ });
530
+ return null;
531
+ }
532
+ ```
533
+
534
+ The override registers above the toolkit default, so the tool drops out of the set sent to the model. Mount the override only while the tool should be hidden (for example, for signed-out users); unmounting it restores the toolkit default.
535
+
536
+ ## Migrating from the component APIs
537
+
538
+ `makeAssistantTool`, `useAssistantTool`, `makeAssistantToolUI`, and `useAssistantToolUI` are deprecated. See [Migrating Tools to Toolkits](/docs/migrations/toolkit-tools) for the mechanical migration.
@@ -0,0 +1,110 @@
1
+ ---
2
+ title: Dynamic Tools
3
+ description: Tools whose executor closes over React state — declare the contract with stubTool() in a "use generative" file and supply the executor with useAuiToolOverrides.
4
+ platforms: ["react"]
5
+ ---
6
+
7
+ Most tools are static: their executor is fixed at build time. But some tools need to read or write **component state** — adding to a list the user can also edit, mutating a canvas, pre-filling a form. The executor for those has to close over a React setter, which can't live in a build-split `"use generative"` file.
8
+
9
+ The pattern: declare the model-facing **contract** in the toolkit with `execute: stubTool()`, and supply the **real executor** at runtime in the component that owns the state with `useAuiToolOverrides`.
10
+
11
+ <Callout type="warn">
12
+ `useAuiToolOverrides` is experimental and its API may change.
13
+ </Callout>
14
+
15
+ ## 1. Declare the contract with `stubTool()`
16
+
17
+ In your `"use generative"` file, give the tool its description, parameters, and renderer, and mark the executor as a stub. The compiler ships the schema to the backend and strips the stub — the model can call the tool, but nothing executes until the component supplies the real implementation. Keeping schemas in a separate non-directive module lets the component import the arg types too:
18
+
19
+ ```tsx title="app/task-board-toolkit.tsx"
20
+ "use generative";
21
+
22
+ import { defineToolkit, stubTool } from "@assistant-ui/react";
23
+ import { manageTasksParameters } from "./state";
24
+
25
+ export default defineToolkit({
26
+ manage_tasks: {
27
+ description:
28
+ 'Manage tasks on the board. Actions: "add" (requires title), ' +
29
+ '"toggle" (requires id), "remove" (requires id), "clear".',
30
+ parameters: manageTasksParameters,
31
+ execute: stubTool(),
32
+ renderText: {
33
+ running: ({ args }) => `Updating tasks: ${args.action}`,
34
+ complete: "Tasks updated",
35
+ },
36
+ },
37
+ });
38
+ ```
39
+
40
+ ## 2. Supply the executor with `useAuiToolOverrides`
41
+
42
+ The component that owns the state registers the toolkit, then renders a small null-returning child that provides the executor closing over its `setState`:
43
+
44
+ ```tsx title="app/TaskBoard.tsx"
45
+ import {
46
+ AuiProvider,
47
+ Tools,
48
+ useAui,
49
+ useAuiToolOverrides,
50
+ } from "@assistant-ui/react";
51
+ import { useState, type Dispatch, type SetStateAction } from "react";
52
+ import type { Task } from "./state";
53
+ import toolkit from "./task-board-toolkit";
54
+
55
+ function TaskBoard() {
56
+ const [tasks, setTasks] = useState<Task[]>([]);
57
+ const aui = useAui({ tools: Tools({ toolkit }) });
58
+
59
+ return (
60
+ <AuiProvider value={aui}>
61
+ <TaskBoardToolOverrides setTasks={setTasks} />
62
+ <TaskList tasks={tasks} />
63
+ </AuiProvider>
64
+ );
65
+ }
66
+
67
+ function TaskBoardToolOverrides({
68
+ setTasks,
69
+ }: {
70
+ setTasks: Dispatch<SetStateAction<Task[]>>;
71
+ }) {
72
+ useAuiToolOverrides({
73
+ manage_tasks: {
74
+ execute: async ({ action, id, title }) => {
75
+ switch (action) {
76
+ case "add":
77
+ setTasks((prev) => [
78
+ ...prev,
79
+ { id: crypto.randomUUID(), title: title ?? "Untitled", done: false },
80
+ ]);
81
+ return { success: true };
82
+ case "toggle":
83
+ setTasks((prev) =>
84
+ prev.map((t) => (t.id === id ? { ...t, done: !t.done } : t)),
85
+ );
86
+ return { success: true };
87
+ case "clear":
88
+ setTasks([]);
89
+ return { success: true };
90
+ default:
91
+ return { success: false, error: "Unknown action" };
92
+ }
93
+ },
94
+ },
95
+ });
96
+ return null;
97
+ }
98
+ ```
99
+
100
+ The override supplies **only** the `execute`; the description, parameters, and `renderText` stay in the toolkit file. An override registers above toolkit defaults, so it wins for that tool name — return a useful payload (e.g. a new item's `id`) and the model picks it up on the next turn.
101
+
102
+ <Callout type="info">
103
+ Keep the override keys stable after mount, and let only one mounted provider
104
+ define a given tool name at a time. The null-returning overrides component
105
+ re-binds the executor whenever the setter changes, without re-running `useAui`.
106
+ </Callout>
107
+
108
+ ## When to reach for this vs. Interactables
109
+
110
+ If you mainly want the model to update a piece of component state with a partial-update tool generated for you, [Interactables](/docs/tools/interactables) does that out of the box — no `stubTool` needed. Use dynamic tools when you want full control over the tool's name, schema, executor logic, and return value. The two compose: the [with-interactables example](https://github.com/assistant-ui/assistant-ui/tree/main/examples/with-interactables) uses both side by side.