Vercel AI SDK: Building Agents and Chat in TypeScript

The AI SDK is Vercel’s open TypeScript toolkit for calling language models, streaming chat into a UI, and running agents that call tools in a loop. What is in version 7, what was renamed, how it reaches MCP servers, and how it compares with the OpenAI Agents SDK, the Claude Agent SDK and LangChain.

7 min read

The Vercel AI SDK, now usually just called the AI SDK, is a TypeScript library for building AI features and agents. You import one package, ai, and get the same functions for every model provider: generateText and streamText for text, an output option for structured data, tool() for tool calling, and a ToolLoopAgent class that runs the call-a-tool-and-continue loop for you. Separate packages add React, Vue, Svelte and Angular hooks for chat interfaces, and an MCP client. As of October 1, 2026, the current major version is AI SDK 7.

This post is about one library. For how it sits among the wider field, including Python-first frameworks, read AI agent frameworks compared.

What the AI SDK is made of

The AI SDK introduction (opens in a new tab) describes it as “the TypeScript toolkit designed to help developers build AI-powered applications and agents with React, Next.js, Vue, Svelte, Node.js, and more.” It lists three primary surfaces:

  • AI SDK Core: one API for generating text, structured objects and tool calls, and for building agents.
  • AI SDK UI: framework hooks for chat and generative interfaces. The main ones are useChat, useCompletion and useObject, in @ai-sdk/react, @ai-sdk/vue, @ai-sdk/svelte and @ai-sdk/angular.
  • AI SDK Harnesses: a HarnessAgent class for running existing agent runtimes such as Claude Code or Codex through the same stream types. The docs mark the harness packages as experimental and warn of breaking changes.

The core APIs

generateText waits for the whole answer and suits background jobs and agents that use tools. streamText returns tokens as they arrive, for anything a person watches. Both take a model, a prompt or messages, and, in version 7, instructions for what earlier versions called system.

Structured output is now part of the same two functions. Per the docs on generating structured data (opens in a new tab), you pass output: Output.object({ schema }) with a Zod, Valibot or JSON schema and read a validated output. The older generateObject and streamObject are deprecated and will be removed in a future version, so new code should not start with them.

Tools are defined with tool(): a description, an inputSchema, and an execute function. The model decides when to call one; the SDK validates the input, runs execute and hands the result back. A tool without execute stops the loop so your own code can handle the call, and a toolApproval setting can hold selected calls until a person approves them.

Agents and loop control

An agent, in the docs’ words, is a language model using tools in a loop. ToolLoopAgent packages the loop: it keeps the message history, calls tools, and stops when the model answers without a tool call, when a tool needs approval, or when a stop condition is met. The loop control docs (opens in a new tab) say ToolLoopAgent stops after 20 steps by default, using isStepCount(20), as a guard against runaway loops. You can raise that, stop when a named tool is called with hasToolCall, or write your own condition, such as a token budget. prepareStep lets you change the model, tools or messages between steps.

This example is trimmed from the agents overview in the current docs. The model is a plain string, which the SDK routes through its default global provider, Vercel’s AI Gateway.

agent.ts (AI SDK 7)
import { ToolLoopAgent, tool, isStepCount } from 'ai';
import { z } from 'zod';

const weatherAgent = new ToolLoopAgent({
  model: 'anthropic/claude-sonnet-5.5',
  tools: {
    weather: tool({
      description: 'Get the weather in a location (in Fahrenheit)',
      inputSchema: z.object({
        location: z.string().describe('The location to get the weather for'),
      }),
      execute: async ({ location }) => ({
        location,
        temperature: 72 + Math.floor(Math.random() * 21) - 10,
      }),
    }),
  },
  stopWhen: isStepCount(10),
});

const result = await weatherAgent.generate({
  prompt: 'What is the weather in San Francisco?',
});

console.log(result.text);  // the final answer
console.log(result.steps); // every step the agent took

What changed in AI SDK 7

If you are reading a tutorial written for version 5 or 6, several names have moved. The AI SDK 7 migration guide (opens in a new tab) lists them, with codemods (npx @ai-sdk/codemod v7) for most:

  • system is now instructions, and stepCountIs is now isStepCount.
  • onFinish and onStepFinish callbacks are now onEnd and onStepEnd; experimental_telemetry is now telemetry.
  • The fullStream property on a streamText result is now stream, and the response helpers on that result, such as toUIMessageStreamResponse, are deprecated in favor of top-level helpers like createUIMessageStreamResponse.
  • All packages are ESM-only, and version 7 requires Node.js 22 or later.
  • ToolLoopAgent is stable.

MCP: connecting the AI SDK to tools on a server

The AI SDK includes an MCP client in @ai-sdk/mcp. According to the MCP tools documentation (opens in a new tab), createMCPClient connects over HTTP (recommended for production), SSE, or stdio for local servers, supports OAuth through an authProvider, and mcpClient.tools() turns the server’s tools into AI SDK tools you can pass to generateText, streamText or an agent. The docs describe it as a lightweight client for tool conversion, not a full MCP client.

One detail matters for anything that writes data. MCP servers can mark tools with hints such as readOnlyHint, and the client exposes them, but it does not turn them into an approval policy for you. The docs suggest a conservative policy: run a tool automatically only when the server marks it read-only, and ask a person for everything else. What MCP is, in project terms, is in what is MCP.

Providers and the AI Gateway

Each model company has its own provider package, such as @ai-sdk/openai, @ai-sdk/anthropic or @ai-sdk/google, all implementing one language model specification so you can switch by changing the model line. Community providers cover others, including Ollama for local models. A plain string like 'anthropic/claude-sonnet-5.5' goes through the default global provider, which the docs set to Vercel’s AI Gateway (opens in a new tab), a separate Vercel service that routes requests across providers with fallbacks and budgets. You can use the SDK without the Gateway by importing a provider directly.

Vercel AI SDK vs agent SDKs

The AI SDK is a model-and-UI toolkit that also runs agents. The others below are agent SDKs first. The table is a summary from each vendor’s current documentation; the linked posts have the detail.

Comparison
                   Languages            Built around                    MCP
AI SDK (Vercel)    TypeScript           Model calls, ToolLoopAgent,     @ai-sdk/mcp client
                                        streaming UI hooks
OpenAI Agents SDK  Python, TypeScript   Agents, handoffs, guardrails,   Stdio, SSE and
                                        built-in tracing                Streamable HTTP servers
Claude Agent SDK   Python, TypeScript   Claude Code's loop and          MCP servers in
                                        built-in tools                  its options
LangChain /        Python, JavaScript   createAgent; LangGraph for      MCP adapters
LangGraph                               durable, stateful graphs
  • Choose the AI SDK when the agent lives in a TypeScript web app, you want a streaming chat UI from the same library, and you want to switch model providers freely.
  • Choose the OpenAI Agents SDK for several agents handing work to each other with guardrails and tracing. Its TypeScript version also has a beta adapter for running AI SDK models.
  • Choose the Claude Agent SDK when the agent should work on files and a shell with tools that already exist.
  • Choose LangGraph for long-running, stateful workflows that need durable execution and pauses for a person; LangGraph vs CrewAI compares it with a role-based alternative, and MCP vs LangChain tools covers how LangChain’s tools relate to MCP.

Giving an AI SDK agent a task board

An agent built with the AI SDK can report its work to fenbs, which is an MCP server at https://fenbs.ai/api/mcp. Issue a token by hand under Settings, with a name, scopes and an optional expiry, and pass it as a bearer header:

Connecting to fenbs
import { createMCPClient } from '@ai-sdk/mcp';

const fenbs = await createMCPClient({
  transport: {
    type: 'http',
    url: 'https://fenbs.ai/api/mcp',
    headers: { Authorization: `Bearer ${process.env.FENBS_TOKEN}` },
  },
});

const tools = await fenbs.tools(); // fenbs_list_items, fenbs_create_item, ...

The token acts as you, with your board role narrowed by the scopes you gave it, and every change the agent makes is recorded in History by name, so it can be told apart from a person’s. Two honest caveats. fenbs sets no MCP tool annotations yet, so the conservative read-only policy from the AI SDK docs would ask for approval on every fenbs tool, including reads; list the read tools by name in your approval policy instead. And fenbs is a plain board: four lanes, no due dates, no settable assignee and no sprints. It records what the agent did; it does not schedule it.

Related

The server and its tools: the fenbs MCP guide. Where a person should approve an agent’s action: human in the loop for AI agents. Other ways teams automate work: AI automation agencies and workflow automation tools.

Questions people ask.

Is the Vercel AI SDK free to use?

The AI SDK is an open-source library under the Apache 2.0 license that you install from npm. You pay the model provider you call, or Vercel if you route requests through its AI Gateway, according to their own pricing.

Do I need to deploy on Vercel to use the AI SDK?

No. It runs in Node.js and in frameworks such as Next.js, Nuxt, SvelteKit and Expo wherever you host them. Only the AI Gateway is a Vercel service, and you can use provider packages directly instead.

Is generateObject deprecated in the AI SDK?

Yes. generateObject and streamObject are deprecated. The current docs use generateText or streamText with output set to Output.object and a schema, which also lets you combine structured output with tool calls.

Can the AI SDK use MCP servers?

Yes. The @ai-sdk/mcp package creates a client over HTTP, SSE or stdio, supports OAuth, and converts the server’s tools into AI SDK tools you pass to generateText, streamText or ToolLoopAgent.

Start with one thing.

There is nothing to set up first. Write one line and you’ve started.