New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@ai-sdk/mcp

Package Overview
Dependencies
Maintainers
3
Versions
351
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ai-sdk/mcp

latest
Source
npmnpm
Version
2.0.85
Version published
Weekly downloads
1.3M
-58.58%
Maintainers
3
Weekly downloads
 
Created
Source

AI SDK - Model Context Protocol Client

The Model Context Protocol (MCP) client for the AI SDK lets you connect to MCP servers and use their tools with AI SDK functions like generateText and streamText.

Setup

npm i ai @ai-sdk/mcp

Skill for Coding Agents

If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:

npx skills add vercel/ai

Usage

import { createMCPClient } from '@ai-sdk/mcp';
import { generateText, isStepCount } from 'ai';

const mcpClient = await createMCPClient({
  transport: {
    type: 'http',
    url: 'https://your-server.com/mcp',
    headers: {
      Authorization: `Bearer ${process.env.MCP_API_KEY}`,
    },
  },
});

try {
  const tools = await mcpClient.tools();

  const { text } = await generateText({
    model: 'openai/gpt-6-astra',
    tools,
    stopWhen: isStepCount(10),
    prompt: 'Use the available tools to answer the user question.',
  });

  console.log(text);
} finally {
  await mcpClient.close();
}

See the Model Context Protocol Client documentation for more information.

Keywords

ai

FAQs

Package last updated on 26 Oct 2026

Related posts