Give a Vercel AI SDK app 100+ tools with MCP

The AI SDK can load tools from any MCP server. Point it at APIStack and your model gets three tools (search_apis, get_api_details and call_api) that reach every API in the catalog, without you writing a tool definition for each one.

Prefer video? · 1:34

Give your AI agent 100+ tools with one MCP URL

Connect APIStack to Claude Code, Cursor, VS Code or your own agent, with a real agent run.

Set it up

npm install ai @ai-sdk/mcp @ai-sdk/openai

Create a free APIStack account and set your key as APISTACK_API_KEY.

import { createMCPClient } from '@ai-sdk/mcp'
import { generateText, stepCountIs } from 'ai'
import { openai } from '@ai-sdk/openai'

const apistack = await createMCPClient({
  transport: {
    type: 'http',
    url: 'https://apistack.online/api/mcp/connect',
    headers: { 'x-api-key': process.env.APISTACK_API_KEY }
  }
})

try {
  const { text, steps } = await generateText({
    model: openai('gpt-5-mini'),
    tools: await apistack.tools(),
    stopWhen: stepCountIs(6),
    prompt: 'Is jane.doe@gmial.com a valid email address to send a receipt to? Check it with APIStack.'
  })
  console.log(steps.flatMap(s => s.toolCalls.map(c => c.toolName)))
  console.log(text)
} finally {
  await apistack.close()
}

Output from a real run (ai 7.0, @ai-sdk/mcp 2.0, gpt-5-mini):

[ 'search_apis', 'get_api_details', 'call_api' ]
Short answer: No — the validator reports jane.doe@gmial.com is not valid for sending a receipt.
- MX (mail exchanger) records: none found → likely undeliverable
- Typo suggestion: gmail.com (high confidence)
- Risk score: 60 (level: high)
...

Fewer, focused tools

If your app only needs a few APIs, add ?apis=email-address-validator,phone-number-validation (or ?categories=finance) to the URL. You then get one tool per API with its own schema, which is faster for the model than searching.

Streaming and route handlers

The same tools work with streamText in a Next.js route handler. Create the client per request and close it in onFinish, or reuse one client across requests in a long-running server.

Related guides