The short answer: load the email API's MCP tools with createMCPClient, pass only the ones the job needs, and set a toolApproval policy so a person approves each send. Read-only tools run on their own; a send comes back as a tool-approval-request until someone answers it.
We ran the script below against the SMTPfast MCP server on 28 November 2026, with ai 7.0.184 and @ai-sdk/mcp 2.0.106, using the AI SDK's mock model in place of the OpenAI call. list_domains ran without a question, the run stopped at send_email, and a denied send was not sent. We build SMTPfast; any email API with a Streamable HTTP MCP server works the same way.
For everything SMTPfast offers agents on one page (the MCP server, inboxes, drafts a person approves, REST and SMTP), see email API for AI agents.
What you need
- Node.js 22 or later (the current
aipackages require it) andnpm install ai @ai-sdk/mcp @ai-sdk/openai. - An
OPENAI_API_KEY, or any other provider the AI SDK supports. - An SMTPfast account with a verified sending domain, and an API key with the scopes the agent needs:
email:send,email:readanddomain:readhere. Create it under API keys in the dashboard; the free plan works.
The script
// npm install ai @ai-sdk/mcp @ai-sdk/openai
import readline from "node:readline/promises";
import { generateText, stepCountIs } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";
import { openai } from "@ai-sdk/openai";
const smtpfast = await createMCPClient({
transport: {
type: "http",
url: "https://smtpfa.st/api/mcp",
headers: { Authorization: `Bearer ${process.env.SMTPFAST_API_KEY}` },
},
});
try {
const all = await smtpfast.tools();
// Give the model only the tools this job needs.
const tools = { list_domains: all.list_domains, check_before_send: all.check_before_send, send_email: all.send_email };
// Run tools the server marks read-only; ask a person before anything else.
const toolApproval = ({ toolCall }) =>
toolCall.toolMetadata?.annotations?.readOnlyHint === true ? "not-applicable" : "user-approval";
const messages = [
{ role: "user", content: "Email [email protected] from [email protected] that the nightly backup finished." },
];
const run = () => generateText({ model: openai("gpt-5-mini"), tools, toolApproval, stopWhen: stepCountIs(5), messages });
let result = await run();
let approvals = result.content.filter((part) => part.type === "tool-approval-request");
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
while (approvals.length > 0) {
const answers = [];
for (const request of approvals) {
console.log(request.toolCall.toolName, JSON.stringify(request.toolCall.input));
const yes = (await rl.question("Send it? [y/N] ")).trim().toLowerCase() === "y";
answers.push({ type: "tool-approval-response", approvalId: request.approvalId, approved: yes });
}
messages.push(...result.response.messages, { role: "tool", content: answers });
result = await run();
approvals = result.content.filter((part) => part.type === "tool-approval-request");
}
rl.close();
console.log(result.text);
} finally {
await smtpfast.close();
}
Save it as mailer.mjs and run it:
export SMTPFAST_API_KEY=sf_...
export OPENAI_API_KEY=sk-...
node mailer.mjs
When the model decides to send, you see the full input first:
send_email {"from":"[email protected]","to":"[email protected]","subject":"...","text":"..."}
Send it? [y/N]
How the pieces work
createMCPClientconnects to the hosted server over Streamable HTTP (type: "http"). The key goes in theAuthorizationheader and stays in your process.smtpfast.tools()turns the server's tools into AI SDK tools. The SMTPfast server has 109; this job needs three. Passing a short list costs fewer tokens and leaves the model fewer wrong choices.toolApprovaldecides per call.@ai-sdk/mcpputs the server's annotations ontoolCall.toolMetadata, and SMTPfast marks every tool that sends, deletes or changes something as not read-only. So lookups run, and everything else waits for a person.- The approval round trip: the paused call comes back as a
tool-approval-requestpart. You add the response messages and atoolmessage with onetool-approval-responseper request, then callgenerateTextagain. An approved call runs; a denied one is reported to the model as denied and never reaches the API. stepCountIs(5)lets the model call a tool and then use its result, up to five steps per call. In ai 7 the same function is also exported asisStepCount.
The AI SDK docs describe annotations as untrusted hints from the server. Here they only decide when to ask; the tool list and the API key's scopes are the hard limits.
Make it safer
- Scope the key. The agent can do whatever its key allows. For notifications,
email:sendanddomain:readare enough. A key can never create keys with more access than itself. - Draft instead of send. For replies to people, pass
save_inbox_draftinstead ofsend_email, with a key that hasinbound:readbut noemail:send. The server then refuses any send, and a person sends the draft. See how to build an AI agent that answers support email. - Check before sending.
check_before_sendtests the sender domain, the content and the links. Tell the model to call it first. - Close the client. Call
close()when the job is done. In a route handler withstreamText, close it when the stream ends, as the AI SDK docs show.
Need the whole API?
If the agent needs most of the API, connect to https://smtpfa.st/api/mcp/compact instead. It has two tools, search_api and call_api, in place of the full list (about 650 tokens of tool definitions instead of about 34,000). With an approval policy on call_api, every call asks, reads included. We measured the trade-off in 109 MCP tools vs 2.
Sources
Checked on 28 November 2026:
- AI SDK: MCP tools (client, transports, annotations and
toolApproval), tool calling, and theai7.0.184 and@ai-sdk/mcp2.0.106 type definitions - SMTPfast: MCP server docs, API keys
Frequently asked questions
How do I let a Vercel AI SDK agent send email?
Create an MCP client with createMCPClient from @ai-sdk/mcp, using transport { type: 'http', url: 'https://smtpfa.st/api/mcp', headers: { Authorization: 'Bearer <key>' } }. Call client.tools() and pass the tools you want (for example send_email and list_domains) to generateText or streamText. Close the client when you are done.
How do I make the AI SDK ask before it sends an email?
Pass a toolApproval policy to generateText or streamText. Returning 'user-approval' for a tool makes the call come back as a tool-approval-request part instead of running. Send back a tool message with a tool-approval-response (approvalId and approved true or false) and call generateText again. A denied call never reaches the email API. In ai 7 you can also set needsApproval: true on a single tool.
Can I use the MCP tool annotations to decide what needs approval?
Yes. @ai-sdk/mcp passes the server's annotations on toolCall.toolMetadata. SMTPfast marks lookups as read-only and sends, deletes and changes as not read-only, so a policy that runs only readOnlyHint tools and asks about the rest asks before every send. The AI SDK docs call annotations untrusted hints, so combine them with a tool list you choose and a scoped API key.
Does this work in a Next.js route handler?
Yes. The same client and tools work in a route handler with streamText. Create the MCP client per request, close it when the stream ends, and handle tool-approval-request parts in your UI. Keep the SMTPfast API key on the server; never send it to the browser.
Ready to get started?
Start sending transactional email today. Free to start, no credit card required.
Start freeRelated Posts
How to Build an AI Agent That Answers Support Email (A Person Approves Each Reply)
Put an inbox on your support address, subscribe a webhook to new mail, and let your code ask a model for a reply and save it as a draft in the thread. The agent's API key can read mail and write drafts but cannot send, so a person reviews and sends every reply. This guide has the full Node.js handler (about 70 lines), the keys to create, and the checks that keep an email from steering the agent.
Can ChatGPT Send Email? How to Connect It to an Email API With MCP
Yes, on ChatGPT Business, Enterprise and Edu. You add an email API's MCP server as a custom MCP server in ChatGPT on the web, sign in with OAuth, and ChatGPT can then send email from your own verified domain, asking you to confirm each send. Pro accounts can connect custom MCP servers only for read and fetch actions, so they cannot send this way. Checked on 28 November 2026.