Vercel AI SDK MCP Client: Summarize X (Twitter) Posts
Connect the Vercel AI SDK to a remote MCP server with createMCPClient, hand its tools to generateText or streamText, and summarize recent X posts.
Tarun Khatri
Published · Updated · 7 min read
The Vercel AI SDK MCP client is createMCPClient from @ai-sdk/mcp: give it a URL and headers, then pass its tools to generateText.
This guide connects it to Weir's MCP server and builds a short script that reads recent X (Twitter) posts on a topic and summarizes them. We run Weir.
import { createMCPClient } from "@ai-sdk/mcp";
const weir = await createMCPClient({
transport: {
type: "http",
url: "https://api.weirapp.io/mcp",
headers: { Authorization: `Bearer ${process.env.WEIR_API_KEY}` },
},
});
const tools = await weir.tools();
Vercel AI SDK MCP setup: install and connect
You need two packages, a Weir key and a model key. The Vercel AI SDK talks to Weir over Streamable HTTP, which its docs recommend for production.
- InstallRun npm i ai @ai-sdk/mcp. AI SDK 7 needs Node.js 22 or later and ES modules.
- Get a Weir keyCreate one under API keys in your Weir dashboard. Save it as WEIR_API_KEY in .env.
- Add a model keyModel strings like anthropic/claude-sonnet-5.5 go through Vercel AI Gateway, so add AI_GATEWAY_API_KEY.
- Run itnode --env-file=.env summarize-x.mjs "AI SDK"
As of 22 October 2026, npm lists ai 7.0.148 and @ai-sdk/mcp 2.0.81.
The client sends your header on every request, so there's no sign-in step. That suits scripts, cron jobs and server routes.
Is it experimental_createMCPClient or createMCPClient?
Use createMCPClient from @ai-sdk/mcp. AI SDK 5 exported experimental_createMCPClient from ai, and some older guides still use that name.
AI SDK 6 moved the client to its own package. The old name lives on there as a deprecated alias, but ai no longer exports it.
Here's what changed in code you'll copy from older MCP examples:
| Older code | AI SDK 7 |
|---|---|
experimental_createMCPClient from ai |
createMCPClient from @ai-sdk/mcp |
stopWhen: stepCountIs(3) |
stopWhen: isStepCount(3) |
system: "..." |
instructions: "..." |
onFinish |
onEnd |
result.toUIMessageStreamResponse() |
createUIMessageStreamResponse() |
The first row changed in AI SDK 6 and the rest in AI SDK 7, whose migration guide covers each one. npx @ai-sdk/codemod v7 makes the 6-to-7 renames for you, though the guide says to check its work.
Vercel AI SDK MCP tools example: summarize X posts
The script takes a topic, lets the model search X through Weir, and prints five bullets. It's 29 lines, shown in two parts. Part one connects:
import { createMCPClient } from "@ai-sdk/mcp";
import { generateText, isStepCount } from "ai";
const topic = process.argv[2] ?? "MCP";
const since = new Date(Date.now() - 7 * 86_400_000).toISOString();
const weir = await createMCPClient({
transport: {
type: "http",
url: "https://api.weirapp.io/mcp",
headers: { Authorization: `Bearer ${process.env.WEIR_API_KEY}` },
},
});
Part two picks the tool, runs the model and always closes the client:
try {
const { search_x } = await weir.tools(); // keep only X search
const { text } = await generateText({
model: "anthropic/claude-sonnet-5.5",
tools: { search_x },
stopWhen: isStepCount(3),
instructions:
"Call search_x once with limit 10, since, and -filter:nativeretweets in query. " +
"Then summarize the posts in 5 bullets, each with its link.",
prompt: `Summarize X posts about ${topic} since ${since}.`,
});
console.log(text);
} finally {
await weir.close();
}
- Why only
search_x? Weir serves 44 tools on a default connection, Reddit included. Each one you pass adds its description to the prompt. - Why
stopWhen? The AI SDK docs saygenerateTextstops after one step by default. Without it, the model calls the tool and never writes the summary. - Why
-filter:nativeretweets? X search returns reposts by default, and a repost carries no likes of its own. That filter inquerydrops them.
Weir marks every data tool read-only, and the client passes that on as readOnlyHint in each tool's metadata.annotations. If you also connect servers that can write, the AI SDK docs show a toolApproval rule that runs read-only tools at once and asks before the rest.
What does the model get back?
The model's call is search_x with your topic in query. We ran it through Weir's MCP server on 22 October 2026, scoped to @vercel so no private accounts land on this page:
→ search_x {"fromUsers": ["vercel"], "query": "\"AI SDK\" -filter:nativeretweets",
"since": "2026-09-22T00:00:00Z", "limit": 3}
← 1 post · 2 credits (1 + 1 × 1) · nextCursor set
2026-10-02 308 likes 102,875 views
"Jev is now in the AI SDK for Python. To test it, we ran two experiments..."
Each post carries its url, so every bullet gets a link.
Only one post matched, yet the reply still carried a cursor. Weir's docs say only a null nextCursor means the end, so a second call could find more. The script calls once on purpose, to keep each run cheap.
Weir bills 1 credit per call plus 1 per X post, and failed calls are free:
Those numbers assume the model follows "call once". Paid packs start at $5 for 25,000 credits and never expire, as of October 2026. Your model tokens are billed separately. Every Weir rate is on our pricing page.
Streaming in Next.js: keep the key on the server
Call Weir from a route handler, never from a client component. Anything in browser code ships to every visitor, Weir key included.
Move the transport object into lib/weir.ts as WEIR, then add app/api/x-summary/route.ts:
import { createMCPClient } from "@ai-sdk/mcp";
import { createUIMessageStreamResponse, isStepCount, streamText, toUIMessageStream } from "ai";
import { WEIR } from "@/lib/weir"; // the transport object from the script
export async function POST(req: Request) {
const weir = await createMCPClient({ transport: WEIR });
const { search_x } = await weir.tools();
const result = streamText({
model: "anthropic/claude-sonnet-5.5",
tools: { search_x },
stopWhen: isStepCount(3),
prompt: (await req.json()).prompt,
onEnd: () => weir.close(),
});
return createUIMessageStreamResponse({ stream: toUIMessageStream({ stream: result.stream }) });
}
The AI SDK docs close a streaming client in onEnd. Set WEIR_API_KEY in your host's environment settings, not in a NEXT_PUBLIC_ variable, which Next.js sends to the browser.
If it doesn't work
createMCPClientisn't exported fromai. Install@ai-sdk/mcpand import it from there.require()fails. AI SDK 7 ships ES modules only, so useimportand a.mjsfile or"type": "module".- The model calls the tool but
textis empty. AddstopWhen: isStepCount(3)so it gets a step to write. - A redirect error. AI SDK 7 rejects redirects by default, and
http://api.weirapp.ioredirects tohttps. Use thehttpsURL. 401 unauthorized.WEIR_API_KEYisn't set where the code runs, so the header saysBearer undefined.- A tool returns
402. Your Weir credits ran out, and retrying won't help.
When not to use Weir
- Your app has to post or DM on X. Weir is read-only.
- You want a user's private data. Weir reads public posts, not bookmarks, DMs or home timelines.
- Price per post matters most. TwitterAPI.io lists $0.15 per 1,000 tweets as of October 2026, less than our $5 pack.
- You need a guarantee. Weir isn't licensed by X or affiliated with it, so access can change.
FAQ
What is experimental_createMCPClient?
It's the older name of the MCP client, exported from ai in AI SDK 5. AI SDK 6 moved the client to @ai-sdk/mcp as createMCPClient. The old name survives there as a deprecated alias, so new code should use createMCPClient.
Which transport should the Vercel AI SDK MCP client use?
Use type: "http" for remote servers like Weir. The AI SDK docs recommend HTTP for production and keep stdio for local servers only. SSE still works with servers that offer it, but Weir serves Streamable HTTP only.
How do I get only some MCP tools in the AI SDK?
weir.tools() returns an object keyed by tool name, so destructure the ones you want. Or pass schemas to tools(): the AI SDK docs say the client then loads only the tools you list, with typed inputs.
Can I call Weir's MCP server from the browser?
Not with a key. A key in client code is public, so keep it in a route handler or server action. The browser calls your route, and your route calls Weir.
Sources
- AI SDK docs, Model Context Protocol (checked 22 October 2026): https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools
- AI SDK docs, tool calling and stopWhen (checked 22 October 2026): https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling
- AI SDK docs, migration guide to 7.0 (checked 22 October 2026): https://ai-sdk.dev/docs/migration-guides/migration-guide-7-0
- AI SDK docs, Node.js quickstart and AI Gateway (checked 22 October 2026): https://ai-sdk.dev/docs/getting-started/nodejs
- AI SDK docs, Next.js quickstart (checked 22 October 2026): https://ai-sdk.dev/docs/getting-started/nextjs-app-router
- Vercel docs, AI SDK with MCP, updated 18 September 2026 (checked 22 October 2026): https://vercel.com/docs/mcp/integrations/ai-sdk
- vercel/ai source,
@ai-sdk/mcpexports at ai@7.0.148 (checked 22 October 2026): https://github.com/vercel/ai/blob/ai@7.0.148/packages/mcp/src/index.ts - vercel/ai source,
ai5.0.0 exports (checked 22 October 2026): https://github.com/vercel/ai/blob/ai@5.0.0/packages/ai/src/index.ts - ai on npm, version 7.0.148 (checked 22 October 2026): https://www.npmjs.com/package/ai
- @ai-sdk/mcp on npm, version 2.0.81 (checked 22 October 2026): https://www.npmjs.com/package/@ai-sdk/mcp
- Next.js docs, environment variables (checked 22 October 2026): https://nextjs.org/docs/app/guides/environment-variables
- TwitterAPI.io pricing (checked 22 October 2026): https://twitterapi.io/pricing
- Weir docs, APIs and frameworks: https://docs.weirapp.io/mcp-frameworks
- Weir docs, MCP: https://docs.weirapp.io/mcp
- Weir docs, pagination: https://docs.weirapp.io/pagination
- Weir billing: https://docs.weirapp.io/billing
- Weir search_x call, run 22 October 2026 (request a811f32b-3ac8-4fe3-a703-96a4d08aab38)