Immutable solution version
MCP tools in AI SDK: HTTP transport, client setup, and production rules
Complete solution
Connect Model Context Protocol servers to AI SDK 7 agents: createMCPClient with HTTP transport, tool conversion, and why stdio stays local.
The AI SDK connects to MCP servers for tools, resources, and prompts through @ai-sdk/mcp. Transport choice is the decision that matters.
import { createMCPClient } from '@ai-sdk/mcp';
const mcpClient = await createMCPClient({ transport: { type: 'http', url: 'https://your-server.com/mcp', headers: { Authorization: 'your auth header' }, }, });
const tools = await mcpClient.tools(); // pass tools into streamText / ToolLoopAgent like any other tools
Rules:
- Use HTTP transport (StreamableHTTPClientTransport style) for production. It is the documented recommendation.
- stdio transport is for local development only. It cannot be deployed to production runtimes (no local subprocess on serverless/edge).
- SSE transport exists as an alternative HTTP option. Prefer the plain HTTP transport unless the server only speaks SSE.
- The client handles MCP protocol negotiation, including newer stateless versions with fallback to the legacy initialize handshake. You do not hand-roll the handshake.
- If you use OpenAI's Responses API, there is a built-in openai.tools.mcp option that integrates MCP server-side without converting tools client-side. Check the OpenAI provider docs for it.
- Treat MCP tools like untrusted third-party tools: validate their outputs before rendering or acting on them, and gate destructive ones with toolApproval.
- Close the client when done (mcpClient.close()) in long-lived processes to avoid leaking connections.
Verification: list the tools after connect and confirm names and schemas look right before letting the model call them. A misconfigured transport usually fails here, not at call time.
Evidence
Verified against the live AI SDK docs 2026-09-26. The MCP tools guide documents createMCPClient with HTTP transport as the production recommendation, stdio as local-only, SSE as an alternative, protocol version negotiation, and the OpenAI Responses API built-in MCP tool option.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_1anGTZUizg-nleVAnafOXw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MCP tools in AI SDK: HTTP transport, client setup, and production rules <span>— Vectle</span></a>