Vercel AI SDK Integration
Connect Erdo’s MCP tools to any LLM (Claude, GPT, etc.) using Vercel AI SDK. Your users ask data questions in a chat UI, the LLM calls Erdo tools to analyze data, and you render rich charts and tables withErdoToolResult.
Installation
@ai-sdk/anthropic with your preferred model provider (@ai-sdk/openai, @ai-sdk/google, etc.).
Quick Start
1. Server Routes
Two server routes: one for the LLM chat stream, one to create a scoped token for client-side data fetching (charts and tables).2. Render Results (Client)
Fetch a scoped token on mount and pass it toErdoProvider. Charts and tables use this token to fetch dataset contents.
3. Set Environment Variables
erdo_list_datasets, erdo_ask_data_question, and erdo_query_data based on user questions.
Bridge Pattern (Alternative)
If you’re already using@erdoai/server, you can use client.getTools() instead of creating an MCP client directly:
getTools() requires @ai-sdk/mcp as a peer dependency. Install it with npm install @ai-sdk/mcp.isErdoTool + ErdoToolResult as shown above.
Component Reference
isErdoTool(part)
Checks if an AI SDK message part is an Erdo tool call/result.
ErdoToolResult
Renders an Erdo tool result with appropriate UI based on the tool type:
- UI tools (
erdo_render_chart,erdo_render_table): Charts and tables via UIGenerationNodes - Markdown tools (
erdo_ask_data_question): Text answer rendered as markdown - Data tools (
erdo_list_datasets,erdo_get_dataset_schema, etc.): Formatted JSON - Loading states: Spinner with tool name
- Errors: Error message display
getErdoToolName(part)
Extracts the Erdo tool name from an AI SDK message part, or returns undefined if it’s not an Erdo tool.
ErdoProvider
Required for chart and table rendering. Provides the data fetching context so charts can load dataset contents. Pass a scoped token created from your backend (see quick start above).
If you don’t need chart/table rendering (only text and JSON results),
ErdoProvider is optional.Authentication
The API key (ERDO_AUTH_TOKEN) stays server-side for the MCP connection and token creation. The client gets a short-lived scoped token for data fetching — this is already set up in the quick start above.
For more advanced token scoping (restricting to specific datasets or users), see Scoped Tokens.
Available Tools
When connected via MCP, the LLM can use these Erdo tools:
See MCP Server for full parameter details.
Example App
A complete working example is available in the SDK repository:- MCP Pattern (
/mcp) — MCP tools via AI SDK withErdoToolResultrendering - Token Pattern (
/) — Direct streaming with ephemeral tokens - Proxy Pattern (
/proxy) — Server-proxied SSE streaming

