Skip to content
Skip to Content
IntegrationsVercel AI SDK

Vercel AI SDK Integration

The SearchMCP  API gives your AI agents access to real-time Google search results. This guide shows how to integrate it into Vercel’s AI SDK  using the official @searchmcp/client.


Install dependencies

Add the required packages:

pnpm add zod @searchmcp/client # or npm install zod @searchmcp/client # or yarn add @searchmcp/client

Define a Search Tool

We’ll wrap the SearchMCPClient in an AI SDK tool that your LLM can call:

import { generateText, tool, stepCountIs } from 'ai'; import { openai } from '@ai-sdk/openai'; import { z } from 'zod'; import { createClient } from '@searchmcp/client'; // Create the SearchMCP client const client = createClient(process.env.SEARCHMCP_API_KEY!); export const searchMcp = tool({ description: 'Search the web for up-to-date information', inputSchema: z.object({ query: z.string().min(1).max(1024).describe('The search query'), numberOfResults: z.number().int().min(1).max(20).default(10), }), execute: async ({ query, numberOfResults }) => { const res = await client.search({ query, numberOfResults, resultType: 'web' // 👈 can also be "images", "news", "shopping", or "videos" }); return (res.results ?? []).map(r => ({ title: r.title, url: r.link, })); }, });

Use the Tool in Generation

Now hook up your tool to an LLM (e.g. OpenAI):

const { text } = await generateText({ model: openai('gpt-4o-mini'), prompt: 'What happened in San Francisco last week?', tools: { searchMcp }, stopWhen: stepCountIs(5), }); console.log(text);

Here the model will call searchMcp automatically if it needs real-world knowledge.


By changing the resultType parameter, you can also search:

  • 🖼️ ImagesresultType: "images"
  • 📰 NewsresultType: "news"
  • 🛒 ShoppingresultType: "shopping"
  • 🎥 VideosresultType: "videos"

This makes it easy to extend your agent with different kinds of Google results using the same tool definition.


Why this matters

  • Bring live Google search into your AI agents
  • Search across web, images, news, shopping, and videos
  • Keep responses up-to-date
  • Works across agents, copilots, LangChain, AutoGen, Semantic Kernel, and more

Next steps

Last updated on