MewCPMewCP
  • AstheTech
  • Contact Us
  • Documentation
  • MewCP Auth API
Have a question?
  • ✉ Contact us - our dev team will reach out as soon as possible

© 2026 MewCP. All rights reserved.

githubx
Getting Started
Connect AI Apps
Frameworks & SDKs
    Vercel AI SDKGoogle ADKCrewAILangChain PythonLangChain TypeScriptLangGraphOpenAI Agents SDKClaude SDKPython MCP ClientTypeScript MCP Client
Authentication
Auth API Guides
powered by Zudoku
Frameworks & SDKs

How to Connect the Vercel AI SDK to MewCP

The AI SDK's MCP client turns MewCP's tools into AI SDK tools you pass to generateText or streamText. Your agent then reaches every app connected to its toolset through one HTTP connection.


Before you start

  • Node.js 18 or newer and a TypeScript project

  • A toolset and its key. See Choose a toolset

  • Your environment set as in Set your environment:

    TerminalCode
    MEWCP_MCP_URL=https://gateway.mewcp.com/personal/mcp MEWCP_API_KEY=API_KEY

Install

TerminalCode
npm install ai @ai-sdk/mcp

The examples use an AI Gateway model string. Any model provider the AI SDK supports works the same way.


Connect

Code
import { createMCPClient } from "@ai-sdk/mcp"; import { generateText, isStepCount } from "ai"; const mcp = await createMCPClient({ transport: { type: "http", url: process.env.MEWCP_MCP_URL!, headers: { Authorization: `Bearer ${process.env.MEWCP_API_KEY}` }, }, }); try { const tools = await mcp.tools(); const { text } = await generateText({ model: "anthropic/claude-sonnet-5.5", tools, // MewCP takes several tool calls per answer: search, get_schema, call_tool. stopWhen: isStepCount(10), prompt: "What is on my calendar tomorrow?", }); console.log(text); } finally { await mcp.close(); }

Keep stopWhen. Without it, generateText and streamText stop after one step, so the agent finds a tool with search and never runs it.


Serve your users

With a project toolset, add x-mewcp-enduser-id to the transport headers, set to the user the agent is acting for. Create the client per request, so each user's calls carry their own ID:

Code
import { createMCPClient } from "@ai-sdk/mcp"; import { generateText, isStepCount } from "ai"; export async function answerFor(userId: string, prompt: string) { const mcp = await createMCPClient({ transport: { type: "http", url: process.env.MEWCP_MCP_URL!, headers: { Authorization: `Bearer ${process.env.MEWCP_API_KEY}`, "x-mewcp-enduser-id": userId, }, }, }); try { const { text } = await generateText({ model: "anthropic/claude-sonnet-5.5", tools: await mcp.tools(), stopWhen: isStepCount(10), prompt, }); return text; } finally { await mcp.close(); } }

Use the same ID you pass as externalUserId when the user connects their accounts through the MewCP Auth API. If they have not connected the app a tool needs, the tool result carries a link for them to connect it, and the model can pass it on.

Run this on your server, for example in a route handler. The key must never reach the browser.


Check it works

List the tools before handing them to the model:

Code
const tools = await mcp.tools(); console.log(Object.keys(tools)); // [ 'search', 'get_schema', 'list_accounts', 'call_tool' ]

Four tools, not the tools of every app, is expected. See What your agent sees.


In production

  • Close the client. Close it when the response is done: in finally for generateText, or in the onEnd callback for streamText.
  • Leave maxRetries off. The client can retry failed tool calls, but call_tool runs actions such as sending an email, and a retry can repeat them.
  • Approve risky calls. Pass a toolApproval policy to generateText or streamText if a person should confirm before the agent acts.

Troubleshooting

The agent searches for a tool and then stops

stopWhen is missing or too low. Set stopWhen: isStepCount(10) so the model can run search, get_schema and call_tool in one answer.

createMCPClient throws an MCPClientError with status 401 or 403

MewCP rejected the key.

  • Check MEWCP_API_KEY is set where the code runs, and the header reads Bearer followed by the whole key.
  • Check the key matches the toolset in MEWCP_MCP_URL: your API Key for the personal toolset, the project's key for a project toolset.
  • A 403 that says the billing period is not active means your MewCP plan needs renewing in the dashboard.

Calls run against the wrong user's accounts

Each client sends the x-mewcp-enduser-id it was created with. Do not share one client across users: create it inside the request, as in Serve your users.


Last checked against the AI SDK's documentation on 13 October 2026.

Last modified on October 15, 2026
Frameworks & SDKsGoogle ADK
On this page
  • Before you start
  • Install
  • Connect
  • Serve your users
  • Check it works
  • In production
  • Troubleshooting
    • The agent searches for a tool and then stops
    • createMCPClient throws an MCPClientError with status 401 or 403
    • Calls run against the wrong user's accounts
TypeScript
TypeScript
TypeScript