Skip to main content

Gmail

Give agents tools to read, send, and draft email, manage labels, filters, and threads, and update mailbox settings in Gmail through Mastra Connect. Each tool call goes through the Mastra platform, which adds the connection's credential. Your application never stores Gmail credentials.

Connect
Direct link to Connect

Before you start, complete the Connect setup to install @mastra/connect and configure your platform project.

Connect an account
Direct link to Connect an account

Run this command from the directory that contains your .env file:

mastra connect add google-mail

The CLI guides you through Gmail's authorization and waits until the connection is active.

Add tools to an agent
Direct link to Add tools to an agent

Pass tools() to the agent and select the google-mail provider:

src/mastra/agents/google-mail-agent.ts
import { Agent } from '@mastra/core/agent'
import { tools } from '@mastra/connect'

export const googleMailAgent = new Agent({
id: 'google-mail-agent',
name: 'Gmail agent',
instructions:
'You help people read, send, and draft email, manage labels, filters, and threads, and update mailbox settings in Gmail.',
model: 'openai/gpt-6-luna',
tools: tools({ providers: ['google-mail'] }),
})

The agent gets 52 Gmail tools, with keys such as google_mail_batch_delete_messages. See Gmail tools for the full list, and the tools() parameters to restrict tools or require approval before a call runs.

On this page