feat(mcp): add per-call auth headers and docs#124
feat(mcp): add per-call auth headers and docs#124sergical wants to merge 4 commits intovercel:mainfrom
Conversation
|
@sergical is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
This is amazing. Thinking more about how we could tie MCP into Chat SDK overall — there seem to be two paths here and I'd love your extended thoughts on the tradeoffs. Option 1: MCP-native (this PR)Chat SDK owns the MCP client lifecycle, connection management, multi-server aggregation, per-call auth, etc. Users interact with MCP through Option 2: MCP-via-AI-SDKAI SDK already has MCP support via import { createMCPClient } from '@ai-sdk/mcp';
import { generateText } from 'ai';
const mcpClient = await createMCPClient({
transport: { type: 'sse', url: 'https://jira-mcp.example.com/mcp' },
});
bot.onNewMention(async (thread, message) => {
const result = await generateText({
model: anthropic('claude-sonnet-4-5'),
tools: await mcpClient.tools(),
prompt: message.text,
});
await thread.post(result.text);
});Thinking out loudThe MCP-native approach has clear benefits around lifecycle management, graceful failure, and per-call auth headers — but I'm curious what deeper integrations you envision that would make Chat SDK the right layer to own this vs. letting AI SDK handle it. For example, could Chat SDK auto-expose MCP tools as slash commands, or route tool calls differently per platform? Would love to hear your thoughts on where this could go — it could be very valuable to have MCP deeply integrated at the Chat SDK level if there are platform-aware features that AI SDK alone can't provide. |
|
Great questions @haydenbleasel! You're right that there are two paths — and they're complementary, not competing. When to use which
They compose well togetherA bot can use both in the same app — Deeper integrations (future)Your instinct about platform-aware features is spot on. Some things that could be interesting down the line:
For now I've added a "Using with AI SDK" section to the MCP docs showing the |
Add `mcpServers` to ChatConfig and expose `chat.mcp` with `listTools()`, `callTool()`, and `refresh()` methods. Supports SSE and Streamable HTTP transports with static or dynamic auth headers. Uses dynamic imports so users who don't configure MCP pay zero cost. Failed server connections log warnings and don't block initialization. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add McpCallToolOptions with per-call headers override for per-user/per-tenant auth scenarios. When headers are provided, a temporary client+transport is created for the duration of the call. Also adds MCP feature docs and API reference updates. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
8e96bb1 to
f965808
Compare
Summary
callTool()now accepts an optionaloptions.headersparameter for per-user/per-tenant authentication. When provided, a temporary MCP client+transport is created with the override headers for the duration of the call.mcp.mdxguide covering configuration, tool listing/calling, transport types, three auth patterns (service-level, per-tenant, per-user), multiple servers, and error codes.mcpServersto theChatconstructor table and amcpproperty section.Test plan
pnpm --filter chat test src/mcp.test.ts)pnpm --filter docs dev→/docs/mcp)Prompts
🤖 Generated with Claude Code