MCP setupAuthorization Bearer

Connect Vercel AI SDK to LeadMagic

For AI SDK Core, @ai-sdk/mcp, @ai-sdk/openai.

Server-side code sends a LeadMagic OAuth access token. User-facing apps pass an OAuth `authProvider` to createMCPClient and host the callback themselves.

Sign-in: Server-side code sends a LeadMagic OAuth access token. User-facing apps pass an OAuth `authProvider` to createMCPClient and host the callback themselves.

createMCPClient (@ai-sdk/mcp)

Recommended

typescript · manual · Token

Needs a LeadMagic OAuth access token (issued by https://clerk.leadmagic.io, scope mcp_all, valid for one day). LeadMagic API keys are rejected.

import { createMCPClient } from "@ai-sdk/mcp";

const leadmagic = await createMCPClient({
  transport: {
    type: "http",
    url: "https://mcp.leadmagic.io/mcp",
    // Server-side: send a LeadMagic OAuth access token.
    headers: { Authorization: `Bearer ${process.env.LEADMAGIC_OAUTH_TOKEN}` },
    // User-facing apps: pass `authProvider` instead and host the OAuth callback.
  },
});

try {
  const tools = await leadmagic.tools();
  // Pass `tools` into generateText, streamText, or your agent.
} finally {
  await leadmagic.close();
}

openai.tools.mcp (OpenAI Responses provider)

typescript · manual · Token

`authorization` takes the access token. The allowedTools list is an example; /clients?format=json has the full tool list. Needs a LeadMagic OAuth access token (issued by https://clerk.leadmagic.io, scope mcp_all, valid for one day). LeadMagic API keys are rejected.

import { openai } from "@ai-sdk/openai";

const tools = {
  leadmagic: openai.tools.mcp({
    serverLabel: "leadmagic",
    serverUrl: "https://mcp.leadmagic.io/mcp",
    serverDescription:
      "LeadMagic B2B enrichment: email, contacts, account intel, hiring signals, ads, jobs, credits.",
    authorization: process.env.LEADMAGIC_OAUTH_TOKEN,
    allowedTools: ["check_credit_balance", "find_work_email", "enrich_contact", "account_intel"],
  }),
};

Client documentation