Mailgent

Mailgent for the Vercel AI SDK

Add Mailgent tools to the Vercel AI SDK and your agent gets an inbox and identity — define them with tool() and stream tool calls in your Next.js app.

The Vercel AI SDK makes tool-calling agents easy to build in TypeScript. Mailgent fits right in: define each capability with the tool() helper and the model can call it during generation or streaming.

That gives an agent in your Next.js app a real inbox and identity, with calls routed to the Mailgent API using a scoped key.

Define tools with tool()

Each Mailgent action becomes a typed tool with a Zod schema and an execute function that calls the API. The SDK handles the tool-call loop with the model.

Keep the agent's key server-side and pass only the scopes the feature needs.

route.ts
import { tool } from "ai";
import { z } from "zod";

const mailSend = tool({
  description: "Send an email from the agent's inbox",
  parameters: z.object({ to: z.string(), subject: z.string(), text: z.string() }),
  execute: async (a) => fetch("https://api.mailgent.dev/v0/mail/send", {
    method: "POST",
    headers: { Authorization: `Bearer ${process.env.MAILGENT_KEY}` },
    body: JSON.stringify(a),
  }).then((r) => r.text()),
});

Stream with confidence

Because the agent's key is scoped, exposing these tools to a model is safe: it can only act within the permissions you grant, and every action is logged under the agent's identity.

FAQ

Does this work with streaming?

Yes. Tools defined with tool() work in both generateText and streamText flows.

Where does the API key live?

Keep it server-side in your route handler or server action; never ship it to the browser.

Give your agent an inbox.

A real email address, a vault, 2FA, and an identity in one API call.

Get started