@assistant-ui/mcp-docs-server 0.1.1

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 (109) hide show
  1. package/.docs/organized/code-examples/local-ollama.md +1135 -0
  2. package/.docs/organized/code-examples/search-agent-for-e-commerce.md +1721 -0
  3. package/.docs/organized/code-examples/with-ai-sdk.md +1081 -0
  4. package/.docs/organized/code-examples/with-cloud.md +1164 -0
  5. package/.docs/organized/code-examples/with-external-store.md +1064 -0
  6. package/.docs/organized/code-examples/with-ffmpeg.md +1305 -0
  7. package/.docs/organized/code-examples/with-langgraph.md +1819 -0
  8. package/.docs/organized/code-examples/with-openai-assistants.md +1175 -0
  9. package/.docs/organized/code-examples/with-react-hook-form.md +1727 -0
  10. package/.docs/organized/code-examples/with-vercel-ai-rsc.md +1157 -0
  11. package/.docs/raw/blog/2024-07-29-hello/index.mdx +65 -0
  12. package/.docs/raw/blog/2024-09-11/index.mdx +10 -0
  13. package/.docs/raw/blog/2024-12-15/index.mdx +10 -0
  14. package/.docs/raw/blog/2025-01-31-changelog/index.mdx +129 -0
  15. package/.docs/raw/docs/about-assistantui.mdx +44 -0
  16. package/.docs/raw/docs/api-reference/context-providers/AssistantRuntimeProvider.mdx +30 -0
  17. package/.docs/raw/docs/api-reference/context-providers/TextContentPartProvider.mdx +26 -0
  18. package/.docs/raw/docs/api-reference/integrations/react-hook-form.mdx +103 -0
  19. package/.docs/raw/docs/api-reference/integrations/vercel-ai-sdk.mdx +145 -0
  20. package/.docs/raw/docs/api-reference/overview.mdx +583 -0
  21. package/.docs/raw/docs/api-reference/primitives/ActionBar.mdx +264 -0
  22. package/.docs/raw/docs/api-reference/primitives/AssistantModal.mdx +129 -0
  23. package/.docs/raw/docs/api-reference/primitives/Attachment.mdx +96 -0
  24. package/.docs/raw/docs/api-reference/primitives/BranchPicker.mdx +87 -0
  25. package/.docs/raw/docs/api-reference/primitives/Composer.mdx +204 -0
  26. package/.docs/raw/docs/api-reference/primitives/ContentPart.mdx +173 -0
  27. package/.docs/raw/docs/api-reference/primitives/Error.mdx +70 -0
  28. package/.docs/raw/docs/api-reference/primitives/Message.mdx +181 -0
  29. package/.docs/raw/docs/api-reference/primitives/Thread.mdx +197 -0
  30. package/.docs/raw/docs/api-reference/primitives/composition.mdx +21 -0
  31. package/.docs/raw/docs/api-reference/runtimes/AssistantRuntime.mdx +33 -0
  32. package/.docs/raw/docs/api-reference/runtimes/AttachmentRuntime.mdx +46 -0
  33. package/.docs/raw/docs/api-reference/runtimes/ComposerRuntime.mdx +69 -0
  34. package/.docs/raw/docs/api-reference/runtimes/ContentPartRuntime.mdx +22 -0
  35. package/.docs/raw/docs/api-reference/runtimes/MessageRuntime.mdx +49 -0
  36. package/.docs/raw/docs/api-reference/runtimes/ThreadListItemRuntime.mdx +32 -0
  37. package/.docs/raw/docs/api-reference/runtimes/ThreadListRuntime.mdx +31 -0
  38. package/.docs/raw/docs/api-reference/runtimes/ThreadRuntime.mdx +48 -0
  39. package/.docs/raw/docs/architecture.mdx +92 -0
  40. package/.docs/raw/docs/cloud/authorization.mdx +152 -0
  41. package/.docs/raw/docs/cloud/overview.mdx +55 -0
  42. package/.docs/raw/docs/cloud/persistence/ai-sdk.mdx +54 -0
  43. package/.docs/raw/docs/cloud/persistence/langgraph.mdx +123 -0
  44. package/.docs/raw/docs/concepts/architecture.mdx +19 -0
  45. package/.docs/raw/docs/concepts/runtime-layer.mdx +163 -0
  46. package/.docs/raw/docs/concepts/why.mdx +9 -0
  47. package/.docs/raw/docs/copilots/make-assistant-readable.mdx +71 -0
  48. package/.docs/raw/docs/copilots/make-assistant-tool-ui.mdx +76 -0
  49. package/.docs/raw/docs/copilots/make-assistant-tool.mdx +117 -0
  50. package/.docs/raw/docs/copilots/model-context.mdx +135 -0
  51. package/.docs/raw/docs/copilots/motivation.mdx +191 -0
  52. package/.docs/raw/docs/copilots/use-assistant-instructions.mdx +62 -0
  53. package/.docs/raw/docs/getting-started.mdx +1133 -0
  54. package/.docs/raw/docs/guides/Attachments.mdx +640 -0
  55. package/.docs/raw/docs/guides/Branching.mdx +59 -0
  56. package/.docs/raw/docs/guides/Editing.mdx +56 -0
  57. package/.docs/raw/docs/guides/Speech.mdx +43 -0
  58. package/.docs/raw/docs/guides/ToolUI.mdx +663 -0
  59. package/.docs/raw/docs/guides/Tools.mdx +496 -0
  60. package/.docs/raw/docs/index.mdx +7 -0
  61. package/.docs/raw/docs/legacy/styled/AssistantModal.mdx +85 -0
  62. package/.docs/raw/docs/legacy/styled/Decomposition.mdx +633 -0
  63. package/.docs/raw/docs/legacy/styled/Markdown.mdx +86 -0
  64. package/.docs/raw/docs/legacy/styled/Scrollbar.mdx +71 -0
  65. package/.docs/raw/docs/legacy/styled/Thread.mdx +84 -0
  66. package/.docs/raw/docs/legacy/styled/ThreadWidth.mdx +21 -0
  67. package/.docs/raw/docs/mcp-docs-server.mdx +324 -0
  68. package/.docs/raw/docs/migrations/deprecation-policy.mdx +41 -0
  69. package/.docs/raw/docs/migrations/v0-7.mdx +188 -0
  70. package/.docs/raw/docs/migrations/v0-8.mdx +160 -0
  71. package/.docs/raw/docs/migrations/v0-9.mdx +75 -0
  72. package/.docs/raw/docs/react-compatibility.mdx +208 -0
  73. package/.docs/raw/docs/runtimes/ai-sdk/rsc.mdx +226 -0
  74. package/.docs/raw/docs/runtimes/ai-sdk/use-assistant-hook.mdx +195 -0
  75. package/.docs/raw/docs/runtimes/ai-sdk/use-chat-hook.mdx +138 -0
  76. package/.docs/raw/docs/runtimes/ai-sdk/use-chat.mdx +136 -0
  77. package/.docs/raw/docs/runtimes/custom/external-store.mdx +1624 -0
  78. package/.docs/raw/docs/runtimes/custom/local.mdx +1185 -0
  79. package/.docs/raw/docs/runtimes/helicone.mdx +60 -0
  80. package/.docs/raw/docs/runtimes/langgraph/index.mdx +320 -0
  81. package/.docs/raw/docs/runtimes/langgraph/tutorial/index.mdx +11 -0
  82. package/.docs/raw/docs/runtimes/langgraph/tutorial/introduction.mdx +28 -0
  83. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-1.mdx +120 -0
  84. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-2.mdx +336 -0
  85. package/.docs/raw/docs/runtimes/langgraph/tutorial/part-3.mdx +385 -0
  86. package/.docs/raw/docs/runtimes/langserve.mdx +126 -0
  87. package/.docs/raw/docs/runtimes/mastra/full-stack-integration.mdx +218 -0
  88. package/.docs/raw/docs/runtimes/mastra/overview.mdx +17 -0
  89. package/.docs/raw/docs/runtimes/mastra/separate-server-integration.mdx +196 -0
  90. package/.docs/raw/docs/runtimes/pick-a-runtime.mdx +222 -0
  91. package/.docs/raw/docs/ui/AssistantModal.mdx +46 -0
  92. package/.docs/raw/docs/ui/AssistantSidebar.mdx +42 -0
  93. package/.docs/raw/docs/ui/Attachment.mdx +82 -0
  94. package/.docs/raw/docs/ui/Markdown.mdx +72 -0
  95. package/.docs/raw/docs/ui/Mermaid.mdx +79 -0
  96. package/.docs/raw/docs/ui/Scrollbar.mdx +59 -0
  97. package/.docs/raw/docs/ui/SyntaxHighlighting.mdx +253 -0
  98. package/.docs/raw/docs/ui/Thread.mdx +47 -0
  99. package/.docs/raw/docs/ui/ThreadList.mdx +49 -0
  100. package/.docs/raw/docs/ui/ToolFallback.mdx +64 -0
  101. package/.docs/raw/docs/ui/primitives/Thread.mdx +197 -0
  102. package/LICENSE +21 -0
  103. package/README.md +128 -0
  104. package/dist/chunk-C7O7EFKU.js +38 -0
  105. package/dist/chunk-CZCDQ3YH.js +420 -0
  106. package/dist/index.js +1 -0
  107. package/dist/prepare-docs/prepare.js +199 -0
  108. package/dist/stdio.js +8 -0
  109. package/package.json +43 -0
@@ -0,0 +1,496 @@
1
+ ---
2
+ title: Tools
3
+ ---
4
+
5
+ Tools enable LLMs to take actions and interact with external systems. assistant-ui provides a comprehensive toolkit for creating, managing, and visualizing tool interactions in real-time.
6
+
7
+ ## Overview
8
+
9
+ Tools in assistant-ui are functions that the LLM can call to perform specific tasks. They bridge the gap between the LLM's reasoning capabilities and real-world actions like:
10
+
11
+ - Fetching data from APIs
12
+ - Performing calculations
13
+ - Interacting with databases
14
+ - Controlling UI elements
15
+ - Executing workflows
16
+
17
+ When tools are executed, you can display custom generative UI components that provide rich, interactive visualizations of the tool's execution and results. Learn more in the [Generative UI guide](/docs/guides/ToolUI).
18
+
19
+ <Callout type="tip">
20
+ If you haven't provided a custom UI for a tool, assistant-ui offers a [`ToolFallback`](/docs/ui/ToolFallback) component that you can add to your codebase to render a default UI for tool executions. You can customize this by creating your own Tool UI component for the tool's name.
21
+ </Callout>
22
+
23
+ ## Tool Creation Methods
24
+
25
+ assistant-ui offers multiple ways to create and register tools, each suited for different use cases:
26
+
27
+ - **`makeAssistantTool`**: Register client-defined tools with the assistant context
28
+ - **`useAssistantTool`**: Hook-based dynamic tool registration
29
+ - **`makeAssistantToolUI`**: UI-only components for existing tools
30
+ - **Direct context registration**: Advanced registration with full model context control
31
+
32
+ ### 1. Using `makeAssistantTool`
33
+
34
+ Register tools with the assistant context. Returns a React component that registers the tool when rendered:
35
+
36
+ ```tsx
37
+ import { makeAssistantTool, tool } from "@assistant-ui/react";
38
+ import { z } from "zod";
39
+
40
+ // Define the tool
41
+ const weatherTool = tool({
42
+ description: "Get current weather for a location",
43
+ parameters: z.object({
44
+ location: z.string().describe("City name or zip code"),
45
+ unit: z.enum(["celsius", "fahrenheit"]).default("celsius")
46
+ }),
47
+ execute: async ({ location, unit }) => {
48
+ // Tool execution logic
49
+ const weather = await fetchWeatherAPI(location, unit);
50
+ return weather;
51
+ }
52
+ });
53
+
54
+ // Create the component
55
+ const WeatherTool = makeAssistantTool(weatherTool);
56
+
57
+ // Place the tool component inside AssistantRuntimeProvider
58
+ function App() {
59
+ return (
60
+ <AssistantRuntimeProvider runtime={runtime}>
61
+ <WeatherTool />
62
+ <Thread />
63
+ </AssistantRuntimeProvider>
64
+ );
65
+ }
66
+ ```
67
+
68
+ <Callout type="tip">
69
+ When using server-side runtimes like Vercel AI SDK, you can pass client-defined tools to your backend using `frontendTools`. See the [Client-Defined Tools with frontendTools](#client-defined-tools-with-frontendtools) section below.
70
+ </Callout>
71
+
72
+ ### 2. Using `useAssistantTool` Hook
73
+
74
+ Register tools dynamically using React hooks. Useful for conditional tools or when tool availability depends on component state:
75
+
76
+ ```tsx
77
+ import { useAssistantTool } from "@assistant-ui/react";
78
+ import { z } from "zod";
79
+
80
+ function DynamicTools() {
81
+ const [dataSource, setDataSource] = useState<"local" | "cloud">("local");
82
+
83
+ useAssistantTool({
84
+ toolName: "searchData",
85
+ description: "Search through the selected data source",
86
+ parameters: z.object({
87
+ query: z.string()
88
+ }),
89
+ execute: async ({ query }) => {
90
+ if (dataSource === "local") {
91
+ return await searchLocalDatabase(query);
92
+ } else {
93
+ return await searchCloudDatabase(query);
94
+ }
95
+ },
96
+ // Re-register when data source changes
97
+ enabled: true
98
+ });
99
+
100
+ return null;
101
+ }
102
+ ```
103
+
104
+ ### 3. Using `makeAssistantToolUI`
105
+
106
+ Create generative UI components for tools that are defined elsewhere. This is UI-only - the tool's execution logic must be registered separately (e.g., in your backend, MCP server, or another component):
107
+
108
+ <Callout type="note">
109
+ This creates only the UI component. The actual tool execution happens where you've defined it (typically in your API route with server-based runtimes like Vercel AI SDK).
110
+ </Callout>
111
+
112
+ ```tsx
113
+ import { makeAssistantToolUI, AssistantToolUI } from "@assistant-ui/react";
114
+
115
+ const SearchResultsUI = makeAssistantToolUI<{
116
+ query: string;
117
+ }, {
118
+ results: Array<{
119
+ id: string;
120
+ url: string;
121
+ title: string;
122
+ snippet: string;
123
+ }>;
124
+ }>({
125
+ toolName: "webSearch", // Must match the registered tool's name
126
+ render: ({ args, result }) => {
127
+ return (
128
+ <div className="search-results">
129
+ <h3>Search: {args.query}</h3>
130
+ {result.results.map((item) => (
131
+ <div key={item.id}>
132
+ <a href={item.url}>{item.title}</a>
133
+ <p>{item.snippet}</p>
134
+ </div>
135
+ ))}
136
+ </div>
137
+ );
138
+ }
139
+ });
140
+
141
+ // Place the tool component inside AssistantRuntimeProvider
142
+ function App() {
143
+ return (
144
+ <AssistantRuntimeProvider runtime={runtime}>
145
+ <SearchResultsUI />
146
+ <Thread />
147
+ </AssistantRuntimeProvider>
148
+ );
149
+ }
150
+ ```
151
+
152
+ ### 4. Advanced: Direct Context Registration
153
+
154
+ Use `registerModelContextProvider` when you need to configure more than just tools:
155
+
156
+ ```tsx
157
+ import { tool, useAssistantRuntime } from "@assistant-ui/react";
158
+ import { useEffect, useState } from "react";
159
+ import { z } from "zod";
160
+
161
+ function MyComponent() {
162
+ const runtime = useAssistantRuntime();
163
+ const [isCreativeMode, setIsCreativeMode] = useState(false);
164
+
165
+ useEffect(() => {
166
+ const calculateTool = tool({
167
+ description: "Perform mathematical calculations",
168
+ parameters: z.object({
169
+ expression: z.string()
170
+ }),
171
+ execute: async ({ expression }) => {
172
+ return eval(expression); // Note: Use proper math parser in production
173
+ }
174
+ });
175
+
176
+ // Register tools with model configuration
177
+ return runtime.registerModelContextProvider({
178
+ getModelContext: () => ({
179
+ tools: { calculate: calculateTool },
180
+ callSettings: {
181
+ temperature: isCreativeMode ? 0.9 : 0.2,
182
+ maxTokens: 1000
183
+ },
184
+ priority: 10 // Higher priority overrides other providers
185
+ })
186
+ });
187
+ }, [runtime, isCreativeMode]);
188
+
189
+ return <div>{/* Your component */}</div>;
190
+ }
191
+ ```
192
+
193
+ Use this approach when you need:
194
+ - Dynamic model parameters (temperature, maxTokens, etc.)
195
+ - Priority-based context merging
196
+ - Multiple context types in one registration
197
+
198
+ ## Tool Paradigms
199
+
200
+ ### Frontend Tools
201
+
202
+ Tools that execute in the browser, accessing client-side resources:
203
+
204
+ ```tsx
205
+ const screenshotTool = tool({
206
+ description: "Capture a screenshot of the current page",
207
+ parameters: z.object({
208
+ selector: z.string().optional()
209
+ }),
210
+ execute: async ({ selector }) => {
211
+ const element = selector ? document.querySelector(selector) : document.body;
212
+ const screenshot = await captureElement(element);
213
+ return { dataUrl: screenshot };
214
+ }
215
+ });
216
+
217
+ const ScreenshotTool = makeAssistantTool(screenshotTool);
218
+ ```
219
+
220
+ ### Backend Tools
221
+
222
+ Tools that trigger server-side operations:
223
+
224
+ ```tsx
225
+ // Backend route (AI SDK)
226
+ export async function POST(req: Request) {
227
+ const { messages } = await req.json();
228
+
229
+ const result = streamText({
230
+ model: openai("gpt-4o"),
231
+ messages,
232
+ tools: {
233
+ queryDatabase: {
234
+ description: "Query the application database",
235
+ parameters: z.object({
236
+ query: z.string(),
237
+ table: z.string()
238
+ }),
239
+ execute: async ({ query, table }) => {
240
+ // Server-side database access
241
+ const results = await db.query(query, { table });
242
+ return results;
243
+ }
244
+ }
245
+ }
246
+ });
247
+
248
+ return result.toDataStreamResponse();
249
+ }
250
+ ```
251
+
252
+ ### Client-Defined Tools with frontendTools
253
+
254
+ Currently, the Vercel AI SDK adapter implements automatic serialization of client-defined tools. When using this adapter, tools registered via `makeAssistantTool`, `useAssistantTool`, or `registerModelContextProvider` are automatically included in API requests. The `frontendTools` utility helps you use these tools server-side:
255
+
256
+ ```tsx
257
+ // Frontend: Define tool with makeAssistantTool
258
+ import { makeAssistantTool, tool } from "@assistant-ui/react";
259
+
260
+ const calculateTool = tool({
261
+ description: "Perform calculations",
262
+ parameters: z.object({
263
+ expression: z.string()
264
+ }),
265
+ execute: async ({ expression }) => {
266
+ return eval(expression); // Note: Use proper math parser in production
267
+ }
268
+ });
269
+
270
+ const CalculateTool = makeAssistantTool(calculateTool);
271
+
272
+ // Backend: Use frontendTools to receive client tools
273
+ import { frontendTools } from "@assistant-ui/react-ai-sdk";
274
+
275
+ export async function POST(req: Request) {
276
+ const { messages, tools } = await req.json();
277
+
278
+ const result = streamText({
279
+ model: openai("gpt-4o"),
280
+ messages,
281
+ tools: {
282
+ ...frontendTools(tools), // Client-defined tools
283
+ // Additional server-side tools
284
+ queryDatabase: {
285
+ description: "Query the application database",
286
+ parameters: z.object({ query: z.string() }),
287
+ execute: async ({ query }) => {
288
+ return await db.query(query);
289
+ }
290
+ }
291
+ }
292
+ });
293
+
294
+ return result.toDataStreamResponse();
295
+ }
296
+ ```
297
+
298
+ <Callout type="note">
299
+ The `frontendTools` utility is currently only available for the Vercel AI SDK integration. Other adapters like LangGraph follow a server-side tool definition model and don't yet implement client tool serialization. Learn more in the [Vercel AI SDK integration guide](/docs/runtimes/ai-sdk/use-chat-hook).
300
+ </Callout>
301
+
302
+ ### Human-in-the-Loop Tools
303
+
304
+ Tools that require human approval or input:
305
+
306
+ ```tsx
307
+ import { makeAssistantTool, tool } from "@assistant-ui/react";
308
+ import { z } from "zod";
309
+
310
+ const refundTool = tool({
311
+ description: "Process a customer refund",
312
+ parameters: z.object({
313
+ orderId: z.string(),
314
+ amount: z.number(),
315
+ reason: z.string()
316
+ }),
317
+ execute: async ({ orderId, amount, reason }) => {
318
+ // Wait for human approval
319
+ const approved = await requestHumanApproval({
320
+ action: "refund",
321
+ details: { orderId, amount, reason }
322
+ });
323
+
324
+ if (!approved) {
325
+ throw new Error("Refund rejected by administrator");
326
+ }
327
+
328
+ return await processRefund(orderId, amount);
329
+ }
330
+ });
331
+
332
+ const RefundTool = makeAssistantTool(refundTool);
333
+ ```
334
+
335
+ ### MCP (Model Context Protocol) Tools
336
+
337
+ Integration with MCP servers:
338
+
339
+ ```tsx
340
+ // Using AI SDK's MCP support
341
+ import { createMCPClient } from "ai/mcp";
342
+
343
+ const mcpClient = createMCPClient({
344
+ servers: {
345
+ github: {
346
+ command: "npx",
347
+ args: ["@modelcontextprotocol/server-github"]
348
+ }
349
+ }
350
+ });
351
+
352
+ // Tools are automatically available through the runtime
353
+ const runtime = useChatRuntime({
354
+ api: "/api/chat",
355
+ tools: await mcpClient.getTools()
356
+ });
357
+ ```
358
+
359
+ ## Advanced Patterns
360
+
361
+ ### Tool Composition
362
+
363
+ Combining multiple tools for complex workflows:
364
+
365
+ ```tsx
366
+ const travelPlannerTool = tool({
367
+ description: "Plan a complete trip itinerary",
368
+ parameters: z.object({
369
+ destination: z.string(),
370
+ dates: z.object({
371
+ start: z.string(),
372
+ end: z.string()
373
+ })
374
+ }),
375
+ execute: async ({ destination, dates }) => {
376
+ // Execute multiple operations
377
+ const weather = await getWeatherAPI(destination);
378
+ const hotels = await searchHotelsAPI({
379
+ location: destination,
380
+ dates
381
+ });
382
+ const activities = await findActivitiesAPI({
383
+ location: destination,
384
+ weather: weather.forecast
385
+ });
386
+
387
+ return {
388
+ weather,
389
+ hotels,
390
+ activities,
391
+ itinerary: generateItinerary({ weather, hotels, activities })
392
+ };
393
+ }
394
+ });
395
+
396
+ const TravelPlannerTool = makeAssistantTool(travelPlannerTool);
397
+ ```
398
+
399
+ ### Conditional Tool Availability
400
+
401
+ Tools that appear based on context:
402
+
403
+ ```tsx
404
+ function ConditionalTools() {
405
+ const { user } = useAuth();
406
+ const { subscription } = useSubscription();
407
+
408
+ // Premium features
409
+ useAssistantTool({
410
+ toolName: "advancedAnalysis",
411
+ description: "Perform advanced data analysis",
412
+ parameters: z.object({
413
+ dataset: z.string()
414
+ }),
415
+ execute: async (args) => {
416
+ // Premium analysis logic
417
+ },
418
+ enabled: subscription?.tier === "premium"
419
+ });
420
+
421
+ // Role-based tools
422
+ useAssistantTool({
423
+ toolName: "adminPanel",
424
+ description: "Access admin controls",
425
+ parameters: z.object({}),
426
+ execute: async () => {
427
+ // Admin actions
428
+ },
429
+ enabled: user?.role === "admin"
430
+ });
431
+ }
432
+ ```
433
+
434
+ ### Tool Error Handling
435
+
436
+ Robust error handling and recovery:
437
+
438
+ ```tsx
439
+ const resilientTool = tool({
440
+ description: "Fetch data with retry logic",
441
+ parameters: z.object({
442
+ endpoint: z.string()
443
+ }),
444
+ execute: async ({ endpoint }, { abortSignal }) => {
445
+ const maxRetries = 3;
446
+ let lastError;
447
+
448
+ for (let i = 0; i < maxRetries; i++) {
449
+ try {
450
+ const response = await fetch(endpoint, { signal: abortSignal });
451
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
452
+ return await response.json();
453
+ } catch (error) {
454
+ lastError = error;
455
+ if (abortSignal.aborted) throw error; // Don't retry on abort
456
+ await new Promise(resolve => setTimeout(resolve, 1000 * i));
457
+ }
458
+ }
459
+
460
+ throw new Error(`Failed after ${maxRetries} attempts: ${lastError.message}`);
461
+ }
462
+ });
463
+
464
+ const ResilientTool = makeAssistantTool(resilientTool);
465
+ ```
466
+
467
+ ## Best Practices
468
+
469
+ 1. **Clear Descriptions**: Write descriptive tool descriptions that help the LLM understand when to use each tool
470
+ 2. **Parameter Validation**: Use Zod schemas to ensure type safety and provide clear parameter descriptions
471
+ 3. **Error Handling**: Always handle potential errors gracefully with user-friendly messages
472
+ 4. **Loading States**: Provide visual feedback during tool execution
473
+ 5. **Security**: Validate permissions and sanitize inputs, especially for destructive operations
474
+ 6. **Performance**: Use abort signals for cancellable operations and implement timeouts
475
+ 7. **Testing**: Test tools in isolation and with the full assistant flow
476
+
477
+ ## Tool Execution Context
478
+
479
+ Tools receive additional context during execution:
480
+
481
+ ```tsx
482
+ execute: async (args, context) => {
483
+ // context.abortSignal - AbortSignal for cancellation
484
+ // context.toolCallId - Unique identifier for this invocation
485
+ }
486
+ ```
487
+
488
+ ## Runtime Integration
489
+
490
+ Each integration handles tools differently:
491
+
492
+ - **Vercel AI SDK**: Tools defined in API routes with `streamText({ tools: {...} })`. Also supports client-defined tools via `frontendTools`.
493
+ - **LangGraph**: Tools defined in your LangGraph graph configuration.
494
+ - **Mastra**: Tools defined as typed functions used by agents and workflows.
495
+
496
+ All integrations support tool UI customization via `makeAssistantToolUI`.
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: "Documentation"
3
+ ---
4
+
5
+ import { redirect } from "next/navigation";
6
+
7
+ <>{redirect("/docs/getting-started")}</>
@@ -0,0 +1,85 @@
1
+ ---
2
+ title: AssistantModal
3
+ ---
4
+
5
+ import { Steps, Step } from "fumadocs-ui/components/steps";
6
+ import { Tabs, Tab } from "fumadocs-ui/components/tabs";
7
+
8
+ ## Overview
9
+
10
+ A chat bubble shown in the bottom right corner of the screen. Useful for support or Q&A use cases.
11
+
12
+ ## Getting Started
13
+
14
+ <Steps>
15
+ <Step>
16
+
17
+ ### Install `@assistant-ui/react-ui`
18
+
19
+ ```sh npm2yarn
20
+ npm install @assistant-ui/react-ui
21
+ ```
22
+
23
+ </Step>
24
+ <Step>
25
+
26
+ ### Import CSS styles
27
+
28
+ Add the following to your `tailwind.config.ts`:
29
+
30
+ <Tabs items={["Tailwind", "Tailwind + shadcn-ui", "Not using Tailwind"]}>
31
+
32
+ ```ts title="/tailwind.config.ts" tab="Tailwind"
33
+ {
34
+ plugins: [
35
+ require("tailwindcss-animate"), // make sure to "npm install tailwindcss-animate"
36
+ require("@assistant-ui/react-ui/tailwindcss")({
37
+ components: ["assistant-modal"],
38
+ })
39
+ ],
40
+ }
41
+ ```
42
+
43
+ ```ts title="/tailwind.config.ts" tab="Tailwind + shadcn-ui"
44
+ {
45
+ plugins: [
46
+ require("tailwindcss-animate"), // make sure to "npm install tailwindcss-animate"
47
+ require("@assistant-ui/react-ui/tailwindcss")({
48
+ components: ["assistant-modal"],
49
+ shadcn: true
50
+ })
51
+ ],
52
+ }
53
+ ```
54
+
55
+ ```ts title="/app/layout.tsx" tab="Not using Tailwind"
56
+ import "@assistant-ui/react-ui/styles/index.css";
57
+ import "@assistant-ui/react-ui/styles/modal.css";
58
+ ```
59
+
60
+ </Tabs>
61
+
62
+ </Step>
63
+ <Step>
64
+
65
+ ### Use it in your app
66
+
67
+ ```tsx title="/app/page.tsx"
68
+ import { useChatRuntime } from "@assistant-ui/react-ai-sdk";
69
+ import { AssistantModal } from "@assistant-ui/react-ui";
70
+
71
+ const MyApp = () => {
72
+ const runtime = useChatRuntime({
73
+ api: "/api/chat",
74
+ });
75
+
76
+ return (
77
+ <div>
78
+ <AssistantModal runtime={runtime} />
79
+ </div>
80
+ );
81
+ };
82
+ ```
83
+
84
+ </Step>
85
+ </Steps>