Documentation Index
Fetch the complete documentation index at: https://smithery.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
The Vercel AI SDK has built-in support for MCP servers. This guide shows how to use Smithery with the AI SDK to add MCP tools to your AI applications.
Installation
npm install ai @ai-sdk/mcp @ai-sdk/anthropic @smithery/api
Quick Start
Use createConnection from @smithery/api/mcp to get a transport for the AI SDK’s MCP client:
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { createConnection } from '@smithery/api/mcp';
const { transport } = await createConnection({
mcpUrl: 'https://exa.run.tools',
});
const mcpClient = await createMCPClient({ transport });
const tools = await mcpClient.tools();
const { text } = await generateText({
model: anthropic('claude-sonnet-4-20250514'),
tools,
prompt: 'Search for the latest news about MCP.',
});
await mcpClient.close();
Smithery handles OAuth, token refresh, and connection management automatically.
Streaming Responses
Use streamText for streaming responses. Close the client in onFinish:
import { createMCPClient } from '@ai-sdk/mcp';
import { streamText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { createConnection } from '@smithery/api/mcp';
const { transport } = await createConnection({
mcpUrl: 'https://exa.run.tools',
});
const mcpClient = await createMCPClient({ transport });
const tools = await mcpClient.tools();
const result = await streamText({
model: anthropic('claude-sonnet-4-20250514'),
tools,
prompt: 'Search the web for the latest AI news',
onFinish: async () => {
await mcpClient.close();
},
});
Multiple MCP Servers
Connect to multiple servers and aggregate their tools:
import { createMCPClient } from '@ai-sdk/mcp';
import { createConnection } from '@smithery/api/mcp';
const servers = [
'https://exa.run.tools',
'https://gmail.run.tools',
];
const clients = await Promise.all(
servers.map(async (mcpUrl) => {
const { transport } = await createConnection({ mcpUrl });
return createMCPClient({ transport });
})
);
// Aggregate tools from all servers
const allTools = Object.assign({}, ...(await Promise.all(clients.map(c => c.tools()))));
Learn More