What it demonstrates
createToolsFromClientSchemas()- Convert client-provided schemas into AI SDK tools- Dynamic tool registration - Tools defined at runtime by the client
- SDK/platform architecture - Generic server infrastructure with client-specific tools
- WebSocket protocol integration - Tool schemas automatically sent via WebSocket
The Pattern
This example shows how to build a chat agent where:- The server is generic infrastructure - it accepts whatever tools the client sends
- The client defines tools dynamically (schemas + execute functions)
- Tool schemas are automatically sent to the server via the WebSocket protocol
- The LLM calls the tools, and results are routed back to the client for execution
Server Implementation
The server usescreateToolsFromClientSchemas() to convert client-provided schemas into AI SDK tools:
src/server.ts
Client Implementation
The client passes tools via thetools option on useAgentChat:
src/client.tsx
How It Works
1
Client defines tools
The client application defines tools with JSON Schema parameters and execute functions. These tools are specific to the embedding application.
2
Schemas sent to server
When the WebSocket connection is established, tool schemas are automatically sent to the server via the
@cloudflare/ai-chat protocol.3
Server converts schemas
createToolsFromClientSchemas() converts the JSON Schema into AI SDK tools that the LLM can call.4
LLM calls tools
The LLM can now call the client-defined tools. Tool calls are sent back to the client for execution.
5
Client executes and returns results
The client’s
execute function runs, and the result is sent back to the server to continue the LLM conversation.When to Use This Pattern
Use Dynamic Client Tools When:
- Building an SDK or platform where third-party developers define tools
- Multi-tenant systems where each tenant has different tools
- Plugin architectures where tools are registered at runtime
- Rapid prototyping where tools change frequently
Use Server-side Tools When:
- Most applications - simpler code, full type safety
- Security-sensitive operations - execute on the server
- Shared tools - all clients use the same tool set
- TypeScript integration - Zod schemas with full type inference
Comparison: Dynamic vs Server-side Tools
Running the Example
- “What’s the page title?” (calls
getPageTitle) - “Where am I?” (calls
getUserLocation) - “What browser am I using?” (calls
getBrowserInfo)
This example uses Workers AI (no API key needed) with
@cf/zai-org/glm-4.7-flash.Related Examples
AI Chat
Server-side tools with approval and onToolCall
Codemode
LLMs write code to orchestrate tools
MCP Client
Connect to MCP servers for dynamic tools
Playground
Kitchen-sink showcase of all SDK features