toKontextTools adapter converts your connected integrations into Vercel AI-compatible tools that work with generateText, streamText, and generateObject.
Install
Complete example
A CLI application that connects to Kontext, loads tools from the user’s integrations, and runs a multi-step conversation:toKontextTools return value
tools— ARecord<string, CoreTool>compatible with the Vercel AI SDK. Each tool maps to an action from your connected integrations. The adapter also injects a parameterless integration-management helper tool that returns a fresh integrations management link the model can share for connect/manage/reconnect flows.systemPrompt— A pre-built string that tells the LLM which integrations are connected and which are not. Pass this as thesystemparameter to give the model context about available capabilities.integrations— Areadonly IntegrationInfo[]array with the current state of each integration (connected: true/false, plus optionalreasonandconnectUrl). Use this to build UI indicators or conditional logic.
System prompt
The generatedsystemPrompt includes a list of all integrations attached to your application and their connection status. This lets the model know what tools are available and respond appropriately when a user asks for something that requires a disconnected integration.
It also tells the model to call the integration-management helper tool for a fresh integrations management link (instead of reusing old links) and to prefer Kontext tools over local shell/CLI commands when Kontext can satisfy the integration request.
You don’t need to write integration-awareness logic yourself. The prompt handles it.
Multi-step conversations with maxSteps
Set maxSteps to allow the model to call multiple tools in sequence before returning a final response. Without this, the model makes one tool call and stops.
Streaming with streamText
Replace generateText with streamText to stream the response as it’s generated:
Custom result formatting
Pass aformatResult function to control how tool outputs are presented to the model:
Auth patterns
CLI applications
For CLI tools, useonAuthRequired to open the browser and return the callback URL:
onAuthRequired or pass it to client.auth.handleCallback().
Web applications
In browser environments, use the React SDK for popup-based OAuth, or handle the redirect flow manually:Next steps
- React SDK — Build browser-based chat UIs with OAuth popup support.
- Cloudflare Agents — Deploy AI applications on Cloudflare Workers with Durable Object storage.
- How Kontext Works — Understand the Kontext architecture and credential flow.