AI SDK MCP: connect the Vercel AI SDK to live TikTok and Instagram data

Updated

Virlo is social listening for TikTok and Instagram Reels. The Vercel AI SDK can stream model answers and call tools, but it ships with no source for how TikTok and Instagram videos are performing. Load Virlo through createMCPClient and generateText or streamText can call trends, hooks, sounds and outlier-video tools backed by a database of 23.1M viral videos. The AI SDK is Vercel's open-source TypeScript toolkit for building AI features and agents across model providers, in Next.js, Node and other JavaScript frameworks.

  • `createMCPClient` with an HTTP transport and a bearer header
  • `tools: await client.tools()` works in `streamText` and `generateText`
  • Close the client in `onEnd` so serverless functions stay clean

Part of Virlo's AI assistant guides. Want a framework with agents and workflows on top? See Mastra. Generating UI with Vercel's v0? See v0.

How do I connect the Virlo MCP server to the AI SDK?

Five steps in a Next.js App Router project; the same client works in any Node runtime. The route below streams a research answer that can call Virlo several times.

  1. Step 1: Create your Virlo account for free

    Create your free Virlo account in under a minute. Already signed up? Open API Keys.
  2. Step 2: Install the AI SDK and its MCP package

    The MCP client ships separately from the core ai package, as @ai-sdk/mcp.

    Terminal
    npm install ai @ai-sdk/mcp
  3. Step 3: Add the key to your environment

    Put a key from the Virlo developer dashboard in .env.local, and add the same variable under Environment Variables in your Vercel project before you deploy.

    .env.local
    VIRLO_API_KEY=virlo_tkn_YOUR_KEY
  4. Step 4: Create the MCP client in a route handler

    Open the client with an http transport, pass await virlo.tools() to streamText, and let stopWhen allow a few tool steps so the model can chain Virlo lookups. The onEnd callback closes the client once the stream finishes. Swap the model string for any provider you use.

    app/api/research/route.ts
    // app/api/research/route.ts
    import { createMCPClient } from '@ai-sdk/mcp'
    import { streamText, stepCountIs } from 'ai'
    
    export async function POST(req: Request) {
      const { prompt } = await req.json()
    
      const virlo = await createMCPClient({
        transport: {
          type: 'http',
          url: 'https://dev.virlo.ai/api/mcp/mcp',
          headers: { Authorization: `Bearer ${process.env.VIRLO_API_KEY}` },
        },
      })
    
      const result = streamText({
        model: 'anthropic/claude-sonnet-5.5',
        tools: await virlo.tools(),
        stopWhen: stepCountIs(5),
        prompt,
        onEnd: async () => {
          await virlo.close()
        },
      })
    
      return result.toUIMessageStreamResponse()
    }
  5. Step 5: Send it a research question

    Hook the route to useChat in your UI, or post a JSON body with prompt from curl. Tool calls and results stream back as parts you can render.

    Your first prompt
    Use Virlo to find the 3 trends to copy with the most creators in [your niche] this week and show what to keep and what to swap for each.

For a one-shot call that is not streamed, use generateText with the same tools and close the client in a finally block.

MCP client vs REST tool vs schema-picked tools: how should the AI SDK reach Virlo?

ApproachCode shapeBest for
createMCPClient + client.tools()Discovers every Virlo research tool at request timeChat UIs where users ask open questions
client.tools() with explicit schemasLoad only named Virlo tools with your own Zod input schemasTyped features where you want autocomplete and a narrow surface
tool() wrapping the REST APIA custom tool whose execute fetches https://api.virlo.ai/v1/content-trendsOne fixed widget, such as a trends card on a dashboard
OAuth authProvider on the transportEach signed-in user authorizes their own Virlo accountProducts where customers connect Virlo themselves

Every approach uses the same hosted Virlo server; the bearer header suits your own key, and authProvider suits per-user sign-in.

AI SDK app on its own vs with Virlo tools

User asks your appModel aloneModel with Virlo
What is trending on TikTok?An answer from training data with no dateThis week's trends to copy with creator counts and examples
Turn this video into a scriptNeeds the user to paste a transcriptFetches the TikTok transcript and hook itself
Which sound fits my Reel?Names famous tracksSounds trending on Instagram Reels in the last 7 days
Who should we partner with?Big creators it has heard ofSmaller creators whose videos beat their follower count

What does an AI SDK route get back when it asks Virlo for trends?

A trends tool call returns structured recipes like these, which render neatly as tool-result parts in a chat UI: what to keep, what to make yours, and how many creators posted it this week.

In Virlo's data, the trend to copy with the most creators this week is "My moon my man couple montage": 659 creators posted it in the last 7 days, as of November 19, 2026.

As of November 19, 2026 at 13:07 UTC

What does an AI SDK route get back when it asks Virlo for trends?
TrendKeep the sameMake it yoursCreators this week
Example video for the My moon my man couple montage trend by @haleyybayleeMy moon my man couple montageThe song 'My Moon My Man' by Feist (often a specific remix or cover) and the theme of showing a romantic partner.The specific person or couple being shown and the setting of the clips.659
Example video for the While they're out partying btw trend by @larpniverseWhile they're out partying btwThe on-screen text 'While they're out partying btw' and the rhythmic breathing audio.The activity being performed, such as gaming, working at a fast-food restaurant, or training.346
Example video for the He wanna pay full price SNL trend trend by @anereslaila1He wanna pay full price SNL trendThe audio 'He wanna pay full price' from an SNL skit featuring Druski.The relatable situation described in the on-screen text, such as child support, birthdays, or family vacations.175
Example video for the But you're not a Buddhist trend trend by @nicolo.contradaBut you're not a Buddhist trendAudio of Bobby and Peggy Hill: "But you're not a Buddhist." "Yes, I am, mom." "Honey, you're not from China."The specific hypocritical or contradictory situation described in the on-screen text.158
Example video for the Shoulder carry mirror selfie trend trend by @thecapcutterxShoulder carry mirror selfie trendCarrying someone over one shoulder while taking a mirror selfie to the same audio.The couple, their outfits, and the room where the selfie is taken.158

See the recipe for all 39 trends to copy

Every trend with its example videos, 30-day chart and client fit is in the Virlo app.

Open Trends to copy

How this sample is made

Source
Virlo's Trends to copy: formats found by Virlo's trend detector and published only after the team checks each one.
Window
Creators who posted each trend in the last 7 days, counted from TikTok and Instagram videos only. Trends made with an AI tool are left out.
Method
Ranked by creators posting this week. Stages: Fresh, Rising, Peaking, Fading.
As of
November 19, 2026 at 13:07 UTC. Refreshes every hour.
Made by
Numbers are pulled automatically from Virlo's data every hour; the text around them is written by the Virlo team.

Suggested citation: Source: Virlo, “AI SDK MCP: connect the Vercel AI SDK to live TikTok and Instagram data”, virlo.ai/vercel-ai-sdk

How do I build a content research chat with the AI SDK and Virlo?

The pieces of a small research app for marketers, using AI SDK UI on the front end:

  • A route handler like the one in the setup, with Virlo's tools and a system prompt that asks for a source video on every idea.
  • useChat on the page, rendering text parts as messages and Virlo tool results as cards with thumbnails and links.
  • A small set of suggested prompts in the UI, each with a [your niche] field the user fills in.
  • A second route that takes a chosen trend and writes three scripts, called without Virlo tools so it only uses what the first route found.
  • Optional: persist chats to your database so a user can return to last week's research.

Virality Score arrives with each video, so the UI can sort cards by how far a video beat its creator's normal views. Scores of 18 and above count as strong.

What should I watch for in serverless and edge deployments?

Create the MCP client inside the request handler, not at module scope, so each invocation opens and closes its own connection. Closing in onEnd (streaming) or finally (non-streaming) prevents dangling connections when a function is frozen.

Keep stopWhen modest. Three to five steps is usually enough for a lookup, a follow-up lookup and an answer, and it caps how long a single request runs.

The HTTP transport is the one the AI SDK recommends for production; Virlo serves Streamable HTTP, so no extra transport package is required.

What can an AI SDK app ask Virlo?

Use these as user prompts or as suggested chips in your UI. Replace the brackets.

  • Trend chip

    What are the top 5 trends to copy in [your niche] this week? Show what to keep and what to make yours for each.

  • Video teardown

    Break down [TikTok link]: hook, on-screen text, format and how far it beat the creator's usual views.

  • Sound picker

    Which TikTok sounds are breaking out this week, and which two fit a [tone] video for [your brand]?

  • Reels research

    Find the 10 Instagram Reels about [topic] with the highest Virality Score this month and list their hooks.

  • Competitor card

    Look up @[competitor] on TikTok and Instagram and return their three standout videos of the month as cards.

  • Script generator

    Using the trend [trend name] from Virlo, write a 30-second script for [your product] that keeps its structure.

  • Hashtag check

    Which hashtags in [your niche] added the most TikTok videos this week?

  • Creator finder

    Find 8 TikTok creators in [your niche] under [N] followers whose videos beat their follower count, as cards with one standout video each.

Vercel AI SDK vs v0 vs AI Gateway: which Vercel product is this?

Vercel ships several AI products with similar names. This page covers the developer SDK.

Vercel AI SDK (this page)

The TypeScript library behind ai, @ai-sdk/* and AI SDK UI. Virlo connects through createMCPClient.

v0

Vercel's app and UI generator that you prompt in a browser. It has its own MCP setup, covered in its own guide.

AI Gateway

Vercel's routing layer for model providers. It decides which model answers; Virlo supplies the data the model uses.

Mastra

An agent framework that builds on top of model SDKs and adds workflows and memory.

What are the limits?

  • Virlo reads public TikTok and Instagram data only, so your app can research and write with it but not post or reach user accounts.
  • Add VIRLO_API_KEY to the Vercel project's Environment Variables for each environment (Preview, Production), or deployed routes will fail to connect.
  • Jobs that create a new marketing agent finish in the background; return a status to the UI and check back instead of holding a stream open.
  • Trends to copy refresh hourly after a team check; sounds and outlier rankings update through the day.
  • For what each Virlo plan includes, see pricing.

Frequently asked questions

How do I use MCP with the Vercel AI SDK?

Install @ai-sdk/mcp, call createMCPClient with an http transport, url and headers, then pass await client.tools() to generateText or streamText. For Virlo, the url is the dev.virlo.ai MCP address and the header is Authorization with your bearer key. Close the client when the call ends.

Is createMCPClient still experimental in the AI SDK?

Current docs import createMCPClient from the @ai-sdk/mcp package without the experimental prefix. Older AI SDK releases exported it from ai as experimental_createMCPClient with the same transport options, so existing code maps across directly. If your project still uses the older import, Virlo connects through it with the same http transport, url and Authorization header shown on this page.

Which MCP transport should I use in the AI SDK?

The http transport, which the AI SDK recommends for production and which speaks Streamable HTTP. Virlo serves exactly that, so a transport object with type http, the Virlo URL and an Authorization header is enough. The SSE transport exists for older servers, and stdio is only for local processes you start yourself.

Can the AI SDK get TikTok data?

With Virlo loaded as MCP tools, yes. Your route can call TikTok trends to copy, outlier videos ranked by Virality Score, trending and breakout sounds, hashtags, creator lookups and transcripts, and stream the results to the UI. Tool results arrive as typed parts, so you can render trend cards or video thumbnails instead of plain text.

Does the AI SDK support MCP OAuth?

Yes. The HTTP and SSE transports accept an authProvider that runs the OAuth flow. Virlo supports OAuth 2.1 with dynamic client registration, so an app can let each user sign in to their own Virlo account instead of sharing one key.

Can I use Virlo with the AI SDK outside Next.js?

Yes. createMCPClient runs in any Node or edge-compatible runtime, including Express, Hono, SvelteKit and plain scripts. Only the response helper changes; the client setup and tools call stay the same. Remember to load VIRLO_API_KEY from that runtime's own environment configuration.

Can an AI SDK app post to Instagram via Virlo?

No. Virlo is read-only research on public TikTok and Instagram data. Your app can analyse and generate with it, while posting runs through whichever publishing tools you already use. That keeps your users' social logins out of your AI routes entirely.

Is the AI SDK the same as v0?

No. The AI SDK is a code library you import into your app; v0 is a hosted generator you prompt to build apps. Both can use Virlo: the SDK through createMCPClient in your code, v0 through its own MCP settings. The v0 guide covers that route.

How do I limit which Virlo tools the AI SDK model can call?

Pass explicit schemas to client.tools() so only the named Virlo tools load, each with your own Zod input schema. That narrows what the model sees, gives you type-safe tool results, and keeps a focused feature such as a trends widget from wandering into creator lookups.

Give your AI SDK app a social media brain

One createMCPClient call streams live TikTok and Instagram research into your UI.